* 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
This commit is contained in:
Alex Roitman 2004-11-20 04:46:47 +00:00
parent b331cf94c7
commit e71b020d1e
7 changed files with 161 additions and 20 deletions

View File

@ -1,3 +1,18 @@
2004-11-19 Alex Roitman <shura@alex.neuro.umn.edu>
* 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 <dallingham@users.sourceforge.net>
* src/ColumnOrder.py: pychecker fixes
* src/DateParser.py: pychecker fixes

View File

@ -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")

View File

@ -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!"),
)

View File

@ -552,6 +552,19 @@
</locale>
</schema>
<schema>
<key>/schemas/apps/gramps/behavior/pop-plugin-status</key>
<applyto>/apps/gramps/behavior/pop-plugin-status</applyto>
<owner>gramps</owner>
<type>bool</type>
<default>0</default>
<locale name="C">
<short>Automatically pop plugin status window</short>
<long>If set to 1, Plugin Status Window will pop automatically
when problems are detected on plugins load and reload.</long>
</locale>
</schema>
<schema>
<key>/schemas/apps/gramps/interface/view</key>
<applyto>/apps/gramps/interface/view</applyto>

View File

@ -2,7 +2,6 @@
<!DOCTYPE glade-interface SYSTEM "http://glade.gnome.org/glade-2.0.dtd">
<glade-interface>
<requires lib="gnome"/>
<widget class="GtkDialog" id="plugstat">
<property name="visible">True</property>
@ -19,6 +18,7 @@
<property name="type_hint">GDK_WINDOW_TYPE_HINT_NORMAL</property>
<property name="gravity">GDK_GRAVITY_NORTH_WEST</property>
<property name="has_separator">False</property>
<signal name="delete_event" handler="on_plugstat_delete_event" last_modification_time="Sat, 20 Nov 2004 04:07:44 GMT"/>
<child internal-child="vbox">
<widget class="GtkVBox" id="vbox37">
@ -36,14 +36,28 @@
<property name="visible">True</property>
<property name="can_default">True</property>
<property name="can_focus">True</property>
<property name="label">gtk-cancel</property>
<property name="label">gtk-close</property>
<property name="use_stock">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
<property name="focus_on_click">True</property>
<property name="response_id">0</property>
<property name="response_id">-7</property>
<signal name="clicked" handler="on_close_clicked" last_modification_time="Thu, 12 Sep 2002 03:21:32 GMT"/>
</widget>
</child>
<child>
<widget class="GtkButton" id="button109">
<property name="visible">True</property>
<property name="can_default">True</property>
<property name="can_focus">True</property>
<property name="label">gtk-help</property>
<property name="use_stock">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
<property name="focus_on_click">True</property>
<property name="response_id">-11</property>
<signal name="clicked" handler="on_help_clicked" last_modification_time="Sat, 20 Nov 2004 03:29:14 GMT"/>
</widget>
</child>
</widget>
<packing>
<property name="padding">0</property>
@ -90,6 +104,25 @@
<property name="fill">True</property>
</packing>
</child>
<child>
<widget class="GtkCheckButton" id="pop_button">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="label" translatable="yes">_Automatically pop out when problems are detected</property>
<property name="use_underline">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
<property name="focus_on_click">True</property>
<property name="active">False</property>
<property name="inconsistent">False</property>
<property name="draw_indicator">True</property>
</widget>
<packing>
<property name="padding">6</property>
<property name="expand">False</property>
<property name="fill">False</property>
</packing>
</child>
</widget>
</child>
</widget>

View File

@ -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 )
#------------------------------------------------------------------------
#

View File

@ -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