hamster-applet r634 - trunk/hamster



Author: tbaugis
Date: Fri Nov 21 17:52:14 2008
New Revision: 634
URL: http://svn.gnome.org/viewvc/hamster-applet?rev=634&view=rev

Log:
adding description field and showing it everywhere.
a description can be added by typing comma (",") after activity name
and then entering description.
the full syntax now is: "activity category, some description"
editing coming soon

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

Modified: trunk/hamster/applet.py
==============================================================================
--- trunk/hamster/applet.py	(original)
+++ trunk/hamster/applet.py	Fri Nov 21 17:52:14 2008
@@ -167,6 +167,19 @@
 
 
 class HamsterApplet(object):
+    def name_painter(self, column, cell, model, iter):
+        activity_name = model.get_value(iter, 1)
+        description = model.get_value(iter, 5)
+
+        text = """%s""" % activity_name
+        if description:
+            text+= """\n<span style="italic" size="small">%s</span>""" % (description)
+            
+        cell.set_property('markup', text)
+            
+        return
+
+
     def __init__(self, applet):
         self.config = GconfStore.get_instance()
         
@@ -190,8 +203,15 @@
         self.treeview.set_tooltip_column(1)
         
         self.treeview.append_column(gtk.TreeViewColumn("Time", gtk.CellRendererText(), text=2))
-        self.treeview.append_column(ExpanderColumn("Name", text = 1))
-        self.treeview.append_column(gtk.TreeViewColumn("", gtk.CellRendererText(), text=3))
+
+        nameColumn = gtk.TreeViewColumn(_("Name"))
+        nameColumn.set_expand(True)
+        nameCell = gtk.CellRendererText()
+        nameColumn.pack_start(nameCell, True)
+        nameCell.set_property("ellipsize", pango.ELLIPSIZE_END)
+        nameColumn.set_cell_data_func(nameCell, self.name_painter)
+        self.treeview.append_column(nameColumn)
+
         
         edit_cell = gtk.CellRendererPixbuf()
         edit_cell.set_property("stock_id", "gtk-edit")

Modified: trunk/hamster/db.py
==============================================================================
--- trunk/hamster/db.py	(original)
+++ trunk/hamster/db.py	Fri Nov 21 17:52:14 2008
@@ -172,6 +172,7 @@
         query = """SELECT a.id AS id,
                           a.start_time AS start_time,
                           a.end_time AS end_time,
+                          a.description as description,
                           b.name AS name, b.id as activity_id
                      FROM facts a
                 LEFT JOIN activities b ON a.activity_id = b.id
@@ -184,6 +185,7 @@
                    SELECT a.id AS id,
                           a.start_time AS start_time,
                           a.end_time AS end_time,
+                          a.description as description,
                           b.name AS name, b.id as activity_id
                      FROM facts a
                 LEFT JOIN activities b ON a.activity_id = b.id
@@ -208,17 +210,26 @@
     def __add_fact(self, activity_name, start_time = None, end_time = None):
         start_time = start_time or datetime.datetime.now()
         
-        # try to lookup activity by it's name in db. active ones have priority
+        #see if we have description of activity somewhere here (delimited by comma)
+        description = None
+        if activity_name.find(",") > 0:
+            activity_name, description = activity_name.split(",", 1)
+        
+        description = description.strip()
+        
+        # now check if maybe there is also a category
         category_id = None
         if activity_name.find("@") > 0:
             #at symbol marks category
-            activity_name, category_name = activity_name.split("@")
+            activity_name, category_name = activity_name.split("@", 1)
             
             if category_name:
+                category_name = category_name.strip()
                 category_id = self.__get_category_by_name(category_name)
                 if not category_id:
                     category_id = self.__add_category(category_name)
         
+        # try to find activity
         activity_id = self.__get_activity_by_name(activity_name, category_id)
 
         if not activity_id:
@@ -293,19 +304,11 @@
 
 
         # finally add the new entry
-        if end_time:
-            insert = """
-                        INSERT INTO facts (activity_id, start_time, end_time)
-                                   VALUES (?, ?, ?)
-            """
-            self.execute(insert, (activity_id, start_time, end_time))
-        else:
-            insert = """
-                        INSERT INTO facts (activity_id, start_time)
-                                   VALUES (?, ?)
-            """
-            self.execute(insert, (activity_id, start_time))
-
+        insert = """
+                    INSERT INTO facts (activity_id, start_time, end_time, description)
+                               VALUES (?, ?, ?, ?)
+        """
+        self.execute(insert, (activity_id, start_time, end_time, description))
 
         fact_id = self.fetchone("select max(id) as max_id from facts")['max_id']
         
@@ -317,6 +320,7 @@
                    SELECT a.id AS id,
                           a.start_time AS start_time,
                           a.end_time AS end_time,
+                          a.description as description,
                           b.name AS name, b.id as activity_id,
                           coalesce(c.name, ?) as category, c.id as category_id
                      FROM facts a
@@ -670,10 +674,12 @@
 
             self.execute("DROP TABLE activities")
             self.execute("ALTER TABLE activities_new RENAME TO activities")
-            
+        
+        if version < 5:
+            self.execute("ALTER TABLE facts add column description varchar2")
 
         #lock down current version
-        self.execute("UPDATE version SET version = 4")
+        self.execute("UPDATE version SET version = 5")
         
         
         """we start with an empty database and then populate with default

Modified: trunk/hamster/reports.py
==============================================================================
--- trunk/hamster/reports.py	(original)
+++ trunk/hamster/reports.py	Fri Nov 21 17:52:14 2008
@@ -106,6 +106,7 @@
             <th>Start</th>
             <th>End</th>
             <th>Duration</th>
+            <th class="largeCell">Description</th>
         </tr>""")
     
     #get id of last activity so we know when to show current duration
@@ -130,6 +131,9 @@
         category = ""
         if fact["category"] != _("Unsorted"): #do not print "unsorted" in list
             category = fact["category"]
+
+        description = fact["description"] or ""            
+            
         # fact date column in HTML report
         report.write("""<tr class="row%s">
                             <td class="smallCell">%s</td>
@@ -138,13 +142,15 @@
                             <td class="smallCell">%s</td>
                             <td class="smallCell">%s</td>
                             <td class="smallCell">%s</td>
+                            <td class="largeCell">%s</td>
                         </tr>
                        """ % (rowcount, _("%(report_b)s %(report_d)s, %(report_Y)s") % stuff.dateDict(fact["start_time"], "report_"),
             fact["name"],
             category, 
             fact["start_time"].strftime('%H:%M'),
             end_time_str,
-            stuff.format_duration(duration) or ""))
+            stuff.format_duration(duration) or "",
+            description))
             
         if rowcount == 1:
             rowcount = 2

Modified: trunk/hamster/stats.py
==============================================================================
--- trunk/hamster/stats.py	(original)
+++ trunk/hamster/stats.py	Fri Nov 21 17:52:14 2008
@@ -54,7 +54,7 @@
 
         self.fact_tree.append_column(gtk.TreeViewColumn("", gtk.CellRendererText(), text=2))
         
-        self.fact_store = gtk.TreeStore(int, str, str, str) #id, caption, duration, date (invisible)
+        self.fact_store = gtk.TreeStore(int, str, str, str, str) #id, caption, duration, date (invisible), description
         self.fact_tree.set_model(self.fact_store)
         
         x_offset = 80 # let's nicely align all graphs
@@ -149,8 +149,16 @@
             cell.set_property('markup', text)
 
         else:
-            cell.set_property('text', "   " + cell_text)
-            
+            activity_name = cell_text
+            description = 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)
+
+
         return
 
     def get_facts(self):
@@ -174,7 +182,8 @@
             day_row = self.fact_store.append(None, [-1,
                                                     fact_date,
                                                     "",
-                                                    current_date.strftime('%Y-%m-%d')])
+                                                    current_date.strftime('%Y-%m-%d'),
+                                                    ""])
             by_day[self.start_date + dt.timedelta(i)] = {"duration": 0, "row_pointer": day_row}
 
         for fact in facts:
@@ -193,7 +202,8 @@
                                     fact["start_time"].strftime('%H:%M') + " " +
                                     fact["name"],
                                     stuff.format_duration(duration),
-                                    fact["start_time"].strftime('%Y-%m-%d')
+                                    fact["start_time"].strftime('%Y-%m-%d'),
+                                    fact["description"]
                                     ])
 
             if fact["name"] not in by_activity: by_activity[fact["name"]] = 0

Modified: trunk/hamster/stuff.py
==============================================================================
--- trunk/hamster/stuff.py	(original)
+++ trunk/hamster/stuff.py	Fri Nov 21 17:52:14 2008
@@ -102,8 +102,8 @@
     def __init__(self, date = None):
         date = date or dt.date.today()
         
-        # ID, Time, Name, Duration, Date
-        self.fact_store = gtk.ListStore(int, str, str, str, str)
+        # ID, Time, Name, Duration, Date, Description
+        self.fact_store = gtk.ListStore(int, str, str, str, str, str)
         
         self.facts = storage.get_facts(date)
         self.totals = {}
@@ -131,5 +131,6 @@
             self.fact_store.append([fact['id'], fact['name'], 
                                     fact["start_time"].strftime("%H:%M"), 
                                     current_duration,
-                                    fact["start_time"].strftime("%Y%m%d")])
+                                    fact["start_time"].strftime("%Y%m%d"),
+                                    fact["description"]])
 



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