[hamster-applet] configuration option for the day start
- From: Toms Baugis <tbaugis src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [hamster-applet] configuration option for the day start
- Date: Mon, 16 Nov 2009 00:14:01 +0000 (UTC)
commit 0975444d343dfa2f2f4fe8d7b8220c8ac6cd7e27
Author: Toms Bauģis <toms baugis gmail com>
Date: Mon Nov 16 00:13:43 2009 +0000
configuration option for the day start
data/hamster-applet.schemas.in | 17 ++++++++
data/preferences.ui | 82 +++++++++++++++++++++++++++++++++++++---
hamster/applet.py | 9 ++++-
hamster/configuration.py | 10 +++++
hamster/db.py | 14 ++++++-
hamster/preferences.py | 19 +++++++++
hamster/stats.py | 9 ++++-
7 files changed, 150 insertions(+), 10 deletions(-)
---
diff --git a/data/hamster-applet.schemas.in b/data/hamster-applet.schemas.in
index 8465e79..97a74d5 100644
--- a/data/hamster-applet.schemas.in
+++ b/data/hamster-applet.schemas.in
@@ -65,5 +65,22 @@
</long>
</locale>
</schema>
+ <schema>
+ <key>/schemas/apps/hamster-applet/general/day_start</key>
+ <applyto>/apps/hamster-applet/general/day_start</applyto>
+ <owner>hamster-applet</owner>
+ <type>int</type>
+ <default>330</default>
+ <locale name="C">
+ <short>Time at witch to consider beginning of new day</short>
+ <long>
+ Activities will be counted as to belong to yesterday if
+ the current time is less than the specified day start and
+ today, if it is over the time.
+ Activities that span two days, will tip over to the side
+ where the largest part of the activity is.
+ </long>
+ </locale>
+ </schema>
</schemalist>
</gconfschemafile>
diff --git a/data/preferences.ui b/data/preferences.ui
index a05a115..11bba93 100644
--- a/data/preferences.ui
+++ b/data/preferences.ui
@@ -23,6 +23,7 @@
<child>
<object class="GtkVBox" id="vbox1">
<property name="visible">True</property>
+ <property name="orientation">vertical</property>
<property name="spacing">12</property>
<child>
<object class="GtkFrame" id="frame2">
@@ -402,6 +403,40 @@
<property name="visible">True</property>
<property name="orientation">vertical</property>
<child>
+ <object class="GtkHBox" id="hbox1">
+ <property name="visible">True</property>
+ <child>
+ <object class="GtkLabel" id="label4">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">New day starts at</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="padding">4</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkAlignment" id="day_start_placeholder">
+ <property name="visible">True</property>
+ <child>
+ <placeholder/>
+ </child>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ <child>
+ <placeholder/>
+ </child>
+ </object>
+ <packing>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
<object class="GtkCheckButton" id="shutdown_track">
<property name="label" translatable="yes">Stop tracking on shutdown</property>
<property name="visible">True</property>
@@ -413,7 +448,7 @@
</object>
<packing>
<property name="expand">False</property>
- <property name="position">0</property>
+ <property name="position">1</property>
</packing>
</child>
<child>
@@ -427,7 +462,7 @@
<signal name="toggled" handler="on_idle_track_toggled"/>
</object>
<packing>
- <property name="position">1</property>
+ <property name="position">2</property>
</packing>
</child>
<child>
@@ -497,7 +532,7 @@
</object>
<packing>
<property name="padding">8</property>
- <property name="position">2</property>
+ <property name="position">3</property>
</packing>
</child>
</object>
@@ -518,6 +553,41 @@
</packing>
</child>
<child>
+ <object class="GtkFrame" id="frame4">
+ <property name="visible">True</property>
+ <property name="label_xalign">0</property>
+ <property name="shadow_type">none</property>
+ <child>
+ <object class="GtkAlignment" id="alignment5">
+ <property name="visible">True</property>
+ <property name="left_padding">12</property>
+ <child>
+ <object class="GtkVBox" id="vbox5">
+ <property name="visible">True</property>
+ <property name="orientation">vertical</property>
+ <child>
+ <placeholder/>
+ </child>
+ <child>
+ <placeholder/>
+ </child>
+ </object>
+ </child>
+ </object>
+ </child>
+ <child type="label">
+ <object class="GtkLabel" id="frame4_label">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes"><b>Day </b></property>
+ <property name="use_markup">True</property>
+ </object>
+ </child>
+ </object>
+ <packing>
+ <property name="position">2</property>
+ </packing>
+ </child>
+ <child>
<object class="GtkFrame" id="frame1">
<property name="visible">True</property>
<property name="label_xalign">0</property>
@@ -526,7 +596,7 @@
<object class="GtkAlignment" id="alignment6">
<property name="visible">True</property>
<property name="xalign">0</property>
- <property name="xscale">0.30000001192092896</property>
+ <property name="xscale">0.10000000149011612</property>
<property name="top_padding">8</property>
<property name="left_padding">12</property>
<child>
@@ -549,7 +619,7 @@
</object>
<packing>
<property name="expand">False</property>
- <property name="position">2</property>
+ <property name="position">3</property>
</packing>
</child>
<child>
@@ -574,7 +644,7 @@
</object>
<packing>
<property name="expand">False</property>
- <property name="position">3</property>
+ <property name="position">4</property>
</packing>
</child>
</object>
diff --git a/hamster/applet.py b/hamster/applet.py
index 2470026..894bc66 100755
--- a/hamster/applet.py
+++ b/hamster/applet.py
@@ -250,6 +250,8 @@ class HamsterApplet(object):
except dbus.DBusException, e:
logging.error("Can't init dbus: %s" % e)
+ self.day_start = self.config.get_day_start()
+
# Load today's data, activities and set label
self.last_activity = None
self.load_day()
@@ -279,6 +281,7 @@ class HamsterApplet(object):
runtime.dispatcher.add_handler('gconf_notify_on_idle_changed', self.on_notify_on_idle_changed)
self.notify_on_idle = self.config.get_notify_on_idle()
+ runtime.dispatcher.add_handler('gconf_on_day_start_changed', self.on_day_start_changed)
# init nagging timeout
if PYNOTIFY:
@@ -524,7 +527,8 @@ class HamsterApplet(object):
"""sets up today's tree and fills it with records
returns information about last activity"""
#today is 5.5 hours ago because our midnight shift happens 5:30am
- today = (dt.datetime.now() - dt.timedelta(hours=5, minutes=30)).date()
+ today = (dt.datetime.now() - dt.timedelta(hours = self.day_start.hour,
+ minutes = self.day_start.minute)).date()
self.last_activity = runtime.storage.get_last_activity()
@@ -811,6 +815,9 @@ class HamsterApplet(object):
runtime.storage.touch_fact(self.last_activity,
end_time = self.dbusIdleListener.getIdleFrom())
+ def on_day_start_changed(self, event, new_minutes):
+ self.day_start = self.config.get_day_start()
+ self.load_day()
"""global shortcuts"""
def on_keybinding_activated(self, event, data):
diff --git a/hamster/configuration.py b/hamster/configuration.py
index 65e45d6..a2ab538 100644
--- a/hamster/configuration.py
+++ b/hamster/configuration.py
@@ -25,6 +25,7 @@ from db import Storage
from dispatcher import Dispatcher
from xdg.BaseDirectory import xdg_data_home
import logging
+import datetime as dt
class Singleton(object):
def __new__(cls, *args, **kwargs):
@@ -91,6 +92,7 @@ class GconfStore(Singleton):
GCONF_STOP_ON_SHUTDOWN = GCONF_DIR + "/stop_on_shutdown"
GCONF_NOTIFY_INTERVAL = GCONF_DIR + "/notify_interval"
GCONF_NOTIFY_ON_IDLE = GCONF_DIR + "/notify_on_idle"
+ GCONF_DAY_START = GCONF_DIR + "/day_start"
__instance = None
@@ -106,6 +108,7 @@ class GconfStore(Singleton):
self._client.notify_add(self.GCONF_STOP_ON_SHUTDOWN, lambda x, y, z, a: runtime.dispatcher.dispatch("gconf_stop_on_shutdown_changed", z.value.get_bool()))
self._client.notify_add(self.GCONF_NOTIFY_INTERVAL, lambda x, y, z, a: runtime.dispatcher.dispatch("gconf_notify_interval_changed", z.value.get_int()))
self._client.notify_add(self.GCONF_NOTIFY_ON_IDLE, lambda x, y, z, a: runtime.dispatcher.dispatch("gconf_notify_on_idle_changed", z.value.get_bool()))
+ self._client.notify_add(self.GCONF_DAY_START, lambda x, y, z, a: runtime.dispatcher.dispatch("gconf_on_day_start_changed", z.value.get_int()))
def get_keybinding(self):
@@ -123,6 +126,10 @@ class GconfStore(Singleton):
def get_notify_on_idle(self):
return self._client.get_bool(self.GCONF_NOTIFY_ON_IDLE) or False
+ def get_day_start(self):
+ minutes = self._client.get_int(self.GCONF_DAY_START) or 5*60 + 30
+ return dt.time(minutes / 60, minutes % 60)
+
#------------------------
def set_keybinding(self, binding):
self._client.set_string(self.GCONF_KEYBINDING, binding)
@@ -139,3 +146,6 @@ class GconfStore(Singleton):
def set_notify_on_idle(self, enabled):
self._client.set_bool(self.GCONF_NOTIFY_ON_IDLE, enabled)
+ def set_day_start(self, time):
+ return self._client.set_int(self.GCONF_DAY_START, time.hour * 60 + time.minute)
+
diff --git a/hamster/db.py b/hamster/db.py
index 934cc8f..d3f8ab3 100644
--- a/hamster/db.py
+++ b/hamster/db.py
@@ -52,7 +52,7 @@ class Storage(storage.Storage):
if self.__setup.im_func.complete:
return
- from configuration import runtime
+ from configuration import runtime, GconfStore
db_file = runtime.database_file
db_path, _ = os.path.split(os.path.realpath(db_file))
@@ -77,7 +77,17 @@ class Storage(storage.Storage):
logging.error("Could not change mode on %s!" % (db_file))
self.__setup.im_func.complete = True
self.run_fixtures()
+
+ self.config = GconfStore()
+
+ runtime.dispatcher.add_handler('gconf_on_day_start_changed', self.__on_day_start_changed)
+ self.day_start = self.config.get_day_start()
+
+
__setup.complete = False
+
+ def __on_day_start_changed(self, event, new_minutes):
+ self.day_start = self.config.get_day_start()
def __get_category_list(self):
return self.fetchall("SELECT * FROM categories ORDER BY category_order")
@@ -465,7 +475,7 @@ class Storage(storage.Storage):
end_date = end_date or date
#FIXME: add preference to set that
- split_time = dt.time(5, 30)
+ split_time = self.day_start
datetime_from = dt.datetime.combine(date, split_time)
datetime_to = dt.datetime.combine(end_date, split_time) + dt.timedelta(days = 1)
diff --git a/hamster/preferences.py b/hamster/preferences.py
index 2c3f489..d773eb1 100755
--- a/hamster/preferences.py
+++ b/hamster/preferences.py
@@ -25,6 +25,11 @@ import os
import gtk
import dispatcher, storage, stuff
+
+import datetime as dt
+import widgets
+
+
from configuration import GconfStore, runtime
def get_prev(selection, model):
@@ -138,6 +143,11 @@ class PreferencesEditor:
selection = self.category_tree.get_selection()
selection.connect('changed', self.category_changed_cb, self.category_store)
+ self.day_start = widgets.TimeInput(dt.time(5,30))
+ self.get_widget("day_start_placeholder").add(self.day_start)
+ self.day_start.connect("time-entered", self.on_day_start_changed)
+
+
self.load_config()
self._gui.connect_signals(self)
@@ -181,6 +191,8 @@ class PreferencesEditor:
self.get_widget("keybinding").set_text(self.config.get_keybinding())
self.get_widget("notify_on_idle").set_active(self.config.get_notify_on_idle())
+ self.day_start.set_time(self.config.get_day_start())
+
def drag_data_get_data(self, treeview, context, selection, target_id,
etime):
@@ -644,6 +656,13 @@ class PreferencesEditor:
def on_keybinding_changed(self, textbox):
self.config.set_keybinding(textbox.get_text())
+ def on_day_start_changed(self, widget):
+ day_start = self.day_start.get_time()
+ if not day_start:
+ return
+
+ self.config.set_day_start(day_start)
+
def on_preferences_window_destroy(self, window):
self.window = None
diff --git a/hamster/stats.py b/hamster/stats.py
index 47d1987..375b081 100644
--- a/hamster/stats.py
+++ b/hamster/stats.py
@@ -30,7 +30,7 @@ import charting
from edit_activity import CustomFactController
import reports, widgets, graphics
-from configuration import runtime
+from configuration import runtime, GconfStore
import webbrowser
from itertools import groupby
@@ -416,11 +416,18 @@ class StatsViewer(object):
self.get_widget("explore_everything").add(self.timeline)
self.get_widget("explore_everything").show_all()
+
+ self.config = GconfStore()
+ runtime.dispatcher.add_handler('gconf_on_day_start_changed', self.on_day_start_changed)
self.report_chooser = None
self.do_graph()
self.init_stats()
+
+ def on_day_start_changed(self, event, new_minutes):
+ self.do_graph()
+
def init_stats(self):
self.stat_facts = runtime.storage.get_facts(dt.date(1970, 1, 1), dt.date.today())
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]