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
This commit is contained in:
Doug Blank 2009-10-27 00:27:40 +00:00
parent 2ed1159e89
commit bb99cd20b1
7 changed files with 38 additions and 6 deletions

View File

@ -85,6 +85,7 @@ def GET_AVAILABLE_GRAMPLETS(name):
"tname": gplug.name, "tname": gplug.name,
"version": gplug.version, "version": gplug.version,
"height": gplug.height, "height": gplug.height,
"expand": gplug.expand,
"title": gplug.gramplet_title, "title": gplug.gramplet_title,
"content": gplug.gramplet, "content": gplug.gramplet,
"detached_width": gplug.detached_width, "detached_width": gplug.detached_width,

View File

@ -36,6 +36,7 @@ class Gramplet(object):
self._generator = None self._generator = None
self._need_to_update = False self._need_to_update = False
self.option_dict = {} self.option_dict = {}
self._signal = {}
self.option_order = [] self.option_order = []
# links to each other: # links to each other:
self.gui = gui # plugin gramplet has link to gui self.gui = gui # plugin gramplet has link to gui
@ -45,15 +46,16 @@ class Gramplet(object):
self.init() self.init()
self.on_load() self.on_load()
self.build_options() self.build_options()
self.dbstate.connect('database-changed', self._db_changed) self.connect(self.dbstate, "database-changed", self._db_changed)
self.dbstate.connect('active-changed', self._active_changed) self.connect(self.dbstate, "active-changed", self._active_changed)
self.gui.textview.connect('button-press-event', self.connect(self.gui.textview, "button-press-event",
self.gui.on_button_press) self.gui.on_button_press)
self.gui.textview.connect('motion-notify-event', self.connect(self.gui.textview, "motion-notify-event",
self.gui.on_motion) self.gui.on_motion)
if self.dbstate.active: # already changed if self.dbstate.active: # already changed
self._db_changed(self.dbstate.db) self._db_changed(self.dbstate.db)
self._active_changed(self.dbstate.active.handle) self._active_changed(self.dbstate.active.handle)
self.post_init()
def init(self): # once, constructor def init(self): # once, constructor
""" """
@ -62,6 +64,9 @@ class Gramplet(object):
""" """
pass pass
def post_init(self):
pass
def build_options(self): def build_options(self):
""" """
External constructor for developers to put code for building External constructor for developers to put code for building
@ -336,3 +341,14 @@ class Gramplet(object):
def save_options(self): def save_options(self):
pass 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)

View File

@ -84,6 +84,9 @@ class AgeOnDateGramplet(Gramplet):
self.gui.get_container_widget().add_with_viewport(vbox) self.gui.get_container_widget().add_with_viewport(vbox)
vbox.show_all() vbox.show_all()
def post_init(self):
self.disconnect("active-changed")
def run(self, obj): def run(self, obj):
""" """
Method that is run when you click the Run button. Method that is run when you click the Run button.

View File

@ -43,6 +43,9 @@ class CalendarGramplet(Gramplet):
self.gui.get_container_widget().add_with_viewport(self.gui.calendar) self.gui.get_container_widget().add_with_viewport(self.gui.calendar)
self.gui.calendar.show() self.gui.calendar.show()
def post_init(self):
self.disconnect("active-changed")
def double_click(self, obj): def double_click(self, obj):
# bring up events on this day # bring up events on this day
year, month, day = self.gui.calendar.get_date() year, month, day = self.gui.calendar.get_date()

View File

@ -38,3 +38,6 @@ class FAQGramplet(Gramplet):
self.render_text("Draft of a <a wiki='FAQ'>Frequently Asked Questions</a> Gramplet\n\n") self.render_text("Draft of a <a wiki='FAQ'>Frequently Asked Questions</a> Gramplet\n\n")
self.render_text(" 1. <a href='http://bugs.gramps-project.org/'>Test 1</a>\n") self.render_text(" 1. <a href='http://bugs.gramps-project.org/'>Test 1</a>\n")
self.render_text(" 2. <a href='http://gramps-project.org//'>Test 2</a>\n") self.render_text(" 2. <a href='http://gramps-project.org//'>Test 2</a>\n")
def post_init(self):
self.disconnect("active-changed")

View File

@ -58,6 +58,9 @@ class PythonGramplet(Gramplet):
self.set_text("Python %s\n%s " % (sys.version, self.prompt)) self.set_text("Python %s\n%s " % (sys.version, self.prompt))
self.gui.textview.connect('key-press-event', self.on_key_press) 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): def format_exception(self, max_tb_level=10):
retval = '' retval = ''
cla, exc, trbk = sys.exc_info() cla, exc, trbk = sys.exc_info()

View File

@ -41,6 +41,9 @@ class TODOGramplet(Gramplet):
def on_load(self): def on_load(self):
self.load_data_to_text() self.load_data_to_text()
def post_init(self):
self.disconnect("active-changed")
def on_save(self): def on_save(self):
self.gui.data = [] # clear out old data self.gui.data = [] # clear out old data
self.save_text_to_data() self.save_text_to_data()