[hamster-applet] brought SingleWindow from billreminder and tuned it up some more. fixes bug 566509
- From: Toms Baugis <tbaugis src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [hamster-applet] brought SingleWindow from billreminder and tuned it up some more. fixes bug 566509
- Date: Sat, 26 Dec 2009 03:12:09 +0000 (UTC)
commit 3bb3f0b8605b77e166393039110f2e2663aeeb04
Author: Toms Bauģis <toms baugis gmail com>
Date: Sat Dec 26 03:11:36 2009 +0000
brought SingleWindow from billreminder and tuned it up some more. fixes bug 566509
hamster/about.py | 62 +++++++++++++++++++++------------------------
hamster/applet.py | 31 ++++++----------------
hamster/configuration.py | 45 ++++++++++++++++++++++++++++++++
hamster/edit_activity.py | 19 ++++++-------
hamster/hamster-applet.py | 11 +++-----
hamster/preferences.py | 12 +++++---
hamster/stats.py | 33 +++++++++--------------
hamster/stats_overview.py | 10 ++-----
8 files changed, 118 insertions(+), 105 deletions(-)
---
diff --git a/hamster/about.py b/hamster/about.py
index 77acc7d..4eaff13 100644
--- a/hamster/about.py
+++ b/hamster/about.py
@@ -31,39 +31,35 @@ def on_url(about, link):
gtk.about_dialog_set_email_hook(on_email)
gtk.about_dialog_set_url_hook(on_url)
-def show_about(parent):
- about = gtk.AboutDialog()
- infos = {
- "program-name" : _("Time Tracker"),
- "name" : _("Time Tracker"), #this should be deprecated in gtk 2.10
- "version" : VERSION,
- "comments" : _("Project Hamster â?? track your time"),
- "copyright" : _(u"Copyright © 2007â??2009 Toms BauÄ£is and others"),
- "website" : "http://projecthamster.wordpress.com/",
- "website-label" : _("Project Hamster Website"),
- "title": _("About Time Tracker"),
- "wrap-license": True
- }
+class About(object):
+ def __init__(self, parent = None):
+ about = gtk.AboutDialog()
+ self.window = about
+ infos = {
+ "program-name" : _("Time Tracker"),
+ "name" : _("Time Tracker"), #this should be deprecated in gtk 2.10
+ "version" : VERSION,
+ "comments" : _("Project Hamster â?? track your time"),
+ "copyright" : _(u"Copyright © 2007â??2009 Toms BauÄ£is and others"),
+ "website" : "http://projecthamster.wordpress.com/",
+ "website-label" : _("Project Hamster Website"),
+ "title": _("About Time Tracker"),
+ "wrap-license": True
+ }
+
+ about.set_authors(["Toms Bauģis <toms baugis gmail com>",
+ "Patryk Zawadzki <patrys pld-linux org>",
+ "PÄ?teris Caune <cuu508 gmail com>",
+ "Juanje Ojeda <jojeda emergya es>"])
+ about.set_artists(["Kalle Persson <kalle kallepersson se>"])
+
+ about.set_translator_credits(_("translator-credits"))
- about.set_authors(["Toms Bauģis <toms baugis gmail com>",
- "Patryk Zawadzki <patrys pld-linux org>",
- "PÄ?teris Caune <cuu508 gmail com>",
- "Juanje Ojeda <jojeda emergya es>"])
- about.set_artists(["Kalle Persson <kalle kallepersson se>"])
+ for prop, val in infos.items():
+ about.set_property(prop, val)
- about.set_translator_credits(_("translator-credits"))
-
- for prop, val in infos.items():
- about.set_property(prop, val)
-
- about.set_logo_icon_name("hamster-applet")
-
- def on_destroy():
- parent.about = None
-
- about.connect("response", lambda self, *args: self.destroy())
- about.connect("destroy", lambda self, *args: on_destroy())
- about.set_screen(parent.get_screen())
- about.show_all()
- parent.about = about
+ about.set_logo_icon_name("hamster-applet")
+
+ about.connect("response", lambda self, *args: self.destroy())
+ about.show_all()
diff --git a/hamster/applet.py b/hamster/applet.py
index c457e69..2841eb5 100755
--- a/hamster/applet.py
+++ b/hamster/applet.py
@@ -32,17 +32,13 @@ import gobject
import dbus, dbus.service, dbus.mainloop.glib
import eds
-from configuration import GconfStore, runtime
+from configuration import GconfStore, runtime, dialogs
import stuff
from KeyBinder import *
from hamsterdbus import HAMSTER_URI, HamsterDbusController
# controllers for other windows
-from edit_activity import CustomFactController
-from stats import StatsViewer
-from about import show_about
-from preferences import PreferencesEditor
import widgets
import idle
@@ -378,8 +374,7 @@ class HamsterApplet(object):
self.notify.msg_low(_(u"No activity"))
def edit_cb(self, n, action):
- custom_fact = CustomFactController(self, None, self.last_activity['id'])
- custom_fact.show()
+ dialogs.edit.show(self.applet, activity_id = self.last_activity['id'])
def switch_cb(self, n, action):
self.__show_toggle(None, not self.button.get_active())
@@ -518,8 +513,7 @@ class HamsterApplet(object):
def _open_edit_activity(self, row, fact):
"""opens activity editor for selected row"""
- custom_fact = CustomFactController(self, None, fact["id"])
- custom_fact.show()
+ dialogs.edit.show(self.applet, fact_id = fact["id"])
def on_today_row_activated(self, tree, path, column):
selection = tree.get_selection()
@@ -552,30 +546,21 @@ class HamsterApplet(object):
"""button events"""
def on_overview(self, menu_item):
runtime.dispatcher.dispatch('panel_visible', False)
- stats_viewer = StatsViewer(self)
- stats_viewer.show()
+ dialogs.stats.show(self.applet)
def show_overview(self, menu_item, verb):
return self.on_overview(menu_item)
def on_custom_fact(self, menu_item):
- custom_fact = CustomFactController(self)
- custom_fact.show()
+ dialogs.edit.show(self.applet)
def on_about (self, component, verb):
- if self.applet.about:
- self.applet.about.present()
- else:
- show_about(self.applet)
+ dialogs.about.show()
def show_preferences(self, menu_item, verb):
runtime.dispatcher.dispatch('panel_visible', False)
-
- if self.preferences_editor and self.preferences_editor.window:
- self.preferences_editor.window.present()
- else:
- self.preferences_editor = PreferencesEditor(self)
- self.preferences_editor.show()
+ dialogs.prefs.show(self.applet)
+
"""signals"""
def after_activity_update(self, widget, renames):
diff --git a/hamster/configuration.py b/hamster/configuration.py
index 5a24b55..08e539e 100644
--- a/hamster/configuration.py
+++ b/hamster/configuration.py
@@ -109,6 +109,51 @@ class RuntimeStore(Singleton):
runtime = RuntimeStore()
+class OneWindow(object):
+ def __init__(self, dialog_class):
+ self.dialogs = {}
+ self.dialog_class = dialog_class
+
+ def on_dialog_destroy(self, params):
+ del self.dialogs[params]
+ #self.dialogs[params] = None
+
+ def show(self, parent = None, **kwargs):
+ params = str(sorted(kwargs.items())) #this is not too safe but will work for most cases
+
+ if params in self.dialogs:
+ self.dialogs[params].window.present()
+ else:
+ if parent:
+ dialog = self.dialog_class(parent, **kwargs)
+ dialog.window.set_transient_for(parent.get_toplevel())
+ else:
+ dialog = self.dialog_class(**kwargs)
+
+ # to make things simple, we hope that the target has defined self.window
+ dialog.window.connect("destroy",
+ lambda window, params: self.on_dialog_destroy(params),
+ params)
+
+ self.dialogs[params] = dialog
+
+class Dialogs(Singleton):
+ """makes sure that we have single instance open for windows where it makes
+ sense"""
+ def __init__(self):
+ from edit_activity import CustomFactController
+ self.edit = OneWindow(CustomFactController)
+
+ from stats import StatsViewer
+ self.stats = OneWindow(StatsViewer)
+
+ from about import About
+ self.about = OneWindow(About)
+
+ from preferences import PreferencesEditor
+ self.prefs = OneWindow(PreferencesEditor)
+
+dialogs = Dialogs()
class GconfStore(Singleton):
"""
diff --git a/hamster/edit_activity.py b/hamster/edit_activity.py
index 6d6d0c8..7b9a685 100644
--- a/hamster/edit_activity.py
+++ b/hamster/edit_activity.py
@@ -21,16 +21,16 @@ import gtk
import time
import datetime as dt
-import stuff, widgets
-from configuration import runtime
-
-
""" TODO:
* hook into notifications and refresh our days if some evil neighbour edit
fact window has dared to edit facts
"""
+from configuration import runtime
+
class CustomFactController:
def __init__(self, parent = None, fact_date = None, fact_id = None):
+ import stuff, widgets
+
self._gui = stuff.load_ui_file("edit_activity.ui")
self.window = self.get_widget('custom_fact_window')
@@ -117,6 +117,8 @@ class CustomFactController:
self.new_name.connect("changed", self.on_new_name_changed)
self.end_time.connect("time-entered", self.on_end_time_entered)
self._gui.connect_signals(self)
+
+ self.window.show_all()
def update_time(self, start_time, end_time):
self.start_time.set_time(start_time)
@@ -275,9 +277,6 @@ class CustomFactController:
self.close_window()
def close_window(self):
- if not self.parent:
- gtk.main_quit()
- else:
- self.window.destroy()
- return False
-
+ self.window.destroy()
+ return False
+
diff --git a/hamster/hamster-applet.py b/hamster/hamster-applet.py
index e4245d2..ad6f0da 100755
--- a/hamster/hamster-applet.py
+++ b/hamster/hamster-applet.py
@@ -99,7 +99,7 @@ if __name__ == "__main__":
# Now the path is set, import our applet
from hamster import defs
- from hamster.configuration import runtime
+ from hamster.configuration import runtime, dialogs
# Setup i18n
locale_dir = os.path.abspath(os.path.join(defs.DATA_DIR, "locale"))
@@ -115,16 +115,13 @@ if __name__ == "__main__":
if options.start_window or options.standalone:
gobject.set_application_name("hamster-applet")
if options.start_window == "stats":
- from hamster.stats import StatsViewer
- stats_viewer = StatsViewer().show()
+ dialogs.stats.show()
elif options.start_window == "edit":
- from hamster.edit_activity import CustomFactController
- CustomFactController().show()
+ dialogs.edit.show()
elif options.start_window == "prefs":
- from hamster.preferences import PreferencesEditor
- PreferencesEditor().show()
+ dialogs.prefs.show()
else: #default to main applet
gnome.init(defs.PACKAGE, defs.VERSION)
diff --git a/hamster/preferences.py b/hamster/preferences.py
index 858fbab..3e2ecb7 100755
--- a/hamster/preferences.py
+++ b/hamster/preferences.py
@@ -24,12 +24,7 @@ pygtk.require('2.0')
import os
import gtk
-import dispatcher, storage, stuff
-
import datetime as dt
-import widgets
-
-from configuration import GconfStore, runtime
def get_prev(selection, model):
(model, iter) = selection.get_selected()
@@ -86,6 +81,8 @@ class ActivityStore(gtk.ListStore):
formats = ["fixed", "symbolic", "minutes"]
appearances = ["text", "icon", "both"]
+from configuration import runtime
+
class PreferencesEditor:
TARGETS = [
('MY_TREE_MODEL_ROW', gtk.TARGET_SAME_WIDGET, 0),
@@ -94,6 +91,10 @@ class PreferencesEditor:
def __init__(self, parent = None):
+ import widgets
+ import dispatcher, storage, stuff
+ from configuration import GconfStore
+
self.parent = parent
self._gui = stuff.load_ui_file("preferences.ui")
self.config = GconfStore()
@@ -181,6 +182,7 @@ class PreferencesEditor:
self.get_widget("notification_preference_frame").hide()
self._gui.connect_signals(self)
+ self.window.show_all()
def load_config(self):
self.get_widget("shutdown_track").set_active(self.config.get_stop_on_shutdown())
diff --git a/hamster/stats.py b/hamster/stats.py
index 4e1f197..76b2109 100644
--- a/hamster/stats.py
+++ b/hamster/stats.py
@@ -22,28 +22,23 @@ import pygtk
pygtk.require('2.0')
import os
+import datetime as dt
+import calendar
+
import gtk, gobject
import pango
import stuff
-
-from configuration import runtime, GconfStore
-
-from stats_overview import OverviewBox
-from stats_reports import ReportsBox
-from stats_stats import StatsBox
-
-import widgets
-import charting
-import datetime as dt
-import calendar
-
from hamster.i18n import C_
-from edit_activity import CustomFactController
-
+from configuration import runtime
class StatsViewer(object):
def __init__(self, parent = None):
+ import widgets
+ from stats_overview import OverviewBox
+ from stats_reports import ReportsBox
+ from stats_stats import StatsBox
+
self.parent = parent# determine if app should shut down on close
self._gui = stuff.load_ui_file("stats.ui")
@@ -245,8 +240,8 @@ class StatsViewer(object):
if iter and model[iter][6]: # TODO - here we should check if heading maybe specifies a date
selected_date = model[iter][6]["date"]
- custom_fact = CustomFactController(self, selected_date)
- custom_fact.show()
+ from configuration import dialogs
+ dialogs.edit.show(fact_date = selected_date)
def on_remove_clicked(self, button):
self.delete_selected()
@@ -258,10 +253,8 @@ class StatsViewer(object):
if model[iter][0] == -1:
return #not a fact
- custom_fact = CustomFactController(self, None, model[iter][0])
- custom_fact.show()
-
-
+ from configuration import dialogs
+ dialogs.edit.show(fact_id = model[iter][0])
def on_close(self, widget, event):
diff --git a/hamster/stats_overview.py b/hamster/stats_overview.py
index 3631bf3..7ea86d1 100644
--- a/hamster/stats_overview.py
+++ b/hamster/stats_overview.py
@@ -26,11 +26,9 @@ import gtk, gobject
import stuff
-from edit_activity import CustomFactController
-
import widgets
-from configuration import runtime
+from configuration import runtime, dialogs
import webbrowser
from itertools import groupby
@@ -135,14 +133,12 @@ class OverviewBox(gtk.VBox):
if model[iter][0] == -1:
return #not a fact
- custom_fact = CustomFactController(self, None, model[iter][0])
- custom_fact.show()
+ dialogs.edit.show(self, fact_id = model[iter][0])
def on_facts_row_activated(self, tree, path, column):
selection = tree.get_selection()
(model, iter) = selection.get_selected()
- custom_fact = CustomFactController(self, None, model[iter][0])
- custom_fact.show()
+ custom_fact = dialogs.edit.show(self.window, fact_id = model[iter][0])
def on_facts_keys(self, tree, event):
if (event.keyval == gtk.keysyms.Delete):
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]