[hamster-applet] now it is possible to zoom out too



commit d3eb2ffaea288b540a96cf2d162774f6b81277bc
Author: Toms Bauģis <toms baugis gmail com>
Date:   Tue Jul 13 16:08:40 2010 +0100

    now it is possible to zoom out too

 src/hamster/overview.py          |   15 +++++++++++++
 src/hamster/widgets/timechart.py |   41 +++++++++++++++++++++++++++++++++++--
 2 files changed, 53 insertions(+), 3 deletions(-)
---
diff --git a/src/hamster/overview.py b/src/hamster/overview.py
index 03ff03f..6929ea1 100644
--- a/src/hamster/overview.py
+++ b/src/hamster/overview.py
@@ -84,6 +84,7 @@ class Overview(object):
         self.current_range = "week"
 
         self.timechart = widgets.TimeChart()
+        self.timechart.connect("zoom-out-clicked", self.on_timechart_zoom_out_clicked)
         self.timechart.connect("range-picked", self.on_timechart_new_range)
         self.timechart.day_start = self.day_start
 
@@ -128,6 +129,20 @@ class Overview(object):
         self.end_date = end_date
         self.search()
 
+    def on_timechart_zoom_out_clicked(self, chart):
+        if (self.end_date - self.start_date < dt.timedelta(days=6)):
+            self.on_week_activate(None)
+        elif (self.end_date - self.start_date < dt.timedelta(days=27)):
+            self.on_month_activate(None)
+        else:
+            self.current_range = "manual"
+            self.start_date = self.view_date.replace(day=1, month=1)
+            self.end_date = self.start_date.replace(year = self.start_date.year + 1) - dt.timedelta(days=1)
+            self.apply_range_select()
+
+
+
+
     def search(self):
         if self.start_date > self.end_date: # make sure the end is always after beginning
             self.start_date, self.end_date = self.end_date, self.start_date
diff --git a/src/hamster/widgets/timechart.py b/src/hamster/widgets/timechart.py
index c8a00c4..98642b1 100644
--- a/src/hamster/widgets/timechart.py
+++ b/src/hamster/widgets/timechart.py
@@ -67,12 +67,25 @@ class VerticalBar(graphics.Sprite):
         elif self.show_label == False and self.key_label in self.sprites:
             self.sprites.remove(self.key_label)
 
+class Icon(graphics.Sprite):
+    def __init__(self, pixbuf, **kwargs):
+        graphics.Sprite.__init__(self, **kwargs)
+        self.pixbuf = pixbuf
+        self.interactive = True
+        self.connect("on-render", self.on_render)
+
+    def on_render(self, sprite):
+        self.graphics.set_source_pixbuf(self.pixbuf, 0, 0)
+        self.graphics.paint()
+        self.graphics.rectangle(0,0,24,24) #transparent rectangle
+        self.graphics.stroke("#000", 0)
 
 
 class TimeChart(graphics.Scene):
     """this widget is kind of half finished"""
     __gsignals__ = {
-        'range-picked': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (gobject.TYPE_PYOBJECT, gobject.TYPE_PYOBJECT)),
+        'range-picked':     (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (gobject.TYPE_PYOBJECT, gobject.TYPE_PYOBJECT)),
+        'zoom-out-clicked': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, ()),
     }
 
     def __init__(self):
@@ -94,6 +107,21 @@ class TimeChart(graphics.Scene):
         self.connect("on-mouse-out", self.on_mouse_out)
         self.connect("on-click", self.on_click)
 
+        self.connect("enter_notify_event", self.on_mouse_enter)
+        self.connect("leave_notify_event", self.on_mouse_leave)
+
+        self.zoom_out_icon = Icon(self.render_icon(gtk.STOCK_ZOOM_OUT, 16), visible = False, z_order = 500)
+        self.add_child(self.zoom_out_icon)
+
+
+    def on_mouse_enter(self, scene, event):
+        if (self.end_time - self.start_time) < dt.timedelta(days=356):
+            self.zoom_out_icon.visible = True
+        self.redraw()
+
+    def on_mouse_leave(self, scene, event):
+        self.zoom_out_icon.visible = False
+        self.redraw()
 
     def on_mouse_over(self, scene, target):
         if isinstance(target, VerticalBar):
@@ -109,7 +137,9 @@ class TimeChart(graphics.Scene):
             bar.fill = self.bar_color
 
     def on_click(self, scene, event, target):
-        if isinstance(target, VerticalBar):
+        if target == self.zoom_out_icon:
+            self.emit("zoom-out-clicked")
+        elif isinstance(target, VerticalBar):
             self.emit("range-picked", target.key.date(), (target.key + self.minor_tick - dt.timedelta(days=1)).date())
         else:
             self.emit("range-picked", target.parent.key.date(), (target.parent.key + dt.timedelta(days=6)).date())
@@ -176,6 +206,9 @@ class TimeChart(graphics.Scene):
 
         self.count_hours()
 
+
+        self.zoom_out_icon.visible = (self.end_time - self.start_time) < dt.timedelta(days=356)
+
         self.redraw()
 
     def on_enter_frame(self, scene, context):
@@ -291,6 +324,8 @@ class TimeChart(graphics.Scene):
             current_time += major_step
 
 
+        self.zoom_out_icon.x = self.width - 24
+
 
     def count_hours(self):
         # go through facts and make array of time used by our fraction
@@ -382,7 +417,7 @@ class TimeChart(graphics.Scene):
         for i, (key, value, normalized) in enumerate(zip(fractions, hours, normalized_hours)):
             bar = VerticalBar(key, step_format, value, normalized)
             bar.z_order = len(fractions) - i
-            bar.interactive = self.minor_tick in (DAY, WEEK) and bar.value > 0
+            bar.interactive = self.minor_tick >= DAY and bar.value > 0
 
             self.add_child(bar)
             self.bars.append(bar)



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]