3
# Copyright (C) 2008-2009 Toms Bauģis <toms.baugis at gmail.com>
5
# This file is part of Project Hamster.
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.
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.
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/>.
23
from .hamster import stuff
24
from .hamster.stuff import format_duration, format_activity
25
from tags import TagCellRenderer
29
def parent_painter(column, cell, model, iter):
30
cell_text = model.get_value(iter, 1)
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
36
text = '<span weight="heavy" rise="-20000">%s</span>' % cell_text
38
cell.set_property('markup', text)
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))
45
markup = stuff.format_activity(activity_name,
48
pad_description = True)
49
cell.set_property('markup', markup)
51
def duration_painter(column, cell, model, iter):
52
cell.set_property('xalign', 1)
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
60
text = '<span weight="heavy" rise="-20000">%s</span>' % text
61
cell.set_property('markup', text)
63
def action_painter(column, cell, model, iter):
64
cell.set_property('xalign', 1)
67
text = model.get_value(iter, 2)
68
if model.get_value(iter, 6) is None:
69
cell.set_property("stock_id", "")
71
cell.set_property("stock_id", "gtk-edit")
74
class FactTree(gtk.TreeView):
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, ))
81
gtk.TreeView.__init__(self)
83
self.set_headers_visible(False)
84
self.set_show_expanders(False)
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)
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)
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)
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)
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)
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)
126
self.store_model.clear()
128
def add_fact(self, fact, parent = None):
129
duration = stuff.duration_minutes(fact["delta"]) / 60
132
fact_time = "%s - %s " % (fact["start_time"].strftime("%H:%M"),
133
fact["end_time"].strftime("%H:%M"))
135
fact_time = fact["start_time"].strftime("%H:%M ")
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'),
145
def add_group(self, group_label, facts):
146
total = sum([stuff.duration_minutes(fact["delta"]) for fact in facts])
148
# adds group of facts with the given label
149
group_row = self.store_model.append(None,
152
stuff.format_duration(total),
159
self.add_fact(fact, group_row)
163
def detach_model(self):
166
def attach_model(self):
167
self.set_model(self.store_model)
170
def get_selected_fact(self):
171
selection = self.get_selection()
172
(model, iter) = selection.get_selected()
173
return model[iter][6]
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
181
if path and path[1] == self.edit_column:
182
self.emit("edit-clicked", self.get_selected_fact())
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())
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())
b'\\ No newline at end of file'