[hamster-applet] knits
- From: Toms Baugis <tbaugis src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [hamster-applet] knits
- Date: Sat, 10 Apr 2010 19:21:25 +0000 (UTC)
commit 2d2a70b53acdd1d64700b88ed6433f49a8fe5bc0
Author: Toms Bauģis <toms baugis gmail com>
Date: Sat Apr 10 20:13:34 2010 +0100
knits
src/hamster/edit_activity.py | 4 ++-
src/hamster/widgets/dayline.py | 54 +++++++++++++++++++++++++--------------
2 files changed, 37 insertions(+), 21 deletions(-)
---
diff --git a/src/hamster/edit_activity.py b/src/hamster/edit_activity.py
index 8235768..6246400 100644
--- a/src/hamster/edit_activity.py
+++ b/src/hamster/edit_activity.py
@@ -131,10 +131,12 @@ class CustomFactController:
self.end_time.set_time(end_time)
self.set_end_date_label(end_time)
+ self.draw_preview(start_time.date(), [start_time, end_time])
+
def draw_preview(self, date, highlight = None):
day_facts = runtime.storage.get_facts(date)
- self.dayline.add_facts(day_facts, highlight)
+ self.dayline.set_facts(day_facts, highlight)
def get_widget(self, name):
""" skip one variable (huh) """
diff --git a/src/hamster/widgets/dayline.py b/src/hamster/widgets/dayline.py
index 5a6445b..1fe2e9e 100644
--- a/src/hamster/widgets/dayline.py
+++ b/src/hamster/widgets/dayline.py
@@ -114,9 +114,12 @@ class DayLine(graphics.Scene):
self.drag_start = None
self.current_x = None
+ self.snap_points = []
- def add_facts(self, facts, highlight):
+ def set_facts(self, facts, highlight):
+ self.remove_child(*self.fact_bars)
+ self.fact_bars = []
for fact in facts:
fact_bar = graphics.Rectangle(0, 0, fill = "#aaa", stroke="#aaa") # dimensions will depend on screen situation
fact_bar.fact = fact
@@ -136,37 +139,46 @@ class DayLine(graphics.Scene):
if highlight:
self.chosen_selection.start_time = highlight[0]
self.chosen_selection.end_time = highlight[1]
+ self.chosen_selection.width = None
self.chosen_selection.fixed = True
+ self.chosen_selection.visible = True
self.redraw()
def on_mouse_down(self, scene, event):
self.drag_start = self.current_x
- if self.chosen_selection in self.sprites:
- self.sprites.remove(self.chosen_selection)
+ self.chosen_selection.visible = False
def on_mouse_up(self, scene):
if self.drag_start:
self.drag_start = None
- self.choose()
+
+ start_time = self.selection.start_time
+ end_time = self.selection.end_time
+ self.new_selection()
+ self.emit("on-time-chosen", start_time, end_time)
def on_click(self, scene, event, targets):
self.drag_start = None
- self.emit("on-time-chosen", self.chosen_selection.start_time, None)
- self.choose()
+ start_time = self.selection.start_time
+ end_time = None
+ if self.fact_bars:
+ times = [bar.fact['start_time'] for bar in self.fact_bars if bar.fact['start_time'] - start_time > dt.timedelta(minutes=1)]
+ times.extend([bar.fact['end_time'] for bar in self.fact_bars if bar.fact['end_time'] - start_time > dt.timedelta(minutes=1)])
+ if times:
+ end_time = min(times)
- def choose(self):
- self.sprites.remove(self.selection)
+ self.new_selection()
- self.chosen_selection = self.selection
- self.chosen_selection.fixed = True
+ self.emit("on-time-chosen", start_time, end_time)
- self.selection = Selection()
- self.add_child(self.selection, self.chosen_selection)
- self.emit("on-time-chosen", self.chosen_selection.start_time, self.chosen_selection.end_time)
+ def new_selection(self):
+ self.sprites.remove(self.selection)
+ self.selection = Selection()
+ self.add_child(self.selection)
self.redraw()
def on_mouse_move(self, scene, event):
@@ -212,6 +224,8 @@ class DayLine(graphics.Scene):
snap_points.append(bar.x)
snap_points.append(bar.x + bar.width)
+ self.snap_points = snap_points
+
if self.view_time < dt.datetime.now() < self.view_time + dt.timedelta(hours = 24):
minutes = round((dt.datetime.now() - self.view_time).seconds / 60 / minute_pixel) + 0.5
@@ -243,15 +257,15 @@ class DayLine(graphics.Scene):
start_x = max(min(self.mouse_x, self.width-1), 0) #mouse, but within screen regions
# check for snap points
- delta, closest_snap = min((abs(start_x - i), i) for i in snap_points)
+ start_x = start_x + 0.5
+ minutes = int(round(start_x * minute_pixel / 15)) * 15
+ if snap_points:
+ delta, closest_snap = min((abs(start_x - i), i) for i in snap_points)
- if abs(closest_snap - start_x) < 5 and (not self.drag_start or self.drag_start != closest_snap):
- start_x = closest_snap
- minutes = int(start_x * minute_pixel)
- else:
- start_x = start_x + 0.5
- minutes = int(round(start_x * minute_pixel / 15)) * 15
+ if abs(closest_snap - start_x) < 5 and (not self.drag_start or self.drag_start != closest_snap):
+ start_x = closest_snap
+ minutes = int(start_x * minute_pixel)
self.current_x = minutes / minute_pixel
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]