From bb99cd20b1f51b8f64678ca4598b6425bb5d93d5 Mon Sep 17 00:00:00 2001 From: Doug Blank Date: Tue, 27 Oct 2009 00:27:40 +0000 Subject: [PATCH] Fixed missing expand option on gramplets; added connect/disconnect signal handling; removed signal to update status bar when gramplet doesn't do anything svn: r13428 --- src/DataViews/GrampletView.py | 1 + src/gen/plug/_gramplet.py | 28 ++++++++++++++++++----- src/plugins/gramplet/AgeOnDateGramplet.py | 3 +++ src/plugins/gramplet/CalendarGramplet.py | 3 +++ src/plugins/gramplet/FaqGramplet.py | 3 +++ src/plugins/gramplet/PythonGramplet.py | 3 +++ src/plugins/gramplet/ToDoGramplet.py | 3 +++ 7 files changed, 38 insertions(+), 6 deletions(-) diff --git a/src/DataViews/GrampletView.py b/src/DataViews/GrampletView.py index f1017cceb..155432b15 100644 --- a/src/DataViews/GrampletView.py +++ b/src/DataViews/GrampletView.py @@ -85,6 +85,7 @@ def GET_AVAILABLE_GRAMPLETS(name): "tname": gplug.name, "version": gplug.version, "height": gplug.height, + "expand": gplug.expand, "title": gplug.gramplet_title, "content": gplug.gramplet, "detached_width": gplug.detached_width, diff --git a/src/gen/plug/_gramplet.py b/src/gen/plug/_gramplet.py index b5ad54fdc..643d2e9dc 100644 --- a/src/gen/plug/_gramplet.py +++ b/src/gen/plug/_gramplet.py @@ -36,6 +36,7 @@ class Gramplet(object): self._generator = None self._need_to_update = False self.option_dict = {} + self._signal = {} self.option_order = [] # links to each other: self.gui = gui # plugin gramplet has link to gui @@ -45,15 +46,16 @@ class Gramplet(object): self.init() self.on_load() self.build_options() - self.dbstate.connect('database-changed', self._db_changed) - self.dbstate.connect('active-changed', self._active_changed) - self.gui.textview.connect('button-press-event', - self.gui.on_button_press) - self.gui.textview.connect('motion-notify-event', - self.gui.on_motion) + self.connect(self.dbstate, "database-changed", self._db_changed) + self.connect(self.dbstate, "active-changed", self._active_changed) + self.connect(self.gui.textview, "button-press-event", + self.gui.on_button_press) + self.connect(self.gui.textview, "motion-notify-event", + self.gui.on_motion) if self.dbstate.active: # already changed self._db_changed(self.dbstate.db) self._active_changed(self.dbstate.active.handle) + self.post_init() def init(self): # once, constructor """ @@ -62,6 +64,9 @@ class Gramplet(object): """ pass + def post_init(self): + pass + def build_options(self): """ External constructor for developers to put code for building @@ -336,3 +341,14 @@ class Gramplet(object): def save_options(self): pass + + def connect(self, signal_obj, signal, method): + id = signal_obj.connect(signal, method) + self._signal[signal] = (id, signal_obj) + + def disconnect(self, signal): + if signal in self._signal: + (id, signal_obj) = self._signal[signal] + signal_obj.disconnect(id) + else: + raise AttributeError("unknown signal: '%s'" % signal) diff --git a/src/plugins/gramplet/AgeOnDateGramplet.py b/src/plugins/gramplet/AgeOnDateGramplet.py index 6061984ef..12185c35c 100644 --- a/src/plugins/gramplet/AgeOnDateGramplet.py +++ b/src/plugins/gramplet/AgeOnDateGramplet.py @@ -84,6 +84,9 @@ class AgeOnDateGramplet(Gramplet): self.gui.get_container_widget().add_with_viewport(vbox) vbox.show_all() + def post_init(self): + self.disconnect("active-changed") + def run(self, obj): """ Method that is run when you click the Run button. diff --git a/src/plugins/gramplet/CalendarGramplet.py b/src/plugins/gramplet/CalendarGramplet.py index 61845d449..9b04a9764 100644 --- a/src/plugins/gramplet/CalendarGramplet.py +++ b/src/plugins/gramplet/CalendarGramplet.py @@ -43,6 +43,9 @@ class CalendarGramplet(Gramplet): self.gui.get_container_widget().add_with_viewport(self.gui.calendar) self.gui.calendar.show() + def post_init(self): + self.disconnect("active-changed") + def double_click(self, obj): # bring up events on this day year, month, day = self.gui.calendar.get_date() diff --git a/src/plugins/gramplet/FaqGramplet.py b/src/plugins/gramplet/FaqGramplet.py index 76a53afd3..36cbab2ce 100644 --- a/src/plugins/gramplet/FaqGramplet.py +++ b/src/plugins/gramplet/FaqGramplet.py @@ -38,3 +38,6 @@ class FAQGramplet(Gramplet): self.render_text("Draft of a Frequently Asked Questions Gramplet\n\n") self.render_text(" 1. Test 1\n") self.render_text(" 2. Test 2\n") + + def post_init(self): + self.disconnect("active-changed") diff --git a/src/plugins/gramplet/PythonGramplet.py b/src/plugins/gramplet/PythonGramplet.py index b5f40cee7..5e79808e7 100644 --- a/src/plugins/gramplet/PythonGramplet.py +++ b/src/plugins/gramplet/PythonGramplet.py @@ -58,6 +58,9 @@ class PythonGramplet(Gramplet): self.set_text("Python %s\n%s " % (sys.version, self.prompt)) self.gui.textview.connect('key-press-event', self.on_key_press) + def post_init(self): + self.disconnect("active-changed") + def format_exception(self, max_tb_level=10): retval = '' cla, exc, trbk = sys.exc_info() diff --git a/src/plugins/gramplet/ToDoGramplet.py b/src/plugins/gramplet/ToDoGramplet.py index 8e7094890..edde70ef7 100644 --- a/src/plugins/gramplet/ToDoGramplet.py +++ b/src/plugins/gramplet/ToDoGramplet.py @@ -41,6 +41,9 @@ class TODOGramplet(Gramplet): def on_load(self): self.load_data_to_text() + def post_init(self): + self.disconnect("active-changed") + def on_save(self): self.gui.data = [] # clear out old data self.save_text_to_data()