hamster-applet r806 - trunk/hamster



Author: tbaugis
Date: Fri Feb 27 11:34:23 2009
New Revision: 806
URL: http://svn.gnome.org/viewvc/hamster-applet?rev=806&view=rev

Log:
showing category in list views

Modified:
   trunk/hamster/applet.py
   trunk/hamster/stats.py
   trunk/hamster/stuff.py

Modified: trunk/hamster/applet.py
==============================================================================
--- trunk/hamster/applet.py	(original)
+++ trunk/hamster/applet.py	Fri Feb 27 11:34:23 2009
@@ -50,6 +50,8 @@
 
 import idle
 
+import pango
+
 try:
     import pynotify
     PYNOTIFY = True
@@ -127,7 +129,6 @@
                           popup_dir in [gnomeapplet.ORIENT_RIGHT]
 
 
-        import pango
         context = self.label.get_pango_context()
         metrics = context.get_metrics(self.label.style.font_desc,
                                       pango.Context.get_language(context))
@@ -283,7 +284,7 @@
         
         self.treeview.append_column(gtk.TreeViewColumn("Time", gtk.CellRendererText(), text=2))
 
-        nameColumn = stuff.ActivityColumn(name=1, description=5)
+        nameColumn = stuff.ActivityColumn(name=1, description=5, category=6)
         self.treeview.append_column(nameColumn)
 
         
@@ -314,6 +315,7 @@
         activity_cell = gtk.CellRendererText()
         self.activity_list.pack_start(activity_cell, True)
         self.activity_list.add_attribute(activity_cell, 'text', 0)
+
         category_cell = stuff.CategoryCell()  
         self.activity_list.pack_start(category_cell, False)
         self.activity_list.add_attribute(category_cell, 'text', 1)

Modified: trunk/hamster/stats.py
==============================================================================
--- trunk/hamster/stats.py	(original)
+++ trunk/hamster/stats.py	Fri Feb 27 11:34:23 2009
@@ -40,8 +40,8 @@
         self.glade = gtk.glade.XML(os.path.join(SHARED_DATA_DIR, "stats.glade"))
         self.window = self.get_widget('stats_window')
 
-        #id, caption, duration, date (invisible), description
-        self.fact_store = gtk.TreeStore(int, str, str, str, str) 
+        #id, caption, duration, date (invisible), description, category
+        self.fact_store = gtk.TreeStore(int, str, str, str, str, str) 
         self.setup_tree()
         
         graph_frame = self.get_widget("graph_frame")
@@ -146,13 +146,11 @@
             else:
                 activity_name = stuff.escape_pango(cell_text)
                 description = stuff.escape_pango(model.get_value(iter, 4))
-        
-                text = "   %s" % activity_name
-                if description:
-                    text+= """\n             <span style="italic" size="small">%s</span>""" % (description)
-                    
-                cell.set_property('markup', text)
-    
+                category = stuff.escape_pango(model.get_value(iter, 5))
+
+                markup = stuff.format_activity(activity_name, category, description, pad_description = True)            
+                cell.set_property('markup', markup)
+
         def duration_painter(column, cell, model, iter):
             text = model.get_value(iter, 2)
             if model.iter_parent(iter) == None:
@@ -163,6 +161,9 @@
             cell.set_property('markup', text)
     
 
+        self.insensitive_color = gtk.Label().style.fg[gtk.STATE_INSENSITIVE].to_string()
+
+
         self.fact_tree = self.get_widget("facts")
         self.fact_tree.set_headers_visible(False)
         self.fact_tree.set_tooltip_column(1)
@@ -224,7 +225,7 @@
                                                     fact_date,
                                                     "",
                                                     current_date.strftime('%Y-%m-%d'),
-                                                    ""])
+                                                    "", ""])
             by_day[self.start_date + dt.timedelta(i)] = {"duration": 0, "row_pointer": day_row}
 
                 
@@ -243,7 +244,8 @@
                                     fact["name"],
                                     stuff.format_duration(duration),
                                     fact["start_time"].strftime('%Y-%m-%d'),
-                                    fact["description"]
+                                    fact["description"],
+                                    fact["category"]
                                     ])
 
             if duration:

Modified: trunk/hamster/stuff.py
==============================================================================
--- trunk/hamster/stuff.py	(original)
+++ trunk/hamster/stuff.py	Fri Feb 27 11:34:23 2009
@@ -60,24 +60,37 @@
         self.set_property('yalign', 0.0)
 
 
+insensitive_color = gtk.Label().style.fg[gtk.STATE_INSENSITIVE].to_string()
+def format_activity(name, category, description, pad_description = False):
+    "returns pango markup for activity with category and description"
+    text = name    
+    if category:
+        text += """ - <span color="%s" size="x-small">%s</span>""" % (insensitive_color, category)
+
+    if description:
+        text+= "\n"
+        if pad_description:
+            text += "          "
+
+        text += """<span style="italic" size="small">%s</span>""" % description
+        
+    return text
+    
 
 class ActivityColumn(gtk.TreeViewColumn):
     def activity_painter(self, column, cell, model, iter):
         activity_name = model.get_value(iter, self.name)
         description = model.get_value(iter, self.description)
-        text = activity_name
-
-        if description:
-            text+= """\n<span style="italic" size="small">%s</span>""" % (description)
-            
-        cell.set_property('markup', text)
-            
+        category = model.get_value(iter, self.category)
+        
+        markup = format_activity(activity_name, category, description)            
+        cell.set_property('markup', markup)
         return
         
-    def __init__(self, name, description):
+    def __init__(self, name, description, category = None):
         gtk.TreeViewColumn.__init__(self)
         
-        self.name, self.description = name, description
+        self.name, self.description, self.category = name, description, category
         self.set_expand(True)
         cell = gtk.CellRendererText()
         self.pack_start(cell, True)
@@ -150,8 +163,8 @@
     def __init__(self, date = None):
         date = date or dt.date.today()
         
-        # ID, Time, Name, Duration, Date, Description
-        self.fact_store = gtk.ListStore(int, str, str, str, str, str)
+        # ID, Time, Name, Duration, Date, Description, Category
+        self.fact_store = gtk.ListStore(int, str, str, str, str, str, str)
         
         self.facts = storage.get_facts(date)
         
@@ -177,5 +190,6 @@
                                     fact["start_time"].strftime("%H:%M"), 
                                     current_duration,
                                     fact["start_time"].strftime("%Y%m%d"),
-                                    escape_pango(fact["description"])])
+                                    escape_pango(fact["description"]),
+                                    escape_pango(fact["category"])])
 



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