[hamster-applet] A rather big shuffle - trying to clean the startup process. Something's maybe broken now. Should not
- From: Toms Baugis <tbaugis src gnome org>
- To: svn-commits-list gnome org
- Subject: [hamster-applet] A rather big shuffle - trying to clean the startup process. Something's maybe broken now. Should not
- Date: Wed, 17 Jun 2009 18:07:34 -0400 (EDT)
commit 047902e38713dc6b6956767b6c8149f396b6ea78
Author: Patryk Zawadski <patrys pld-linux org>
Date: Wed Jun 17 23:06:31 2009 +0100
A rather big shuffle - trying to clean the startup process. Something's maybe broken now. Should not, though.
hamster/KeyBinder.py | 15 +++----
hamster/__init__.py | 90 ---------------------------------------------
hamster/about.py | 5 +--
hamster/applet.py | 71 +++++++++++++++++------------------
hamster/charting.py | 2 +-
hamster/configuration.py | 69 +++++++++++++++++++++++++---------
hamster/db.py | 73 +++++++++++++++++++++++++++++-------
hamster/edit_activity.py | 27 +++++++------
hamster/hamster-applet.py | 21 +++-------
hamster/hamsterdbus.py | 38 +++++++++---------
hamster/preferences.py | 6 +-
hamster/reports.py | 2 +-
hamster/stats.py | 37 +++++++++---------
hamster/storage.py | 1 -
hamster/stuff.py | 4 +-
hamster/widgets.py | 4 +-
16 files changed, 219 insertions(+), 246 deletions(-)
---
diff --git a/hamster/KeyBinder.py b/hamster/KeyBinder.py
index 14a0b6e..9c8a730 100644
--- a/hamster/KeyBinder.py
+++ b/hamster/KeyBinder.py
@@ -20,13 +20,12 @@
import gtk, gconf
-import hamster, hamster.keybinder
-from hamster.configuration import GconfStore
-from hamster import dispatcher
+import keybinder
+from configuration import GconfStore, runtime
class Keybinder(object):
def __init__(self):
- self.config = GconfStore.get_instance()
+ self.config = GconfStore()
self.bound = False
self.prevbinding = None
@@ -36,7 +35,7 @@ class Keybinder(object):
# This is for uninstalled cases, the real default is in the schema
self.key_combination = "<Super>H"
- dispatcher.add_handler("gconf_keybinding_changed", self.on_keybinding_changed)
+ runtime.dispatcher.add_handler("gconf_keybinding_changed", self.on_keybinding_changed)
self.bind()
@@ -46,7 +45,7 @@ class Keybinder(object):
self.bind()
def on_keybinding_activated(self):
- dispatcher.dispatch('keybinding_activated')
+ runtime.dispatcher.dispatch('keybinding_activated')
def get_key_combination(self):
return self.key_combination
@@ -57,7 +56,7 @@ class Keybinder(object):
try:
print 'Binding shortcut %s to popup hamster' % self.key_combination
- hamster.keybinder.tomboy_keybinder_bind(self.key_combination, self.on_keybinding_activated)
+ keybinder.tomboy_keybinder_bind(self.key_combination, self.on_keybinding_activated)
self.bound = True
except KeyError:
# if the requested keybinding conflicts with an existing one, a KeyError will be thrown
@@ -68,7 +67,7 @@ class Keybinder(object):
def unbind(self):
try:
print 'Unbinding shortcut %s to popup hamster' % self.prevbinding
- hamster.keybinder.tomboy_keybinder_unbind(self.prevbinding)
+ keybinder.tomboy_keybinder_unbind(self.prevbinding)
self.bound = False
except KeyError:
# if the requested keybinding is not bound, a KeyError will be thrown
diff --git a/hamster/__init__.py b/hamster/__init__.py
index a90b9a3..8b13789 100644
--- a/hamster/__init__.py
+++ b/hamster/__init__.py
@@ -1,91 +1 @@
-# -*- coding: utf-8 -*-
-# Copyright (C) 2007, 2008 Toms Bauģis <toms.baugis at gmail.com>
-# Copyright (C) 2007 Patryk Zawadzki <patrys at pld-linux.org>
-# Copyright (C) 2008 PÄ?teris Caune <cuu508 at gmail.com>
-
-# This file is part of Project Hamster.
-
-# Project Hamster is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-
-# Project Hamster is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-
-# You should have received a copy of the GNU General Public License
-# along with Project Hamster. If not, see <http://www.gnu.org/licenses/>.
-
-
-import os
-from os.path import join, exists, isdir, isfile, dirname, abspath, expanduser
-from shutil import copy as copyfile
-import gtk
-import gettext
-import locale
-
-# Autotools set the actual data_dir in defs.py
-from db import Storage
-import defs
-from dispatcher import Dispatcher
-
-# Init i18n
-gettext.install("hamster-applet", unicode = True)
-
-# Allow to use not installed hamster
-UNINSTALLED_HAMSTER = False
-def _check(path):
- return exists(path) and isdir(path) and isfile(path+"/AUTHORS")
-
-name = join(dirname(__file__), '..')
-if _check(name):
- UNINSTALLED_HAMSTER = True
-
-# Sets SHARED_DATA_DIR to local copy, or the system location
-# Typically shared data dir is /usr/share/hamster-applet
-if UNINSTALLED_HAMSTER:
- SHARED_DATA_DIR = abspath(join(dirname(__file__), '..', 'data'))
-else:
- SHARED_DATA_DIR = join(defs.DATA_DIR, "hamster-applet")
-print "Data Dir: %s" % SHARED_DATA_DIR
-
-USER_HAMSTER_DIR = expanduser("~/.gnome2/hamster-applet")
-DB_FILE = 'hamster.db'
-HAMSTER_DB = join(USER_HAMSTER_DIR, DB_FILE)
-if not exists(USER_HAMSTER_DIR):
- try:
- os.makedirs(USER_HAMSTER_DIR, 0744)
- except Exception , msg:
- print 'Error:could not create user dir (%s): %s' % (USER_HAMSTER_DIR, msg)
-
-#check if db is here
-if not exists(HAMSTER_DB):
- print "Database not found in %s - installing default from %s!" % (HAMSTER_DB, SHARED_DATA_DIR)
- copyfile(join(SHARED_DATA_DIR, DB_FILE), HAMSTER_DB)
-
- #change also permissions - sometimes they are 444
- try:
- os.chmod(HAMSTER_DB, 0664)
- except Exception, msg:
- print 'Error:could not change mode on %s!' % (HAMSTER_DB)
-
-# Init storage
-
-dispatcher = Dispatcher()
-storage = None
-trace_sql = False
-
-# Path to images, icons
-ART_DATA_DIR = join(SHARED_DATA_DIR, "art")
-
-
-def __init_db():
- """work around the problem that we need hamster before setting
- locale info, but that triggers init of DB and thus sets strings
- before they have been localized"""
- global storage
- storage = Storage(dispatcher)
-
diff --git a/hamster/about.py b/hamster/about.py
index 03e8466..2be2d2c 100644
--- a/hamster/about.py
+++ b/hamster/about.py
@@ -19,11 +19,8 @@
from os.path import join
-from hamster import SHARED_DATA_DIR
-from hamster.defs import VERSION
+from defs import VERSION
import gtk
-import hamster
-
def on_email(about, mail):
gtk.show_uri(gtk.gdk.Screen(), "mailto:%s" % mail, 0L)
diff --git a/hamster/applet.py b/hamster/applet.py
index d7eeece..1ad5309 100755
--- a/hamster/applet.py
+++ b/hamster/applet.py
@@ -32,19 +32,18 @@ import gnomeapplet
import gobject
import dbus, dbus.service, dbus.mainloop.glib
-from hamster import dispatcher, storage
-import hamster.eds
-from hamster.configuration import GconfStore
+import eds
+from configuration import GconfStore, runtime
-from hamster import stuff
-from hamster.KeyBinder import *
-from hamster.hamsterdbus import HAMSTER_URI, HamsterDbusController
+import stuff
+from KeyBinder import *
+from hamsterdbus import HAMSTER_URI, HamsterDbusController
# controllers for other windows
-from hamster.edit_activity import CustomFactController
-from hamster.stats import StatsViewer
-from hamster.about import show_about
-from hamster.preferences import PreferencesEditor
+from edit_activity import CustomFactController
+from stats import StatsViewer
+from about import show_about
+from preferences import PreferencesEditor
import idle
@@ -213,7 +212,7 @@ class HamsterApplet(object):
self.applet.about = None
self.open_fact_editors = []
- self.config = GconfStore.get_instance()
+ self.config = GconfStore()
self.button = PanelButton()
self.button.connect('toggled', self.on_toggle)
@@ -261,27 +260,27 @@ class HamsterApplet(object):
- dispatcher.add_handler('panel_visible', self.__show_toggle)
- dispatcher.add_handler('activity_updated', self.after_activity_update)
- dispatcher.add_handler('day_updated', self.after_fact_update)
+ runtime.dispatcher.add_handler('panel_visible', self.__show_toggle)
+ runtime.dispatcher.add_handler('activity_updated', self.after_activity_update)
+ runtime.dispatcher.add_handler('day_updated', self.after_fact_update)
self._gui.connect_signals(self)
# init hotkey
- dispatcher.add_handler('keybinding_activated', self.on_keybinding_activated)
+ runtime.dispatcher.add_handler('keybinding_activated', self.on_keybinding_activated)
# init idle check
- dispatcher.add_handler('gconf_timeout_enabled_changed', self.on_timeout_enabled_changed)
+ runtime.dispatcher.add_handler('gconf_timeout_enabled_changed', self.on_timeout_enabled_changed)
self.timeout_enabled = self.config.get_timeout_enabled()
- dispatcher.add_handler('gconf_notify_on_idle_changed', self.on_notify_on_idle_changed)
+ 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()
# init nagging timeout
if PYNOTIFY:
self.notify = Notifier(self.button)
- dispatcher.add_handler('gconf_notify_interval_changed', self.on_notify_interval_changed)
+ runtime.dispatcher.add_handler('gconf_notify_interval_changed', self.on_notify_interval_changed)
self.on_notify_interval_changed(None, self.config.get_notify_interval())
@@ -350,9 +349,9 @@ class HamsterApplet(object):
def refresh_dropdown(self):
- self.all_activities = storage.get_autocomplete_activities()
- self.all_categories = storage.get_category_list()
- self.eds_tasks = hamster.eds.get_eds_tasks()
+ self.all_activities = runtime.storage.get_autocomplete_activities()
+ self.all_categories = runtime.storage.get_category_list()
+ self.eds_tasks = eds.get_eds_tasks()
#add evolution tasks to dropdown, yay!
for activity in self.eds_tasks:
@@ -362,7 +361,7 @@ class HamsterApplet(object):
store = self.activity_combo.get_model()
store.clear()
- categorized_activities = storage.get_sorted_activities()
+ categorized_activities = runtime.storage.get_sorted_activities()
for activity in categorized_activities:
activity_category = activity['name']
if activity['category']:
@@ -480,7 +479,7 @@ class HamsterApplet(object):
idle_minutes = idle.getIdleSec() / 60.0
current_time = dt.datetime.now()
idle_from = current_time - dt.timedelta(minutes = idle_minutes)
- storage.touch_fact(self.last_activity, end_time = idle_from)
+ runtime.storage.touch_fact(self.last_activity, end_time = idle_from)
# if we have date change - let's finish previous task and start a new one
@@ -539,11 +538,11 @@ class HamsterApplet(object):
#today is 5.5 hours ago because our midnight shift happens 5:30am
today = (dt.datetime.now() - dt.timedelta(hours=5, minutes=30)).date()
- self.last_activity = storage.get_last_activity()
+ self.last_activity = runtime.storage.get_last_activity()
fact_store = self.treeview.get_model()
fact_store.clear()
- facts = storage.get_facts(today)
+ facts = runtime.storage.get_facts(today)
by_category = {}
@@ -587,7 +586,7 @@ class HamsterApplet(object):
(cur, col) = self.treeview.get_cursor()
- storage.remove_fact(model[iter][0])
+ runtime.storage.remove_fact(model[iter][0])
self.treeview.set_cursor(cur)
@@ -680,7 +679,7 @@ class HamsterApplet(object):
return False
def on_toggle(self, widget):
- dispatcher.dispatch('panel_visible', self.button.get_active())
+ runtime.dispatcher.dispatch('panel_visible', self.button.get_active())
def on_activity_list_key_pressed(self, entry, event):
#tab will trigger going through autocomplete values when there are any
@@ -712,8 +711,8 @@ class HamsterApplet(object):
if activity_name == "":
return
- storage.add_fact(activity_name)
- dispatcher.dispatch('panel_visible', False)
+ runtime.storage.add_fact(activity_name)
+ runtime.dispatcher.dispatch('panel_visible', False)
"""listview events"""
def on_todays_keys(self, tree, event):
@@ -749,27 +748,27 @@ class HamsterApplet(object):
description = description.decode('utf8', 'replace')
activity_name = "%s, %s" % (activity_name, description)
- storage.add_fact(activity_name)
- dispatcher.dispatch('panel_visible', False)
+ runtime.storage.add_fact(activity_name)
+ runtime.dispatcher.dispatch('panel_visible', False)
def on_windows_keys(self, tree, event_key):
if (event_key.keyval == gtk.keysyms.Escape
or (event_key.keyval == gtk.keysyms.w
and event_key.state & gtk.gdk.CONTROL_MASK)):
- dispatcher.dispatch('panel_visible', False)
+ runtime.dispatcher.dispatch('panel_visible', False)
return True
return False
"""button events"""
def on_stop_tracking(self, button):
- storage.touch_fact(self.last_activity)
+ runtime.storage.touch_fact(self.last_activity)
self.last_activity = None
self.update_label()
- dispatcher.dispatch('panel_visible', False)
+ runtime.dispatcher.dispatch('panel_visible', False)
def on_overview(self, menu_item):
- dispatcher.dispatch('panel_visible', False)
+ runtime.dispatcher.dispatch('panel_visible', False)
stats_viewer = StatsViewer(self)
stats_viewer.show()
@@ -787,7 +786,7 @@ class HamsterApplet(object):
show_about(self.applet)
def show_preferences(self, menu_item, verb):
- dispatcher.dispatch('panel_visible', False)
+ runtime.dispatcher.dispatch('panel_visible', False)
if self.preferences_editor and self.preferences_editor.window:
self.preferences_editor.window.present()
diff --git a/hamster/charting.py b/hamster/charting.py
index 36d5e8b..8e3315a 100644
--- a/hamster/charting.py
+++ b/hamster/charting.py
@@ -41,7 +41,7 @@ import math
from sys import maxint
import datetime as dt
import time
-from hamster import graphics
+import graphics
# Tango colors
light = [(252, 233, 79), (252, 175, 62), (233, 185, 110),
diff --git a/hamster/configuration.py b/hamster/configuration.py
index 99c0392..a8199f9 100644
--- a/hamster/configuration.py
+++ b/hamster/configuration.py
@@ -17,11 +17,52 @@
# You should have received a copy of the GNU General Public License
# along with Project Hamster. If not, see <http://www.gnu.org/licenses/>.
-
import gconf
-from hamster import dispatcher
+import gettext
+import os
+import defs
+from db import Storage
+from dispatcher import Dispatcher
+
+class Singleton(object):
+ def __new__(cls, *args, **kwargs):
+ if '__instance' not in vars(cls):
+ cls.__instance = object.__new__(cls, *args, **kwargs)
+ return cls.__instance
-class GconfStore(object):
+class RuntimeStore(Singleton):
+ """
+ Handles one-shot configuration that is not stored between sessions
+ """
+ database_file = ""
+ data_dir = ""
+ dispatcher = None
+ storage = None
+ trace_sql = False
+
+ def __init__(self):
+ print "Doing init!"
+
+ gettext.install("hamster-applet", unicode = True)
+
+ # Typically shared data dir is /usr/share/hamster-applet
+ if os.path.realpath(__file__).startswith('/home/'):
+ data_dir = os.path.realpath(os.path.join(os.path.dirname(__file__), '..', 'data'))
+ else:
+ data_dir = os.path.join(defs.DATA_DIR, "hamster-applet")
+ self.data_dir = data_dir
+ self.dispatcher = Dispatcher()
+ self.storage = Storage(self.dispatcher)
+
+ def get_art_dir(self):
+ return os.path.join(self.data_dir, "art")
+
+ art_dir = property(get_art_dir, None)
+
+runtime = RuntimeStore()
+runtime.database_file = os.path.expanduser("~/.gnome2/hamster-applet/hamster.db")
+
+class GconfStore(Singleton):
"""
Handles storing to and retrieving values from GConf
"""
@@ -38,28 +79,18 @@ class GconfStore(object):
__instance = None
- @staticmethod
- def get_instance():
- if not GconfStore.__instance:
- GconfStore.__instance = GconfStore()
- return GconfStore.__instance
-
def __init__(self):
- """
- Do not use the constructor directly. Always use L{get_instance}
- Because otherwise you will have lots of signals running arround
- """
super(GconfStore, self).__init__()
self._client = gconf.client_get_default()
self.__connect_notifications()
def __connect_notifications(self):
self._client.add_dir(self.GCONF_DIR, gconf.CLIENT_PRELOAD_RECURSIVE)
- self._client.notify_add(self.GCONF_KEYBINDING, lambda x, y, z, a: dispatcher.dispatch("gconf_keybinding_changed", z.value.get_string()))
- self._client.notify_add(self.GCONF_ENABLE_TIMEOUT, lambda x, y, z, a: dispatcher.dispatch("gconf_timeout_enabled_changed", z.value.get_bool()))
- self._client.notify_add(self.GCONF_STOP_ON_SHUTDOWN, lambda x, y, z, a: dispatcher.dispatch("gconf_stop_on_shutdown_changed", z.value.get_bool()))
- self._client.notify_add(self.GCONF_NOTIFY_INTERVAL, lambda x, y, z, a: dispatcher.dispatch("gconf_notify_interval_changed", z.value.get_int()))
- self._client.notify_add(self.GCONF_NOTIFY_ON_IDLE, lambda x, y, z, a: dispatcher.dispatch("gconf_notify_on_idle_changed", z.value.get_bool()))
+ self._client.notify_add(self.GCONF_KEYBINDING, lambda x, y, z, a: runtime.dispatcher.dispatch("gconf_keybinding_changed", z.value.get_string()))
+ self._client.notify_add(self.GCONF_ENABLE_TIMEOUT, lambda x, y, z, a: runtime.dispatcher.dispatch("gconf_timeout_enabled_changed", z.value.get_bool()))
+ 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()))
def get_keybinding(self):
@@ -92,4 +123,4 @@ class GconfStore(object):
def set_notify_on_idle(self, enabled):
self._client.set_bool(self.GCONF_NOTIFY_ON_IDLE, enabled)
-
+
diff --git a/hamster/db.py b/hamster/db.py
index c969562..ddac00e 100644
--- a/hamster/db.py
+++ b/hamster/db.py
@@ -30,18 +30,54 @@ except ImportError:
except ImportError:
print "Error: Neither sqlite3 nor pysqlite2 found"
raise
+
import os, time
import datetime
-import hamster
-import hamster.storage
-from hamster import stuff
+import storage
+import stuff
+from shutil import copy as copyfile
import datetime as dt
-import copy
-
-class Storage(hamster.storage.Storage):
- # we are saving data under $HOME/.gnome2/hamster-applet/hamster.db
+import gettext
+
+DB_FILE = 'hamster.db'
+
+class Storage(storage.Storage):
con = None # Connection will be created on demand
+ def __setup(self):
+ """
+ Delayed setup so we don't do everything at the same time
+ """
+ if self.__setup.im_func.complete:
+ return
+
+ from configuration import runtime
+
+ db_file = runtime.database_file
+ db_path, _ = os.path.split(os.path.realpath(db_file))
+
+ if not os.path.exists(db_path):
+ try:
+ os.makedirs(db_path, 0744)
+ except Exception, msg:
+ print 'Error:could not create user dir (%s): %s' % (db_path, msg)
+
+ data_dir = runtime.data_dir
+
+ #check if db is here
+ if not os.path.exists(db_file):
+ print "Database not found in %s - installing default from %s!" % (db_file, data_dir)
+ copyfile(os.path.join(data_dir, DB_FILE), db_file)
+
+ #change also permissions - sometimes they are 444
+ try:
+ os.chmod(db_file, 0664)
+ except Exception, msg:
+ print 'Error:could not change mode on %s!' % (db_file)
+ self.__setup.im_func.complete = True
+ self.run_fixtures()
+ __setup.complete = False
+
def __get_category_list(self):
return self.fetchall("SELECT * FROM categories ORDER BY category_order")
@@ -628,8 +664,10 @@ class Storage(hamster.storage.Storage):
""" Here be dragons (lame connection/cursor wrappers) """
def get_connection(self):
+ from configuration import runtime
if self.con is None:
- self.con = sqlite.connect(hamster.HAMSTER_DB, detect_types=sqlite.PARSE_DECLTYPES|sqlite.PARSE_COLNAMES)
+ db_file = runtime.database_file
+ self.con = sqlite.connect(db_file, detect_types=sqlite.PARSE_DECLTYPES|sqlite.PARSE_COLNAMES)
self.con.row_factory = sqlite.Row
return self.con
@@ -637,10 +675,13 @@ class Storage(hamster.storage.Storage):
connection = property(get_connection, None)
def fetchall(self, query, params = None):
+ from configuration import runtime
+ self.__setup()
+
con = self.connection
cur = con.cursor()
- if hamster.trace_sql:
+ if runtime.trace_sql:
print query, params
if params:
@@ -661,8 +702,13 @@ class Storage(hamster.storage.Storage):
return None
def execute(self, statement, params = ()):
- """execute sql statement. optionally you can give multiple statements
- to save on cursor creation and closure"""
+ """
+ execute sql statement. optionally you can give multiple statements
+ to save on cursor creation and closure
+ """
+ from configuration import runtime
+ self.__setup()
+
con = self.connection
cur = con.cursor()
@@ -672,7 +718,7 @@ class Storage(hamster.storage.Storage):
if isinstance(statement, list):
for i in range(len(statement)):
- if hamster.trace_sql:
+ if runtime.trace_sql:
print statement[i], params[i]
res = cur.execute(statement[i], params[i])
@@ -881,7 +927,4 @@ class Storage(hamster.storage.Storage):
nonwork_cat_id = self.__add_category(nonwork_category["name"])
for entry in nonwork_category["entries"]:
self.__add_activity(entry, nonwork_cat_id)
-
-
-
diff --git a/hamster/edit_activity.py b/hamster/edit_activity.py
index 2861074..49192e5 100644
--- a/hamster/edit_activity.py
+++ b/hamster/edit_activity.py
@@ -25,9 +25,10 @@ import os
import gtk
import gobject
-from hamster import dispatcher, storage, SHARED_DATA_DIR, stuff
-from hamster import graphics, widgets
-import hamster.eds
+import stuff
+import graphics, widgets
+import eds
+from configuration import runtime
import time
import datetime as dt
@@ -330,7 +331,7 @@ class CustomFactController:
start_date, end_date = None, None
if fact_id:
- fact = storage.get_fact(fact_id)
+ fact = runtime.storage.get_fact(fact_id)
label = fact['name']
if fact['category'] != _("Unsorted"):
@@ -355,7 +356,7 @@ class CustomFactController:
elif fact_date and fact_date != dt.date.today():
# if there is previous activity with end time - attach to it
# otherwise let's start at 8am
- last_activity = storage.get_facts(fact_date)
+ last_activity = runtime.storage.get_facts(fact_date)
if last_activity and last_activity[len(last_activity)-1]["end_time"]:
start_date = last_activity[len(last_activity)-1]["end_time"]
else:
@@ -385,7 +386,7 @@ class CustomFactController:
self.dayline = Dayline()
self.dayline.on_time_changed = self.update_time
- self.dayline.on_more_data = storage.get_facts
+ self.dayline.on_more_data = runtime.storage.get_facts
self._gui.get_object("day_preview").add(self.dayline)
self.on_in_progress_toggled(self.get_widget("in_progress"))
@@ -399,7 +400,7 @@ class CustomFactController:
def draw_preview(self, date, highlight = None):
- day_facts = storage.get_facts(date)
+ day_facts = runtime.storage.get_facts(date)
self.dayline.draw(day_facts, highlight)
@@ -449,7 +450,7 @@ class CustomFactController:
def refresh_menu(self):
#first populate the autocomplete - contains all entries in lowercase
self.activities.clear()
- all_activities = storage.get_autocomplete_activities()
+ all_activities = runtime.storage.get_autocomplete_activities()
for activity in all_activities:
activity_category = activity['name']
if activity['category']:
@@ -464,7 +465,7 @@ class CustomFactController:
store.clear()
#populate fresh list from DB
- categorized_activities = storage.get_sorted_activities()
+ categorized_activities = runtime.storage.get_sorted_activities()
for activity in categorized_activities:
activity_category = activity['name']
@@ -475,7 +476,7 @@ class CustomFactController:
activity_category])
# finally add TODO tasks from evolution to both lists
- tasks = hamster.eds.get_eds_tasks()
+ tasks = eds.get_eds_tasks()
for activity in tasks:
activity_category = "%s %s" % (activity['name'], activity['category'])
self.activities.append([activity['name'],activity['category'],activity_category])
@@ -549,14 +550,14 @@ class CustomFactController:
# we don't do updates, we do insert/delete. So now it is time to delete
if self.fact_id:
- storage.remove_fact(self.fact_id)
+ runtime.storage.remove_fact(self.fact_id)
- storage.add_fact(activity, start_time, end_time)
+ runtime.storage.add_fact(activity, start_time, end_time)
# hide panel only on add - on update user will want to see changes
if not self.fact_id:
- dispatcher.dispatch('panel_visible', False)
+ runtime.dispatcher.dispatch('panel_visible', False)
self.close_window()
diff --git a/hamster/hamster-applet.py b/hamster/hamster-applet.py
index 41ed89b..42344c9 100755
--- a/hamster/hamster-applet.py
+++ b/hamster/hamster-applet.py
@@ -33,8 +33,8 @@ if os.path.exists(os.path.join(name, 'AUTHORS')):
sys.path.insert(0, name)
# Now the path is set, import our applet
-import hamster
from hamster import defs
+from hamster.configuration import runtime
# Setup i18n
locale_dir = os.path.abspath(os.path.join(defs.DATA_DIR, "locale"))
@@ -47,7 +47,6 @@ for module in (gettext, locale):
module.bind_textdomain_codeset('hamster-applet','UTF-8')
-hamster.__init_db()
from hamster.applet import HamsterApplet
def applet_factory(applet, iid):
@@ -56,11 +55,6 @@ def applet_factory(applet, iid):
hamster_applet = HamsterApplet(applet)
- applet.setup_menu_from_file(hamster.SHARED_DATA_DIR, "Hamster_Applet.xml",
- None, [("about", hamster_applet.on_about),
- ("overview", hamster_applet.show_overview),
- ("preferences", hamster_applet.show_preferences)])
-
applet.show_all()
applet.set_background_widget(applet)
@@ -68,12 +62,11 @@ def applet_factory(applet, iid):
def on_destroy(event):
from hamster.configuration import GconfStore
- config = GconfStore.get_instance()
+ config = GconfStore()
# handle config option to stop tracking on shutdown
if config.get_stop_on_shutdown():
- from hamster import storage
- last_activity = storage.get_last_activity()
+ last_activity = runtime.storage.get_last_activity()
if last_activity and last_activity['end_time'] is None:
storage.touch_fact(last_activity)
@@ -106,7 +99,7 @@ if __name__ == "__main__":
elif opt in ("-s", "--start"):
start_window = args
elif opt in ("-t", "--trace-sql"):
- hamster.trace_sql = True
+ runtime.trace_sql = True
except getopt.GetoptError:
@@ -131,13 +124,13 @@ if __name__ == "__main__":
elif start_window:
if start_window == "stats":
- from hamster.stats import StatsViewer
+ from stats import StatsViewer
stats_viewer = StatsViewer().show()
elif start_window == "edit":
- from hamster.edit_activity import CustomFactController
+ from edit_activity import CustomFactController
CustomFactController().show()
elif start_window == "prefs":
- from hamster.preferences import PreferencesEditor
+ from preferences import PreferencesEditor
PreferencesEditor().show()
gtk.main()
diff --git a/hamster/hamsterdbus.py b/hamster/hamsterdbus.py
index b86d84b..7725649 100644
--- a/hamster/hamsterdbus.py
+++ b/hamster/hamsterdbus.py
@@ -23,7 +23,7 @@ import dbus.service
import datetime
from calendar import timegm
-from hamster import storage
+from configuration import runtime
# DBus service parameters
HAMSTER_URI = "org.gnome.Hamster"
@@ -85,7 +85,7 @@ class HamsterDbusController(dbus.service.Object):
u start_time: Seconds since epoch (timestamp)
u end_time: Seconds since epoch (timestamp)
"""
- return HamsterDbusController.to_dbus_fact(storage.get_last_activity())
+ return HamsterDbusController.to_dbus_fact(runtime.storage.get_last_activity())
@dbus.service.method(HAMSTER_URI, in_signature='i', out_signature='a{sv}')
def GetFactById(self, fact_id):
@@ -100,7 +100,7 @@ class HamsterDbusController(dbus.service.Object):
u start_time: Seconds since epoch (timestamp)
u end_time: Seconds since epoch (timestamp)
"""
- return HamsterDbusController.to_dbus_fact(storage.get_fact(fact_id))
+ return HamsterDbusController.to_dbus_fact(runtime.storage.get_fact(fact_id))
@dbus.service.method(HAMSTER_URI, out_signature='a(ss)')
def GetActivities(self):
@@ -110,7 +110,7 @@ class HamsterDbusController(dbus.service.Object):
s category: Category name
"""
activities = []
- for act in storage.get_autocomplete_activities():
+ for act in runtime.storage.get_autocomplete_activities():
activities.append((act[ACT_KEY] or '', act[CAT_KEY] or ''))
return activities
@@ -121,7 +121,7 @@ class HamsterDbusController(dbus.service.Object):
s category: Category name
"""
categories = []
- for i in storage.get_category_list():
+ for i in runtime.storage.get_category_list():
categories.append(i[ACT_KEY] or '')
return categories
@@ -145,7 +145,7 @@ class HamsterDbusController(dbus.service.Object):
if end_time:
end = datetime.datetime.utcfromtimestamp(end_time)
- fact = storage.add_fact(activity, start, end)
+ fact = runtime.storage.add_fact(activity, start, end)
return fact[FCT_KEY]
@dbus.service.method(HAMSTER_URI, in_signature='ss')
@@ -159,10 +159,10 @@ class HamsterDbusController(dbus.service.Object):
category_id = None
if category:
- category_id = storage.get_category_by_name(category) \
- or storage.add_category(category)
+ category_id = runtime.storage.get_category_by_name(category) \
+ or runtime.storage.add_category(category)
- storage.add_activity(activity, category_id)
+ runtime.storage.add_activity(activity, category_id)
@dbus.service.method(HAMSTER_URI, in_signature='s')
def AddCategory(self, category):
@@ -170,15 +170,15 @@ class HamsterDbusController(dbus.service.Object):
Parameters:
s category: category name
"""
- if category and not storage.get_category_by_name(category):
- storage.add_category(category)
+ if category and not runtime.storage.get_category_by_name(category):
+ runtime.storage.add_category(category)
@dbus.service.method(HAMSTER_URI)
def StopTracking(self):
"""Stops the current fact tracking"""
- last_activity = storage.get_last_activity()
+ last_activity = runtime.storage.get_last_activity()
if last_activity:
- storage.touch_fact(last_activity)
+ runtime.storage.touch_fact(last_activity)
@dbus.service.method(HAMSTER_URI, in_signature='i')
def RemoveFact(self, fact_id):
@@ -186,7 +186,7 @@ class HamsterDbusController(dbus.service.Object):
Parameters:
i id: Unique fact identifier
"""
- storage.remove_fact(fact_id)
+ runtime.storage.remove_fact(fact_id)
@dbus.service.method(HAMSTER_URI, in_signature='ss')
def RemoveActivity(self, activity, category):
@@ -195,11 +195,11 @@ class HamsterDbusController(dbus.service.Object):
s activity: Activity name
s category: Category name. Use '' for Unsorted activity
"""
- category_id = storage.get_category_by_name(category)
- activity_id = storage.get_activity_by_name(activity, category_id)
+ category_id = runtime.storage.get_category_by_name(category)
+ activity_id = runtime.storage.get_activity_by_name(activity, category_id)
if activity_id:
- storage.remove_activity(activity_id)
+ runtime.storage.remove_activity(activity_id)
@dbus.service.method(HAMSTER_URI, in_signature='s')
def RemoveCategory(self, category):
@@ -207,9 +207,9 @@ class HamsterDbusController(dbus.service.Object):
Parameters:
s category: Category name
"""
- category_id = storage.get_category_by_name(category)
+ category_id = runtime.storage.get_category_by_name(category)
if category_id:
- storage.remove_category(category_id)
+ runtime.storage.remove_category(category_id)
@dbus.service.signal(HAMSTER_URI, signature='i')
def FactUpdated(self, fact_id):
diff --git a/hamster/preferences.py b/hamster/preferences.py
index 14a95e6..c7b0665 100755
--- a/hamster/preferences.py
+++ b/hamster/preferences.py
@@ -24,8 +24,8 @@ pygtk.require('2.0')
import os
import gtk
-from hamster import dispatcher, storage, SHARED_DATA_DIR, stuff
-from hamster.configuration import GconfStore
+import dispatcher, storage, stuff
+from configuration import GconfStore
def get_prev(selection, model):
(model, iter) = selection.get_selected()
@@ -92,7 +92,7 @@ class PreferencesEditor:
def __init__(self, parent = None):
self.parent = parent
self._gui = stuff.load_ui_file("preferences.ui")
- self.config = GconfStore.get_instance()
+ self.config = GconfStore()
self.window = self.get_widget('preferences_window')
diff --git a/hamster/reports.py b/hamster/reports.py
index cdfaef5..fcaf839 100644
--- a/hamster/reports.py
+++ b/hamster/reports.py
@@ -18,7 +18,7 @@
# You should have received a copy of the GNU General Public License
# along with Project Hamster. If not, see <http://www.gnu.org/licenses/>.
-from hamster import stuff, storage
+import stuff
import os
import datetime as dt
from xml.dom.minidom import Document
diff --git a/hamster/stats.py b/hamster/stats.py
index d207cfe..849abd9 100644
--- a/hamster/stats.py
+++ b/hamster/stats.py
@@ -25,11 +25,12 @@ import os
import gtk, gobject
import pango
-from hamster import dispatcher, storage, SHARED_DATA_DIR, stuff
-from hamster import charting
+import stuff
+import charting
-from hamster.edit_activity import CustomFactController
-from hamster import reports, widgets, graphics
+from edit_activity import CustomFactController
+import reports, widgets, graphics
+from configuration import runtime
import webbrowser
from itertools import groupby
@@ -119,7 +120,7 @@ class ReportChooserDialog(gtk.Dialog):
button_all.set_active(True)
self.category_box.pack_start(button_all)
- categories = storage.get_category_list()
+ categories = runtime.storage.get_category_list()
for category in categories:
button = gtk.RadioButton(button_all, category['name'].encode("utf-8"))
button.value = category['id']
@@ -374,13 +375,13 @@ class StatsViewer(object):
self.week_view.set_active(True)
- dispatcher.add_handler('activity_updated', self.after_activity_update)
- dispatcher.add_handler('day_updated', self.after_fact_update)
+ runtime.dispatcher.add_handler('activity_updated', self.after_activity_update)
+ runtime.dispatcher.add_handler('day_updated', self.after_fact_update)
selection = self.fact_tree.get_selection()
selection.connect('changed', self.on_fact_selection_changed,
self.fact_store)
- self.popular_categories = [cat[0] for cat in storage.get_popular_categories()]
+ self.popular_categories = [cat[0] for cat in runtime.storage.get_popular_categories()]
self._gui.connect_signals(self)
self.fact_tree.grab_focus()
@@ -394,7 +395,7 @@ class StatsViewer(object):
gtk.gdk.Color(*[int(b*65536.0) for b in self.background]))
if not self.stat_facts:
- self.stat_facts = storage.get_facts(dt.date(1970, 1, 1), dt.date.today())
+ self.stat_facts = runtime.storage.get_facts(dt.date(1970, 1, 1), dt.date.today())
by_year = self._totals(self.stat_facts,
lambda fact: fact["start_time"].year,
@@ -891,7 +892,7 @@ than 15 minutes you seem to be a busy bee." % ("<b>%d</b>" % short_percent))
def get_totals(self, facts, all_days):
# get list of used activities in interval
activities = [act[0] for act in
- storage.get_interval_activity_ids(self.start_date, self.end_date)]
+ runtime.storage.get_interval_activity_ids(self.start_date, self.end_date)]
# fill in the activity totals blanks
# don't want to add ability to be able to specify color per bar
@@ -977,7 +978,7 @@ than 15 minutes you seem to be a busy bee." % ("<b>%d</b>" % short_percent))
label2 = self.get_widget("dayview_caption")
label2.set_markup("%s" % (dayview_caption))
- fact_list = storage.get_facts(self.start_date, self.end_date)
+ fact_list = runtime.storage.get_facts(self.start_date, self.end_date)
self.get_facts(fact_list)
@@ -1114,7 +1115,7 @@ than 15 minutes you seem to be a busy bee." % ("<b>%d</b>" % short_percent))
if path > 0:
selection.select_path(path)
- storage.remove_fact(model[iter][0])
+ runtime.storage.remove_fact(model[iter][0])
def copy_selected(self):
selection = self.fact_tree.get_selection()
@@ -1178,7 +1179,7 @@ than 15 minutes you seem to be a busy bee." % ("<b>%d</b>" % short_percent))
# TODO - set cursor to the pasted entry when done
# TODO - revisit parsing of selected date
- added_fact = storage.add_fact(activity_name, start_time, end_time)
+ added_fact = runtime.storage.add_fact(activity_name, start_time, end_time)
"""keyboard events"""
@@ -1279,7 +1280,7 @@ than 15 minutes you seem to be a busy bee." % ("<b>%d</b>" % short_percent))
category):
self.report_chooser = None
- facts = storage.get_facts(start_date, end_date, category_id = category)
+ facts = runtime.storage.get_facts(start_date, end_date, category_id = category)
reports.simple(facts,
self.start_date,
self.end_date,
@@ -1309,8 +1310,8 @@ than 15 minutes you seem to be a busy bee." % ("<b>%d</b>" % short_percent))
self.do_graph()
def after_fact_update(self, event, date):
- self.stat_facts = storage.get_facts(dt.date(1970, 1, 1), dt.date.today())
- self.popular_categories = [cat[0] for cat in storage.get_popular_categories()]
+ self.stat_facts = runtime.storage.get_facts(dt.date(1970, 1, 1), dt.date.today())
+ self.popular_categories = [cat[0] for cat in runtime.storage.get_popular_categories()]
if self.get_widget("pages").get_current_page() == 0:
self.do_graph()
@@ -1318,8 +1319,8 @@ than 15 minutes you seem to be a busy bee." % ("<b>%d</b>" % short_percent))
self.stats()
def on_close(self, widget, event):
- dispatcher.del_handler('activity_updated', self.after_activity_update)
- dispatcher.del_handler('day_updated', self.after_fact_update)
+ runtime.dispatcher.del_handler('activity_updated', self.after_activity_update)
+ runtime.dispatcher.del_handler('day_updated', self.after_fact_update)
self.close_window()
def on_window_key_pressed(self, tree, event_key):
diff --git a/hamster/storage.py b/hamster/storage.py
index 05b1da1..1b3dfa0 100644
--- a/hamster/storage.py
+++ b/hamster/storage.py
@@ -24,7 +24,6 @@ import datetime
class Storage(object):
def __init__(self, parent):
self.parent = parent
- self.run_fixtures()
def run_fixtures(self):
pass
diff --git a/hamster/stuff.py b/hamster/stuff.py
index abe6b1d..88b2282 100644
--- a/hamster/stuff.py
+++ b/hamster/stuff.py
@@ -31,9 +31,9 @@ import locale
import os
def load_ui_file(name):
- from hamster import SHARED_DATA_DIR
+ from configuration import runtime
ui = gtk.Builder()
- ui.add_from_file(os.path.join(SHARED_DATA_DIR, name))
+ ui.add_from_file(os.path.join(runtime.data_dir, name))
return ui
def zero_hour(date):
diff --git a/hamster/widgets.py b/hamster/widgets.py
index cc3d63f..ec738a0 100644
--- a/hamster/widgets.py
+++ b/hamster/widgets.py
@@ -17,7 +17,7 @@
# You should have received a copy of the GNU General Public License
# along with Project Hamster. If not, see <http://www.gnu.org/licenses/>.
-from hamster.stuff import format_duration, figure_time
+from stuff import format_duration, figure_time
import gtk
import datetime as dt
import calendar
@@ -362,4 +362,4 @@ class TimeInput(gtk.Entry):
self.popup.show()
-
\ No newline at end of file
+
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]