~ubuntu-branches/ubuntu/wily/hamster-applet/wily

« back to all changes in this revision

Viewing changes to hamster/stuff.py

  • Committer: Bazaar Package Importer
  • Author(s): Pedro Fragoso
  • Date: 2008-12-15 17:42:14 UTC
  • mto: (1.1.16 upstream) (20.1.1 lucid-proposed)
  • mto: This revision was merged to the branch mainline in revision 6.
  • Revision ID: james.westby@ubuntu.com-20081215174214-ri1ezw1c2pdnl3i6
Tags: upstream-2.25.3
ImportĀ upstreamĀ versionĀ 2.25.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
 
24
24
import gtk
25
25
from hamster import storage
 
26
import pango
26
27
from pango import ELLIPSIZE_END
 
28
 
27
29
import datetime as dt
28
30
 
 
31
class CategoryCell(gtk.CellRendererText):
 
32
    def __init__(self):
 
33
        gtk.CellRendererText.__init__(self)        
 
34
        self.set_property('alignment', pango.ALIGN_RIGHT)
 
35
        
 
36
        insensitive_color = gtk.Label().style.fg[gtk.STATE_INSENSITIVE]
 
37
        self.set_property('foreground-gdk', insensitive_color)
 
38
        self.set_property('scale', pango.SCALE_SMALL)
 
39
        self.set_property('yalign', 0.0)
 
40
 
29
41
class ExpanderColumn(gtk.TreeViewColumn):
30
42
    def __init__(self, label, text):
31
43
        gtk.TreeViewColumn.__init__(self, label)
90
102
    def __init__(self, date = None):
91
103
        date = date or dt.date.today()
92
104
        
93
 
        # ID, Time, Name, Duration, Date
94
 
        self.fact_store = gtk.ListStore(int, str, str, str, str)
 
105
        # ID, Time, Name, Duration, Date, Description
 
106
        self.fact_store = gtk.ListStore(int, str, str, str, str, str)
95
107
        
96
 
        # Dummy ID to distinct between fact_store, Name, Duration
97
 
        self.total_store = gtk.ListStore(int, str, str)
98
 
 
99
108
        self.facts = storage.get_facts(date)
100
109
        self.totals = {}
101
110
        
109
118
                delta = dt.datetime.now() - fact["start_time"]
110
119
                duration = 24 * delta.days + delta.seconds / 60
111
120
            
112
 
            fact_name = fact['name']
 
121
            fact_category = fact['category']
113
122
            
114
 
            if fact_name not in self.totals:
115
 
                self.totals[fact_name] = 0
 
123
            if fact_category not in self.totals:
 
124
                self.totals[fact_category] = 0
116
125
 
117
126
            if duration:
118
 
                self.totals[fact_name] += duration
 
127
                self.totals[fact_category] += duration
119
128
 
120
129
            current_duration = format_duration(duration)
121
130
 
122
131
            self.fact_store.append([fact['id'], fact['name'], 
123
132
                                    fact["start_time"].strftime("%H:%M"), 
124
133
                                    current_duration,
125
 
                                    fact["start_time"].strftime("%Y%m%d")])
126
 
 
127
 
        # now we are good to append totals!
128
 
        # no sorting - chronological is intuitive
129
 
        for total in self.totals:
130
 
            if (self.totals[total]) > 0: # TODO - check if this zero check is still necessary (it was 6min check before) 
131
 
                self.total_store.append([-1, format_duration(self.totals[total]), total])
 
134
                                    fact["start_time"].strftime("%Y%m%d"),
 
135
                                    fact["description"]])
132
136