diff --git a/gramps2/ChangeLog b/gramps2/ChangeLog index e6e2dceeb..c60a299f2 100644 --- a/gramps2/ChangeLog +++ b/gramps2/ChangeLog @@ -1,3 +1,7 @@ +2005-11-20 Martin Hawlisch + * src/plugins/FilterEditor.py: Corrected plugin registration + * src/GrampsCfg.py: Add validation for GRAMPS ID prefixes + 2005-11-19 Don Allingham * src/WriteGedcom.py: add space between given and surname in output. * src/ReadGedcom.py: encoding list change diff --git a/gramps2/src/GrampsCfg.py b/gramps2/src/GrampsCfg.py index 5374c1941..54847ec2a 100644 --- a/gramps2/src/GrampsCfg.py +++ b/gramps2/src/GrampsCfg.py @@ -26,6 +26,7 @@ # #------------------------------------------------------------------------- import os +import sets from gettext import gettext as _ #------------------------------------------------------------------------- @@ -48,6 +49,7 @@ import const import Utils import DateHandler import GrampsDisplay +import QuestionDialog from WindowUtils import GladeIf #------------------------------------------------------------------------- @@ -150,6 +152,7 @@ class GrampsPreferences: self.gladeif.connect('button7','clicked',self.on_propertybox_help) self.window = self.top.get_widget("preferences") + self.window.connect('delete_event',self.on_close_clicked) self.tree = self.top.get_widget("tree") self.store = gtk.TreeStore(gobject.TYPE_STRING) self.selection = self.tree.get_selection() @@ -197,26 +200,16 @@ class GrampsPreferences: lds.connect('toggled', lambda obj: GrampsKeys.save_uselds(obj.get_active())) - ipr = self.top.get_widget("iprefix") - ipr.set_text(GrampsKeys.get_person_id_prefix()) - ipr.connect('changed', - lambda obj: GrampsKeys.save_iprefix(obj.get_text())) - opr = self.top.get_widget("oprefix") - opr.set_text(GrampsKeys.get_object_id_prefix()) - opr.connect('changed', - lambda obj: GrampsKeys.save_oprefix(obj.get_text())) - fpr = self.top.get_widget("fprefix") - fpr.set_text(GrampsKeys.get_family_id_prefix()) - fpr.connect('changed', - lambda obj: GrampsKeys.save_fprefix(obj.get_text())) - spr = self.top.get_widget("sprefix") - spr.set_text(GrampsKeys.get_source_id_prefix()) - spr.connect('changed', - lambda obj: GrampsKeys.save_sprefix(obj.get_text())) - ppr = self.top.get_widget("pprefix") - ppr.set_text(GrampsKeys.get_place_id_prefix()) - ppr.connect('changed', - lambda obj: GrampsKeys.save_pprefix(obj.get_text())) + self.ipr = self.top.get_widget("iprefix") + self.ipr.set_text(GrampsKeys.get_person_id_prefix()) + self.opr = self.top.get_widget("oprefix") + self.opr.set_text(GrampsKeys.get_object_id_prefix()) + self.fpr = self.top.get_widget("fprefix") + self.fpr.set_text(GrampsKeys.get_family_id_prefix()) + self.spr = self.top.get_widget("sprefix") + self.spr.set_text(GrampsKeys.get_source_id_prefix()) + self.ppr = self.top.get_widget("pprefix") + self.ppr.set_text(GrampsKeys.get_place_id_prefix()) sb2 = self.top.get_widget("stat2") sb3 = self.top.get_widget("stat3") @@ -324,7 +317,61 @@ class GrampsPreferences: resemail.set_text(GrampsKeys.get_researcher_email()) resemail.connect('changed', lambda obj: GrampsKeys.save_researcher_email(obj.get_text())) + + def save_prefix(self): + """ Validate the GRAMPS ID definitions to be usable""" + ip = self.ipr.get_text() + op = self.opr.get_text() + fp = self.fpr.get_text() + sp = self.spr.get_text() + pp = self.ppr.get_text() + + # Do validation to the GRAMPS-ID format strings + invalid_chars = sets.Set("# \t\n\r") + prefixes = [ip,op,fp,sp,pp] + testnums = [1,234,567890] + testresult = {} # used to test that IDs for different objects will be different + formaterror = False # true if formatstring is invalid + incompatible = False # true if ID string is possibly not GEDCOM compatible + for p in prefixes: + if invalid_chars & sets.Set(p): + incompatible = True + for n in testnums: + try: + testresult[p % n] = 1 + except: + formaterror = True + + idexampletext = _('Example for valid IDs are:\n'+ + 'I%d which will be displayed as I123 or\n'+ + 'S%06d which will be displayed as S000123.') + if formaterror: + QuestionDialog.ErrorDialog( _("Invalid GRAMPS ID prefix"), + _("The GRAMPS ID prefix is invalid.\n")+ + idexampletext, + self.window) + return False + elif incompatible: + QuestionDialog.OkDialog( _("Incompatible GRAMPS ID prefix"), + _("The GRAMPS ID prefix is in an unusual format and may"+ + " cause problems when exporting the database to GEDCOM format.\n")+ + idexampletext, + self.window) + elif len(testresult) != len(prefixes)*len(testnums): + QuestionDialog.ErrorDialog( _("Unsuited GRAMPS ID prefix"), + _("The GRAMPS ID prefix is unsuited because it does not"+ + " distinguish between different objects.\n")+ + idexampletext, + self.window) + return False + GrampsKeys.save_iprefix(ip) + GrampsKeys.save_oprefix(op) + GrampsKeys.save_fprefix(fp) + GrampsKeys.save_sprefix(sp) + GrampsKeys.save_pprefix(pp) + return True + def select(self,obj): store,node = self.selection.get_selected() if node: @@ -335,7 +382,9 @@ class GrampsPreferences: def on_propertybox_help(self,obj): GrampsDisplay.help('gramps-prefs') - def on_close_clicked(self,obj): + def on_close_clicked(self,obj=None,dummy=None): + if not self.save_prefix(): + return False self.gladeif.close() self.window.destroy() diff --git a/gramps2/src/plugins/FilterEditor.py b/gramps2/src/plugins/FilterEditor.py index f4f14062a..9e8bff4ba 100644 --- a/gramps2/src/plugins/FilterEditor.py +++ b/gramps2/src/plugins/FilterEditor.py @@ -937,7 +937,7 @@ class SystemFilterEditor(Tool.Tool): def __init__(self,db,person,options_class,name,callback=None,parent=None): Tool.Tool.__init__(self,db,person,options_class,name) - FilterEditor(const.system_filters,database,parent) + FilterEditor(const.system_filters,db,parent) #------------------------------------------------------------------------ # @@ -960,7 +960,7 @@ class FilterEditorOptions(Tool.ToolOptions): from PluginMgr import register_tool register_tool( - name = 'sfilted', + name = 'cfilted', category = Tool.TOOL_UTILS, tool_class = CustomFilterEditor, options_class = FilterEditorOptions,