[hamster-applet] fix bug 667475 - stop overview listening to data change events when not displayed
- From: Toms Baugis <tbaugis src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [hamster-applet] fix bug 667475 - stop overview listening to data change events when not displayed
- Date: Fri, 10 Feb 2012 23:15:23 +0000 (UTC)
commit 08fb28609e946e20f333979a9c92594967622561
Author: Toms BauÄis <toms baugis gmail com>
Date: Sat Feb 11 01:13:19 2012 +0200
fix bug 667475 - stop overview listening to data change events when not displayed
the overview and stats windows never got really destroyed because of the even
handles and other references pointing to them, and so where listening to
on-change events and such.
now instead of the futile destruction attempts, we just hide the window
and not listen to the on-change events. should be good enough for now.
src/hamster/configuration.py | 15 ++-----
src/hamster/overview.py | 79 ++++++++++++++++++--------------
src/hamster/preferences.py | 19 +++++---
src/hamster/stats.py | 102 ++++++++++++++++++++++--------------------
4 files changed, 116 insertions(+), 99 deletions(-)
---
diff --git a/src/hamster/configuration.py b/src/hamster/configuration.py
index f4aafee..5d61682 100644
--- a/src/hamster/configuration.py
+++ b/src/hamster/configuration.py
@@ -84,27 +84,21 @@ class OneWindow(object):
self.dialogs = {}
self.get_dialog_class = get_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()
+ window = self.dialogs[params].window
+ if not window.get_visible():
+ self.dialogs[params].show()
+ window.present()
else:
if parent:
dialog = self.get_dialog_class()(parent, **kwargs)
if isinstance(parent, gtk.Widget):
dialog.window.set_transient_for(parent.get_toplevel())
-
- # 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)
-
else:
dialog = self.get_dialog_class()(**kwargs)
@@ -113,7 +107,6 @@ class OneWindow(object):
lambda window, params: gtk.main_quit(),
params)
-
self.dialogs[params] = dialog
class Dialogs(Singleton):
diff --git a/src/hamster/overview.py b/src/hamster/overview.py
index 3898aed..6eeb472 100644
--- a/src/hamster/overview.py
+++ b/src/hamster/overview.py
@@ -43,33 +43,13 @@ class Overview(object):
self.parent = parent# determine if app should shut down on close
self._gui = load_ui_file("overview.ui")
self.report_chooser = None
-
- self.facts = None
-
self.window = self.get_widget("tabs_window")
-
- self.day_start = conf.get("day_start_minutes")
- self.day_start = dt.time(self.day_start / 60, self.day_start % 60)
-
- self.view_date = (dt.datetime.today() - dt.timedelta(hours = self.day_start.hour,
- minutes = self.day_start.minute)).date()
+ self.window.connect("delete_event", self.on_delete_window)
self.range_pick = widgets.RangePick()
self.get_widget("range_pick_box").add(self.range_pick)
self.range_pick.connect("range-selected", self.on_range_selected)
- #set to monday
- self.start_date = self.view_date - dt.timedelta(self.view_date.weekday() + 1)
-
- # look if we need to start on sunday or monday
- self.start_date = self.start_date + dt.timedelta(stuff.locale_first_weekday())
-
- # see if we have not gotten carried away too much in all these calculations
- if (self.view_date - self.start_date) == dt.timedelta(7):
- self.start_date += dt.timedelta(7)
-
- self.end_date = self.start_date + dt.timedelta(6)
-
self.overview = OverviewBox()
self.get_widget("overview_tab").add(self.overview)
self.fact_tree = self.overview.fact_tree # TODO - this is upside down, should maybe get the overview tab over here
@@ -80,13 +60,9 @@ class Overview(object):
self.reports = TotalsBox()
self.get_widget("reports_tab").add(self.reports)
- self.current_range = "week"
-
self.timechart = widgets.TimeChart()
self.timechart.connect("zoom-out-clicked", self.on_timechart_zoom_out_clicked)
self.timechart.connect("range-picked", self.on_timechart_new_range)
- self.timechart.day_start = self.day_start
-
self.get_widget("by_day_box").add(self.timechart)
self._gui.connect_signals(self)
@@ -94,7 +70,41 @@ class Overview(object):
runtime.storage.connect('facts-changed',self.after_activity_update)
conf.connect('conf-changed', self.on_conf_change)
+ self.show()
+
+ def show(self):
+ self.position_window()
+ self.window.show_all()
+
+ self.facts = None
+
+ self.day_start = conf.get("day_start_minutes")
+ self.day_start = dt.time(self.day_start / 60, self.day_start % 60)
+
+ self.view_date = (dt.datetime.today() - dt.timedelta(hours = self.day_start.hour,
+ minutes = self.day_start.minute)).date()
+
+ #set to monday
+ self.start_date = self.view_date - dt.timedelta(self.view_date.weekday() + 1)
+
+ # look if we need to start on sunday or monday
+ self.start_date = self.start_date + dt.timedelta(stuff.locale_first_weekday())
+
+ # see if we have not gotten carried away too much in all these calculations
+ if (self.view_date - self.start_date) == dt.timedelta(7):
+ self.start_date += dt.timedelta(7)
+
+ self.end_date = self.start_date + dt.timedelta(6)
+
+ self.current_range = "week"
+
+ self.timechart.day_start = self.day_start
+
+
+ self.search()
+
+ def position_window(self):
if conf.get("overview_window_maximized"):
self.window.maximize()
else:
@@ -106,9 +116,6 @@ class Overview(object):
else:
self.window.set_position(gtk.WIN_POS_CENTER)
- self.window.show_all()
-
- self.search()
def on_fact_tree_button_press(self, treeview, event):
if event.button == 3:
@@ -140,8 +147,6 @@ class Overview(object):
self.apply_range_select()
-
-
def search(self):
if self.start_date > self.end_date: # make sure the end is always after beginning
self.start_date, self.end_date = self.end_date, self.start_date
@@ -187,8 +192,12 @@ class Overview(object):
return True
def after_activity_update(self, widget):
+ if not self.window.get_visible():
+ return
+
self.search()
+
def on_search_icon_press(self, widget, position, data):
if position == gtk.ENTRY_ICON_SECONDARY:
widget.set_text('')
@@ -404,12 +413,14 @@ class Overview(object):
w, h = self.window.get_size()
conf.set("overview_window_box", [x, y, w, h])
-
if not self.parent:
gtk.main_quit()
else:
- self.window.destroy()
+ self.window.hide()
+ self.facts = None
return False
- def show(self):
- self.window.show()
+ def on_delete_window(self, window, event):
+ self.close_window()
+ return True
+
diff --git a/src/hamster/preferences.py b/src/hamster/preferences.py
index b34e190..a080146 100755
--- a/src/hamster/preferences.py
+++ b/src/hamster/preferences.py
@@ -89,6 +89,8 @@ from configuration import runtime, conf, load_ui_file
import widgets
from lib import stuff, trophies
+
+
class PreferencesEditor:
TARGETS = [
('MY_TREE_MODEL_ROW', gtk.TARGET_SAME_WIDGET, 0),
@@ -100,6 +102,7 @@ class PreferencesEditor:
self.parent = parent
self._gui = load_ui_file("preferences.ui")
self.window = self.get_widget('preferences_window')
+ self.window.connect("delete_event", self.on_delete_window)
# Translators: 'None' refers here to the Todo list choice in Hamster preferences (Tracking tab)
self.activities_sources = [("", _("None")),
@@ -185,7 +188,6 @@ class PreferencesEditor:
# create and fill workspace tree
self.workspace_tree = self.get_widget('workspace_list')
-# self.get_widget("workspaces_label").set_mnemonic_widget(self.workspace_tree)
self.workspace_store = WorkspaceStore()
self.wNameColumn = gtk.TreeViewColumn(_("Name"))
@@ -230,6 +232,11 @@ class PreferencesEditor:
self._gui.connect_signals(self)
+ self.show()
+
+
+ def show(self):
+ self.get_widget("notebook1").set_current_page(0)
self.window.show_all()
@@ -371,8 +378,6 @@ class PreferencesEditor:
return
-
-
def get_widget(self, name):
""" skip one variable (huh) """
return self._gui.get_object(name)
@@ -381,8 +386,6 @@ class PreferencesEditor:
"""returns store, so we can add some watchers in case if anything changes"""
return self.activity_store
- def show(self):
- self.window.show_all()
# callbacks
def category_edited_cb(self, cell, path, new_text, model):
@@ -668,11 +671,15 @@ class PreferencesEditor:
def on_close(self, widget, event):
self.close_window()
+ def on_delete_window(self, window, event):
+ self.close_window()
+ return True
+
def close_window(self):
if not self.parent:
gtk.main_quit()
else:
- self.window.destroy()
+ self.window.hide()
return False
def on_workspace_tracking_toggled(self, checkbox):
diff --git a/src/hamster/stats.py b/src/hamster/stats.py
index ff31dbd..073749f 100644
--- a/src/hamster/stats.py
+++ b/src/hamster/stats.py
@@ -46,61 +46,16 @@ class Stats(object):
self.parent = parent# determine if app should shut down on close
- self.stat_facts = None
-
- day_start = conf.get("day_start_minutes")
- day_start = dt.time(day_start / 60, day_start % 60)
self.timechart = widgets.TimeChart()
self.timechart.interactive = False
- self.timechart.day_start = day_start
self.get_widget("explore_everything").add(self.timechart)
self.get_widget("explore_everything").show_all()
runtime.storage.connect('activities-changed',self.after_fact_update)
runtime.storage.connect('facts-changed',self.after_fact_update)
-
- self.init_stats()
-
self.window.set_position(gtk.WIN_POS_CENTER)
- self._gui.connect_signals(self)
- self.window.show_all()
- self.stats()
-
-
-
- def init_stats(self):
- self.stat_facts = runtime.storage.get_facts(dt.date(1970, 1, 2), dt.date.today())
-
- if not self.stat_facts or self.stat_facts[-1].start_time.year == self.stat_facts[0].start_time.year:
- self.get_widget("explore_controls").hide()
- else:
- by_year = stuff.totals(self.stat_facts,
- lambda fact: fact.start_time.year,
- lambda fact: 1)
-
- year_box = self.get_widget("year_box")
- class YearButton(gtk.ToggleButton):
- def __init__(self, label, year, on_clicked):
- gtk.ToggleButton.__init__(self, label)
- self.year = year
- self.connect("clicked", on_clicked)
-
- all_button = YearButton(C_("years", "All").encode("utf-8"),
- None,
- self.on_year_changed)
- year_box.pack_start(all_button)
- self.bubbling = True # TODO figure out how to properly work with togglebuttons as radiobuttons
- all_button.set_active(True)
- self.bubbling = False # TODO figure out how to properly work with togglebuttons as radiobuttons
-
- years = sorted(by_year.keys())
- for year in years:
- year_box.pack_start(YearButton(str(year), year, self.on_year_changed))
-
- year_box.show_all()
-
self.chart_category_totals = charting.Chart(value_format = "%.1f",
max_bar_width = 20,
legend_width = 70,
@@ -123,8 +78,6 @@ class Stats(object):
self.get_widget("explore_category_starts_ends").add(self.chart_category_starts_ends)
-
-
#ah, just want summary look just like all the other text on the page
class CairoText(graphics.Scene):
def __init__(self):
@@ -151,6 +104,55 @@ class Stats(object):
self.get_widget("explore_summary").add(self.explore_summary)
self.get_widget("explore_summary").show_all()
+
+ self._gui.connect_signals(self)
+ self.show()
+
+ def show(self):
+ self.window.show_all()
+ self.stat_facts = None
+ day_start = conf.get("day_start_minutes")
+ day_start = dt.time(day_start / 60, day_start % 60)
+ self.timechart.day_start = day_start
+ self.init_stats()
+ self.get_widget("year_box").get_children()[0].set_active(True)
+ self.stats()
+
+
+
+ def init_stats(self):
+ self.stat_facts = runtime.storage.get_facts(dt.date(1970, 1, 2), dt.date.today())
+
+ if not self.stat_facts or self.stat_facts[-1].start_time.year == self.stat_facts[0].start_time.year:
+ self.get_widget("explore_controls").hide()
+ else:
+ by_year = stuff.totals(self.stat_facts,
+ lambda fact: fact.start_time.year,
+ lambda fact: 1)
+
+ year_box = self.get_widget("year_box")
+ if len(year_box.get_children()) == 0:
+ class YearButton(gtk.ToggleButton):
+ def __init__(self, label, year, on_clicked):
+ gtk.ToggleButton.__init__(self, label)
+ self.year = year
+ self.connect("clicked", on_clicked)
+
+ all_button = YearButton(C_("years", "All").encode("utf-8"),
+ None,
+ self.on_year_changed)
+ year_box.pack_start(all_button)
+ self.bubbling = True # TODO figure out how to properly work with togglebuttons as radiobuttons
+ all_button.set_active(True)
+ self.bubbling = False # TODO figure out how to properly work with togglebuttons as radiobuttons
+
+ years = sorted(by_year.keys())
+ for year in years:
+ year_box.pack_start(YearButton(str(year), year, self.on_year_changed))
+
+ year_box.show_all()
+
+
def stats(self, year = None):
facts = self.stat_facts
if year:
@@ -421,6 +423,9 @@ than 15 minutes, you seem to be a busy bee.") % ("<b>%d</b>" % short_percent)
def after_fact_update(self, event):
+ if not self.window.get_visible():
+ return
+
self.stat_facts = runtime.storage.get_facts(dt.date(1970, 1, 1), dt.date.today())
self.stats()
@@ -436,12 +441,13 @@ than 15 minutes, you seem to be a busy bee.") % ("<b>%d</b>" % short_percent)
def on_stats_window_deleted(self, widget, event):
self.close_window()
+ return True
def close_window(self):
if not self.parent:
gtk.main_quit()
else:
- self.window.destroy()
+ self.window.hide()
return False
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]