[hamster-applet] happy zoom-in clicking and hovering (bug 623872)
- From: Toms Baugis <tbaugis src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [hamster-applet] happy zoom-in clicking and hovering (bug 623872)
- Date: Tue, 13 Jul 2010 15:09:25 +0000 (UTC)
commit 41ca57cfae47abca7faa769f654efd0023c12d86
Author: Toms Bauģis <toms baugis gmail com>
Date: Tue Jul 13 15:01:29 2010 +0100
happy zoom-in clicking and hovering (bug 623872)
src/hamster/overview.py | 8 +++++-
src/hamster/widgets/timechart.py | 50 +++++++++++++++++++++++++++----------
2 files changed, 43 insertions(+), 15 deletions(-)
---
diff --git a/src/hamster/overview.py b/src/hamster/overview.py
index 4ea0b4c..03ff03f 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("range-picked", self.on_timechart_new_range)
self.timechart.day_start = self.day_start
self.get_widget("by_day_box").add(self.timechart)
@@ -122,6 +123,11 @@ class Overview(object):
self.get_widget("fact_tree_popup").popup( None, None, None, event.button, time)
return True
+ def on_timechart_new_range(self, chart, start_date, end_date):
+ self.start_date = start_date
+ self.end_date = end_date
+ self.search()
+
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
@@ -357,7 +363,7 @@ class Overview(object):
def on_close_activate(self, action):
self.close_window()
-
+
def close_window(self):
# properly saving window state and position
maximized = self.window.get_window().get_state() & gtk.gdk.WINDOW_STATE_MAXIMIZED
diff --git a/src/hamster/widgets/timechart.py b/src/hamster/widgets/timechart.py
index ff8ed2a..c8a00c4 100644
--- a/src/hamster/widgets/timechart.py
+++ b/src/hamster/widgets/timechart.py
@@ -18,7 +18,7 @@
# along with Project Hamster. If not, see <http://www.gnu.org/licenses/>.
import os # for locale
-import gtk, pango
+import gobject, gtk, pango
from .. import graphics, stuff
@@ -43,9 +43,10 @@ class VerticalBar(graphics.Sprite):
self.fill = None
self.key_label = graphics.Label(key.strftime(format), x=2, y=0, size=8, color="#000")
- self.show_label = True
self.add_child(self.key_label)
+ self.show_label = True
+
self.connect("on-render", self.on_render)
def on_render(self, sprite):
@@ -60,6 +61,7 @@ class VerticalBar(graphics.Sprite):
self.graphics.rectangle(0, self.height - min(size, 3), self.width, min(size, 3))
self.graphics.fill(self.fill)
+
if self.show_label and self.key_label not in self.sprites:
self.add_child(self.key_label)
elif self.show_label == False and self.key_label in self.sprites:
@@ -69,6 +71,9 @@ class VerticalBar(graphics.Sprite):
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)),
+ }
def __init__(self):
graphics.Scene.__init__(self)
@@ -78,6 +83,8 @@ class TimeChart(graphics.Scene):
self.day_start = dt.time() # ability to start day at another hour
self.first_weekday = stuff.locale_first_weekday()
+ self.interactive = True
+
self.minor_tick = None
self.tick_totals = []
self.bars = []
@@ -85,16 +92,28 @@ class TimeChart(graphics.Scene):
self.connect("on-enter-frame", self.on_enter_frame)
self.connect("on-mouse-over", self.on_mouse_over)
self.connect("on-mouse-out", self.on_mouse_out)
+ self.connect("on-click", self.on_click)
- def on_mouse_over(self, scene, targets):
- bar = targets[0]
- bar.fill = self.get_style().base[gtk.STATE_PRELIGHT].to_string()
- self.redraw()
+ def on_mouse_over(self, scene, target):
+ if isinstance(target, VerticalBar):
+ bar = target
+ bar.fill = self.get_style().base[gtk.STATE_PRELIGHT].to_string()
+ self.set_tooltip_text(stuff.format_duration(bar.value))
+
+ self.redraw()
+
+ def on_mouse_out(self, scene, target):
+ if isinstance(target, VerticalBar):
+ bar = target
+ bar.fill = self.bar_color
+
+ def on_click(self, scene, event, target):
+ if 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())
- def on_mouse_out(self, scene, targets):
- bar = targets[0]
- bar.fill = self.bar_color
def draw(self, durations, start_date, end_date):
self.durations = durations
@@ -226,13 +245,13 @@ class TimeChart(graphics.Scene):
if not bar.fill:
bar.fill = self.bar_color
+ bar.key_label.interactive = (self.end_time - self.start_time) > dt.timedelta(10) and self.minor_tick == DAY
+
if (self.end_time - self.start_time) > dt.timedelta(10) \
and self.minor_tick == DAY and first_weekday(bar.key) == False:
- if bar.show_label:
- bar.show_label = False
+ bar.show_label = False
else:
- if bar.show_label == False:
- bar.show_label = True
+ bar.show_label = True
@@ -360,7 +379,10 @@ class TimeChart(graphics.Scene):
self.sprites.remove(bar)
self.bars = []
- for key, value, normalized in zip(fractions, hours, normalized_hours):
+ 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
+
self.add_child(bar)
self.bars.append(bar)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]