From d1bdabf5fc7b465786e0c80ef53fda2cc8c53d73 Mon Sep 17 00:00:00 2001 From: Alex Roitman Date: Sat, 20 Nov 2004 04:46:47 +0000 Subject: [PATCH] * src/Plugins.py: Remove redundant list of failed plugins. Properly reload plugins. Work around what seems to be a Python bug. Allow setting the preference for showing up the plugin status upon load/reload if problems are detected. Support Help button. Automatically close old status window when new one is opened. * src/plugins.glade: Add Help button and the check button. * src/data/gramps.schemas: Add pop-plugin-status key. * src/GrampsGconfKeys.py: Add get/save methods for new key. * src/*.gladep: Remove from CVS. * src/plugins/IndivComplete.py: Typo. * src/plugins/Partition.py: Comment out wrong class instantiation. This plugin is dysfunctional, and we should either remove it or fix it. svn: r3743 --- ChangeLog | 15 ++++++ src/GrampsGconfKeys.py | 6 +++ src/Plugins.py | 94 +++++++++++++++++++++++++++++++----- src/data/gramps.schemas | 13 +++++ src/plugins.glade | 39 +++++++++++++-- src/plugins/IndivComplete.py | 2 +- src/plugins/Partition.py | 12 +++-- 7 files changed, 161 insertions(+), 20 deletions(-) diff --git a/ChangeLog b/ChangeLog index 087f0a309..a89fe28ce 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,18 @@ +2004-11-19 Alex Roitman + * src/Plugins.py: Remove redundant list of failed plugins. + Properly reload plugins. Work around what seems to be a Python bug. + Allow setting the preference for showing up the plugin status + upon load/reload if problems are detected. Support Help button. + Automatically close old status window when new one is opened. + * src/plugins.glade: Add Help button and the check button. + * src/data/gramps.schemas: Add pop-plugin-status key. + * src/GrampsGconfKeys.py: Add get/save methods for new key. + * src/*.gladep: Remove from CVS. + * src/plugins/IndivComplete.py: Typo. + * src/plugins/Partition.py: Comment out wrong class instantiation. + This plugin is dysfunctional, and we should either remove it or + fix it. + 2004-11-18 Don Allingham * src/ColumnOrder.py: pychecker fixes * src/DateParser.py: pychecker fixes diff --git a/src/GrampsGconfKeys.py b/src/GrampsGconfKeys.py index 55580972a..ccf1f5b9b 100644 --- a/src/GrampsGconfKeys.py +++ b/src/GrampsGconfKeys.py @@ -200,6 +200,12 @@ def get_usetips(): def save_usetips(val): set_bool("/apps/gramps/behavior/use-tips",val) +def get_pop_plugin_status(): + return get_bool("/apps/gramps/behavior/pop-plugin-status") + +def save_pop_plugin_status(val): + set_bool("/apps/gramps/behavior/pop-plugin-status",val) + # preferences keys def get_person_id_prefix(): return get_string("/apps/gramps/preferences/iprefix") diff --git a/src/Plugins.py b/src/Plugins.py index 3325f75cd..8f8d415bb 100644 --- a/src/Plugins.py +++ b/src/Plugins.py @@ -36,6 +36,7 @@ importers, exporters, and document generators. import gobject import gtk import gtk.glade +import gnome #------------------------------------------------------------------------- # @@ -72,7 +73,6 @@ _tools = [] _imports = [] _exports = [] _success = [] -_failed = [] _expect = [] _attempt = [] _loaddir = [] @@ -82,6 +82,7 @@ _drawdoc = [] _failmsg = [] _bkitems = [] +_status_up = None #------------------------------------------------------------------------- # # Default relationship calculator @@ -326,14 +327,30 @@ class PluginStatus: """Displays a dialog showing the status of loaded plugins""" def __init__(self): + global _status_up + if _status_up: + _status_up.close(None) + _status_up = self + import cStringIO self.glade = gtk.glade.XML(const.pluginsFile,"plugstat","gramps") self.top = self.glade.get_widget("plugstat") self.top.set_title("%s - GRAMPS" % _('Plugin status')) window = self.glade.get_widget("text") + self.pop_button = self.glade.get_widget("pop_button") + if GrampsGconfKeys.get_pop_plugin_status(): + self.pop_button.set_active(1) + else: + self.pop_button.set_active(0) + self.pop_button.connect('toggled', + lambda obj: GrampsGconfKeys.save_pop_plugin_status(self.pop_button.get_active())) + GrampsGconfKeys.client.notify_add("/apps/gramps/behavior/pop-plugin-status", + self.pop_button_update) self.glade.signal_autoconnect({ - 'on_close_clicked' : self.close + 'on_close_clicked' : self.close, + 'on_help_clicked' : self.help, + 'on_plugstat_delete_event' : self.on_delete, }) info = cStringIO.StringIO() @@ -357,9 +374,20 @@ class PluginStatus: info.seek(0) window.get_buffer().set_text(info.read()) + def on_delete(self,obj1,obj2): + _status_up = None + def close(self,obj): self.top.destroy() - + _status_up = None + + def help(self,obj): + """Display the GRAMPS manual""" + gnome.help_display('gramps-manual','gramps-getting-started') + + def pop_button_update(self, client,cnxn_id,entry,data): + self.pop_button.set_active(GrampsGconfKeys.get_pop_plugin_status()) + #------------------------------------------------------------------------- # # load_plugins @@ -372,7 +400,7 @@ def load_plugins(direct): responsible for registering itself in the correct manner. No attempt is done in this routine to register the tasks.""" - global _success,_failed,_attempt,_loaddir + global _success,_attempt,_loaddir,_failmsg # if the directory does not exist, do nothing if not os.path.isdir(direct): @@ -409,33 +437,53 @@ def load_plugins(direct): except: _failmsg.append((filename,sys.exc_info())) + if GrampsGconfKeys.get_pop_plugin_status() and len(_expect)+len(_failmsg): + PluginStatus() + #------------------------------------------------------------------------- # # reload_plugins # #------------------------------------------------------------------------- -def reload_plugins(obj): +def reload_plugins(obj=None,junk1=None,junk2=None,junk3=None): """Treated as a callback, causes all plugins to get reloaded. This is useful when writing and debugging a plugin""" pymod = compile(r"^(.*)\.py$") - # attempt to reload all plugins that have succeeded - # in the past + global _success,_attempt,_loaddir,_failmsg + + oldfailmsg = _failmsg[:] + _failmsg = [] + + # attempt to reload all plugins that have succeeded in the past for plugin in _success: + filename = os.path.basename(plugin.__file__) + filename = filename.replace('pyc','py') + filename = filename.replace('pyo','py') try: reload(plugin) except: - _failmsg.append((plugin,sys.exc_info())) + _failmsg.append((filename,sys.exc_info())) # attempt to load the plugins that have failed in the past - for plugin in _failed: + for (filename,message) in oldfailmsg: + name = os.path.split(filename) + match = pymod.match(name[1]) + if not match: + continue + _attempt.append(filename) + plugin = match.groups()[0] try: - __import__(plugin) - del _failmsg[plugin] + # For some strange reason second importing of a failed plugin + # results in success. Then reload reveals the actual error. + # Looks like a bug in Python. + a = __import__(plugin) + reload(a) + _success.append(a) except: - _failmsg.append((plugin,sys.exc_info())) + _failmsg.append((filename,sys.exc_info())) # attempt to load any new files found for directory in _loaddir: @@ -445,7 +493,7 @@ def reload_plugins(obj): if not match: continue if filename in _attempt: - return + continue _attempt.append(filename) plugin = match.groups()[0] try: @@ -455,6 +503,14 @@ def reload_plugins(obj): except: _failmsg.append((filename,sys.exc_info())) + if GrampsGconfKeys.get_pop_plugin_status(): + global _status_up + if len(_failmsg): + PluginStatus() + elif _status_up: + _status_up.close(None) + _status_up = None + #------------------------------------------------------------------------- # # Plugin registering @@ -765,3 +821,15 @@ def get_draw_doc_menu(main_menu,callback=None,obj=None): callback(menuitem) index = index + 1 main_menu.set_menu(myMenu) + +#------------------------------------------------------------------------- +# +# Register the plugin reloading tool +# +#------------------------------------------------------------------------- +register_tool( + reload_plugins, + _("Reload plugins"), + category=_("Debug"), + description=_("Attempt to reload plugins. Note: This tool itself is not reloaded!"), + ) diff --git a/src/data/gramps.schemas b/src/data/gramps.schemas index 948e45083..b94b7c845 100644 --- a/src/data/gramps.schemas +++ b/src/data/gramps.schemas @@ -552,6 +552,19 @@ + + /schemas/apps/gramps/behavior/pop-plugin-status + /apps/gramps/behavior/pop-plugin-status + gramps + bool + 0 + + Automatically pop plugin status window + If set to 1, Plugin Status Window will pop automatically + when problems are detected on plugins load and reload. + + + /schemas/apps/gramps/interface/view /apps/gramps/interface/view diff --git a/src/plugins.glade b/src/plugins.glade index 3aded359b..3af6053f8 100644 --- a/src/plugins.glade +++ b/src/plugins.glade @@ -2,7 +2,6 @@ - True @@ -19,6 +18,7 @@ GDK_WINDOW_TYPE_HINT_NORMAL GDK_GRAVITY_NORTH_WEST False + @@ -36,14 +36,28 @@ True True True - gtk-cancel + gtk-close True GTK_RELIEF_NORMAL True - 0 + -7 + + + + True + True + True + gtk-help + True + GTK_RELIEF_NORMAL + True + -11 + + + 0 @@ -90,6 +104,25 @@ True + + + + True + True + _Automatically pop out when problems are detected + True + GTK_RELIEF_NORMAL + True + False + False + True + + + 6 + False + False + + diff --git a/src/plugins/IndivComplete.py b/src/plugins/IndivComplete.py index ca37e7ab2..2c330e37f 100644 --- a/src/plugins/IndivComplete.py +++ b/src/plugins/IndivComplete.py @@ -57,7 +57,7 @@ import gtk _person_handle = "" _filter_num = 0 _use_srcs = 0 -_options = ( _person_id, _filter_num, _use_srcs ) +_options = ( _person_handle, _filter_num, _use_srcs ) #------------------------------------------------------------------------ # diff --git a/src/plugins/Partition.py b/src/plugins/Partition.py index e20df1a7a..27cda705d 100644 --- a/src/plugins/Partition.py +++ b/src/plugins/Partition.py @@ -1,4 +1,8 @@ +# +# Gramps - a GTK+/GNOME based genealogy program +# # Copyright (C) 2003 Jesper Zedlitz +# Copyright (C) 2003-2004 Donald N. Allingham # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -15,6 +19,8 @@ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # +# $Id$ + "Export/Partition" #------------------------------------------------------------------------ @@ -50,7 +56,7 @@ import WriteXML personSeen = [] familySeen = [] -database_for_unlinked_persons = RelLib.GrampsDB() +#database_for_unlinked_persons = RelLib.GrampsDB() prefix = "/tmp/test" #------------------------------------------------------------------------- @@ -63,8 +69,8 @@ def work_on_person( db, person ): if (len(person.get_family_handle_list()) + len(person.get_parent_family_handle_list())) > 0: database = db - else: - database = database_for_unlinked_persons + #else: + # database = database_for_unlinked_persons if( database.get_person_handle_map().has_key( person.get_handle() ) ): return