From 7f7c4335e218fb9344a6871d0406a817721f4a4d Mon Sep 17 00:00:00 2001 From: Alex Roitman Date: Wed, 20 Dec 2006 07:22:19 +0000 Subject: [PATCH] 2006-12-19 Alex Roitman * src/PluginUtils/_Plugins.py: Emit signal on rebuild, rebuild open plugin dialogs on rebuild. * src/ViewManager.py: Use signal to rebuild plugin menus. * src/DisplayState.py (DisplayState.__signals__): Register signal to indicate plugin reloading. svn: r7827 --- gramps2/ChangeLog | 7 +++++++ gramps2/src/DisplayState.py | 1 + gramps2/src/PluginUtils/_Plugins.py | 18 ++++++++++++++++-- gramps2/src/ViewManager.py | 26 ++++++++++++++++---------- 4 files changed, 40 insertions(+), 12 deletions(-) diff --git a/gramps2/ChangeLog b/gramps2/ChangeLog index e5d6299e6..52338488d 100644 --- a/gramps2/ChangeLog +++ b/gramps2/ChangeLog @@ -1,3 +1,10 @@ +2006-12-19 Alex Roitman + * src/PluginUtils/_Plugins.py: Emit signal on rebuild, rebuild + open plugin dialogs on rebuild. + * src/ViewManager.py: Use signal to rebuild plugin menus. + * src/DisplayState.py (DisplayState.__signals__): Register signal + to indicate plugin reloading. + 2006-12-19 Don Allingham * src/ViewManager.py (ViewManager.post_load_newdb): make sure to enable the readonly menu items diff --git a/gramps2/src/DisplayState.py b/gramps2/src/DisplayState.py index bfe342c16..93a9dd75a 100644 --- a/gramps2/src/DisplayState.py +++ b/gramps2/src/DisplayState.py @@ -254,6 +254,7 @@ class DisplayState(GrampsDb.GrampsDBCallback): __signals__ = { 'filters-changed' : (str,), 'nameformat-changed' : None, + 'plugins-reloaded' : (list,list), } def __init__(self, window, status, progress, warnbtn, uimanager): diff --git a/gramps2/src/PluginUtils/_Plugins.py b/gramps2/src/PluginUtils/_Plugins.py index 84eb3eb2b..d562d899d 100644 --- a/gramps2/src/PluginUtils/_Plugins.py +++ b/gramps2/src/PluginUtils/_Plugins.py @@ -195,6 +195,7 @@ class PluginDialog(ManagedWindow.ManagedWindow): """ ilist = [] + self.store.clear() # build the tree items and group together based on the category name item_hash = {} @@ -265,6 +266,10 @@ class ReportPlugins(PluginDialog): _("Select a report from those available on the left."), _("_Generate"), _("Generate selected report"), REPORTS) + uistate.connect('plugins-reloaded',self.rebuild_reports) + + def rebuild_reports(self,tool_list,report_list): + self.build_plugin_tree(report_list,standalone_categories) #------------------------------------------------------------------------- # @@ -275,6 +280,9 @@ class ToolPlugins(PluginDialog): """Displays the dialog box that allows the user to select the tool that is desired.""" + __signals__ = { + 'plugins-reloaded' : (list,list), + } def __init__(self,dbstate,uistate,track): """Display the dialog box, and build up the list of available reports. This is used to build the selection tree on the left @@ -292,6 +300,11 @@ class ToolPlugins(PluginDialog): _("_Run"), _("Run selected tool"), TOOLS) + + uistate.connect('plugins-reloaded',self.rebuild_tools) + + def rebuild_tools(self,tool_list,report_list): + self.build_plugin_tree(tool_list,_Tool.tool_categories) #------------------------------------------------------------------------- # @@ -300,12 +313,11 @@ class ToolPlugins(PluginDialog): #------------------------------------------------------------------------- class Reload(_Tool.Tool): def __init__(self, dbstate, uistate, options_class, name, callback=None): - _Tool.Tool.__init__(self,dbstate,options_class,name) - """ Treated as a callback, causes all plugins to get reloaded. This is useful when writing and debugging a plugin. """ + _Tool.Tool.__init__(self,dbstate,options_class,name) pymod = re.compile(r"^(.*)\.py$") @@ -396,6 +408,8 @@ class Reload(_Tool.Tool): # Re-generate tool and report menus # FIXME: This needs to be fixed! # build_plugin_menus(rebuild=True) + uistate.emit('plugins-reloaded', + (_PluginMgr.tool_list,_PluginMgr.report_list)) class ReloadOptions(_Tool.ToolOptions): """ diff --git a/gramps2/src/ViewManager.py b/gramps2/src/ViewManager.py index ab56db3cf..15ee786b8 100644 --- a/gramps2/src/ViewManager.py +++ b/gramps2/src/ViewManager.py @@ -422,8 +422,10 @@ class ViewManager: self.actiongroup.set_visible(False) self.readonlygroup.set_visible(False) self.fileactions.set_sensitive(False) - self.build_tools_menu() - self.build_report_menu() + self.build_tools_menu(tool_list) + self.build_report_menu(report_list) + self.uistate.connect('plugins-reloaded', + self.rebuild_report_and_tool_menus) self.fileactions.set_sensitive(True) self.uistate.widget.set_sensitive(True) Config.client.notify_add("/apps/gramps/interface/statusbar", @@ -1018,23 +1020,27 @@ class ViewManager: import Exporter Exporter.Exporter(self.state, self.uistate) - def build_tools_menu(self): + def rebuild_report_and_tool_menus(self,tool_list,report_list): + self.build_tools_menu(tool_list) + self.build_report_menu(report_list) + + def build_tools_menu(self,tool_list): self.toolactions = gtk.ActionGroup('ToolWindow') (ui, actions) = self.build_plugin_menu('ToolsMenu', - tool_list, - Tool.tool_categories, - make_tool_callback) + tool_list, + Tool.tool_categories, + make_tool_callback) self.toolactions.add_actions(actions) self.uistate.uimanager.add_ui_from_string(ui) self.uimanager.insert_action_group(self.toolactions, 1) self.uistate.uimanager.ensure_update() - def build_report_menu(self): + def build_report_menu(self,report_list): self.reportactions = gtk.ActionGroup('ReportWindow') (ui, actions) = self.build_plugin_menu('ReportsMenu', - report_list, - standalone_categories, - make_report_callback) + report_list, + standalone_categories, + make_report_callback) self.reportactions.add_actions(actions) self.uistate.uimanager.add_ui_from_string(ui) self.uimanager.insert_action_group(self.reportactions, 1)