1
# -.- coding: utf-8 -.-
3
# GNOME Activity Journal
5
# Copyright © 2009-2010 Seif Lotfy <seif@lotfy.com>
6
# Copyright © 2010 Siegfried Gevatter <siegfried@gevatter.com>
8
# This program is free software: you can redistribute it and/or modify
9
# it under the terms of the GNU General Public License as published by
10
# the Free Software Foundation, either version 3 of the License, or
11
# (at your option) any later version.
13
# This program is distributed in the hope that it will be useful,
14
# but WITHOUT ANY WARRANTY; without even the implied warranty of
15
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
# GNU Lesser General Public License for more details.
18
# You should have received a copy of the GNU Lesser General Public License
19
# along with this program. If not, see <http://www.gnu.org/licenses/>.
25
from daywidgets import *
26
from histogramwidget import histogramdata
27
from config import settings
29
class ActivityView(gtk.VBox):
31
def __init__(self, cal):
33
gtk.VBox.__init__(self)
40
self.__first_run = True
44
self._set_today_timestamp()
50
def set_num_days(self, dayrange):
51
self.dayrange = dayrange
52
self.cal.histogram.set_dayrange(dayrange)
55
def _set_searchbox(self):
56
self.searchbox = searchbox
57
self.pack_start(self.searchbox, False, False)
58
self.searchbox.connect("search", self._handle_search_results)
59
self.searchbox.connect("clear", self._clear_search_results)
61
def _clear_search_results(self, widget):
62
self.cal.histogram.clear_highlighted()
66
def _handle_search_results(self, widget, results):
67
datastore = self.cal.histogram.datastore
70
offset =time.mktime(time.gmtime(t)) - time.mktime(time.localtime(t))
73
timestamp = int(time.mktime(time.localtime(r[0]))) / 86400
74
keys.append(offset + timestamp*86400)
77
for i, (date, nitems) in enumerate(datastore):
80
self.cal.histogram.set_highlighted(dates)
84
def _set_timeline(self):
85
def selection_callback(widget, datastore, i):
86
if i < len(datastore):
87
selection_date = datastore[i][0]
88
end = selection_date + 86399
89
start = selection_date - (self.dayrange - 1) * 86400
90
self.set_dayrange(start, end)
92
histogramdata.datelist(90, self.cal.histogram.set_data)
93
self.cal.histogram.add_selection_callback(selection_callback)
95
def _set_view_type(self, refresh=False):
98
if w != self.searchbox:
101
if settings.get("view", "Journal") == "Journal":
102
self.daysbox = gtk.HBox(True)
104
self.daysbox = gtk.VBox()
106
self.pack_start(self.daysbox, True, True, 6)
109
self.daysbox.show_all()
111
def jump(self, offset):
112
self.start = self.start + offset
113
if time.time() > self.start:
114
diff = self.start - self.cal.histogram.datastore[0][0]
115
self.cal.histogram.set_selected(diff / 86400)
116
self.set_dayrange(self.start, self.end+offset)
118
def set_dayrange(self, start, end):
121
self.dayrange = int(int((end - start)) / 86400) + 1
124
def _set_today_timestamp(self, dayinfocus=None):
126
Return the dayrange of seconds between the min_timestamp and max_timestamp
128
# For the local timezone
130
dayinfocus = int(time.mktime(time.strptime(
131
time.strftime("%d %B %Y") , "%d %B %Y")))
132
self.end = dayinfocus + 86399
133
self.start = dayinfocus - (self.dayrange - 1) * 86400
138
return # nothing to do - TODO: should this be allowed to happen?
139
for w in self.daysbox:
140
self.daysbox.remove(w)
141
for i in xrange(self.dayrange):
142
if not settings.get("view", "Journal") == "Journal":
143
i = (self.dayrange - 1) - i
144
ptime = datetime.datetime.fromtimestamp(
145
self.start + i*86400).strftime("%A, %d %B %Y")
146
if not self.days.has_key(ptime):
147
dayview = DayWidget(self.start + i*86400,
148
self.start + i*86400 + 86400)
149
self.days[ptime] = dayview
150
self.daysbox.pack_start(self.days[ptime], True, True, 3)
151
self.days[ptime].refresh()