From ad337312d4ca49957e2b52ae5d02c018a3548167 Mon Sep 17 00:00:00 2001 From: Don Allingham Date: Wed, 29 Dec 2004 05:06:10 +0000 Subject: [PATCH] * src/DateEdit.py: use global date displayer/parser * src/DateHandler.py: provide global date displayer/parser instead of having a bunch of different classes have their own handler that needs to be updated with the handlers change. * src/EditPerson.py: use global date displayer/parser * src/EventEdit.py: use global date displayer/parser * src/FamilyView.py: use global date displayer/parser * src/GenericFilter.py: use global date displayer/parser * src/GrampsCfg.py: remove unused statements * src/ImageSelect.py: use global date displayer/parser * src/Marriage.py: use global date displayer/parser * src/ReadXML.py: use global date displayer/parser * src/RelLib.py: don't require get_display_info, eliminate needed for importing const and GrampsCfg * src/SelectChild.py: don't require get_display_info * src/Sources.py: use global date displayer/parser * src/plugins/RelCalc.py: don't require get_display_info svn: r3841 --- gramps2/ChangeLog | 19 +++++++++++ gramps2/src/DateEdit.py | 19 +++++------ gramps2/src/DateHandler.py | 59 ++++++++++++---------------------- gramps2/src/EditPerson.py | 4 +-- gramps2/src/EventEdit.py | 4 +-- gramps2/src/FamilyView.py | 34 +++++++++++--------- gramps2/src/GenericFilter.py | 10 +++--- gramps2/src/GrampsCfg.py | 2 -- gramps2/src/ImageSelect.py | 4 +-- gramps2/src/Marriage.py | 2 +- gramps2/src/ReadXML.py | 2 +- gramps2/src/RelLib.py | 50 ++++++---------------------- gramps2/src/SelectChild.py | 23 +++++++++++-- gramps2/src/Sources.py | 4 +-- gramps2/src/plugins/RelCalc.py | 29 +++++++++++------ 15 files changed, 129 insertions(+), 136 deletions(-) diff --git a/gramps2/ChangeLog b/gramps2/ChangeLog index 5be1a69b2..4a9fc3f83 100644 --- a/gramps2/ChangeLog +++ b/gramps2/ChangeLog @@ -1,3 +1,22 @@ +2004-12-28 Don Allingham + * src/DateEdit.py: use global date displayer/parser + * src/DateHandler.py: provide global date displayer/parser + instead of having a bunch of different classes have their + own handler that needs to be updated with the handlers change. + * src/EditPerson.py: use global date displayer/parser + * src/EventEdit.py: use global date displayer/parser + * src/FamilyView.py: use global date displayer/parser + * src/GenericFilter.py: use global date displayer/parser + * src/GrampsCfg.py: remove unused statements + * src/ImageSelect.py: use global date displayer/parser + * src/Marriage.py: use global date displayer/parser + * src/ReadXML.py: use global date displayer/parser + * src/RelLib.py: don't require get_display_info, eliminate + needed for importing const and GrampsCfg + * src/SelectChild.py: don't require get_display_info + * src/Sources.py: use global date displayer/parser + * src/plugins/RelCalc.py: don't require get_display_info + 2004-12-27 Don Allingham * src/ChooseParents.py: remove TreeModelFilter stuff. * src/GenericFilter.py: Add a combobox that handles filter diff --git a/gramps2/src/DateEdit.py b/gramps2/src/DateEdit.py index 8affa4abe..f8d87c85a 100644 --- a/gramps2/src/DateEdit.py +++ b/gramps2/src/DateEdit.py @@ -84,16 +84,13 @@ QUAL_TEXT = ( (Date.QUAL_ESTIMATED, _('Estimated')), (Date.QUAL_CALCULATED, _('Calculated')) ) -dd = DateHandler.create_display() -dp = DateHandler.create_parser() - CAL_TO_MONTHS_NAMES = { - Date.CAL_GREGORIAN : dd._MONS, - Date.CAL_JULIAN : dd._MONS, - Date.CAL_HEBREW : dd._hebrew, - Date.CAL_FRENCH : dd._french, - Date.CAL_PERSIAN : dd._persian, - Date.CAL_ISLAMIC : dd._islamic } + Date.CAL_GREGORIAN : DateHandler.displayer._MONS, + Date.CAL_JULIAN : DateHandler.displayer._MONS, + Date.CAL_HEBREW : DateHandler.displayer._hebrew, + Date.CAL_FRENCH : DateHandler.displayer._french, + Date.CAL_PERSIAN : DateHandler.displayer._persian, + Date.CAL_ISLAMIC : DateHandler.displayer._islamic } #------------------------------------------------------------------------- # @@ -148,7 +145,7 @@ class DateEdit: text = unicode(self.text_obj.get_text()) if text != self.text: self.text = text - self.date_obj.copy(dp.parse(text)) + self.date_obj.copy(DateHandler.parser.parse(text)) self.check() def invoke_date_editor(self,obj): @@ -161,7 +158,7 @@ class DateEdit: the_date = date_dialog.return_date if the_date: self.date_obj.copy(the_date) - self.text_obj.set_text(dd.display(self.date_obj)) + self.text_obj.set_text(DateHandler.displayer.display(self.date_obj)) self.check() #------------------------------------------------------------------------- diff --git a/gramps2/src/DateHandler.py b/gramps2/src/DateHandler.py index 55ccc98b4..211e8ef95 100644 --- a/gramps2/src/DateHandler.py +++ b/gramps2/src/DateHandler.py @@ -68,44 +68,6 @@ _lang_to_display = { 'en' : DateDisplay.DateDisplay, } -#------------------------------------------------------------------------- -# -# Functions -# -#------------------------------------------------------------------------- -def create_parser(): - """ - Creates a new date parser class, based on the current locale. - - @returns: DateParser class specific to the locale specific. If - no parser exists for the current locale, the English language - parser is returned. - @rtype: DateParser - """ - try: - return _lang_to_parser[_lang]() - except: - import traceback - traceback.print_stack() - print "Date parser for",_lang,"not available" - return DateParser.DateParser() - -def create_display(): - """ - Creates a new date displayer class, based on the current locale. - - @returns: DateDisplay class specific to the locale specific. If - no parser exists for the current locale, the English language - parser is returned. - @rtype: DateDisplay - """ - try: - val = GrampsGconfKeys.get_date_format(_lang_to_display[_lang].formats) - return _lang_to_display[_lang](val) - except: - print "Date displayer for",_lang,"not available" - return DateDisplay.DateDisplay(3) - def get_date_formats(): """ Returns the lists supported formats for date parsers and displayers @@ -149,3 +111,24 @@ from Plugins import load_plugins from const import datesDir load_plugins(datesDir) +#------------------------------------------------------------------------- +# +# Initialize global parser +# +#------------------------------------------------------------------------- + +try: + parser = _lang_to_parser[_lang]() +except: + import traceback + traceback.print_stack() + print "Date parser for",_lang,"not available, using default" + parser = DateParser.DateParser() + +try: + val = GrampsGconfKeys.get_date_format(_lang_to_display[_lang].formats) + displayer = _lang_to_display[_lang](val) +except: + print "Date displayer for",_lang,"not available, using default" + displayer = DateDisplay.DateDisplay(3) + diff --git a/gramps2/src/EditPerson.py b/gramps2/src/EditPerson.py index 6d9e774b1..722edd02f 100644 --- a/gramps2/src/EditPerson.py +++ b/gramps2/src/EditPerson.py @@ -100,8 +100,8 @@ class EditPerson: def __init__(self,parent,person,db,callback=None): """Creates an edit window. Associates a person with the window.""" - self.dp = DateHandler.create_parser() - self.dd = DateHandler.create_display() + self.dp = DateHandler.parser + self.dd = DateHandler.displayer self.person = person self.orig_surname = person.get_primary_name().get_group_name() self.parent = parent diff --git a/gramps2/src/EventEdit.py b/gramps2/src/EventEdit.py index 9d27fc17c..1e8a83eb7 100644 --- a/gramps2/src/EventEdit.py +++ b/gramps2/src/EventEdit.py @@ -81,8 +81,8 @@ class EventEditor: self.plist = [] self.pmap = {} - self.dp = DateHandler.create_parser() - self.dd = DateHandler.create_display() + self.dp = DateHandler.parser + self.dd = DateHandler.displayer values = {} for v in elist: diff --git a/gramps2/src/FamilyView.py b/gramps2/src/FamilyView.py index 004f1d1e6..12007d131 100644 --- a/gramps2/src/FamilyView.py +++ b/gramps2/src/FamilyView.py @@ -183,7 +183,6 @@ class FamilyView: def init_interface(self): fv = GrampsGconfKeys.get_family_view() - self.dd = DateHandler.create_display() self.set_widgets(fv) already_init = self.cadded[fv] @@ -926,18 +925,21 @@ class FamilyView: dd = self.parent.db.get_event_from_handle(self.person.get_death_handle()) if bd and dd: - n = "%s [%s]\n\t%s %s\n\t%s %s " % (GrampsCfg.get_nameof()(self.person), - self.person.get_gramps_id(), - _BORN,self.dd.display(bd.get_date_object()), - _DIED,self.dd.display(dd.get_date_object())) + n = "%s [%s]\n\t%s %s\n\t%s %s " % ( + GrampsCfg.get_nameof()(self.person), + self.person.get_gramps_id(), + _BORN,DateHandler.displayer.display(bd.get_date_object()), + _DIED,DateHandler.displayer.display(dd.get_date_object())) elif bd: - n = "%s [%s]\n\t%s %s" % (GrampsCfg.get_nameof()(self.person), - self.person.get_gramps_id(), - _BORN,self.dd.display(bd.get_date_object())) + n = "%s [%s]\n\t%s %s" % ( + GrampsCfg.get_nameof()(self.person), + self.person.get_gramps_id(), + _BORN,DateHandler.displayer.display(bd.get_date_object())) elif dd: - n = "%s [%s]\n\t%s %s" % (GrampsCfg.get_nameof()(self.person), - self.person.get_gramps_id(), - _DIED,self.dd.display(dd.get_date_object())) + n = "%s [%s]\n\t%s %s" % ( + GrampsCfg.get_nameof()(self.person), + self.person.get_gramps_id(), + _DIED,DateHandler.displayer.display(dd.get_date_object())) else: n = "%s [%s]" % (GrampsCfg.get_nameof()(self.person), self.person.get_gramps_id()) @@ -976,13 +978,13 @@ class FamilyView: sp = self.parent.db.get_person_from_handle(sp_id) event = self.find_marriage(fm) if event: - mdate = " - %s" % self.dd.display(event.get_date_object()) + mdate = " - %s" % DateHandler.displayer.display(event.get_date_object()) else: mdate = "" - v = "%s [%s]\n\t%s%s" % (GrampsCfg.get_nameof()(sp), - sp.get_gramps_id(), - const.family_relations[fm.get_relationship()][0], - mdate) + v = "%s [%s]\n\t%s%s" % ( + GrampsCfg.get_nameof()(sp), + sp.get_gramps_id(), + const.family_relations[fm.get_relationship()][0], mdate) self.spouse_model.set(node,0,v) self.spouse_model.set(node,1,f) else: diff --git a/gramps2/src/GenericFilter.py b/gramps2/src/GenericFilter.py index 22dc09f7d..526ebf02b 100644 --- a/gramps2/src/GenericFilter.py +++ b/gramps2/src/GenericFilter.py @@ -53,8 +53,6 @@ from TransTable import TransTable from gettext import gettext as _ from Utils import for_each_ancestor -_date_parser = DateHandler.create_parser() - #------------------------------------------------------------------------- # # date_cmp @@ -977,7 +975,7 @@ class HasEvent(Rule): def __init__(self,list): Rule.__init__(self,list) if self.list and self.list[0]: - self.date = _date_parser.parse(self.list[0]) + self.date = DateHandler.parser.parse(self.list[0]) else: self.date = None @@ -1030,7 +1028,7 @@ class HasFamilyEvent(Rule): def __init__(self,list): Rule.__init__(self,list) if self.list and self.list[0]: - self.date = _date_parser.parse(self.list[0]) + self.date = DateHandler.parser.parse(self.list[0]) else: self.date = None @@ -1141,7 +1139,7 @@ class HasBirth(Rule): def __init__(self,list): Rule.__init__(self,list) if self.list and self.list[0]: - self.date = _date_parser.parse(self.list[0]) + self.date = DateHandler.parser.parse(self.list[0]) else: self.date = None @@ -1187,7 +1185,7 @@ class HasDeath(Rule): def __init__(self,list): Rule.__init__(self,list) if self.list and self.list[0]: - self.date = _date_parser.parse(self.list[0]) + self.date = DateHandler.parser.parse(self.list[0]) else: self.date = None diff --git a/gramps2/src/GrampsCfg.py b/gramps2/src/GrampsCfg.py index e99264939..173882d34 100644 --- a/gramps2/src/GrampsCfg.py +++ b/gramps2/src/GrampsCfg.py @@ -112,7 +112,6 @@ def get_toolbar_style(): def set_calendar_date_format(): format_list = DateHandler.get_date_formats() DateHandler.set_format(GrampsGconfKeys.get_date_format(format_list)) - RelLib.display.set_format(GrampsGconfKeys.get_date_format(format_list)) #------------------------------------------------------------------------- # @@ -279,7 +278,6 @@ class GrampsPreferences: lastnamegen_obj = self.top.get_widget("lastnamegen") menu = gtk.Menu() - choice = 0 for index in range(0,len(_surname_styles)): name = _surname_styles[index] item = gtk.MenuItem(name) diff --git a/gramps2/src/ImageSelect.py b/gramps2/src/ImageSelect.py index a026ac31c..03b724dc8 100644 --- a/gramps2/src/ImageSelect.py +++ b/gramps2/src/ImageSelect.py @@ -876,8 +876,8 @@ class GlobalMediaProperties: def __init__(self,db,obj,update,parent,parent_window=None): self.parent = parent - self.dp = DateHandler.create_parser() - self.dd = DateHandler.create_display() + self.dp = DateHandler.parser + self.dd = DateHandler.displayer if obj: if self.parent.parent.child_windows.has_key(obj.get_handle()): self.parent.parent.child_windows[obj.get_handle()].present(None) diff --git a/gramps2/src/Marriage.py b/gramps2/src/Marriage.py index c1d1eb1ed..091d5f9cf 100644 --- a/gramps2/src/Marriage.py +++ b/gramps2/src/Marriage.py @@ -84,7 +84,7 @@ class Marriage: self.cb = callback self.update_fv = update self.pmap = {} - self.dp = DateHandler.create_parser() + self.dp = DateHandler.parser if family: self.srcreflist = family.get_source_references() diff --git a/gramps2/src/ReadXML.py b/gramps2/src/ReadXML.py index 7d5a7d278..5f62b8acb 100644 --- a/gramps2/src/ReadXML.py +++ b/gramps2/src/ReadXML.py @@ -286,7 +286,7 @@ class GrampsParser: self.gid2oid = {} self.gid2sid = {} self.change = change - self.dp = DateHandler.create_parser() + self.dp = DateHandler.parser self.ord = None self.objref = None diff --git a/gramps2/src/RelLib.py b/gramps2/src/RelLib.py index 4a9a8c920..6ffd0969b 100644 --- a/gramps2/src/RelLib.py +++ b/gramps2/src/RelLib.py @@ -43,8 +43,6 @@ import time #------------------------------------------------------------------------- import Date import DateHandler -import GrampsCfg -import const #------------------------------------------------------------------------- # @@ -58,14 +56,6 @@ CONF_NORMAL = 2 CONF_LOW = 1 CONF_VERY_LOW = 0 -#------------------------------------------------------------------------- -# -# Class definitions -# -#------------------------------------------------------------------------- -display = DateHandler.create_display() -parser = DateHandler.create_parser() - #------------------------------------------------------------------------- # # Class definitions @@ -429,24 +419,6 @@ class Person(PrimaryObject,SourceNote): """ return self.complete - def get_display_info(self): - """ - Returns a list consisting of the information typically used for a - display. The data consists of: Display Name, ID, Gender, Date of Birth, - Date of Death, sort name, etc. - """ - if self.gender == Person.male: - gender = const.male - elif self.gender == Person.female: - gender = const.female - else: - gender = const.unknown - bday = self.birth_handle - dday = self.death_handle - return [ GrampsCfg.get_display_name()(self), self.gramps_id, - gender, bday, dday, self.get_primary_name().get_sort_name(), - GrampsCfg.get_display_surname()(self.primary_name)] - def set_primary_name(self,name): """ Sets the primary name of the Person to the specified @@ -1399,12 +1371,12 @@ class Event(PrimaryObject,DataObj): def set_date(self, date) : """attempts to sets the date of the Event instance""" - self.date = parser.parse(date) + self.date = DateHandler.parser.parse(date) def get_date(self) : """returns a string representation of the date of the Event instance""" if self.date: - return display.display(self.date) + return DateHandler.displayer.display(self.date) return u"" def get_preferred_date(self) : @@ -1415,7 +1387,7 @@ class Event(PrimaryObject,DataObj): """returns a string representation of the date of the Event instance, enclosing the results in quotes if it is not a valid date""" if self.date: - return display.quote_display(self.date) + return DateHandler.displayer.quote_display(self.date) return u"" def get_date_object(self): @@ -1639,7 +1611,7 @@ class MediaObject(PrimaryObject,SourceNote): def get_date(self) : """returns a string representation of the date of the Event instance""" if self.date: - return display.display(self.date) + return DateHandler.displayer.display(self.date) return u"" def get_date_object(self): @@ -1650,7 +1622,7 @@ class MediaObject(PrimaryObject,SourceNote): def set_date(self, date) : """attempts to sets the date of the Event instance""" - self.date = parser.parse(date) + self.date = DateHandler.parser.parse(date) def set_date_object(self,date): """sets the Date object associated with the Event""" @@ -1720,10 +1692,6 @@ class Source(PrimaryObject): self.pubinfo, self.note, self.media_list, self.abbrev, self.change, self.datamap) = data - def get_display_info(self): - return [self.title,self.gramps_id,self.author, - self.title.upper(),self.author.upper()] - def add_media_reference(self,media_id): """Adds a MediaObject object to the Source instance's image list""" self.media_list.append(media_id) @@ -1863,12 +1831,12 @@ class LdsOrd(SourceNote): """attempts to sets the date of the ordinance""" if not self.date: self.date = Date.Date() - parser.set_date(self.date,date) + DateHandler.parser.set_date(self.date,date) def get_date(self) : """returns a string representation of the date of the ordinance""" if self.date: - return display.display(self.date) + return DateHandler.displayer.display(self.date) return u"" def get_date_object(self): @@ -2213,13 +2181,13 @@ class Address(DataObj): def set_date(self,text): """attempts to sets the date that the person lived at the address from the passed string""" - self.date = parser.parse(text) + self.date = DateHandler.parser.parse(text) def get_date(self): """returns a string representation of the date that the person lived at the address""" if self.date: - return display.display(self.date) + return DateHandler.displayer.display(self.date) return u"" def get_preferred_date(self): diff --git a/gramps2/src/SelectChild.py b/gramps2/src/SelectChild.py index eb696c2ca..09daa966a 100644 --- a/gramps2/src/SelectChild.py +++ b/gramps2/src/SelectChild.py @@ -242,8 +242,27 @@ class SelectChild: node = None for idval in person_list: - dinfo = self.db.get_person_from_handle(idval).get_display_info() - rdata = [dinfo[0],dinfo[1],dinfo[3],dinfo[5],dinfo[6]] + person = self.db.get_person_from_handle(idval) + name = person.get_primary_name().get_name() + if person.gender == RelLib.Person.male: + gender = _("male") + elif person.gender == RelLib.Person.female: + gender = _("female") + else: + gender = _("unknown") + + bh = person.get_birth_handle() + dh = person.get_death_handle() + if bh: + bdate = self.db.get_event_from_handle(bh).get_date() + else: + bdate = "" + if dh: + ddate = self.db.get_event_from_handle(bh).get_date() + else: + ddate = "" + + rdata = [name,person.get_gramps_id(),gender,bdate,ddate] new_node = self.refmodel.add(rdata) names = dinfo[0].split(',') if len(names): diff --git a/gramps2/src/Sources.py b/gramps2/src/Sources.py index 207892785..811caf21f 100644 --- a/gramps2/src/Sources.py +++ b/gramps2/src/Sources.py @@ -344,14 +344,12 @@ class SourceEditor: self.author_field = self.get_widget("sauthor") self.pub_field = self.get_widget("spubinfo") - self.dd = DateHandler.create_display() - self.date_entry_field = self.get_widget("sdate") if self.source_ref: self.active_source = self.db.get_source_from_handle(self.source_ref.get_base_handle()) self.date_obj = self.source_ref.get_date() - self.date_entry_field.set_text(self.dd.display(self.date_obj)) + self.date_entry_field.set_text(DateHandler.displayer.display(self.date_obj)) self.private.set_active(self.source_ref.get_privacy()) else: self.date_obj = Date.Date() diff --git a/gramps2/src/plugins/RelCalc.py b/gramps2/src/plugins/RelCalc.py index a1fa99718..b8cae7b50 100644 --- a/gramps2/src/plugins/RelCalc.py +++ b/gramps2/src/plugins/RelCalc.py @@ -42,6 +42,7 @@ import gtk.glade # #------------------------------------------------------------------------- +import RelLib import Utils import GrampsCfg import ListModel @@ -88,21 +89,31 @@ class RelCalc: self.people = self.glade.get_widget("peopleList") - self.clist = ListModel.ListModel(self.people, [(_('Name'),3,150),(_('ID'),1,50), - (_('Birth Date'),4,150), - ('',-1,0),('',-1,0)], + self.clist = ListModel.ListModel(self.people, + [(_('Name'),3,150),(_('ID'),1,50), + (_('Birth Date'),4,150), + ('',-1,0),('',-1,0)], self.on_apply_clicked) self.clist.new_model() for key in self.db.get_person_handles(sort_handles=False): p = self.db.get_person_from_handle(key) if p == self.person: continue - val = self.db.get_person_from_handle(key).get_display_info() - event = self.db.get_event_from_handle(val[3]) - event_date = "" - if event: - event_date = event.get_date () - self.clist.add([val[0],val[1],event_date,val[5],val[6]],p.get_handle()) + bh = p.get_birth_handle() + if bh: + bdate = self.db.get_event_from_handle(bh).get_date() + else: + bdate = "" + name = p.get_primary_name() + if p.get_gender() == RelLib.Person.male: + gender = _("male") + elif p.get_gender() == RelLib.Person.female: + gender = _("female") + else: + gender = _("unknown") + self.clist.add([name.get_name(), gender, bdate, + name.get_sort_name(), bdate], + p.get_handle()) self.clist.connect_model()