* src/plugins/FilterEditor.py: Corrected plugin registration

* src/GrampsCfg.py: Add validation for GRAMPS ID prefixes


svn: r5408
This commit is contained in:
Martin Hawlisch 2005-11-20 21:20:49 +00:00
parent 421cda654c
commit e0ccdacfbd
3 changed files with 76 additions and 23 deletions

View File

@ -1,3 +1,7 @@
2005-11-20 Martin Hawlisch <Martin.Hawlisch@gmx.de>
* src/plugins/FilterEditor.py: Corrected plugin registration
* src/GrampsCfg.py: Add validation for GRAMPS ID prefixes
2005-11-19 Don Allingham <don@gramps-project.org> 2005-11-19 Don Allingham <don@gramps-project.org>
* src/WriteGedcom.py: add space between given and surname in output. * src/WriteGedcom.py: add space between given and surname in output.
* src/ReadGedcom.py: encoding list change * src/ReadGedcom.py: encoding list change

View File

@ -26,6 +26,7 @@
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
import os import os
import sets
from gettext import gettext as _ from gettext import gettext as _
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
@ -48,6 +49,7 @@ import const
import Utils import Utils
import DateHandler import DateHandler
import GrampsDisplay import GrampsDisplay
import QuestionDialog
from WindowUtils import GladeIf from WindowUtils import GladeIf
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
@ -150,6 +152,7 @@ class GrampsPreferences:
self.gladeif.connect('button7','clicked',self.on_propertybox_help) self.gladeif.connect('button7','clicked',self.on_propertybox_help)
self.window = self.top.get_widget("preferences") self.window = self.top.get_widget("preferences")
self.window.connect('delete_event',self.on_close_clicked)
self.tree = self.top.get_widget("tree") self.tree = self.top.get_widget("tree")
self.store = gtk.TreeStore(gobject.TYPE_STRING) self.store = gtk.TreeStore(gobject.TYPE_STRING)
self.selection = self.tree.get_selection() self.selection = self.tree.get_selection()
@ -197,26 +200,16 @@ class GrampsPreferences:
lds.connect('toggled', lds.connect('toggled',
lambda obj: GrampsKeys.save_uselds(obj.get_active())) lambda obj: GrampsKeys.save_uselds(obj.get_active()))
ipr = self.top.get_widget("iprefix") self.ipr = self.top.get_widget("iprefix")
ipr.set_text(GrampsKeys.get_person_id_prefix()) self.ipr.set_text(GrampsKeys.get_person_id_prefix())
ipr.connect('changed', self.opr = self.top.get_widget("oprefix")
lambda obj: GrampsKeys.save_iprefix(obj.get_text())) self.opr.set_text(GrampsKeys.get_object_id_prefix())
opr = self.top.get_widget("oprefix") self.fpr = self.top.get_widget("fprefix")
opr.set_text(GrampsKeys.get_object_id_prefix()) self.fpr.set_text(GrampsKeys.get_family_id_prefix())
opr.connect('changed', self.spr = self.top.get_widget("sprefix")
lambda obj: GrampsKeys.save_oprefix(obj.get_text())) self.spr.set_text(GrampsKeys.get_source_id_prefix())
fpr = self.top.get_widget("fprefix") self.ppr = self.top.get_widget("pprefix")
fpr.set_text(GrampsKeys.get_family_id_prefix()) self.ppr.set_text(GrampsKeys.get_place_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()))
sb2 = self.top.get_widget("stat2") sb2 = self.top.get_widget("stat2")
sb3 = self.top.get_widget("stat3") sb3 = self.top.get_widget("stat3")
@ -325,6 +318,60 @@ class GrampsPreferences:
resemail.connect('changed', resemail.connect('changed',
lambda obj: GrampsKeys.save_researcher_email(obj.get_text())) 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): def select(self,obj):
store,node = self.selection.get_selected() store,node = self.selection.get_selected()
if node: if node:
@ -335,7 +382,9 @@ class GrampsPreferences:
def on_propertybox_help(self,obj): def on_propertybox_help(self,obj):
GrampsDisplay.help('gramps-prefs') 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.gladeif.close()
self.window.destroy() self.window.destroy()

View File

@ -937,7 +937,7 @@ class SystemFilterEditor(Tool.Tool):
def __init__(self,db,person,options_class,name,callback=None,parent=None): def __init__(self,db,person,options_class,name,callback=None,parent=None):
Tool.Tool.__init__(self,db,person,options_class,name) 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 from PluginMgr import register_tool
register_tool( register_tool(
name = 'sfilted', name = 'cfilted',
category = Tool.TOOL_UTILS, category = Tool.TOOL_UTILS,
tool_class = CustomFilterEditor, tool_class = CustomFilterEditor,
options_class = FilterEditorOptions, options_class = FilterEditorOptions,