From 4b4fd78f7e86b72eaef27d9aa8b840e69201cdf8 Mon Sep 17 00:00:00 2001 From: Don Allingham Date: Tue, 12 Oct 2004 01:29:39 +0000 Subject: [PATCH] * src/DateParser.py: dynamically detect numerical parsing based off locale. Do not depend on strptime. * src/Utils.py: remove last remains of SingleDate * src/PeopleModel.py: display "error" instead of a blank string on an error * src/EventEdit.py: removed unused parameter * src/Exporter.py: remove unused gnome.ui import * src/plugins/FanChart.py: remove old Calendar reference * src/plugins/Verify.py: remove old Calendar reference svn: r3620 --- ChangeLog | 11 +++++++++++ src/DateParser.py | 22 ++++++++++++++-------- src/EventEdit.py | 4 ++-- src/Exporter.py | 1 + src/PeopleModel.py | 3 +-- src/Utils.py | 8 ++++---- src/plugins/FanChart.py | 6 +++--- src/plugins/Verify.py | 5 ++--- 8 files changed, 38 insertions(+), 22 deletions(-) diff --git a/ChangeLog b/ChangeLog index 80c0fe21d..5b380c153 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2004-10-11 Don Allingham + * src/DateParser.py: dynamically detect numerical parsing based + off locale. Do not depend on strptime. + * src/Utils.py: remove last remains of SingleDate + * src/PeopleModel.py: display "error" instead of a blank string + on an error + * src/EventEdit.py: removed unused parameter + * src/Exporter.py: remove unused gnome.ui import + * src/plugins/FanChart.py: remove old Calendar reference + * src/plugins/Verify.py: remove old Calendar reference + 2004-10-11 Alex Roitman * src/DateDisplay.py (_display_gregorian): Prepend month and day with zeros if needed for the ISO format. diff --git a/src/DateParser.py b/src/DateParser.py index 177d02b1f..2b0a057b7 100644 --- a/src/DateParser.py +++ b/src/DateParser.py @@ -58,6 +58,7 @@ class DateParser: # determine the code set returned by nl_langinfo _codeset = locale.nl_langinfo(locale.CODESET) + _fmt_parse = re.compile(".*%(\S).*%(\S).*%(\S).*") # RFC-2822 only uses capitalized English abbreviated names, no locales. _rfc_days = ('Sun','Mon','Tue','Wed','Thu','Fri','Sat') @@ -245,6 +246,13 @@ class DateParser: Date.CAL_HEBREW : self._parse_hebrew, Date.CAL_ISLAMIC : self._parse_islamic, } + + fmt = locale.nl_langinfo(locale.D_FMT) + match = self._fmt_parse.match(fmt.lower()) + if match: + self.dmy = (match.groups() == ('d','m','y')) + else: + self.dmy = True def _get_int(self,val): """ @@ -321,12 +329,6 @@ class DateParser: if subparser == None: subparser = self._parse_greg_julian - try: - value = time.strptime(text) - return (value[2],value[1],value[0],False) - except ValueError: - pass - value = subparser(text) if value != Date.EMPTY: return value @@ -356,8 +358,12 @@ class DateParser: match = self._numeric.match(text) if match: groups = match.groups() - m = self._get_int(groups[1]) - d = self._get_int(groups[3]) + if self.dmy: + m = self._get_int(groups[3]) + d = self._get_int(groups[1]) + else: + m = self._get_int(groups[1]) + d = self._get_int(groups[3]) y = self._get_int(groups[4]) if gregorian_valid((d,m)): return (d,m,y,False) diff --git a/src/EventEdit.py b/src/EventEdit.py index f6a51ef53..9d27fc17c 100644 --- a/src/EventEdit.py +++ b/src/EventEdit.py @@ -272,7 +272,7 @@ class EventEditor: """Display the relevant portion of GRAMPS manual""" gnome.help_display('gramps-manual','gramps-edit-complete') - def get_place(self,field,trans): + def get_place(self,field): text = strip(unicode(field.get_text())) if text: if self.pmap.has_key(text): @@ -289,7 +289,7 @@ class EventEditor: ename = unicode(self.event_menu.child.get_text()) #self.date = self.dp.parse(unicode(self.date_field.get_text())) ecause = unicode(self.cause_field.get_text()) - eplace_obj = self.get_place(self.place_field,trans) + eplace_obj = self.get_place(self.place_field) buf = self.note_field.get_buffer() enote = unicode(buf.get_text(buf.get_start_iter(),buf.get_end_iter(),gtk.FALSE)) diff --git a/src/Exporter.py b/src/Exporter.py index 654ef594f..e636a453b 100644 --- a/src/Exporter.py +++ b/src/Exporter.py @@ -40,6 +40,7 @@ from gettext import gettext as _ #------------------------------------------------------------------------- import gtk import gnome +import gnome.ui #------------------------------------------------------------------------- # diff --git a/src/PeopleModel.py b/src/PeopleModel.py index 9012e8cf8..6b7b29537 100644 --- a/src/PeopleModel.py +++ b/src/PeopleModel.py @@ -178,8 +178,7 @@ class PeopleModel(gtk.GenericTreeModel): try: return COLUMN_DEFS[col][COLUMN_DEF_LIST](self,self.db.person_map[str(node)],node) except: - print "except" - return u'' + return u'error' def reset_visible(self): self.visible = {} diff --git a/src/Utils.py b/src/Utils.py index cf236605f..363431eb2 100644 --- a/src/Utils.py +++ b/src/Utils.py @@ -647,16 +647,16 @@ def probably_alive(person,db): sp_death_handle = spouse.get_death_handle() if sp_birth_handle: spouse_birth = db.get_event_from_handle(sp_birth_handle) - if spouse_birth.get_date() != "": - d = SingleDate (spouse_birth.get_date_object().get_start_date()) - d.set_year (d.get_year() + max_age_difference) + if not spouse_birth.get_date().is_empty(): + d = Date(spouse_birth.get_date_object()) + d.set_year(d.get_year() + max_age_difference) if not not_too_old (d): return False if sp_death_handle: spouse_death = db.get_event_from_handle(sp_death_handle) if spouse_death.get_date() != "": - d = SingleDate (spouse_death.get_date_object().get_start_date()) + d = Date(spouse_death.get_date_object()) d.set_year (d.get_year() - min_generation) if not not_too_old (d): return False diff --git a/src/plugins/FanChart.py b/src/plugins/FanChart.py index dcb93fa1a..6d71c003f 100644 --- a/src/plugins/FanChart.py +++ b/src/plugins/FanChart.py @@ -35,7 +35,7 @@ import gtk import BaseDoc import Report import Errors -import Calendar +import Date from QuestionDialog import ErrorDialog from SubstKeywords import SubstKeywords @@ -206,7 +206,7 @@ class FanChart: birth_handle = person.get_birth_handle() if birth_handle: b = self.database.get_event_from_handle(birth_handle).get_date_object().get_year() - if b == Calendar.UNDEF: + if b == 0: b = "" else: b = "" @@ -214,7 +214,7 @@ class FanChart: death_handle = person.get_death_handle() if death_handle: d = self.database.get_event_from_handle(death_handle).get_date_object().get_year() - if d == Calendar.UNDEF: + if d == 0: d = "" else: d = "" diff --git a/src/plugins/Verify.py b/src/plugins/Verify.py index 82f447f29..dba6af6f3 100644 --- a/src/plugins/Verify.py +++ b/src/plugins/Verify.py @@ -50,7 +50,6 @@ import gtk.glade #------------------------------------------------------------------------ import RelLib import Utils -import Gregorian from gettext import gettext as _ @@ -117,8 +116,8 @@ class Verify: event = self.db.get_event_from_handle(event_handle) dateObj = event.get_date_object() if dateObj: - if dateObj.get_calendar().NAME != Gregorian.Gregorian.NAME: - dateObj.set_calendar(Gregorian.Gregorian) + if dateObj.get_calendar() != Date.CAL_GREGORIAN: + dateObj.set_calendar(Date.CAL_GREGORIAN) year = dateObj.get_year() return year