[hamster-applet] fixed bug 617768 - dealing with sentence style activities (well, in a way)
- From: Toms Baugis <tbaugis src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [hamster-applet] fixed bug 617768 - dealing with sentence style activities (well, in a way)
- Date: Thu, 6 May 2010 13:41:08 +0000 (UTC)
commit a4d5d20dad4fac8382f8110e7fa40151a20a0b42
Author: Toms Bauģis <toms baugis gmail com>
Date: Thu May 6 14:40:59 2010 +0100
fixed bug 617768 - dealing with sentence style activities (well, in a way)
data/applet.ui | 22 +--------
data/hamster.ui | 23 +---------
src/hamster-standalone | 9 +---
src/hamster/applet.py | 8 +--
src/hamster/widgets/facttree.py | 94 ++++++++++++++++++++++++++++++++++-----
5 files changed, 92 insertions(+), 64 deletions(-)
---
diff --git a/data/applet.ui b/data/applet.ui
index 446fbb8..896ca79 100644
--- a/data/applet.ui
+++ b/data/applet.ui
@@ -29,12 +29,10 @@
<property name="visible">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="border_width">12</property>
- <property name="orientation">vertical</property>
<property name="spacing">6</property>
<child>
<object class="GtkVBox" id="vbox2">
<property name="visible">True</property>
- <property name="orientation">vertical</property>
<child>
<object class="GtkHBox" id="current_activity_box">
<property name="visible">True</property>
@@ -42,7 +40,6 @@
<object class="GtkVBox" id="vbox6">
<property name="width_request">520</property>
<property name="visible">True</property>
- <property name="orientation">vertical</property>
<child>
<object class="GtkHBox" id="hbox1">
<property name="visible">True</property>
@@ -52,6 +49,7 @@
<property name="visible">True</property>
<property name="xalign">0</property>
<property name="label">Just an activity</property>
+ <property name="wrap">True</property>
<attributes>
<attribute name="weight" value="bold"/>
<attribute name="size" value="15000"/>
@@ -63,21 +61,6 @@
</packing>
</child>
<child>
- <object class="GtkLabel" id="last_activity_category">
- <property name="visible">True</property>
- <property name="xalign">0</property>
- <property name="label"> - Work</property>
- <attributes>
- <attribute name="weight" value="bold"/>
- <attribute name="size" value="15000"/>
- </attributes>
- </object>
- <packing>
- <property name="expand">False</property>
- <property name="position">1</property>
- </packing>
- </child>
- <child>
<object class="GtkAlignment" id="tag_box">
<property name="visible">True</property>
<property name="left_padding">4</property>
@@ -87,7 +70,7 @@
</child>
</object>
<packing>
- <property name="position">2</property>
+ <property name="position">1</property>
</packing>
</child>
</object>
@@ -102,7 +85,6 @@
<child>
<object class="GtkVBox" id="activity_info_box">
<property name="visible">True</property>
- <property name="orientation">vertical</property>
<child>
<object class="GtkLabel" id="last_activity_duration">
<property name="visible">True</property>
diff --git a/data/hamster.ui b/data/hamster.ui
index 8600346..de5de72 100644
--- a/data/hamster.ui
+++ b/data/hamster.ui
@@ -10,7 +10,6 @@
<child>
<object class="GtkVBox" id="vbox1">
<property name="visible">True</property>
- <property name="orientation">vertical</property>
<child>
<object class="GtkMenuBar" id="menu">
<property name="visible">True</property>
@@ -138,7 +137,6 @@
<property name="visible">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="border_width">12</property>
- <property name="orientation">vertical</property>
<property name="spacing">20</property>
<child>
<object class="GtkHBox" id="current_activity_box">
@@ -147,7 +145,6 @@
<object class="GtkVBox" id="vbox6">
<property name="width_request">520</property>
<property name="visible">True</property>
- <property name="orientation">vertical</property>
<child>
<object class="GtkHBox" id="hbox1">
<property name="visible">True</property>
@@ -157,6 +154,7 @@
<property name="visible">True</property>
<property name="xalign">0</property>
<property name="label">Just an activity</property>
+ <property name="wrap">True</property>
<attributes>
<attribute name="weight" value="bold"/>
<attribute name="size" value="15000"/>
@@ -168,22 +166,6 @@
</packing>
</child>
<child>
- <object class="GtkLabel" id="last_activity_category">
- <property name="visible">True</property>
- <property name="no_show_all">True</property>
- <property name="xalign">0</property>
- <property name="label"> - Work</property>
- <attributes>
- <attribute name="weight" value="bold"/>
- <attribute name="size" value="15000"/>
- </attributes>
- </object>
- <packing>
- <property name="expand">False</property>
- <property name="position">1</property>
- </packing>
- </child>
- <child>
<object class="GtkAlignment" id="tag_box">
<property name="visible">True</property>
<property name="left_padding">4</property>
@@ -193,7 +175,7 @@
</child>
</object>
<packing>
- <property name="position">2</property>
+ <property name="position">1</property>
</packing>
</child>
</object>
@@ -209,7 +191,6 @@
<object class="GtkVBox" id="activity_info_box">
<property name="visible">True</property>
<property name="no_show_all">True</property>
- <property name="orientation">vertical</property>
<child>
<object class="GtkLabel" id="last_activity_duration">
<property name="visible">True</property>
diff --git a/src/hamster-standalone b/src/hamster-standalone
index 0c003da..d626804 100755
--- a/src/hamster-standalone
+++ b/src/hamster-standalone
@@ -240,12 +240,10 @@ class ProjectHamster(object):
delta = dt.datetime.now() - activity['start_time']
duration = delta.seconds / 60
- self.get_widget("last_activity_name").set_text(activity['name'])
if activity['category'] != _("Unsorted"):
- self.get_widget("last_activity_category") \
- .set_text(" - %s" % activity['category'])
- self.get_widget("last_activity_category").show()
-
+ self.get_widget("last_activity_name").set_text("%s - %s" % (activity['name'], activity['category']))
+ else:
+ self.get_widget("last_activity_name").set_text(activity['name'])
self._gui.get_object("more_info_button").hide()
@@ -259,7 +257,6 @@ class ProjectHamster(object):
self.get_widget("start_tracking").show()
self.get_widget("last_activity_name").set_text(_("No activity"))
- self.get_widget("last_activity_category").hide()
self.get_widget("activity_info_box").hide()
self._gui.get_object("more_info_button").show()
diff --git a/src/hamster/applet.py b/src/hamster/applet.py
index 6e5794b..71e22bb 100755
--- a/src/hamster/applet.py
+++ b/src/hamster/applet.py
@@ -403,11 +403,10 @@ class HamsterApplet(object):
delta = dt.datetime.now() - activity['start_time']
duration = delta.seconds / 60
- self.get_widget("last_activity_name").set_text(activity['name'])
if activity['category'] != _("Unsorted"):
- self.get_widget("last_activity_category") \
- .set_text(" - %s" % activity['category'])
- self.get_widget("last_activity_category").show()
+ self.get_widget("last_activity_name").set_text("%s - %s" % (activity['name'], activity['category']))
+ else:
+ self.get_widget("last_activity_name").set_text(activity['name'])
self._gui.get_object("more_info_button").hide()
@@ -422,7 +421,6 @@ class HamsterApplet(object):
self.get_widget("start_tracking").show()
self.get_widget("last_activity_name").set_text(_("No activity"))
- self.get_widget("last_activity_category").hide()
self.get_widget("activity_info_box").hide()
self._gui.get_object("more_info_button").show()
diff --git a/src/hamster/widgets/facttree.py b/src/hamster/widgets/facttree.py
index a7e3f2b..2780c18 100644
--- a/src/hamster/widgets/facttree.py
+++ b/src/hamster/widgets/facttree.py
@@ -80,6 +80,7 @@ class FactTree(gtk.TreeView):
self.connect("button-release-event", self._on_button_release_event)
self.connect("key-release-event", self._on_key_released)
self.connect("configure-event", lambda *args: self.columns_autosize())
+ self.connect("motion-notify-event", self._on_motion)
self.show()
@@ -278,6 +279,28 @@ class FactTree(gtk.TreeView):
return False
+ def _on_motion(self, view, event):
+ 'As the pointer moves across the view, show a tooltip.'
+
+ path = view.get_path_at_pos(int(event.x), int(event.y))
+
+ if path:
+ path, col, x, y = path
+
+ model = self.get_model()
+ data = model[path][0]
+
+ self.set_tooltip_text(None)
+ if data and "id" in data:
+ renderer = view.get_column(0).get_cell_renderers()[0]
+
+ label, x, y, w = renderer.labels[data["id"]]["activity"]
+ if w != -1:
+ self.set_tooltip_text(label)
+
+ self.trigger_tooltip_query()
+
+
class FactCellRenderer(gtk.GenericCellRenderer):
""" We need all kinds of wrapping and spanning and the treeview just does
@@ -367,7 +390,10 @@ class FactCellRenderer(gtk.GenericCellRenderer):
self.set_color(context, text_color)
+ self.layout.set_width(-1)
+
self.layout.set_markup("<b>%s</b>" % stuff.escape_pango(parent["label"]))
+
if self.data["first"]:
y = 5
else:
@@ -391,17 +417,21 @@ class FactCellRenderer(gtk.GenericCellRenderer):
text_color = self.selected_color
selected = True
- def show_label(label, x, y, w):
+ def show_label(label_info):
+ label, x, y, w = label_info
self.layout.set_markup(label)
context.move_to(x, y)
if w:
self.layout.set_width(w)
+ else:
+ self.layout.set_width(-1)
+
context.show_layout(self.layout)
self.set_color(context, text_color)
labels = self.labels[fact["id"]]
- show_label(*labels["interval"])
+ show_label(labels["interval"])
# for the right-aligned delta with have reserved space for scrollbar
# but about it's existance we find only on expose, so we realign
@@ -410,13 +440,21 @@ class FactCellRenderer(gtk.GenericCellRenderer):
context.move_to(width - w, labels["delta"][2])
context.show_layout(self.layout)
- show_label(*labels["activity"])
+
+ label, label_x, label_y, label_w = labels["activity"]
+ self.layout.set_markup(label)
+ self.layout.set_ellipsize(pango.ELLIPSIZE_END)
+ context.move_to(label_x, label_y)
+ self.layout.set_width(label_w)
+ context.show_layout(self.layout)
+ self.layout.set_ellipsize(pango.ELLIPSIZE_NONE)
+
if fact["category"]:
if not selected:
self.set_color(context, widget.get_style().text[gtk.STATE_INSENSITIVE])
- show_label(*labels["category"])
+ show_label(labels["category"])
if fact["tags"]:
@@ -440,7 +478,7 @@ class FactCellRenderer(gtk.GenericCellRenderer):
if fact["description"]:
self.set_color(context, text_color)
- show_label(*labels["description"])
+ show_label(labels["description"])
@@ -486,26 +524,58 @@ class FactCellRenderer(gtk.GenericCellRenderer):
# both sides, in letter length
cell_start = widget.longest_interval
+
cell_width = cell_width - widget.longest_interval - widget.longest_duration
layout.set_markup(stuff.escape_pango(fact["name"]))
- label_w, label_h = layout.get_pixel_size()
+ label_w, activity_label_height = layout.get_pixel_size()
+
+
+ category_label = " - <small>%s</small>" % stuff.escape_pango(fact["category"])
+ layout.set_markup(category_label)
+ category_width, label_h = layout.get_pixel_size()
+
+
+ activity_width = cell_width - category_width - 12
+
+ if label_w > activity_width:
+ activity_width = min(activity_width, label_w)
+ labels["activity"] = (stuff.escape_pango(fact["name"]),
+ cell_start,
+ 2,
+ activity_width * pango.SCALE)
+ else:
+ activity_width = label_w
+ labels["activity"] = (stuff.escape_pango(fact["name"]),
+ cell_start,
+ 2,
+ -1)
+
- labels["activity"] = (stuff.escape_pango(fact["name"]), cell_start, 2, -1)
- labels["category"] = (" - <small>%s</small>" % stuff.escape_pango(fact["category"]),
- cell_start + label_w, 2, -1)
+ labels["category"] = (category_label, cell_start + activity_width, 2, category_width * pango.SCALE)
- tag_cell_start = cell_start + widget.longest_activity_category
+
+ tag_cell_start = cell_start + activity_width + category_width + 12
tag_cell_end = cell_start + cell_width
+ tag_cell_top = 2
cell_height = label_h + 4
- cur_x, cur_y = tag_cell_start, 2
+ cur_x, cur_y = tag_cell_start, tag_cell_top
if fact["tags"]:
layout.set_font_description(self.tag_font)
+ # if we don't fit, jump to the next line
+ temp_tag = Tag(fact["tags"][0])
+ tag_w, tag_h = temp_tag.width, temp_tag.height
+ if tag_cell_start + tag_w >= tag_cell_end:
+ tag_cell_start = cell_start
+ tag_cell_top += activity_label_height + 4
+ cur_y = tag_cell_top
+
+
for i, tag in enumerate(fact["tags"]):
temp_tag = Tag(tag)
tag_w, tag_h = temp_tag.width, temp_tag.height
@@ -517,7 +587,7 @@ class FactCellRenderer(gtk.GenericCellRenderer):
cell_height = max(cell_height, cur_y + tag_h + 4)
- labels["tags"] = (None, tag_cell_start, 2, tag_cell_end)
+ labels["tags"] = (None, tag_cell_start, tag_cell_top, tag_cell_end)
layout.set_font_description(self.label_font)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]