~kklimonda/ubuntu/natty/hamster-applet/lp.697667

« back to all changes in this revision

Viewing changes to hamster/widgets/facttree.py

  • Committer: Bazaar Package Importer
  • Author(s): Chris Coulson
  • Date: 2010-02-10 02:52:31 UTC
  • mfrom: (1.1.14 upstream)
  • Revision ID: james.westby@ubuntu.com-20100210025231-x0q5h4q7nlvihl09
Tags: 2.29.90-0ubuntu1
* New upstream version
  - workspace tracking - switch activity, when switching desktops
  - chart improvements - theme friendly and less noisier
  - for those without GNOME panel there is now a standalone version, 
    accessible via Applications -> Accessories -> Time Tracker
  - overview window remembers position
  - maintaining cursor on the selected row after edits / refreshes
  - descriptions once again in the main input field, delimited by comma
  - activity suggestion box now sorts items by recency (Patryk Zawadzki)
  - searching
  - simplified save report dialog, thanks to the what you see is what you 
    report revamp
  - overview/stats replaced with activities / totals and stats accessible 
    from totals
  - interactive graphs to drill down in totals
  - miscellaneous performance improvements
  - pixel-perfect graphs
* Updated 01_startup-fix.patch to apply to new source layout
* debian/control:
  - Add build-depend on gnome-doc-utils

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# - coding: utf-8 -
2
 
 
3
 
# Copyright (C) 2008-2009 Toms Bauģis <toms.baugis at gmail.com>
4
 
 
5
 
# This file is part of Project Hamster.
6
 
 
7
 
# Project Hamster is free software: you can redistribute it and/or modify
8
 
# it under the terms of the GNU General Public License as published by
9
 
# the Free Software Foundation, either version 3 of the License, or
10
 
# (at your option) any later version.
11
 
 
12
 
# Project Hamster is distributed in the hope that it will be useful,
13
 
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 
# GNU General Public License for more details.
16
 
 
17
 
# You should have received a copy of the GNU General Public License
18
 
# along with Project Hamster.  If not, see <http://www.gnu.org/licenses/>.
19
 
 
20
 
import gtk, gobject
21
 
import datetime as dt
22
 
 
23
 
from .hamster import stuff
24
 
from .hamster.stuff import format_duration, format_activity
25
 
from tags import TagCellRenderer
26
 
 
27
 
import pango
28
 
 
29
 
def parent_painter(column, cell, model, iter):
30
 
    cell_text = model.get_value(iter, 1)
31
 
    
32
 
    if model.get_value(iter, 6) is None:
33
 
        if model.get_path(iter) == (0,):
34
 
            text = '<span weight="heavy">%s</span>' % cell_text
35
 
        else:
36
 
            text = '<span weight="heavy" rise="-20000">%s</span>' % cell_text
37
 
            
38
 
        cell.set_property('markup', text)
39
 
 
40
 
    else:
41
 
        activity_name = stuff.escape_pango(cell_text)
42
 
        description = stuff.escape_pango(model.get_value(iter, 4))
43
 
        category = stuff.escape_pango(model.get_value(iter, 5))
44
 
 
45
 
        markup = stuff.format_activity(activity_name,
46
 
                                       category,
47
 
                                       description,
48
 
                                       pad_description = True)            
49
 
        cell.set_property('markup', markup)
50
 
 
51
 
def duration_painter(column, cell, model, iter):
52
 
    cell.set_property('xalign', 1)
53
 
 
54
 
 
55
 
    text = model.get_value(iter, 2)
56
 
    if model.get_value(iter, 6) is None:
57
 
        if model.get_path(iter) == (0,):
58
 
            text = '<span weight="heavy">%s</span>' % text
59
 
        else:
60
 
            text = '<span weight="heavy" rise="-20000">%s</span>' % text
61
 
    cell.set_property('markup', text)
62
 
 
63
 
def action_painter(column, cell, model, iter):
64
 
    cell.set_property('xalign', 1)
65
 
 
66
 
 
67
 
    text = model.get_value(iter, 2)
68
 
    if model.get_value(iter, 6) is None:
69
 
        cell.set_property("stock_id", "")
70
 
    else:
71
 
        cell.set_property("stock_id", "gtk-edit")
72
 
 
73
 
 
74
 
class FactTree(gtk.TreeView):
75
 
    __gsignals__ = {
76
 
        "edit-clicked": (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (gobject.TYPE_PYOBJECT, )),
77
 
        "double-click": (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (gobject.TYPE_PYOBJECT, ))
78
 
    }
79
 
    
80
 
    def __init__(self):
81
 
        gtk.TreeView.__init__(self)
82
 
        
83
 
        self.set_headers_visible(False)
84
 
        self.set_show_expanders(False)
85
 
 
86
 
        self.store_model = gtk.TreeStore(int, str, str, str, str, str, gobject.TYPE_PYOBJECT)
87
 
        #id, caption, duration, date (invisible), description, category
88
 
        self.set_model(self.store_model)
89
 
 
90
 
 
91
 
        # name
92
 
        nameColumn = gtk.TreeViewColumn()
93
 
        nameCell = gtk.CellRendererText()
94
 
        #nameCell.set_property("ellipsize", pango.ELLIPSIZE_END)
95
 
        nameColumn.pack_start(nameCell, True)
96
 
        nameColumn.set_cell_data_func(nameCell, parent_painter)
97
 
        self.append_column(nameColumn)
98
 
 
99
 
        tag_cell = TagCellRenderer()
100
 
        tag_cell.set_font_size(8);
101
 
        tagColumn = gtk.TreeViewColumn("", tag_cell, data=6)
102
 
        tagColumn.set_expand(True)
103
 
        self.append_column(tagColumn)
104
 
        
105
 
 
106
 
        # duration
107
 
        timeColumn = gtk.TreeViewColumn()
108
 
        timeCell = gtk.CellRendererText()
109
 
        timeColumn.pack_end(timeCell, True)
110
 
        timeColumn.set_cell_data_func(timeCell, duration_painter)
111
 
        self.append_column(timeColumn)
112
 
 
113
 
        edit_cell = gtk.CellRendererPixbuf()
114
 
        edit_cell.set_property("mode", gtk.CELL_RENDERER_MODE_ACTIVATABLE)
115
 
        self.edit_column = gtk.TreeViewColumn("", edit_cell)
116
 
        self.edit_column.set_cell_data_func(edit_cell, action_painter)
117
 
        self.append_column(self.edit_column)
118
 
 
119
 
        self.connect("row-activated", self._on_row_activated)
120
 
        self.connect("button-release-event", self._on_button_release_event)
121
 
        self.connect("key-press-event", self._on_key_pressed)
122
 
 
123
 
        self.show()
124
 
    
125
 
    def clear(self):
126
 
        self.store_model.clear()
127
 
        
128
 
    def add_fact(self, fact, parent = None):
129
 
        duration = stuff.duration_minutes(fact["delta"]) / 60
130
 
 
131
 
        if fact["end_time"]:
132
 
            fact_time = "%s - %s " % (fact["start_time"].strftime("%H:%M"),
133
 
                                   fact["end_time"].strftime("%H:%M"))
134
 
        else:
135
 
            fact_time = fact["start_time"].strftime("%H:%M ")
136
 
 
137
 
        self.store_model.append(parent, [fact["id"],
138
 
                                   "%s %s" % (fact_time, fact["name"]),
139
 
                                   stuff.format_duration(fact["delta"]),
140
 
                                   fact["start_time"].strftime('%Y-%m-%d'),
141
 
                                   fact["description"],
142
 
                                   fact["category"],
143
 
                                   fact])
144
 
 
145
 
    def add_group(self, group_label, facts):
146
 
        total = sum([stuff.duration_minutes(fact["delta"]) for fact in facts])
147
 
        
148
 
        # adds group of facts with the given label
149
 
        group_row = self.store_model.append(None,
150
 
                                    [-1,
151
 
                                     group_label,
152
 
                                     stuff.format_duration(total),
153
 
                                     "",
154
 
                                     "",
155
 
                                     "",
156
 
                                     None])
157
 
        
158
 
        for fact in facts:
159
 
            self.add_fact(fact, group_row)
160
 
 
161
 
        self.expand_all()
162
 
 
163
 
    def detach_model(self):
164
 
        self.set_model()
165
 
 
166
 
    def attach_model(self):
167
 
        self.set_model(self.store_model)
168
 
        self.expand_all()
169
 
        
170
 
    def get_selected_fact(self):
171
 
        selection = self.get_selection()
172
 
        (model, iter) = selection.get_selected()
173
 
        return model[iter][6]
174
 
 
175
 
 
176
 
    def _on_button_release_event(self, tree, event):
177
 
        # a hackish solution to make edit icon keyboard accessible
178
 
        pointer = event.window.get_pointer() # x, y, flags
179
 
        path = self.get_path_at_pos(pointer[0], pointer[1]) #column, innerx, innery
180
 
        
181
 
        if path and path[1] == self.edit_column:
182
 
            self.emit("edit-clicked", self.get_selected_fact())
183
 
            return True
184
 
        
185
 
        return False
186
 
 
187
 
    def _on_row_activated(self, tree, path, column):
188
 
        if column == self.edit_column:
189
 
            self.emit_stop_by_name ('row-activated')
190
 
            self.emit("edit-clicked", self.get_selected_fact())
191
 
            return True
192
 
 
193
 
 
194
 
    def _on_key_pressed(self, tree, event):
195
 
        # capture ctrl+e and pretend that user click on edit
196
 
        if (event.keyval == gtk.keysyms.e  \
197
 
              and event.state & gtk.gdk.CONTROL_MASK):
198
 
            self.emit("edit-clicked", self.get_selected_fact())
199
 
            return True
200
 
            
201
 
        return False
202
 
            
 
 
b'\\ No newline at end of file'