[hamster-applet] moving utility modules into utils to have cleaner structure



commit d9eef340b687cde8ada4e14ebf893e2b0a23b6bb
Author: Toms Bauģis <toms baugis gmail com>
Date:   Sat Aug 21 14:08:33 2010 +0100

    moving utility modules into utils to have cleaner structure

 src/docky_control/2.0/hamster_control.py |    4 ++--
 src/docky_control/2.1/hamster_control.py |    4 ++--
 src/hamster-applet                       |    2 +-
 src/hamster-cli                          |    5 +++--
 src/hamster-service                      |    2 +-
 src/hamster-time-tracker                 |    8 ++++----
 src/hamster/applet.py                    |   15 +++++----------
 src/hamster/client.py                    |    2 +-
 src/hamster/configuration.py             |    6 ++++--
 src/hamster/db.py                        |    2 +-
 src/hamster/edit_activity.py             |   12 ++++++------
 src/hamster/overview.py                  |   10 +++++-----
 src/hamster/overview_activities.py       |    5 +++--
 src/hamster/overview_totals.py           |   13 ++++++-------
 src/hamster/preferences.py               |    4 ++--
 src/hamster/reports.py                   |    4 ++--
 src/hamster/stats.py                     |    9 +++++----
 src/hamster/{ => utils}/charting.py      |    0
 src/hamster/{ => utils}/graphics.py      |    0
 src/hamster/{ => utils}/i18n.py          |    0
 src/hamster/{ => utils}/pytweener.py     |    0
 src/hamster/{ => utils}/stuff.py         |    6 ------
 src/hamster/{ => utils}/trophies.py      |    0
 src/hamster/widgets/activityentry.py     |    3 +--
 src/hamster/widgets/dateinput.py         |    1 -
 src/hamster/widgets/dayline.py           |    3 +--
 src/hamster/widgets/facttree.py          |    5 ++---
 src/hamster/widgets/rangepick.py         |    6 +++---
 src/hamster/widgets/tags.py              |    2 +-
 src/hamster/widgets/timechart.py         |    2 +-
 src/hamster/widgets/timeinput.py         |    3 +--
 31 files changed, 63 insertions(+), 75 deletions(-)
---
diff --git a/src/docky_control/2.0/hamster_control.py b/src/docky_control/2.0/hamster_control.py
index 708e5a0..f0acd33 100755
--- a/src/docky_control/2.0/hamster_control.py
+++ b/src/docky_control/2.0/hamster_control.py
@@ -32,8 +32,8 @@ from signal import signal, SIGTERM
 from sys import exit
 
 
-from hamster import client, stuff
-from hamster import i18n
+from hamster import client
+from hamster.utils import stuff, i18n
 i18n.setup_i18n()
 
 
diff --git a/src/docky_control/2.1/hamster_control.py b/src/docky_control/2.1/hamster_control.py
index d810f9b..2456191 100755
--- a/src/docky_control/2.1/hamster_control.py
+++ b/src/docky_control/2.1/hamster_control.py
@@ -36,8 +36,8 @@ except ImportError, e:
 	exit()
 
 
-from hamster import client, stuff
-from hamster import i18n
+from hamster import client
+from hamster.utils import stuff, i18n
 i18n.setup_i18n()
 
 
diff --git a/src/hamster-applet b/src/hamster-applet
index 86e053b..fa9950a 100755
--- a/src/hamster-applet
+++ b/src/hamster-applet
@@ -90,7 +90,7 @@ if __name__ == "__main__":
                             format = log_format)
 
     try:
-        from hamster import i18n
+        from hamster.utils import i18n
         i18n.setup_i18n()
 
         from hamster.configuration import runtime, dialogs
diff --git a/src/hamster-cli b/src/hamster-cli
index 5142a1c..3fc2c9d 100755
--- a/src/hamster-cli
+++ b/src/hamster-cli
@@ -26,7 +26,8 @@ import optparse
 import re
 import datetime as dt
 
-from hamster import client, stuff
+from hamster import client
+from hamster.utils import stuff
 
 class ConfigurationError(Exception):
     '''An error of configuration.'''
@@ -211,7 +212,7 @@ def fact_dict(fact_data, with_date):
 
 
 if __name__ == '__main__':
-    from hamster import i18n
+    from hamster.utils import i18n
     i18n.setup_i18n()
 
     usage = _(
diff --git a/src/hamster-service b/src/hamster-service
index 93f63d8..cad1590 100755
--- a/src/hamster-service
+++ b/src/hamster-service
@@ -13,7 +13,7 @@ if "org.gnome.Hamster" in dbus.SessionBus().list_names():
 
 
 if __name__ == '__main__':
-    from hamster import i18n
+    from hamster.utils import i18n
     i18n.setup_i18n()
 
     from hamster import db
diff --git a/src/hamster-time-tracker b/src/hamster-time-tracker
index 9b6581d..946eaf4 100755
--- a/src/hamster-time-tracker
+++ b/src/hamster-time-tracker
@@ -28,7 +28,7 @@ import dbus, dbus.service, dbus.mainloop.glib
 class ProjectHamster(object):
     def __init__(self, window_name = None):
         # load window of activity switcher and todays view
-        self._gui = stuff.load_ui_file("hamster.ui")
+        self._gui = load_ui_file("hamster.ui")
         self.window = self._gui.get_object('hamster-window')
         self.window.connect("delete_event", self.close_window)
 
@@ -479,7 +479,7 @@ class WindowServer(dbus.service.Object):
 
 
 if __name__ == "__main__":
-    from hamster import i18n
+    from hamster.utils import i18n
     i18n.setup_i18n()
 
     # determine the window we will be launching
@@ -501,7 +501,7 @@ if __name__ == "__main__":
         storage.toggle()
         sys.exit()
 
-    from hamster.configuration import runtime, dialogs, conf
+    from hamster.configuration import runtime, dialogs, conf, load_ui_file
 
     # if there is windowserver hanging in dbus - call that and exit
     bus = dbus.SessionBus()
@@ -515,7 +515,7 @@ if __name__ == "__main__":
     gtk.gdk.threads_init()
     gtk.window_set_default_icon_name("hamster-applet")
 
-    from hamster import stuff, widgets, idle, trophies
+    from hamster.utils import stuff, widgets, idle, trophies
 
     try:
         import wnck
diff --git a/src/hamster/applet.py b/src/hamster/applet.py
index 9ab5b5d..d747202 100755
--- a/src/hamster/applet.py
+++ b/src/hamster/applet.py
@@ -24,22 +24,17 @@ import datetime as dt
 
 import pygtk
 pygtk.require("2.0")
-import gtk
+import gtk, pango
 
 import gnomeapplet
 import gobject
 import dbus, dbus.service, dbus.mainloop.glib
 import locale
 
-from configuration import conf, runtime, dialogs
+from configuration import conf, runtime, dialogs, load_ui_file
 
-import stuff, trophies
-
-# controllers for other windows
-import widgets
-import idle
-
-import pango
+import widgets, idle
+from utils import stuff, trophies
 
 try:
     import wnck
@@ -194,7 +189,7 @@ class HamsterApplet(object):
                                           ])
 
         # load window of activity switcher and todays view
-        self._gui = stuff.load_ui_file("applet.ui")
+        self._gui = load_ui_file("applet.ui")
         self.window = self._gui.get_object('hamster-window')
         # on close don't destroy the popup, just hide it instead
         self.window.connect("delete_event", lambda *args: self.__show_toggle(False))
diff --git a/src/hamster/client.py b/src/hamster/client.py
index 0f558a1..6fad885 100644
--- a/src/hamster/client.py
+++ b/src/hamster/client.py
@@ -23,7 +23,7 @@ import datetime as dt
 from calendar import timegm
 import dbus, dbus.mainloop.glib
 import gobject
-from trophies import checker
+from utils.trophies import checker
 
 
 def from_dbus_fact(fact):
diff --git a/src/hamster/configuration.py b/src/hamster/configuration.py
index 0248505..f4aafee 100644
--- a/src/hamster/configuration.py
+++ b/src/hamster/configuration.py
@@ -148,8 +148,10 @@ class Dialogs(Singleton):
 dialogs = Dialogs()
 
 
-
-
+def load_ui_file(name):
+    ui = gtk.Builder()
+    ui.add_from_file(os.path.join(runtime.data_dir, name))
+    return ui
 
 class GConfStore(gobject.GObject, Singleton):
     """
diff --git a/src/hamster/db.py b/src/hamster/db.py
index 6ad68aa..1925d7f 100644
--- a/src/hamster/db.py
+++ b/src/hamster/db.py
@@ -35,7 +35,7 @@ except ImportError:
 import os, time
 import datetime
 import storage
-import stuff
+from utils import stuff
 from shutil import copy as copyfile
 import datetime as dt
 import gio
diff --git a/src/hamster/edit_activity.py b/src/hamster/edit_activity.py
index 284e63d..d80fb7b 100644
--- a/src/hamster/edit_activity.py
+++ b/src/hamster/edit_activity.py
@@ -21,17 +21,17 @@ import gtk
 import time
 import datetime as dt
 
-""" TODO:
-     * hook into notifications and refresh our days if some evil neighbour edit
-       fact window has dared to edit facts
+""" TODO: hook into notifications and refresh our days if some evil neighbour
+          edit fact window has dared to edit facts
 """
-from configuration import runtime, conf
-import stuff, widgets
+import widgets
+from configuration import runtime, conf, load_ui_file
+from utils import stuff
 
 class CustomFactController:
     def __init__(self,  parent = None, fact_date = None, fact_id = None):
 
-        self._gui = stuff.load_ui_file("edit_activity.ui")
+        self._gui = load_ui_file("edit_activity.ui")
         self.window = self.get_widget('custom_fact_window')
 
         self.parent, self.fact_id = parent, fact_id
diff --git a/src/hamster/overview.py b/src/hamster/overview.py
index 9f2b537..dfcf394 100644
--- a/src/hamster/overview.py
+++ b/src/hamster/overview.py
@@ -29,10 +29,10 @@ import webbrowser
 import gtk, gobject
 import pango
 
-import stuff
-from i18n import C_
-from configuration import runtime, conf, dialogs
-import widgets, reports, trophies
+import widgets, reports
+from configuration import runtime, conf, dialogs, load_ui_file
+from utils import stuff, trophies
+from utils.i18n import C_
 
 from overview_activities import OverviewBox
 from overview_totals import TotalsBox
@@ -41,7 +41,7 @@ from overview_totals import TotalsBox
 class Overview(object):
     def __init__(self, parent = None):
         self.parent = parent# determine if app should shut down on close
-        self._gui = stuff.load_ui_file("overview.ui")
+        self._gui = load_ui_file("overview.ui")
         self.report_chooser = None
 
         self.facts = None
diff --git a/src/hamster/overview_activities.py b/src/hamster/overview_activities.py
index f34e7e3..2d0dffe 100644
--- a/src/hamster/overview_activities.py
+++ b/src/hamster/overview_activities.py
@@ -34,9 +34,10 @@ import calendar
 import time
 from collections import defaultdict
 
-import stuff, widgets, trophies
-from i18n import C_
+import widgets
 from configuration import runtime, dialogs
+from utils import stuff, trophies
+from utils.i18n import C_
 
 
 class OverviewBox(gtk.VBox):
diff --git a/src/hamster/overview_totals.py b/src/hamster/overview_totals.py
index 9263a5a..bb3d6e1 100644
--- a/src/hamster/overview_totals.py
+++ b/src/hamster/overview_totals.py
@@ -28,19 +28,18 @@ from gettext import ngettext
 
 import os
 import gtk, gobject
-
-import stuff, widgets
-import charting, reports
-from configuration import runtime, dialogs
-
-from hamster.i18n import C_
 from collections import defaultdict
 
+import widgets, reports
+from configuration import runtime, dialogs, load_ui_file
+from utils import stuff, charting
+from utils.i18n import C_
+
 
 class TotalsBox(gtk.VBox):
     def __init__(self):
         gtk.VBox.__init__(self)
-        self._gui = stuff.load_ui_file("overview_totals.ui")
+        self._gui = load_ui_file("overview_totals.ui")
         self.get_widget("reports_vbox").reparent(self) #mine!
 
         self.start_date, self.end_date = None, None
diff --git a/src/hamster/preferences.py b/src/hamster/preferences.py
index 9a80587..9b6de13 100755
--- a/src/hamster/preferences.py
+++ b/src/hamster/preferences.py
@@ -83,7 +83,7 @@ class WorkspaceStore(gtk.ListStore):
 formats = ["fixed", "symbolic", "minutes"]
 appearances = ["text", "icon", "both"]
 
-from configuration import runtime, conf
+from configuration import runtime, conf, load_ui_file
 import widgets
 import storage, stuff, trophies
 
@@ -96,7 +96,7 @@ class PreferencesEditor:
 
     def __init__(self, parent = None):
         self.parent = parent
-        self._gui = stuff.load_ui_file("preferences.ui")
+        self._gui = load_ui_file("preferences.ui")
         self.window = self.get_widget('preferences_window')
 
         # Translators: 'None' refers here to the Todo list choice in Hamster preferences (Tracking tab)
diff --git a/src/hamster/reports.py b/src/hamster/reports.py
index af11122..743a402 100644
--- a/src/hamster/reports.py
+++ b/src/hamster/reports.py
@@ -27,9 +27,9 @@ import itertools
 import re
 from string import Template
 
-from i18n import C_
 from configuration import runtime
-import stuff, trophies
+from utils import stuff, trophies
+from utils.i18n import C_
 
 def simple(facts, start_date, end_date, format, path):
     facts = copy.deepcopy(facts) # dont want to do anything bad to the input
diff --git a/src/hamster/stats.py b/src/hamster/stats.py
index 810a0a1..2a00e5e 100644
--- a/src/hamster/stats.py
+++ b/src/hamster/stats.py
@@ -32,14 +32,15 @@ import math
 import gtk, gobject
 import pango
 
-import stuff, charting, graphics, widgets
-from configuration import runtime, conf
+import widgets
+from utils import stuff, charting, graphics
+from configuration import runtime, conf, load_ui_file
 
-from hamster.i18n import C_
+from utils.i18n import C_
 
 class Stats(object):
     def __init__(self, parent = None):
-        self._gui = stuff.load_ui_file("stats.ui")
+        self._gui = load_ui_file("stats.ui")
         self.report_chooser = None
         self.window = self.get_widget("stats_window")
 
diff --git a/src/hamster/utils/__init__.py b/src/hamster/utils/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/src/hamster/charting.py b/src/hamster/utils/charting.py
similarity index 100%
rename from src/hamster/charting.py
rename to src/hamster/utils/charting.py
diff --git a/src/hamster/graphics.py b/src/hamster/utils/graphics.py
similarity index 100%
rename from src/hamster/graphics.py
rename to src/hamster/utils/graphics.py
diff --git a/src/hamster/i18n.py b/src/hamster/utils/i18n.py
similarity index 100%
rename from src/hamster/i18n.py
rename to src/hamster/utils/i18n.py
diff --git a/src/hamster/pytweener.py b/src/hamster/utils/pytweener.py
similarity index 100%
rename from src/hamster/pytweener.py
rename to src/hamster/utils/pytweener.py
diff --git a/src/hamster/stuff.py b/src/hamster/utils/stuff.py
similarity index 98%
rename from src/hamster/stuff.py
rename to src/hamster/utils/stuff.py
index cf0dcc9..bcff4d1 100644
--- a/src/hamster/stuff.py
+++ b/src/hamster/utils/stuff.py
@@ -130,12 +130,6 @@ def duration_minutes(duration):
         return duration
 
 
-def load_ui_file(name):
-    from configuration import runtime
-    ui = gtk.Builder()
-    ui.add_from_file(os.path.join(runtime.data_dir, name))
-    return ui
-
 def zero_hour(date):
     return dt.datetime.combine(date.date(), dt.time(0,0))
 
diff --git a/src/hamster/trophies.py b/src/hamster/utils/trophies.py
similarity index 100%
rename from src/hamster/trophies.py
rename to src/hamster/utils/trophies.py
diff --git a/src/hamster/widgets/activityentry.py b/src/hamster/widgets/activityentry.py
index 228b589..0ad67e9 100644
--- a/src/hamster/widgets/activityentry.py
+++ b/src/hamster/widgets/activityentry.py
@@ -21,8 +21,7 @@ import gtk, gobject, pango
 import datetime as dt
 
 from ..configuration import runtime
-from .. import stuff, graphics
-from ..stuff import format_duration
+from ..utils import stuff, graphics
 from .. import external
 
 class ActivityEntry(gtk.Entry):
diff --git a/src/hamster/widgets/dateinput.py b/src/hamster/widgets/dateinput.py
index 45b6bc9..37cede8 100644
--- a/src/hamster/widgets/dateinput.py
+++ b/src/hamster/widgets/dateinput.py
@@ -17,7 +17,6 @@
 # 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 ..stuff import format_duration
 import gtk
 import datetime as dt
 import calendar
diff --git a/src/hamster/widgets/dayline.py b/src/hamster/widgets/dayline.py
index 95f3927..026929d 100644
--- a/src/hamster/widgets/dayline.py
+++ b/src/hamster/widgets/dayline.py
@@ -23,8 +23,7 @@ import gobject
 import time
 import datetime as dt
 
-from .. import stuff
-from .. import graphics, pytweener
+from ..utils import stuff, graphics, pytweener
 from ..configuration import conf
 
 
diff --git a/src/hamster/widgets/facttree.py b/src/hamster/widgets/facttree.py
index dabd969..726945e 100644
--- a/src/hamster/widgets/facttree.py
+++ b/src/hamster/widgets/facttree.py
@@ -23,9 +23,8 @@ import gtk, gobject
 import cairo
 import datetime as dt
 
-from .. import stuff, graphics
-from ..stuff import format_duration
-from .tags import Tag
+from ..utils import stuff, graphics
+from tags import Tag
 
 import pango
 
diff --git a/src/hamster/widgets/rangepick.py b/src/hamster/widgets/rangepick.py
index 55acee5..ba77096 100644
--- a/src/hamster/widgets/rangepick.py
+++ b/src/hamster/widgets/rangepick.py
@@ -17,8 +17,8 @@
 # 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 .. import stuff
-
+from ..utils import stuff
+from ..configuration import load_ui_file
 
 import gtk, gobject, pango
 import datetime as dt
@@ -37,7 +37,7 @@ class RangePick(gtk.ToggleButton):
     def __init__(self, date = None):
         gtk.ToggleButton.__init__(self)
 
-        self._gui = stuff.load_ui_file("range_pick.ui")
+        self._gui = load_ui_file("range_pick.ui")
         self.popup = self.get_widget("range_popup")
 
         hbox = gtk.HBox()
diff --git a/src/hamster/widgets/tags.py b/src/hamster/widgets/tags.py
index 67b743a..361b69a 100644
--- a/src/hamster/widgets/tags.py
+++ b/src/hamster/widgets/tags.py
@@ -21,7 +21,7 @@ import gtk, gobject
 import pango, cairo
 from math import pi
 
-from .. import graphics
+from ..utils import graphics
 from ..configuration import runtime
 
 class TagsEntry(gtk.Entry):
diff --git a/src/hamster/widgets/timechart.py b/src/hamster/widgets/timechart.py
index 6bf5451..1b18752 100644
--- a/src/hamster/widgets/timechart.py
+++ b/src/hamster/widgets/timechart.py
@@ -20,7 +20,7 @@
 import os  # for locale
 import gobject, gtk, pango
 
-from .. import graphics, stuff
+from ..utils import graphics, stuff
 
 import time, datetime as dt
 import calendar
diff --git a/src/hamster/widgets/timeinput.py b/src/hamster/widgets/timeinput.py
index a5e3b39..5628acb 100644
--- a/src/hamster/widgets/timeinput.py
+++ b/src/hamster/widgets/timeinput.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 ..stuff import format_duration
+from ..utils.stuff import format_duration
 import gtk
 from gtk import keysyms
 import datetime as dt
@@ -265,4 +265,3 @@ class TimeInput(gtk.Entry):
             self.show_popup()
 
         return True
-



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]