From 451688b309884daa410fff70391ac432f055dea8 Mon Sep 17 00:00:00 2001 From: Alex Roitman Date: Thu, 3 Aug 2006 19:49:29 +0000 Subject: [PATCH] 2006-08-03 Alex Roitman * src/Filters/Rules/Person/_HasIdOf.py: Cleanup. * src/Filters/Rules/Person/__init__.py (editor_rule_list): Add RegExpIdOf. * src/Filters/Rules/Person/_RegExpIdOf.py: Cleanup. * src/Filters/Rules/_RegExpIdBase.py: Cleanup. * src/Filters/Rules/Person/_HasRelationship.py: Cleanup. * src/Filters/Rules/Family/_HasIdOf.py: Cleanup. * src/Filters/Rules/Family/_RegExpIdOf.py: Cleanup. * src/FilterEditor/_EditRule.py: Clean, localization fixes, ID selection fixes. * src/NameDisplay.py: Import gettext. * src/Filters/Rules/Family/_HasRelType.py (labels): Use lowercase. * src/FilterEditor/_EditFilter.py (on_add_clicked, on_edit_clicked): Catch exception. svn: r7115 --- gramps2/ChangeLog | 16 ++ gramps2/src/FilterEditor/_EditFilter.py | 15 +- gramps2/src/FilterEditor/_EditRule.py | 151 ++++++++++-------- gramps2/src/Filters/Rules/Family/_HasIdOf.py | 6 +- .../src/Filters/Rules/Family/_HasRelType.py | 2 +- .../src/Filters/Rules/Family/_RegExpIdOf.py | 12 +- gramps2/src/Filters/Rules/Person/_HasIdOf.py | 4 +- .../src/Filters/Rules/Person/_RegExpIdOf.py | 27 +--- gramps2/src/Filters/Rules/Person/__init__.py | 1 + gramps2/src/Filters/Rules/_RegExpIdBase.py | 16 +- gramps2/src/NameDisplay.py | 7 + 11 files changed, 146 insertions(+), 111 deletions(-) diff --git a/gramps2/ChangeLog b/gramps2/ChangeLog index 933bc5220..81f28aa0c 100644 --- a/gramps2/ChangeLog +++ b/gramps2/ChangeLog @@ -1,3 +1,19 @@ +2006-08-03 Alex Roitman + * src/Filters/Rules/Person/_HasIdOf.py: Cleanup. + * src/Filters/Rules/Person/__init__.py (editor_rule_list): Add + RegExpIdOf. + * src/Filters/Rules/Person/_RegExpIdOf.py: Cleanup. + * src/Filters/Rules/_RegExpIdBase.py: Cleanup. + * src/Filters/Rules/Person/_HasRelationship.py: Cleanup. + * src/Filters/Rules/Family/_HasIdOf.py: Cleanup. + * src/Filters/Rules/Family/_RegExpIdOf.py: Cleanup. + * src/FilterEditor/_EditRule.py: Clean, localization fixes, ID + selection fixes. + * src/NameDisplay.py: Import gettext. + * src/Filters/Rules/Family/_HasRelType.py (labels): Use lowercase. + * src/FilterEditor/_EditFilter.py (on_add_clicked, + on_edit_clicked): Catch exception. + 2006-08-03 Zsolt Foldvari * src/plugins/Check.py (cleanup_deleted_name_formats): Change hardcoded values with constants. diff --git a/gramps2/src/FilterEditor/_EditFilter.py b/gramps2/src/FilterEditor/_EditFilter.py index f559da105..ef4e8b2f4 100644 --- a/gramps2/src/FilterEditor/_EditFilter.py +++ b/gramps2/src/FilterEditor/_EditFilter.py @@ -50,6 +50,7 @@ import const import ListModel import ManagedWindow import GrampsDisplay +import Errors #------------------------------------------------------------------------- # @@ -165,8 +166,11 @@ class EditFilter(ManagedWindow.ManagedWindow): def on_add_clicked(self,obj): from _EditRule import EditRule - EditRule(self.space, self.dbstate, self.uistate, self.track, - self.filterdb, None, _('Add Rule'), self.update_rule) + try: + EditRule(self.space, self.dbstate, self.uistate, self.track, + self.filterdb, None, _('Add Rule'), self.update_rule) + except Errors.WindowActiveError: + pass def on_edit_clicked(self,obj): store, node = self.rlist.get_selected() @@ -175,8 +179,11 @@ class EditFilter(ManagedWindow.ManagedWindow): d = self.rlist.get_object(node) - EditRule(self.space, self.dbstate, self.uistate, self.track, - self.filterdb, d, _('Edit Rule'), self.update_rule) + try: + EditRule(self.space, self.dbstate, self.uistate, self.track, + self.filterdb, d, _('Edit Rule'), self.update_rule) + except Errors.WindowActiveError: + pass def update_rule(self, old_rule, new_rule): if old_rule: diff --git a/gramps2/src/FilterEditor/_EditRule.py b/gramps2/src/FilterEditor/_EditRule.py index 19a09cdd5..93010272b 100644 --- a/gramps2/src/FilterEditor/_EditRule.py +++ b/gramps2/src/FilterEditor/_EditRule.py @@ -48,19 +48,20 @@ log = logging.getLogger(".FilterEdit") #------------------------------------------------------------------------- import gtk import gobject -import GrampsDisplay #------------------------------------------------------------------------- # # GRAMPS modules # #------------------------------------------------------------------------- +import GrampsDisplay import const import RelLib from Filters import Rules import AutoComp from Selectors import selector_factory -SelectPerson = selector_factory('Person') +from NameDisplay import displayer as _nd +import Utils import ManagedWindow #------------------------------------------------------------------------- @@ -76,17 +77,14 @@ def by_rule_name(f,s): # Constants # #------------------------------------------------------------------------- -_name2list = { - _('Personal event:') : RelLib.EventType().get_map(), - _('Family event:') : RelLib.EventType().get_map(), - _('Personal attribute:') : RelLib.AttributeType().get_map(), - _('Family attribute:') : RelLib.AttributeType().get_map(), +_name2typeclass = { + _('Personal event:') : RelLib.EventType, + _('Family event:') : RelLib.EventType, + _('Personal attribute:') : RelLib.AttributeType, + _('Family attribute:') : RelLib.AttributeType, + _('Relationship type:') : RelLib.FamilyRelType, } -_menulist = { - _('Relationship type:') : RelLib.FamilyRelType().get_map(), - } - #------------------------------------------------------------------------- # # MyBoolean - check button with standard interface @@ -99,10 +97,19 @@ class MyBoolean(gtk.CheckButton): self.show() def get_text(self): + """ + This method returns the text to save. It should be the same + no matter the present locale (English or numeric types). + This class sets this to get_display_text, but when localization + is an issue (events/attr/etc types) then it has to be overridden. + """ return str(int(self.get_active())) def set_text(self,val): - is_active = not not int(val) + """ + This method sets the selector state to display the passed value. + """ + is_active = bool(int(val)) self.set_active(is_active) #------------------------------------------------------------------------- @@ -210,14 +217,25 @@ class MyPlaces(gtk.Entry): # #------------------------------------------------------------------------- class MyID(gtk.HBox): + + obj_name = { + 'Person' : _('Person'), + 'Family' : _('Family'), + 'Event' : _('Event'), + 'Place' : _('Place'), + 'Source' : _('Source'), + 'MediaObject' : _('Media Object'), + 'Repository' : _('Repository'), + } - def __init__(self, dbstate, uistate, track): + def __init__(self, dbstate, uistate, track, obj_class='Person'): gtk.HBox.__init__(self,False,6) self.dbstate = dbstate self.db = dbstate.db self.uistate = uistate self.track = track + self.obj_class = obj_class self.entry = gtk.Entry() self.entry.show() self.button = gtk.Button() @@ -227,14 +245,15 @@ class MyID(gtk.HBox): self.pack_start(self.entry) self.add(self.button) self.tooltips = gtk.Tooltips() - self.tooltips.set_tip(self.button,_('Select person from a list')) + self.tooltips.set_tip(self.button,_('Select %s from a list') + % self.obj_name[obj_class]) self.tooltips.enable() self.show() self.set_text('') def button_press(self,obj): - inst = SelectPerson(self.dbstate, self.uistate, self.track, - _('Select Person')) + selector = selector_factory(self.obj_class) + inst = selector(self.dbstate, self.uistate, self.track) val = inst.run() if val == None: self.set_text('') @@ -244,13 +263,37 @@ class MyID(gtk.HBox): def get_text(self): return unicode(self.entry.get_text()) + def name_from_gramps_id(self,gramps_id): + if self.obj_class == 'Person': + person = self.db.get_person_from_gramps_id(gramps_id) + print gramps_id + name = _nd.display_name(person.get_primary_name()) + elif self.obj_class == 'Family': + family = self.db.get_family_from_gramps_id(gramps_id) + name = Utils.family_name(family, self.db) + elif self.obj_class == 'Event': + event = self.db.get_event_from_gramps_id(gramps_id) + name = str(event.get_type) + elif self.obj_class == 'Place': + place = self.db.get_place_from_gramps_id(gramps_id) + name = place.get_title() + elif self.obj_class == 'Source': + source = self.db.get_source_from_gramps_id(gramps_id) + name = source.get_title() + elif self.obj_class == 'MediaObject': + obj = self.db.get_object_from_gramps_id(gramps_id) + name = obj.get_path() + elif self.obj_class == 'Repository': + repo = self.db.get_repository_from_gramps_id(gramps_id) + name = repo.get_name() + return name + def set_text(self,val): try: - p = self.db.get_person_from_handle(val) - n = p.get_primary_name().get_name() - self.tooltips.set_tip(self.entry,n) - except: - self.tooltips.set_tip(self.entry,_('Not a valid person')) + name = self.name_from_gramps_id(val) + self.tooltips.set_tip(self.entry,name) + except AttributeError: + self.tooltips.set_tip(self.entry,_('Not a valid ID')) self.entry.set_text(val) #------------------------------------------------------------------------- @@ -260,48 +303,21 @@ class MyID(gtk.HBox): #------------------------------------------------------------------------- class MySelect(gtk.ComboBoxEntry): - def __init__(self, values): + def __init__(self, type_class): gtk.ComboBoxEntry.__init__(self) - AutoComp.fill_combo(self, values) + self.type_class = type_class + self.sel = AutoComp.StandardCustomSelector(type_class._I2SMAP, self, + type_class._CUSTOM, + type_class._DEFAULT) self.show() def get_text(self): - return unicode(self.child.get_text()) + return self.type_class(self.sel.get_values()).xml_str() def set_text(self,val): - self.child.set_text(_(val)) - -#------------------------------------------------------------------------- -# -# -# -#------------------------------------------------------------------------- -class MyListSelect(gtk.ComboBox): - - def __init__(self,data_list): - gtk.ComboBox.__init__(self) - store = gtk.ListStore(str) - self.set_model(store) - cell = gtk.CellRendererText() - self.pack_start(cell,True) - self.add_attribute(cell,'text',0) - self.data_list = data_list - - for item in data_list: - store.append(row=[item]) - self.set_active(0) - self.show() - - def get_text(self): - active = self.get_active() - if active < 0: - return str(-1) - return str(active) - - def set_text(self,val): - active = int(val) - if active >=0: - self.set_active(active) + tc = self.type_class() + tc.set_from_xml_str(val) + self.sel.set_values((tc.val,tc.string)) #------------------------------------------------------------------------- # @@ -379,26 +395,23 @@ class EditRule(ManagedWindow.ManagedWindow): table.set_row_spacings(6) table.show() for v in arglist: - v1 = _(v) - l = gtk.Label(v1) + l = gtk.Label(v) l.set_alignment(1,0.5) l.show() if v == _('Place:'): t = MyPlaces([]) elif v == _('Number of generations:'): t = MyInteger(1,32) - elif v == _('ID:'): - t = MyID(self.dbstate, self.uistate, self.track) + elif v == _('Person ID:'): + t = MyID(self.dbstate, self.uistate, self.track, 'Person') + elif v == _('Family ID:'): + t = MyID(self.dbstate, self.uistate, self.track, 'Family') elif v == _('Source ID:'): t = MySource(self.db) elif v == _('Filter name:'): t = MyFilters(self.filterdb.get_filters(self.space)) - elif _name2list.has_key(v1): - data =_name2list[v1] - t = MySelect(data.values()) - elif _menulist.has_key(v1): - data =_menulist[v1] - t = MyListSelect(data.values()) + elif _name2typeclass.has_key(v): + t = MySelect(_name2typeclass[v]) elif v == _('Inclusive:'): t = MyBoolean(_('Include original person')) elif v == _('Case sensitive:'): @@ -516,8 +529,8 @@ class EditRule(ManagedWindow.ManagedWindow): page = self.notebook.get_current_page() (class_obj,vallist,tlist) = self.page[page] value_list = [] - for x in tlist: - value_list.append(unicode(x.get_text())) + for selector_class in tlist: + value_list.append(unicode(selector_class.get_text())) new_rule = class_obj(value_list) self.update_rule(self.active_rule, new_rule) diff --git a/gramps2/src/Filters/Rules/Family/_HasIdOf.py b/gramps2/src/Filters/Rules/Family/_HasIdOf.py index 11c2448e1..24cb2a572 100644 --- a/gramps2/src/Filters/Rules/Family/_HasIdOf.py +++ b/gramps2/src/Filters/Rules/Family/_HasIdOf.py @@ -40,10 +40,8 @@ from Filters.Rules import HasGrampsId # #------------------------------------------------------------------------- class HasIdOf(HasGrampsId): - """Rule that checks for a person with a specific GRAMPS ID""" + """Rule that checks for a family with a specific GRAMPS ID""" - labels = [ _('ID:') ] + labels = [ _('Family ID:') ] name = _('Family with ') description = _("Matches a family with a specified GRAMPS ID") - category = _('General filters') - diff --git a/gramps2/src/Filters/Rules/Family/_HasRelType.py b/gramps2/src/Filters/Rules/Family/_HasRelType.py index 18c89d92a..f09a8e9e3 100644 --- a/gramps2/src/Filters/Rules/Family/_HasRelType.py +++ b/gramps2/src/Filters/Rules/Family/_HasRelType.py @@ -42,7 +42,7 @@ from Filters.Rules._Rule import Rule class HasRelType(Rule): """Rule that checks for a person with a particular personal attribute""" - labels = [ _('Relationship Type:') ] + labels = [ _('Relationship type:') ] name = _('Family with the relationship type') description = _("Matches family with the relationship type " "of a particular value") diff --git a/gramps2/src/Filters/Rules/Family/_RegExpIdOf.py b/gramps2/src/Filters/Rules/Family/_RegExpIdOf.py index a789ebb12..2f1f64b28 100644 --- a/gramps2/src/Filters/Rules/Family/_RegExpIdOf.py +++ b/gramps2/src/Filters/Rules/Family/_RegExpIdOf.py @@ -26,7 +26,6 @@ # #------------------------------------------------------------------------- from gettext import gettext as _ -import re #------------------------------------------------------------------------- # @@ -41,8 +40,11 @@ from Filters.Rules._RegExpIdBase import RegExpIdBase # #------------------------------------------------------------------------- class RegExpIdOf(RegExpIdBase): - """Rule that checks for a person with a specific GRAMPS ID""" - - name = _('Families with ') - description = _("Matches families with a GRAMPS ID that contains the regular expression") + """ + Rule that checks for a family whose GRAMPS ID + matches regular expression. + """ + name = _('Families with matching regular expression') + description = _("Matches families whose GRAMPS ID matches " + "the regular expression") diff --git a/gramps2/src/Filters/Rules/Person/_HasIdOf.py b/gramps2/src/Filters/Rules/Person/_HasIdOf.py index f3ca7bb4a..3ffbda604 100644 --- a/gramps2/src/Filters/Rules/Person/_HasIdOf.py +++ b/gramps2/src/Filters/Rules/Person/_HasIdOf.py @@ -42,8 +42,6 @@ from Filters.Rules import HasGrampsId class HasIdOf(HasGrampsId): """Rule that checks for a person with a specific GRAMPS ID""" - labels = [ _('ID:') ] + labels = [ _('Person ID:') ] name = _('People with ') description = _("Matches people with a specified GRAMPS ID") - category = _('General filters') - diff --git a/gramps2/src/Filters/Rules/Person/_RegExpIdOf.py b/gramps2/src/Filters/Rules/Person/_RegExpIdOf.py index 5e6bb422f..e1121c6ba 100644 --- a/gramps2/src/Filters/Rules/Person/_RegExpIdOf.py +++ b/gramps2/src/Filters/Rules/Person/_RegExpIdOf.py @@ -26,35 +26,24 @@ # #------------------------------------------------------------------------- from gettext import gettext as _ -import re #------------------------------------------------------------------------- # # GRAMPS modules # #------------------------------------------------------------------------- -from Filters.Rules._Rule import Rule +from Filters.Rules._RegExpIdBase import RegExpIdBase #------------------------------------------------------------------------- # # HasIdOf # #------------------------------------------------------------------------- -class RegExpIdOf(Rule): - """Rule that checks for a person with a specific GRAMPS ID""" +class RegExpIdOf(RegExpIdBase): + """Rule that checks for a person whose GRAMPS ID + matches regular expression. + """ - labels = [ _('ID:') ] - name = _('People with ') - description = _("Matches people with a GRAMPS ID that contains the regular expression") - category = _('General filters') - - def __init__(self, list): - Rule.__init__(self, list) - - try: - self.match = re.compile(list[0],re.I|re.U|re.L) - except: - self.match = re.compile('') - - def apply(self,db,person): - return self.match.match(person.gramps_id) != None + name = _('People with matching regular expression') + description = _("Matches people whose GRAMPS ID matches " + "the regular expression") diff --git a/gramps2/src/Filters/Rules/Person/__init__.py b/gramps2/src/Filters/Rules/Person/__init__.py index 3e55f9de6..a67341a8c 100644 --- a/gramps2/src/Filters/Rules/Person/__init__.py +++ b/gramps2/src/Filters/Rules/Person/__init__.py @@ -151,6 +151,7 @@ editor_rule_list = [ HasTextMatchingSubstringOf, HasNote, HasNoteRegexp, + RegExpIdOf, ] def register(rule): diff --git a/gramps2/src/Filters/Rules/_RegExpIdBase.py b/gramps2/src/Filters/Rules/_RegExpIdBase.py index bd683ba4e..9c280209c 100644 --- a/gramps2/src/Filters/Rules/_RegExpIdBase.py +++ b/gramps2/src/Filters/Rules/_RegExpIdBase.py @@ -41,11 +41,15 @@ from _Rule import Rule # #------------------------------------------------------------------------- class RegExpIdBase(Rule): - """Rule that checks for a person with a specific GRAMPS ID""" + """ + Rule that checks for an object whose GRAMPS ID + matches regular expression. + """ - labels = [ _('ID:') ] - name = _('Families with ') - description = _("Matches families with a GRAMPS ID that contains the regular expression") + labels = [ _('Regular expression:') ] + name = _('Objects with ') + description = _("Matches objects whose GRAMPS ID matches " + "the regular expression") category = _('General filters') def __init__(self, list): @@ -56,5 +60,5 @@ class RegExpIdBase(Rule): except: self.match = re.compile('') - def apply(self,db,person): - return self.match.match(person.gramps_id) != None + def apply(self,db,obj): + return self.match.match(obj.gramps_id) != None diff --git a/gramps2/src/NameDisplay.py b/gramps2/src/NameDisplay.py index d99443896..2bf669ffd 100644 --- a/gramps2/src/NameDisplay.py +++ b/gramps2/src/NameDisplay.py @@ -24,6 +24,13 @@ Class handling language-specific displaying of names. """ +#------------------------------------------------------------------------- +# +# Python modules +# +#------------------------------------------------------------------------- +from gettext import gettext as _ + #------------------------------------------------------------------------- # # GRAMPS modules