From 7329720f0714be6a316232dd9f56e7d061075288 Mon Sep 17 00:00:00 2001 From: Alex Roitman Date: Fri, 3 Feb 2006 22:03:53 +0000 Subject: [PATCH] * RelLib/_*.py: Make objects serialize all the way down to built-in python objects, so that Gramps classes are never pickled. * Date.py, CalSdn.py: Move to RelLib. * src/dates/Date_*.py: Use new Date. * src/plugins/*.py: Use new Date. * src/GrampsDb/_*.py: Use new Date, new unserialize. * src/*.py: Use new Date. svn: r5875 --- gramps2/ChangeLog | 9 + gramps2/src/AddSpouse.py | 9 +- gramps2/src/AddrEdit.py | 7 +- gramps2/src/ChooseParents.py | 11 +- gramps2/src/Date.py | 514 +---------------- gramps2/src/DateDisplay.py | 5 +- gramps2/src/DateEdit.py | 23 +- gramps2/src/DateParser.py | 11 +- gramps2/src/EditMedia.py | 7 +- gramps2/src/Errors.py | 11 +- gramps2/src/EventEdit.py | 11 +- gramps2/src/GenericFilter.py | 5 +- gramps2/src/GrampsDb/_GrampsBSDDB.py | 4 +- gramps2/src/GrampsDb/_GrampsDbBase.py | 2 +- gramps2/src/GrampsDb/_ReadGedcom.py | 45 +- gramps2/src/GrampsDb/_ReadXML.py | 35 +- gramps2/src/GrampsDb/_WriteGedcom.py | 21 +- gramps2/src/GrampsDb/_WriteXML.py | 19 +- gramps2/src/ImageSelect.py | 7 +- gramps2/src/Marriage.py | 5 +- gramps2/src/NameEdit.py | 5 +- gramps2/src/PeopleModel.py | 49 +- gramps2/src/RelLib/_Address.py | 15 +- gramps2/src/RelLib/_AddressBase.py | 8 +- gramps2/src/RelLib/_Attribute.py | 11 +- gramps2/src/RelLib/_AttributeBase.py | 8 +- gramps2/src/RelLib/_BaseObject.py | 9 +- gramps2/src/{CalSdn.py => RelLib/_CalSdn.py} | 78 ++- gramps2/src/RelLib/_Date.py | 565 +++++++++++++++++++ gramps2/src/RelLib/_DateBase.py | 21 +- gramps2/src/RelLib/_Event.py | 18 +- gramps2/src/RelLib/_EventRef.py | 10 +- gramps2/src/RelLib/_Family.py | 29 +- gramps2/src/RelLib/_LdsOrd.py | 13 +- gramps2/src/RelLib/_Location.py | 10 +- gramps2/src/RelLib/_LocationBase.py | 9 +- gramps2/src/RelLib/_MediaBase.py | 8 +- gramps2/src/RelLib/_MediaObject.py | 20 +- gramps2/src/RelLib/_MediaRef.py | 13 +- gramps2/src/RelLib/_Name.py | 18 +- gramps2/src/RelLib/_Note.py | 9 +- gramps2/src/RelLib/_NoteBase.py | 15 +- gramps2/src/RelLib/_Person.py | 115 ++-- gramps2/src/RelLib/_Place.py | 35 +- gramps2/src/RelLib/_PrivateSourceNote.py | 9 +- gramps2/src/RelLib/_RepoRef.py | 10 +- gramps2/src/RelLib/_Repository.py | 16 +- gramps2/src/RelLib/_Source.py | 26 +- gramps2/src/RelLib/_SourceNote.py | 12 +- gramps2/src/RelLib/_SourceRef.py | 14 +- gramps2/src/RelLib/_Url.py | 9 +- gramps2/src/RelLib/_UrlBase.py | 8 +- gramps2/src/RelLib/__init__.py | 5 +- gramps2/src/ReportUtils.py | 17 +- gramps2/src/RepositoryRefEdit.py | 3 +- gramps2/src/SelectChild.py | 5 +- gramps2/src/Sort.py | 8 +- gramps2/src/Sources.py | 5 +- gramps2/src/Utils.py | 23 +- gramps2/src/dates/Date_de.py | 4 +- gramps2/src/dates/Date_es.py | 4 +- gramps2/src/dates/Date_fi.py | 4 +- gramps2/src/dates/Date_fr.py | 4 +- gramps2/src/dates/Date_nl.py | 4 +- gramps2/src/dates/Date_ru.py | 4 +- gramps2/src/dates/Date_sv.py | 4 +- gramps2/src/plugins/ExportVCalendar.py | 4 +- gramps2/src/plugins/ExportVCard.py | 4 +- gramps2/src/plugins/ImportGeneWeb.py | 27 +- gramps2/src/plugins/TestcaseGenerator.py | 84 +-- gramps2/src/plugins/Verify.py | 7 +- gramps2/src/plugins/WriteGeneWeb.py | 22 +- gramps2/src/plugins/rel_hu.py | 5 +- 73 files changed, 1298 insertions(+), 905 deletions(-) rename gramps2/src/{CalSdn.py => RelLib/_CalSdn.py} (86%) create mode 100644 gramps2/src/RelLib/_Date.py diff --git a/gramps2/ChangeLog b/gramps2/ChangeLog index 764f57490..03680a430 100644 --- a/gramps2/ChangeLog +++ b/gramps2/ChangeLog @@ -1,3 +1,12 @@ +2006-02-03 Alex Roitman + * RelLib/_*.py: Make objects serialize all the way down to built-in + python objects, so that Gramps classes are never pickled. + * Date.py, CalSdn.py: Move to RelLib. + * src/dates/Date_*.py: Use new Date. + * src/plugins/*.py: Use new Date. + * src/GrampsDb/_*.py: Use new Date, new unserialize. + * src/*.py: Use new Date. + 2006-02-03 Richard Taylor * src/TreeViews/_PersonTreeView.py: added more columns diff --git a/gramps2/src/AddSpouse.py b/gramps2/src/AddSpouse.py index 3442b7a6e..ee9564ca1 100644 --- a/gramps2/src/AddSpouse.py +++ b/gramps2/src/AddSpouse.py @@ -1,7 +1,7 @@ # # Gramps - a GTK+/GNOME based genealogy program # -# Copyright (C) 2000-2005 Donald N. Allingham +# Copyright (C) 2000-2006 Donald N. Allingham # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -54,7 +54,6 @@ import RelLib import const import Utils import PeopleModel -import Date import Marriage import NameDisplay import GenericFilter @@ -152,11 +151,11 @@ class AddSpouse: if birth_ref: birth = self.db.get_event_from_handle(birth_ref.ref) - date_obj = Date.Date(birth.get_date_object()) + date_obj = RelLib.Date(birth.get_date_object()) year = date_obj.get_year() if year: date_obj.set_year(year-50) - date_obj.set_modifier(Date.MOD_AFTER) + date_obj.set_modifier(RelLib.Date.MOD_AFTER) text = DateHandler.displayer.display(date_obj) rule = GenericFilter.HasBirth([text,"",""]) filt.add_rule(rule) @@ -373,7 +372,7 @@ class LikelyFilter(GenericFilter.Rule): person = db.get_person_from_handle(self.list[0]) if person.birth_handle: birth = db.get_event_from_handle(person.birth_handle) - dateobj = Date.Date(birth.date) + dateobj = RelLib.Date(birth.date) year = dateobj.get_year() dateobj.set_year(year+40) self.lower = dateobj.sortval diff --git a/gramps2/src/AddrEdit.py b/gramps2/src/AddrEdit.py index 683fd3c50..518e06094 100644 --- a/gramps2/src/AddrEdit.py +++ b/gramps2/src/AddrEdit.py @@ -1,7 +1,7 @@ # # Gramps - a GTK+/GNOME based genealogy program # -# Copyright (C) 2000-2005 Donald N. Allingham +# Copyright (C) 2000-2006 Donald N. Allingham # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -48,7 +48,6 @@ import gtk.glade import GrampsDisplay import const import Utils -import Date import RelLib import Sources import DateEdit @@ -124,7 +123,7 @@ class AddressEditor(DisplayState.ManagedWindow): if self.addr: self.srcreflist = self.addr.get_source_references() - self.addr_date_obj = Date.Date(self.addr.get_date_object()) + self.addr_date_obj = RelLib.Date(self.addr.get_date_object()) self.addr_start.set_text(DateHandler.get_date(self.addr)) self.street.set_text(self.addr.get_street()) self.city.set_text(self.addr.get_city()) @@ -146,7 +145,7 @@ class AddressEditor(DisplayState.ManagedWindow): Utils.bold_label(self.general_label) else: Utils.unbold_label(self.general_label) - self.addr_date_obj = Date.Date() + self.addr_date_obj = RelLib.Date() self.srcreflist = [] self.addr = RelLib.Address() self.switch_page() diff --git a/gramps2/src/ChooseParents.py b/gramps2/src/ChooseParents.py index b286e0cb5..5b6887b6e 100644 --- a/gramps2/src/ChooseParents.py +++ b/gramps2/src/ChooseParents.py @@ -1,7 +1,7 @@ # # Gramps - a GTK+/GNOME based genealogy program # -# Copyright (C) 2000-2005 Donald N. Allingham +# Copyright (C) 2000-2006 Donald N. Allingham # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -63,7 +63,6 @@ import RelLib import const import Utils import PeopleModel -import Date import NameDisplay import DateHandler import GenericFilter @@ -247,18 +246,18 @@ class ChooseParents: if birth_ref: birth = self.db.get_event_from_handle(birth_ref.ref) - date_obj = Date.Date(birth.get_date_object()) + date_obj = RelLib.Date(birth.get_date_object()) year = date_obj.get_year() if year: date_obj.set_year(year-10) - date_obj.set_modifier(Date.MOD_BEFORE) + date_obj.set_modifier(RelLib.Date.MOD_BEFORE) rule = GenericFilter.HasBirth( [DateHandler.displayer.display(date_obj),"",""]) filt.add_rule(rule) - date_obj = Date.Date(birth.get_date_object()) + date_obj = RelLib.Date(birth.get_date_object()) date_obj.set_year(year-60) - date_obj.set_modifier(Date.MOD_AFTER) + date_obj.set_modifier(RelLib.Date.MOD_AFTER) rule = GenericFilter.HasBirth( [DateHandler.displayer.display(date_obj),"",""]) filt.add_rule(rule) diff --git a/gramps2/src/Date.py b/gramps2/src/Date.py index 49b19fce8..3bcfead40 100644 --- a/gramps2/src/Date.py +++ b/gramps2/src/Date.py @@ -1,7 +1,7 @@ # # Gramps - a GTK+/GNOME based genealogy program # -# Copyright (C) 2000-2005 Donald N. Allingham +# Copyright (C) 2000-2006 Donald N. Allingham # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -20,514 +20,6 @@ # $Id$ -"Support for dates" -__author__ = "Donald N. Allingham" -__version__ = "$Revision$" - -from gettext import gettext as _ -from Errors import DateError -from CalSdn import * - -#------------------------------------------------------------------------- -# -# Constants -# -#------------------------------------------------------------------------- - -MOD_NONE = 0 -MOD_BEFORE = 1 -MOD_AFTER = 2 -MOD_ABOUT = 3 -MOD_RANGE = 4 -MOD_SPAN = 5 -MOD_TEXTONLY = 6 - -QUAL_NONE = 0 -QUAL_ESTIMATED = 1 -QUAL_CALCULATED= 2 - -CAL_GREGORIAN = 0 -CAL_JULIAN = 1 -CAL_HEBREW = 2 -CAL_FRENCH = 3 -CAL_PERSIAN = 4 -CAL_ISLAMIC = 5 - -EMPTY = (0,0,0,False) - -_POS_DAY = 0 -_POS_MON = 1 -_POS_YR = 2 -_POS_SL = 3 -_POS_RDAY = 4 -_POS_RMON = 5 -_POS_RYR = 6 -_POS_RSL = 7 - -_calendar_convert = [ - gregorian_sdn, - julian_sdn, - hebrew_sdn, - french_sdn, - persian_sdn, - islamic_sdn, - ] - -_calendar_change = [ - gregorian_ymd, - julian_ymd, - hebrew_ymd, - french_ymd, - persian_ymd, - islamic_ymd, - ] - -#------------------------------------------------------------------------- -# -# Date class -# -#------------------------------------------------------------------------- -class Date: - """ - The core date handling class for GRAMPs. Supports partial dates, - compound dates and alternate calendars. - """ - - calendar_names = ["Gregorian", - "Julian", - "Hebrew", - "French Republican", - "Persian", - "Islamic"] - - - ui_calendar_names = [_("Gregorian"), - _("Julian"), - _("Hebrew"), - _("French Republican"), - _("Persian"), - _("Islamic")] - - def __init__(self,source=None): - """ - Creates a new Date instance. - """ - if source: - self.calendar = source.calendar - self.modifier = source.modifier - self.quality = source.quality - self.dateval = source.dateval - self.text = source.text - self.sortval = source.sortval - else: - self.calendar = CAL_GREGORIAN - self.modifier = MOD_NONE - self.quality = QUAL_NONE - self.dateval = EMPTY - self.text = u"" - self.sortval = 0 - - def copy(self,source): - """ - Copy all the attributes of the given Date instance - to the present instance, without creating a new object. - """ - self.calendar = source.calendar - self.modifier = source.modifier - self.quality = source.quality - self.dateval = source.dateval - self.text = source.text - self.sortval = source.sortval - - def __cmp__(self,other): - """ - Comparison function. Allows the usage of equality tests. - This allows you do run statements like 'date1 <= date2' - """ - if isinstance(other,Date): - return cmp(self.sortval,other.sortval) - else: - return -1 - - def is_equal(self,other): - """ - Return 1 if the given Date instance is the same as the present - instance IN ALL REGARDS. Needed, because the __cmp__ only looks - at the sorting value, and ignores the modifiers/comments. - """ - if self.modifier == other.modifier and self.modifier == MOD_TEXTONLY: - value = self.text == other.text - else: - value = (self.calendar == other.calendar and - self.modifier == other.modifier and - self.quality == other.quality and - self.dateval == other.dateval) - return value - - def __str__(self): - """ - Produces a string representation of the Date object. If the - date is not valid, the text representation is displayed. If - the date is a range or a span, a string in the form of - 'YYYY-MM-DD - YYYY-MM-DD' is returned. Otherwise, a string in - the form of 'YYYY-MM-DD' is returned. - """ - if self.quality == QUAL_ESTIMATED: - qual = "est " - elif self.quality == QUAL_CALCULATED: - qual = "calc " - else: - qual = "" - - if self.modifier == MOD_BEFORE: - pref = "bef " - elif self.modifier == MOD_AFTER: - pref = "aft " - elif self.modifier == MOD_ABOUT: - pref = "abt " - else: - pref = "" - - if self.calendar != CAL_GREGORIAN: - cal = " (%s)" % self.calendar_names[self.calendar] - else: - cal = "" - - - if self.modifier == MOD_TEXTONLY: - val = self.text - elif self.modifier == MOD_RANGE or self.modifier == MOD_SPAN: - val = "%04d-%02d-%02d - %04d-%02d-%02d" % ( - self.dateval[_POS_YR],self.dateval[_POS_MON],self.dateval[_POS_DAY], - self.dateval[_POS_RYR],self.dateval[_POS_RMON],self.dateval[_POS_RDAY]) - else: - val = "%04d-%02d-%02d" % ( - self.dateval[_POS_YR],self.dateval[_POS_MON],self.dateval[_POS_DAY]) - return "%s%s%s%s" % (qual,pref,val,cal) - - def get_sort_value(self): - """ - Returns the sort value of Date object. If the value is a - text string, 0 is returned. Otherwise, the calculated sort - date is returned. The sort date is rebuilt on every assignment. - - The sort value is an integer representing the value. A date of - March 5, 1990 would have the value of 19900305. - """ - return self.sortval - - def get_modifier(self): - """ - Returns an integer indicating the calendar selected. The valid - values are:: - - MOD_NONE = no modifier (default) - MOD_BEFORE = before - MOD_AFTER = after - MOD_ABOUT = about - MOD_RANGE = date range - MOD_SPAN = date span - MOD_TEXTONLY = text only - """ - return self.modifier - - def set_modifier(self,val): - """ - Sets the modifier for the date. - """ - if val not in (MOD_NONE,MOD_BEFORE,MOD_AFTER,MOD_ABOUT,MOD_RANGE,MOD_SPAN,MOD_TEXTONLY): - raise DateError("Invalid modifier") - self.modifier = val - - def get_quality(self): - """ - Returns an integer indicating the calendar selected. The valid - values are:: - - QUAL_NONE = normal (default) - QUAL_ESTIMATED = estimated - QUAL_CALCULATED = calculated - """ - return self.quality - - def set_quality(self,val): - """ - Sets the quality selected for the date. - """ - if val not in (QUAL_NONE,QUAL_ESTIMATED,QUAL_CALCULATED): - raise DateError("Invalid quality") - self.quality = val - - def get_calendar(self): - """ - Returns an integer indicating the calendar selected. The valid - values are:: - - CAL_GREGORIAN - Gregorian calendar - CAL_JULIAN - Julian calendar - CAL_HEBREW - Hebrew (Jewish) calendar - CAL_FRENCH - French Republican calendar - CAL_PERSIAN - Persian calendar - CAL_ISLAMIC - Islamic calendar - """ - return self.calendar - - def set_calendar(self,val): - """ - Sets the calendar selected for the date. - """ - if val not in (CAL_GREGORIAN,CAL_JULIAN,CAL_HEBREW,CAL_FRENCH,CAL_PERSIAN,CAL_ISLAMIC): - raise DateError("Invalid calendar") - self.calendar = val - - def get_start_date(self): - """ - Returns a tuple representing the start date. If the date is a - compound date (range or a span), it is the first part of the - compound date. If the date is a text string, a tuple of - (0,0,0,False) is returned. Otherwise, a date of (DD,MM,YY,slash) - is returned. If slash is True, then the date is in the form of 1530/1. - """ - if self.modifier == MOD_TEXTONLY: - val = EMPTY - else: - val = self.dateval[0:4] - return val - - def get_stop_date(self): - """ - Returns a tuple representing the second half of a compound date. - If the date is not a compound date, (including text strings) a tuple - of (0,0,0,False) is returned. Otherwise, a date of (DD,MM,YY,slash) - is returned. If slash is True, then the date is in the form of 1530/1. - """ - if self.modifier == MOD_RANGE or self.modifier == MOD_SPAN: - val = self.dateval[4:8] - else: - val = EMPTY - return val - - def _get_low_item(self,index): - if self.modifier == MOD_TEXTONLY: - val = 0 - else: - val = self.dateval[index] - return val - - def _get_low_item_valid(self,index): - if self.modifier == MOD_TEXTONLY: - val = False - else: - val = self.dateval[index] != 0 - return val - - def _get_high_item(self,index): - if self.modifier == MOD_SPAN or self.modifier == MOD_RANGE: - val = self.dateval[index] - else: - val = 0 - return val - - def get_year(self): - """ - Returns the year associated with the date. If the year is - not defined, a zero is returned. If the date is a compound - date, the lower date year is returned. - """ - return self._get_low_item(_POS_YR) - - def set_year(self,year): - """ - """ - self.dateval = self.dateval[0:2] + (year,) + self.dateval[3:] - self.calc_sort_value() - - def get_year_valid(self): - return self._get_low_item_valid(_POS_YR) - - def get_month(self): - """ - Returns the month associated with the date. If the month is - not defined, a zero is returned. If the date is a compound - date, the lower date month is returned. - """ - return self._get_low_item(_POS_MON) - - def get_month_valid(self): - return self._get_low_item_valid(_POS_MON) - - def get_day(self): - """ - Returns the day of the month associated with the date. If - the day is not defined, a zero is returned. If the date is - a compound date, the lower date day is returned. - """ - return self._get_low_item(_POS_DAY) - - def get_day_valid(self): - return self._get_low_item_valid(_POS_DAY) - - def get_valid(self): - """ Returns true if any part of the date is valid""" - return self.modifier != MOD_TEXTONLY - - def get_incomplete(self): - pass - - def get_stop_year(self): - """ - Returns the day of the year associated with the second - part of a compound date. If the year is not defined, a zero - is returned. - """ - return self._get_high_item(_POS_RYR) - - def get_stop_month(self): - """ - Returns the month of the month associated with the second - part of a compound date. If the month is not defined, a zero - is returned. - """ - return self._get_high_item(_POS_RMON) - - def get_stop_day(self): - """ - Returns the day of the month associated with the second - part of a compound date. If the day is not defined, a zero - is returned. - """ - return self._get_high_item(_POS_RDAY) - - def get_high_year(self): - """ - Returns the high year estimate. For compound dates with non-zero - stop year, the stop year is returned. Otherwise, the start year - is returned. - """ - if self.is_compound(): - ret = self.get_stop_year() - if ret: - return ret - else: - return self.get_year() - - def get_text(self): - """ - Returns the text value associated with an invalid date. - """ - return self.text - - def set(self,quality,modifier,calendar,value,text=None): - """ - Sets the date to the specified value. Parameters are:: - - quality - The date quality for the date (see get_quality - for more information) - modified - The date modifier for the date (see get_modifier - for more information) - calendar - The calendar associated with the date (see - get_calendar for more information). - value - A tuple representing the date information. For a - non-compound date, the format is (DD,MM,YY,slash) - and for a compound date the tuple stores data as - (DD,MM,YY,slash1,DD,MM,YY,slash2) - text - A text string holding either the verbatim user input - or a comment relating to the date. - - The sort value is recalculated. - """ - - if modifier in (MOD_NONE,MOD_BEFORE,MOD_AFTER,MOD_ABOUT) and len(value) < 4: - raise DateError("Invalid value. Should be: (DD,MM,YY,slash)") - if modifier in (MOD_RANGE,MOD_SPAN) and len(value) < 8: - raise DateError("Invalid value. Should be: (DD,MM,YY,slash1,DD,MM,YY,slash2)") - if modifier not in (MOD_NONE,MOD_BEFORE,MOD_AFTER,MOD_ABOUT,MOD_RANGE,MOD_SPAN,MOD_TEXTONLY): - raise DateError("Invalid modifier") - if quality not in (QUAL_NONE,QUAL_ESTIMATED,QUAL_CALCULATED): - raise DateError("Invalid quality") - if calendar not in (CAL_GREGORIAN,CAL_JULIAN,CAL_HEBREW,CAL_FRENCH,CAL_PERSIAN,CAL_ISLAMIC): - raise DateError("Invalid calendar") - - self.quality = quality - self.modifier = modifier - self.calendar = calendar - self.dateval = value - year = max(value[_POS_YR],1) - month = max(value[_POS_MON],1) - day = max(value[_POS_DAY],1) - if year == 0 and month == 0 and day == 0: - self.sortval = 0 - else: - self.sortval = _calendar_convert[calendar](year,month,day) - if text: - self.text = text - - def calc_sort_value(self): - year = max(self.dateval[_POS_YR],1) - month = max(self.dateval[_POS_MON],1) - day = max(self.dateval[_POS_DAY],1) - if year == 0 and month == 0 and day == 0: - self.sortval = 0 - else: - self.sortval = _calendar_convert[self.calendar](year,month,day) - - def convert_calendar(self,calendar): - """ - Converts the date from the current calendar to the specified - calendar. - """ - if calendar == self.calendar: - return - (y,m,d) = _calendar_change[calendar](self.sortval) - if self.is_compound(): - ry = max(self.dateval[_POS_RYR],1) - rm = max(self.dateval[_POS_RMON],1) - rd = max(self.dateval[_POS_RDAY],1) - sdn = _calendar_convert[self.calendar](ry,rm,rd) - (ny,nm,nd) = _calendar_change[calendar](sdn) - self.dateval = (d,m,y,self.dateval[_POS_SL], - nd,nm,ny,self.dateval[_POS_RSL]) - else: - self.dateval = (d,m,y,self.dateval[_POS_SL]) - self.calendar = calendar - - def set_as_text(self,text): - """ - Sets the day to a text string, and assigns the sort value - to zero. - """ - self.modifier = MOD_TEXTONLY - self.text = text - self.sortval = 0 - - def set_text_value(self,text): - """ - Sets the text string to a given text. - """ - self.text = text - - def is_empty(self): - """ - Returns True if the date contains no information (empty text). - """ - return (self.modifier == MOD_TEXTONLY and not self.text) or \ - (self.get_start_date()==EMPTY and self.get_stop_date()==EMPTY) - - def is_compound(self): - """ - Returns True if the date is a date range or a date span. - """ - return self.modifier == MOD_RANGE or self.modifier == MOD_SPAN - - def is_regular(self): - """ - Returns True if the date is a regular date. - - The regular date is a single exact date, i.e. not text-only, not - a range or a span, not estimated/calculated, not about/before/after - date, and having year, month, and day all non-zero. - """ - return self.modifier == MOD_NONE and self.quality == QUAL_NONE\ - and self.get_year_valid() and self.get_month_valid()\ - and self.get_day_valid() +# FIXME: this module is only needed to to enable db upgrade +from RelLib import Date diff --git a/gramps2/src/DateDisplay.py b/gramps2/src/DateDisplay.py index a22371950..1a669e2f8 100644 --- a/gramps2/src/DateDisplay.py +++ b/gramps2/src/DateDisplay.py @@ -2,7 +2,7 @@ # # Gramps - a GTK+/GNOME based genealogy program # -# Copyright (C) 2004-2005 Donald N. Allingham +# Copyright (C) 2004-2006 Donald N. Allingham # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -28,9 +28,8 @@ localized tasks. __author__ = "Donald N. Allingham" __version__ = "$Revision$" -import Date from gettext import gettext as _ - +from RelLib import Date import GrampsLocale class DateDisplay: diff --git a/gramps2/src/DateEdit.py b/gramps2/src/DateEdit.py index c76ac0a7c..e0422ecfa 100644 --- a/gramps2/src/DateEdit.py +++ b/gramps2/src/DateEdit.py @@ -1,7 +1,7 @@ # # Gramps - a GTK+/GNOME based genealogy program # -# Copyright (C) 2002-2005 Donald N. Allingham +# Copyright (C) 2002-2006 Donald N. Allingham # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -58,7 +58,7 @@ import gtk.glade # gramps modules # #------------------------------------------------------------------------- -import Date +from RelLib import Date import DateHandler import const import Utils @@ -130,11 +130,16 @@ class DateEdit: Check current date object and display LED indicating the validity. """ if self.date_obj.get_modifier() == Date.MOD_TEXTONLY: - self.pixmap_obj.set_from_pixbuf(self.pixmap_obj.render_icon(gtk.STOCK_DIALOG_ERROR,gtk.ICON_SIZE_MENU)) + self.pixmap_obj.set_from_pixbuf( + self.pixmap_obj.render_icon(gtk.STOCK_DIALOG_ERROR, + gtk.ICON_SIZE_MENU)) elif self.date_obj.is_regular(): - self.pixmap_obj.set_from_pixbuf(self.pixmap_obj.render_icon(gtk.STOCK_YES,gtk.ICON_SIZE_MENU)) + self.pixmap_obj.set_from_pixbuf( + self.pixmap_obj.render_icon(gtk.STOCK_YES,gtk.ICON_SIZE_MENU)) else: - self.pixmap_obj.set_from_pixbuf(self.pixmap_obj.render_icon(gtk.STOCK_DIALOG_WARNING,gtk.ICON_SIZE_MENU)) + self.pixmap_obj.set_from_pixbuf( + self.pixmap_obj.render_icon(gtk.STOCK_DIALOG_WARNING, + gtk.ICON_SIZE_MENU)) def parse_and_check(self,obj,val): """ @@ -185,7 +190,7 @@ class DateEditorDialog: """ # Create self.date as a copy of the given Date object. - self.date = Date.Date(date) + self.date = Date(date) self.top = gtk.glade.XML(const.gladeFile, "date_edit","gramps" ) self.top_window = self.top.get_widget('date_edit') @@ -194,7 +199,7 @@ class DateEditorDialog: Utils.set_titles(self.top_window,title,_('Date selection')) self.calendar_box = self.top.get_widget('calendar_box') - for name in Date.Date.ui_calendar_names: + for name in Date.ui_calendar_names: self.calendar_box.append_text(name) self.calendar_box.set_active(self.date.get_calendar()) self.calendar_box.connect('changed',self.switch_calendar) @@ -263,7 +268,7 @@ class DateEditorDialog: elif response == gtk.RESPONSE_OK: (the_quality,the_modifier,the_calendar,the_value,the_text) = \ self.build_date_from_ui() - self.return_date = Date.Date(self.date) + self.return_date = Date(self.date) self.return_date.set( quality=the_quality, modifier=the_modifier, @@ -293,7 +298,7 @@ class DateEditorDialog: if modifier == Date.MOD_TEXTONLY: return (Date.QUAL_NONE,Date.MOD_TEXTONLY,Date.CAL_GREGORIAN, - Date.EMPTY,text) + Date.EMPTY,text) quality = QUAL_TEXT[self.quality_box.get_active()][0] diff --git a/gramps2/src/DateParser.py b/gramps2/src/DateParser.py index 72fa6aa1f..694afa1c9 100644 --- a/gramps2/src/DateParser.py +++ b/gramps2/src/DateParser.py @@ -1,7 +1,7 @@ # # Gramps - a GTK+/GNOME based genealogy program # -# Copyright (C) 2004-2005 Donald N. Allingham +# Copyright (C) 2004-2006 Donald N. Allingham # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -42,9 +42,9 @@ import calendar # GRAMPS modules # #------------------------------------------------------------------------- -import Date +from RelLib import Date, DateError import GrampsLocale -from Errors import DateError + #------------------------------------------------------------------------- # # Top-level module functions @@ -497,7 +497,8 @@ class DateParser: if match: grps = match.groups() start = self._parse_subdate(grps[0]) - mod = self.modifier_after_to_int.get(grps[1].lower(),Date.MOD_NONE) + mod = self.modifier_after_to_int.get(grps[1].lower(), + Date.MOD_NONE) if bc: date.set(qual,mod,cal,self.invert_year(start)) else: @@ -558,7 +559,7 @@ class DateParser: """ Parses the text, returning a Date object. """ - new_date = Date.Date() + new_date = Date() try: self.set_date(new_date,text) except DateError: diff --git a/gramps2/src/EditMedia.py b/gramps2/src/EditMedia.py index 7c79b44b9..66c5edb66 100644 --- a/gramps2/src/EditMedia.py +++ b/gramps2/src/EditMedia.py @@ -1,7 +1,7 @@ # # Gramps - a GTK+/GNOME based genealogy program # -# Copyright (C) 2000-2005 Donald N. Allingham +# Copyright (C) 2000-2006 Donald N. Allingham # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -47,7 +47,6 @@ import RelLib import GrampsMime import DateEdit import DateHandler -import Date import ImgManip import DisplayState import GrampsDisplay @@ -89,11 +88,11 @@ class EditMedia(DisplayState.ManagedWindow): self.db = self.state.db self.idle = None if obj: - self.date_object = Date.Date(self.obj.get_date_object()) + self.date_object = RelLib.Date(self.obj.get_date_object()) self.alist = self.obj.get_attribute_list()[:] self.refs = 0 else: - self.date_object = Date.Date() + self.date_object = RelLib.Date() self.alist = [] self.refs = 1 diff --git a/gramps2/src/Errors.py b/gramps2/src/Errors.py index 9f869f59c..5665306a7 100644 --- a/gramps2/src/Errors.py +++ b/gramps2/src/Errors.py @@ -1,7 +1,7 @@ # # Gramps - a GTK+/GNOME based genealogy program # -# Copyright (C) 2003-2005 Donald N. Allingham +# Copyright (C) 2003-2006 Donald N. Allingham # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -33,15 +33,6 @@ class FilterError(Exception): def messages(self): return (self.value,self.value2) -class DateError(Exception): - """Error used to report Date errors""" - def __init__(self,value=""): - Exception.__init__(self) - self.value = value - - def __str__(self): - return self.value - class DatabaseError(Exception): """Error used to report Date errors""" def __init__(self,value=""): diff --git a/gramps2/src/EventEdit.py b/gramps2/src/EventEdit.py index 74f2d43ee..9c82aa29a 100644 --- a/gramps2/src/EventEdit.py +++ b/gramps2/src/EventEdit.py @@ -1,7 +1,7 @@ # # Gramps - a GTK+/GNOME based genealogy program # -# Copyright (C) 2000-2005 Donald N. Allingham +# Copyright (C) 2000-2006 Donald N. Allingham # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -49,7 +49,6 @@ import const import Utils import AutoComp import RelLib -import Date from DateHandler import parser as _dp, displayer as _dd import DateEdit import GrampsDisplay @@ -122,10 +121,10 @@ class EventEditor(DisplayState.ManagedWindow): if event: self.srcreflist = self.event.get_source_references() - self.date = Date.Date(self.event.get_date_object()) + self.date = RelLib.Date(self.event.get_date_object()) else: self.srcreflist = [] - self.date = Date.Date(None) + self.date = RelLib.Date(None) self.top = gtk.glade.XML(const.gladeFile, "event_edit","gramps") self.gladeif = GladeIf(self.top) @@ -454,7 +453,7 @@ class EventRefEditor(DisplayState.ManagedWindow): if self.event: self.event_added = False - self.date = Date.Date(self.event.get_date_object()) + self.date = RelLib.Date(self.event.get_date_object()) if self.event_ref: if self.event_ref.get_role()[0] == default_role: self.expander.set_expanded(True) @@ -468,7 +467,7 @@ class EventRefEditor(DisplayState.ManagedWindow): self.event.set_handle(self.db.create_id()) self.event.set_gramps_id(self.db.find_next_event_gramps_id()) self.event_added = True - self.date = Date.Date(None) + self.date = RelLib.Date(None) self.expander.set_expanded(True) self.warning.hide() diff --git a/gramps2/src/GenericFilter.py b/gramps2/src/GenericFilter.py index 002f4eef0..1553435f5 100644 --- a/gramps2/src/GenericFilter.py +++ b/gramps2/src/GenericFilter.py @@ -54,7 +54,6 @@ import gtk #------------------------------------------------------------------------- import const import RelLib -import Date import DateHandler import NameDisplay from TransUtils import strip_context as __ @@ -71,9 +70,9 @@ def date_cmp(rule,value): od = value.get_start_date() cmp_rule = (sd[2],sd[1],sd[0]) cmp_value = (od[2],od[1],od[0]) - if s == Date.MOD_BEFORE: + if s == RelLib.Date.MOD_BEFORE: return cmp_rule > cmp_value - elif s == Date.MOD_AFTER: + elif s == RelLib.Date.MOD_AFTER: return cmp_rule < cmp_value else: return cmp_rule == cmp_value diff --git a/gramps2/src/GrampsDb/_GrampsBSDDB.py b/gramps2/src/GrampsDb/_GrampsBSDDB.py index 6114f7bb9..6af6b3056 100644 --- a/gramps2/src/GrampsDb/_GrampsBSDDB.py +++ b/gramps2/src/GrampsDb/_GrampsBSDDB.py @@ -59,7 +59,7 @@ _MINVERSION = 5 _DBVERSION = 9 def find_surname(key,data): - return str(data[3].surname) + return str(data[3][3]) def find_idmap(key,data): return str(data[1]) @@ -980,7 +980,7 @@ class GrampsBSDDB(GrampsDbBase): self.env.txn_checkpoint() self.env.set_flags(db.DB_TXN_NOSYNC,1) # async txn - if not transaction.no_magic: + if self.secondary_connected and not transaction.no_magic: # Disconnect unneeded secondary indices self.surnames.close() junk = db.DB(self.env) diff --git a/gramps2/src/GrampsDb/_GrampsDbBase.py b/gramps2/src/GrampsDb/_GrampsDbBase.py index 5273a5db3..e1208c6eb 100644 --- a/gramps2/src/GrampsDb/_GrampsDbBase.py +++ b/gramps2/src/GrampsDb/_GrampsDbBase.py @@ -395,7 +395,7 @@ class GrampsDbBase(GrampsDBCallback): if old_data: old_person = Person(old_data) if (old_data[2] != person.gender or - old_data[3].first_name != person.primary_name.first_name): + old_data[3][2]!= person.primary_name.first_name): self.genderStats.uncount_person(old_person) self.genderStats.count_person(person,self) else: diff --git a/gramps2/src/GrampsDb/_ReadGedcom.py b/gramps2/src/GrampsDb/_ReadGedcom.py index ded9af5e9..b81d17e61 100644 --- a/gramps2/src/GrampsDb/_ReadGedcom.py +++ b/gramps2/src/GrampsDb/_ReadGedcom.py @@ -58,7 +58,6 @@ import gtk.glade #------------------------------------------------------------------------- import Errors import RelLib -import Date import DateParser import NameDisplay import DisplayTrace @@ -1856,7 +1855,7 @@ class GedcomParser: return None def extract_date(self,text): - dateobj = Date.Date() + dateobj = RelLib.Date() try: match = rangeRegexp.match(text) if match: @@ -1865,17 +1864,17 @@ class GedcomParser: pass if cal1 == "FRENCH R": - cal = Date.CAL_FRENCH + cal = RelLib.Date.CAL_FRENCH elif cal1 == "JULIAN": - cal = Date.CAL_JULIAN + cal = RelLib.Date.CAL_JULIAN elif cal1 == "HEBREW": - cal = Date.CAL_HEBREW + cal = RelLib.Date.CAL_HEBREW else: - cal = Date.CAL_GREGORIAN + cal = RelLib.Date.CAL_GREGORIAN start = self.dp.parse(data1) stop = self.dp.parse(data2) - dateobj.set(Date.QUAL_NONE, Date.MOD_RANGE, cal, + dateobj.set(RelLib.Date.QUAL_NONE, RelLib.Date.MOD_RANGE, cal, start.get_start_date() + stop.get_start_date()) return dateobj @@ -1886,17 +1885,17 @@ class GedcomParser: pass if cal1 == "FRENCH R": - cal = Date.CAL_FRENCH + cal = RelLib.Date.CAL_FRENCH elif cal1 == "JULIAN": - cal = Date.CAL_JULIAN + cal = RelLib.Date.CAL_JULIAN elif cal1 == "HEBREW": - cal = Date.CAL_HEBREW + cal = RelLib.Date.CAL_HEBREW else: - cal = Date.CAL_GREGORIAN + cal = RelLib.Date.CAL_GREGORIAN start = self.dp.parse(data1) stop = self.dp.parse(data2) - dateobj.set(Date.QUAL_NONE, Date.MOD_SPAN, cal, + dateobj.set(RelLib.Date.QUAL_NONE, RelLib.Date.MOD_SPAN, cal, start.get_start_date() + stop.get_start_date()) return dateobj @@ -1905,11 +1904,11 @@ class GedcomParser: (abt,cal,data) = match.groups() dateobj = self.dp.parse("%s %s" % (abt, data)) if cal == "FRENCH R": - dateobj.set_calendar(Date.CAL_FRENCH) + dateobj.set_calendar(RelLib.Date.CAL_FRENCH) elif cal == "JULIAN": - dateobj.set_calendar(Date.CAL_JULIAN) + dateobj.set_calendar(RelLib.Date.CAL_JULIAN) elif cal == "HEBREW": - dateobj.set_calendar(Date.CAL_HEBREW) + dateobj.set_calendar(RelLib.Date.CAL_HEBREW) return dateobj else: dval = self.dp.parse(text) @@ -2384,7 +2383,7 @@ def create_id(): if __name__ == "__main__": import sys - import hotshot, hotshot.stats + import hotshot#, hotshot.stats import const from GrampsDb import gramps_db_factory, gramps_db_reader_factory @@ -2397,7 +2396,7 @@ if __name__ == "__main__": database = db_class() database.load("test.grdb",lambda x: None, mode="w") np = NoteParser(sys.argv[1],False) - g = GedcomParser(database,sys.argv[1],callback, codeset, np.get_map(),np.get_lines()) + g = GedcomParser(database,sys.argv[1],callback, codeset, np.get_map(),np.get_lines(),np.get_persons()) if False: pr = hotshot.Profile('mystats.profile') @@ -2405,12 +2404,12 @@ if __name__ == "__main__": pr.runcall(g.parse_gedcom_file,False) print "Finished" pr.close() - print "Loading profile" - stats = hotshot.stats.load('mystats.profile') - print "done" - stats.strip_dirs() - stats.sort_stats('time','calls') - stats.print_stats(100) +## print "Loading profile" +## stats = hotshot.stats.load('mystats.profile') +## print "done" +## stats.strip_dirs() +## stats.sort_stats('time','calls') +## stats.print_stats(100) else: import time t = time.time() diff --git a/gramps2/src/GrampsDb/_ReadXML.py b/gramps2/src/GrampsDb/_ReadXML.py index cf8fe45cd..d25f10b33 100644 --- a/gramps2/src/GrampsDb/_ReadXML.py +++ b/gramps2/src/GrampsDb/_ReadXML.py @@ -45,7 +45,6 @@ import gtk # #------------------------------------------------------------------------- from QuestionDialog import ErrorDialog, WarningDialog, MissingMediaDialog -import Date import GrampsMime import RelLib import const @@ -1144,22 +1143,22 @@ class GrampsParser: rd = 0 if attrs.has_key("cformat"): - cal = Date.Date.calendar.index(attrs['calendar']) + cal = RelLib.Date.calendar.index(attrs['calendar']) else: - cal = Date.CAL_GREGORIAN + cal = RelLib.Date.CAL_GREGORIAN if attrs.has_key('quality'): val = attrs['quality'] if val == 'estimated': - qual = Date.QUAL_ESTIMATED + qual = RelLib.Date.QUAL_ESTIMATED elif val == 'calculated': - qual = Date.QUAL_CALCULATED + qual = RelLib.Date.QUAL_CALCULATED else: - qual = Date.QUAL_NONE + qual = RelLib.Date.QUAL_NONE else: - qual = Date.QUAL_NONE + qual = RelLib.Date.QUAL_NONE - dv.set(qual,Date.MOD_RANGE,cal,(d,m,y,False,rd,rm,ry,False)) + dv.set(qual,RelLib.Date.MOD_RANGE,cal,(d,m,y,False,rd,rm,ry,False)) def start_dateval(self,attrs): if self.source_ref: @@ -1197,31 +1196,31 @@ class GrampsParser: d = 0 if attrs.has_key("cformat"): - cal = Date.Date.calendar_names.index(attrs['cformat']) + cal = RelLib.Date.calendar_names.index(attrs['cformat']) else: - cal = Date.CAL_GREGORIAN + cal = RelLib.Date.CAL_GREGORIAN if attrs.has_key('type'): val = attrs['type'] if val == "about": - mod = Date.MOD_ABOUT + mod = RelLib.Date.MOD_ABOUT elif val == "after": - mod = Date.MOD_AFTER + mod = RelLib.Date.MOD_AFTER else: - mod = Date.MOD_BEFORE + mod = RelLib.Date.MOD_BEFORE else: - mod = Date.MOD_NONE + mod = RelLib.Date.MOD_NONE if attrs.has_key('quality'): val = attrs['quality'] if val == 'estimated': - qual = Date.QUAL_ESTIMATED + qual = RelLib.Date.QUAL_ESTIMATED elif val == 'calculated': - qual = Date.QUAL_CALCULATED + qual = RelLib.Date.QUAL_CALCULATED else: - qual = Date.QUAL_NONE + qual = RelLib.Date.QUAL_NONE else: - qual = Date.QUAL_NONE + qual = RelLib.Date.QUAL_NONE dv.set(qual,mod,cal,(d,m,y,False)) diff --git a/gramps2/src/GrampsDb/_WriteGedcom.py b/gramps2/src/GrampsDb/_WriteGedcom.py index ba0b0e52f..19b24e4a2 100644 --- a/gramps2/src/GrampsDb/_WriteGedcom.py +++ b/gramps2/src/GrampsDb/_WriteGedcom.py @@ -1,7 +1,7 @@ # # Gramps - a GTK+/GNOME based genealogy program # -# Copyright (C) 2000-2005 Donald N. Allingham +# Copyright (C) 2000-2006 Donald N. Allingham # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -48,7 +48,6 @@ import gtk.glade import RelLib import GenericFilter import const -import Date import _GedcomInfo as GedcomInfo import Errors import ansel_utf8 @@ -81,15 +80,15 @@ _month = [ "JUL", "AUG", "SEP", "OCT", "NOV", "DEC" ] _calmap = { - Date.CAL_HEBREW : (_hmonth, '@#HEBREW@'), - Date.CAL_FRENCH : (_fmonth, '@#FRENCH R@'), - Date.CAL_JULIAN : (_month, '@#JULIAN@'), + RelLib.Date.CAL_HEBREW : (_hmonth, '@#HEBREW@'), + RelLib.Date.CAL_FRENCH : (_fmonth, '@#FRENCH R@'), + RelLib.Date.CAL_JULIAN : (_month, '@#JULIAN@'), } _caldef = { - Date.MOD_ABOUT : "ABT", - Date.MOD_BEFORE : "BEF", - Date.MOD_AFTER : "AFT", + RelLib.Date.MOD_ABOUT : "ABT", + RelLib.Date.MOD_BEFORE : "BEF", + RelLib.Date.MOD_AFTER : "AFT", } #------------------------------------------------------------------------- @@ -1142,13 +1141,13 @@ class GedcomWriter: def print_date(self,prefix,date): start = date.get_start_date() - if start != Date.EMPTY: + if start != RelLib.Date.EMPTY: cal = date.get_calendar() mod = date.get_modifier() - if date.get_modifier() == Date.MOD_SPAN: + if date.get_modifier() == RelLib.Date.MOD_SPAN: val = "FROM %s TO %s" % (make_date(start,cal,mod), make_date(date.get_stop_date(),cal,mod)) - elif date.get_modifier() == Date.MOD_RANGE: + elif date.get_modifier() == RelLib.Date.MOD_RANGE: val = "BET %s AND %s" % (make_date(start,cal,mod), make_date(date.get_stop_date(),cal,mod)) else: diff --git a/gramps2/src/GrampsDb/_WriteXML.py b/gramps2/src/GrampsDb/_WriteXML.py index c50f7efe9..277958d62 100644 --- a/gramps2/src/GrampsDb/_WriteXML.py +++ b/gramps2/src/GrampsDb/_WriteXML.py @@ -50,7 +50,6 @@ import gtk #------------------------------------------------------------------------- import const import RelLib -import Date from QuestionDialog import ErrorDialog import _ConstXML from _GrampsDbBase import \ @@ -90,7 +89,9 @@ def exportData(database, filename, person, callback=None): try: g = XmlWriter(database,callback,0,compress) + t = time.time() ret = g.write(filename) + print time.time()-t except: import DisplayTrace @@ -678,15 +679,15 @@ class XmlWriter: sp = ' '*indent cal= date.get_calendar() - if cal != Date.CAL_GREGORIAN: - calstr = ' cformat="%s"' % Date.Date.calendar_names[cal] + if cal != RelLib.Date.CAL_GREGORIAN: + calstr = ' cformat="%s"' % RelLib.Date.calendar_names[cal] else: calstr = '' qual = date.get_quality() - if qual == Date.QUAL_ESTIMATED: + if qual == RelLib.Date.QUAL_ESTIMATED: qual_str = ' quality="estimated"' - elif qual == Date.QUAL_CALCULATED: + elif qual == RelLib.Date.QUAL_CALCULATED: qual_str = ' quality="calculated"' else: qual_str = "" @@ -699,16 +700,16 @@ class XmlWriter: if d1 != "" or d2 != "": self.g.write('%s\n' % (sp,d1,d2,qual_str,calstr)) - elif mode != Date.MOD_TEXTONLY: + elif mode != RelLib.Date.MOD_TEXTONLY: date_str = self.get_iso_date(date.get_start_date()) if date_str == "": return - if mode == Date.MOD_BEFORE: + if mode == RelLib.Date.MOD_BEFORE: mode_str = ' type="before"' - elif mode == Date.MOD_AFTER: + elif mode == RelLib.Date.MOD_AFTER: mode_str = ' type="after"' - elif mode == Date.MOD_ABOUT: + elif mode == RelLib.Date.MOD_ABOUT: mode_str = ' type="about"' else: mode_str = "" diff --git a/gramps2/src/ImageSelect.py b/gramps2/src/ImageSelect.py index d5c050669..1c6058a01 100644 --- a/gramps2/src/ImageSelect.py +++ b/gramps2/src/ImageSelect.py @@ -1,7 +1,7 @@ # # Gramps - a GTK+/GNOME based genealogy program # -# Copyright (C) 2000-2005 Donald N. Allingham +# Copyright (C) 2000-2006 Donald N. Allingham # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -57,7 +57,6 @@ import GrampsMime import Sources import DateEdit import DateHandler -import Date import ImgManip import Spell import DisplayState @@ -970,11 +969,11 @@ class GlobalMediaProperties(DisplayState.ManagedWindow): self.db = self.state.db self.idle = None if obj: - self.date_object = Date.Date(self.obj.get_date_object()) + self.date_object = RelLib.Date(self.obj.get_date_object()) self.alist = self.obj.get_attribute_list()[:] self.refs = 0 else: - self.date_object = Date.Date() + self.date_object = RelLib.Date() self.alist = [] self.refs = 1 diff --git a/gramps2/src/Marriage.py b/gramps2/src/Marriage.py index c1d9f21b0..c75c4a893 100644 --- a/gramps2/src/Marriage.py +++ b/gramps2/src/Marriage.py @@ -1,7 +1,7 @@ # # Gramps - a GTK+/GNOME based genealogy program # -# Copyright (C) 2000-2005 Donald N. Allingham +# Copyright (C) 2000-2006 Donald N. Allingham # # This program is free software; you can redistribute it and/or modiy # it under the terms of the GNU General Public License as published by @@ -56,7 +56,6 @@ import DateHandler import Sources import GrampsKeys import NameDisplay -import Date import DateEdit import DateHandler import Spell @@ -240,7 +239,7 @@ class Marriage: lds_ord = self.family.get_lds_sealing() self.seal_stat = 0 - self.lds_date_object = Date.Date() + self.lds_date_object = RelLib.Date() if GrampsKeys.get_uselds() or lds_ord: if lds_ord: place_handle = lds_ord.get_place_handle() diff --git a/gramps2/src/NameEdit.py b/gramps2/src/NameEdit.py index 9d1281ccc..55ff40b75 100644 --- a/gramps2/src/NameEdit.py +++ b/gramps2/src/NameEdit.py @@ -1,7 +1,7 @@ # # Gramps - a GTK+/GNOME based genealogy program # -# Copyright (C) 2000-2005 Donald N. Allingham +# Copyright (C) 2000-2006 Donald N. Allingham # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -47,7 +47,6 @@ import AutoComp import Sources import RelLib import NameDisplay -import Date import DateEdit import DateHandler import Spell @@ -101,7 +100,7 @@ class NameEditor(DisplayState.ManagedWindow): self.date_obj = self.name.get_date_object() else: self.srcreflist = [] - self.date_obj = Date.Date() + self.date_obj = RelLib.Date() self.name = RelLib.Name() self.date.set_text(DateHandler.displayer.display(self.date_obj)) diff --git a/gramps2/src/PeopleModel.py b/gramps2/src/PeopleModel.py index 34ad68625..d056e4ee5 100644 --- a/gramps2/src/PeopleModel.py +++ b/gramps2/src/PeopleModel.py @@ -1,7 +1,7 @@ # # Gramps - a GTK+/GNOME based genealogy program # -# Copyright (C) 2000-2005 Donald N. Allingham +# Copyright (C) 2000-2006 Donald N. Allingham # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -158,7 +158,8 @@ class PeopleModel(gtk.GenericTreeModel): while node: n,d = node if n in flist: - primary_name = d[_NAME_COL] + primary_name = Name() + primary_name.unserialize(d[_NAME_COL]) surname = ngn(self.db,primary_name) self.sortnames[n] = nsn(primary_name) try: @@ -307,7 +308,9 @@ class PeopleModel(gtk.GenericTreeModel): return None def column_sort_name(self,data,node): - return data[_NAME_COL].get_sort_name() + n = Name() + n.unserialize(data[_NAME_COL]) + return n.get_sort_name() def column_spouse(self,data,node): spouses_names = u"" @@ -326,7 +329,9 @@ class PeopleModel(gtk.GenericTreeModel): return spouses_names def column_name(self,data,node): - return NameDisplay.displayer.sorted_name(data[_NAME_COL]) + n = Name() + n.unserialize(data[_NAME_COL]) + return NameDisplay.displayer.sorted_name(n) def column_id(self,data,node): return data[_ID_COL] @@ -340,13 +345,17 @@ class PeopleModel(gtk.GenericTreeModel): def column_birth_day(self,data,node): if data[_BIRTH_COL]: - birth = self.db.get_event_from_handle(data[_BIRTH_COL].ref) + b=EventRef() + b.unserialize(data[_BIRTH_COL]) + birth = self.db.get_event_from_handle(b.ref) date_str = DateHandler.get_date(birth) if date_str != "": return cgi.escape(date_str) for event_ref in data[_EVENT_COL]: - event = self.db.get_event_from_handle(event_ref.ref) + er = EventRef() + er.unserialize(event_ref) + event = self.db.get_event_from_handle(er.ref) etype = event.get_type()[0] date_str = DateHandler.get_date(event) if (etype in [Event.BAPTISM, Event.CHRISTEN] @@ -357,13 +366,17 @@ class PeopleModel(gtk.GenericTreeModel): def column_death_day(self,data,node): if data[_DEATH_COL]: - death = self.db.get_event_from_handle(data[_DEATH_COL].ref) + dr = EventRef() + dr.unserialize(data[_DEATH_COL]) + death = self.db.get_event_from_handle(dr.ref) date_str = DateHandler.get_date(death) if date_str != "": return cgi.escape(date_str) for event_ref in data[_EVENT_COL]: - event = self.db.get_event_from_handle(event_ref.ref) + er = EventRef() + er.unserialize(event_ref) + event = self.db.get_event_from_handle(er.ref) etype = event.get_type()[0] date_str = DateHandler.get_date(event) if (etype in [Event.BURIAL, Event.CREMATION] @@ -374,13 +387,17 @@ class PeopleModel(gtk.GenericTreeModel): def column_cause_of_death(self,data,node): if data[_DEATH_COL]: - return self.db.get_event_from_handle(data[_DEATH_COL].ref).get_cause() + dr = EventRef() + dr.unserialize(data[_DEATH_COL]) + return self.db.get_event_from_handle(dr.ref).get_cause() else: return u"" def column_birth_place(self,data,node): if data[_BIRTH_COL]: - event = self.db.get_event_from_handle(data[_BIRTH_COL].ref) + br = EventRef() + br.unserialize(data[_BIRTH_COL]) + event = self.db.get_event_from_handle(br.ref) if event: place_handle = event.get_place_handle() if place_handle: @@ -389,7 +406,9 @@ class PeopleModel(gtk.GenericTreeModel): return cgi.escape(place_title) for event_ref in data[_EVENT_COL]: - event = self.db.get_event_from_handle(event_ref.ref) + er = EventRef() + er.unserialize(event_ref) + event = self.db.get_event_from_handle(er.ref) etype = event.get_type()[0] if etype in [Event.BAPTISM, Event.CHRISTEN]: place_handle = event.get_place_handle() @@ -402,7 +421,9 @@ class PeopleModel(gtk.GenericTreeModel): def column_death_place(self,data,node): if data[_DEATH_COL]: - event = self.db.get_event_from_handle(data[_DEATH_COL].ref) + dr = EventRef() + dr.unserialize(data[_DEATH_COL]) + event = self.db.get_event_from_handle(dr.ref) if event: place_handle = event.get_place_handle() if place_handle: @@ -411,7 +432,9 @@ class PeopleModel(gtk.GenericTreeModel): return cgi.escape(place_title) for event_ref in data[_EVENT_COL]: - event = self.db.get_event_from_handle(event_ref.ref) + er = EventRef() + er.unserialize(event_ref) + event = self.db.get_event_from_handle(er.ref) etype = event.get_type()[0] if etype in [Event.BURIAL, Event.CREMATION]: place_handle = event.get_place_handle() diff --git a/gramps2/src/RelLib/_Address.py b/gramps2/src/RelLib/_Address.py index f55c0fc29..d240bc9d2 100644 --- a/gramps2/src/RelLib/_Address.py +++ b/gramps2/src/RelLib/_Address.py @@ -1,7 +1,7 @@ # # Gramps - a GTK+/GNOME based genealogy program # -# Copyright (C) 2000-2005 Donald N. Allingham +# Copyright (C) 2000-2006 Donald N. Allingham # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -53,6 +53,19 @@ class Address(PrivateSourceNote,DateBase,LocationBase): else: self.street = "" + def serialize(self): + return (PrivateSourceNote.serialize(self), + DateBase.serialize(self), + self.city,self.state, + self.country,self.postal,self.phone,self.street) + + def unserialize(self,data): + (psn,date,self.city,self.state, + self.country,self.postal,self.phone,self.street) = data + PrivateSourceNote.unserialize(self,psn) + DateBase.unserialize(self,date) + return self + def get_text_data_list(self): """ Returns the list of all textual attributes of the object. diff --git a/gramps2/src/RelLib/_AddressBase.py b/gramps2/src/RelLib/_AddressBase.py index e99b116b6..dda3dc96e 100644 --- a/gramps2/src/RelLib/_AddressBase.py +++ b/gramps2/src/RelLib/_AddressBase.py @@ -1,7 +1,7 @@ # # Gramps - a GTK+/GNOME based genealogy program # -# Copyright (C) 2000-2005 Donald N. Allingham +# Copyright (C) 2000-2006 Donald N. Allingham # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -56,6 +56,12 @@ class AddressBase: else: self.address_list = [] + def serialize(self): + return [addr.serialize() for addr in self.address_list] + + def unserialize(self,data): + self.address_list = [Address().unserialize(item) for item in data] + def add_address(self,address): """ Adds the L{Address} instance to the object's list of addresses diff --git a/gramps2/src/RelLib/_Attribute.py b/gramps2/src/RelLib/_Attribute.py index 581cd0e84..09bee153f 100644 --- a/gramps2/src/RelLib/_Attribute.py +++ b/gramps2/src/RelLib/_Attribute.py @@ -1,7 +1,7 @@ # # Gramps - a GTK+/GNOME based genealogy program # -# Copyright (C) 2000-2005 Donald N. Allingham +# Copyright (C) 2000-2006 Donald N. Allingham # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -67,6 +67,15 @@ class Attribute(PrivateSourceNote): self.type = (Attribute.CUSTOM,"") self.value = "" + def serialize(self): + return (PrivateSourceNote.serialize(self), + self.type,self.value) + + def unserialize(self,data): + (psn,self.type,self.value) = data + PrivateSourceNote.unserialize(self,psn) + return self + def get_text_data_list(self): """ Returns the list of all textual attributes of the object. diff --git a/gramps2/src/RelLib/_AttributeBase.py b/gramps2/src/RelLib/_AttributeBase.py index a6a1407bd..341bba918 100644 --- a/gramps2/src/RelLib/_AttributeBase.py +++ b/gramps2/src/RelLib/_AttributeBase.py @@ -1,7 +1,7 @@ # # Gramps - a GTK+/GNOME based genealogy program # -# Copyright (C) 2000-2005 Donald N. Allingham +# Copyright (C) 2000-2006 Donald N. Allingham # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -56,6 +56,12 @@ class AttributeBase: else: self.attribute_list = [] + def serialize(self): + return [attr.serialize() for attr in self.attribute_list] + + def unserialize(self,data): + self.attribute_list = [Attribute().unserialize(item) for item in data] + def add_attribute(self,attribute): """ Adds the L{Attribute} instance to the object's list of attributes diff --git a/gramps2/src/RelLib/_BaseObject.py b/gramps2/src/RelLib/_BaseObject.py index 1922d6c6b..01ecdeeda 100644 --- a/gramps2/src/RelLib/_BaseObject.py +++ b/gramps2/src/RelLib/_BaseObject.py @@ -1,7 +1,7 @@ # # Gramps - a GTK+/GNOME based genealogy program # -# Copyright (C) 2000-2005 Donald N. Allingham +# Copyright (C) 2000-2006 Donald N. Allingham # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -48,6 +48,13 @@ class BaseObject: Initialize a BaseObject. """ pass + + def serialize(self): + assert False, "Needs to be overridden in the derived class" + + def unserialize(self,data): + assert False, "Needs to be overridden in the derived class" + return self def matches_string(self,pattern,case_sensitive=False): """ diff --git a/gramps2/src/CalSdn.py b/gramps2/src/RelLib/_CalSdn.py similarity index 86% rename from gramps2/src/CalSdn.py rename to gramps2/src/RelLib/_CalSdn.py index 699cc2911..d93f9003d 100644 --- a/gramps2/src/CalSdn.py +++ b/gramps2/src/RelLib/_CalSdn.py @@ -1,7 +1,7 @@ # # Gramps - a GTK+/GNOME based genealogy program # -# Copyright (C) 2000-2004 Donald N. Allingham +# Copyright (C) 2000-2006 Donald N. Allingham # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -20,8 +20,18 @@ # $Id$ -import math +#------------------------------------------------------------------------- +# +# Python modules +# +#------------------------------------------------------------------------- +import cmath +#------------------------------------------------------------------------- +# +# Constants +# +#------------------------------------------------------------------------- _GRG_SDN_OFFSET = 32045 _GRG_DAYS_PER_5_MONTHS = 153 _GRG_DAYS_PER_4_YEARS = 1461 @@ -73,7 +83,8 @@ def _tishri1(metonic_year, molad_day, molad_halakim): if ((molad_halakim >= _HBR_NOON) or ((not leap_year) and dow == _HBR_TUESDAY and molad_halakim >= _HBR_AM3_11_20) or - (last_was_leap_year and dow == _HBR_MONDAY and molad_halakim >= _HBR_AM9_32_43)) : + (last_was_leap_year and dow == _HBR_MONDAY + and molad_halakim >= _HBR_AM9_32_43)) : tishri1 += 1 dow += 1 if dow == 7: @@ -116,8 +127,8 @@ def _tishri_molad(inputDay): if moladDay > inputDay - 74: break - moladHalakim = moladHalakim + \ - (_HBR_HALAKIM_PER_LUNAR_CYCLE * _HBR_MONTHS_PER_YEAR[metonicYear]) + moladHalakim = moladHalakim + (_HBR_HALAKIM_PER_LUNAR_CYCLE + * _HBR_MONTHS_PER_YEAR[metonicYear]) moladDay = moladDay + (moladHalakim / _HBR_HALAKIM_PER_DAY) moladHalakim = moladHalakim % _HBR_HALAKIM_PER_DAY else: @@ -136,7 +147,7 @@ def _molad_of_metonic_cycle(metonic_cycle): r1 = r1 + (metonic_cycle * (_HBR_HALAKIM_PER_METONIC_CYCLE & 0xFFFF)) r2 = r1 >> 16 - r2 = r2 + (metonic_cycle * ((_HBR_HALAKIM_PER_METONIC_CYCLE >> 16) & 0xFFFF)) + r2 = r2 + (metonic_cycle * ((_HBR_HALAKIM_PER_METONIC_CYCLE >> 16)&0xFFFF)) # Calculate r2r1 / HALAKIM_PER_DAY. The remainder will be in r1, the # upper 16 bits of the quotient will be in d2 and the lower 16 bits @@ -159,7 +170,8 @@ def _start_of_year(year): metonic_year = (year - 1) % 19; (molad_day, molad_halakim) = _molad_of_metonic_cycle(metonic_cycle) - molad_halakim = molad_halakim + (_HBR_HALAKIM_PER_LUNAR_CYCLE * _HBR_YEAR_OFFSET[metonic_year]) + molad_halakim = molad_halakim + (_HBR_HALAKIM_PER_LUNAR_CYCLE + * _HBR_YEAR_OFFSET[metonic_year]) molad_day = molad_day + (molad_halakim / _HBR_HALAKIM_PER_DAY) molad_halakim = molad_halakim % _HBR_HALAKIM_PER_DAY @@ -172,7 +184,8 @@ def hebrew_sdn(year, month, day): if month == 1 or month == 2: # It is Tishri or Heshvan - don't need the year length. - (metonic_cycle,metonic_year,molad_day,molad_halakim,tishri1) = _start_of_year(year) + (metonic_cycle,metonic_year, + molad_day,molad_halakim,tishri1) = _start_of_year(year) if month == 1: sdn = tishri1 + day - 1 else: @@ -181,13 +194,16 @@ def hebrew_sdn(year, month, day): # It is Kislev - must find the year length. # Find the start of the year. - (metonic_cycle,metonic_year,molad_day,molad_halakim,tishri1) = _start_of_year(year) + (metonic_cycle,metonic_year, + molad_day,molad_halakim,tishri1) = _start_of_year(year) # Find the end of the year. - molad_halakim = molad_halakim + (_HBR_HALAKIM_PER_LUNAR_CYCLE*_HBR_MONTHS_PER_YEAR[metonic_year]) + molad_halakim = molad_halakim + (_HBR_HALAKIM_PER_LUNAR_CYCLE + *_HBR_MONTHS_PER_YEAR[metonic_year]) molad_day = molad_day + (molad_halakim / _HBR_HALAKIM_PER_DAY) molad_halakim = molad_halakim % _HBR_HALAKIM_PER_DAY - tishri1_after = _tishri1((metonic_year + 1) % 19, molad_day, molad_halakim) + tishri1_after = _tishri1((metonic_year + 1) + % 19, molad_day, molad_halakim) year_length = tishri1_after - tishri1 @@ -198,7 +214,8 @@ def hebrew_sdn(year, month, day): elif month == 4 or month == 5 or month == 6: # It is Tevet, Shevat or Adar I - don't need the year length - (metonic_cycle,metonic_year,molad_day,molad_halakim,tishri1_after) = _start_of_year(year+1) + (metonic_cycle,metonic_year, + molad_day,molad_halakim,tishri1_after) = _start_of_year(year+1) if _HBR_MONTHS_PER_YEAR[(year - 1) % 19] == 12: length_of_adarI_andII = 29 @@ -213,7 +230,8 @@ def hebrew_sdn(year, month, day): sdn = tishri1_after + day - length_of_adarI_andII - 178 else: # It is Adar II or later - don't need the year length. - (metonic_cycle,metonic_year,molad_day,molad_halakim,tishri1_after) = _start_of_year(year+1) + (metonic_cycle,metonic_year, + molad_day,molad_halakim,tishri1_after) = _start_of_year(year+1) if month == 7: sdn = tishri1_after + day - 207 @@ -257,7 +275,8 @@ def hebrew_ymd(sdn): # We need the length of the year to figure this out, so find # Tishri 1 of the next year. */ - halakim = halakim + (_HBR_HALAKIM_PER_LUNAR_CYCLE * _HBR_MONTHS_PER_YEAR[metonicYear]) + halakim = halakim + (_HBR_HALAKIM_PER_LUNAR_CYCLE + * _HBR_MONTHS_PER_YEAR[metonicYear]) day = day + (halakim / _HBR_HALAKIM_PER_DAY) halakim = halakim % _HBR_HALAKIM_PER_DAY; tishri1After = _tishri1((metonicYear + 1) % 19, day, halakim); @@ -463,24 +482,24 @@ def persian_sdn(year, month, day): v1 = (month - 1) * 31 else: v1 = ((month - 1) * 30) + 6 - v2 = math.floor(((epyear * 682) - 110) / 2816) + v2 = cmath.floor(((epyear * 682) - 110) / 2816) v3 = (epyear - 1) * 365 + day - v4 = math.floor(epbase / 2820) * 1029983 + v4 = cmath.floor(epbase / 2820) * 1029983 - return int(math.ceil(v1 + v2 + v3 + v4 + _PRS_EPOCH - 1)) + return int(cmath.ceil(v1 + v2 + v3 + v4 + _PRS_EPOCH - 1)) def persian_ymd(sdn): - sdn = math.floor(sdn) + 0.5 + sdn = cmath.floor(sdn) + 0.5 depoch = sdn - 2121446 - cycle = math.floor(depoch / 1029983) + cycle = cmath.floor(depoch / 1029983) cyear = depoch % 1029983 if cyear == 1029982: ycycle = 2820 else: - aux1 = math.floor(cyear / 366) + aux1 = cmath.floor(cyear / 366) aux2 = cyear % 366 - ycycle = math.floor(((2134*aux1)+(2816*aux2)+2815)/1028522) + aux1 + 1; + ycycle = cmath.floor(((2134*aux1)+(2816*aux2)+2815)/1028522) + aux1 + 1 year = ycycle + (2820 * cycle) + 474 if year <= 0: @@ -488,23 +507,22 @@ def persian_ymd(sdn): yday = sdn - persian_sdn(year, 1, 1) + 1 if yday < 186: - month = math.ceil(yday / 31) + month = cmath.ceil(yday / 31) else: - month = math.ceil((yday - 6) / 30) + month = cmath.ceil((yday - 6) / 30) day = (sdn - persian_sdn(year, month, 1)) + 1 return (int(year), int(month), int(day)) def islamic_sdn(year, month, day): - v1 = math.ceil(29.5 * (month - 1)) + v1 = cmath.ceil(29.5 * (month - 1)) v2 = (year - 1) * 354 - v3 = math.floor((3 + (11 *year)) / 30) + v3 = cmath.floor((3 + (11 *year)) / 30) - return int(math.ceil((day + v1 + v2 + v3 + _ISM_EPOCH) - 1)) + return int(cmath.ceil((day + v1 + v2 + v3 + _ISM_EPOCH) - 1)) def islamic_ymd(sdn): - sdn = math.floor(sdn) + 0.5 - year = int(math.floor(((30*(sdn-_ISM_EPOCH))+10646)/10631)) - month = int(min(12, math.ceil((sdn-(29+islamic_sdn(year,1,1)))/29.5) + 1)) + sdn = cmath.floor(sdn) + 0.5 + year = int(cmath.floor(((30*(sdn-_ISM_EPOCH))+10646)/10631)) + month = int(min(12, cmath.ceil((sdn-(29+islamic_sdn(year,1,1)))/29.5) + 1)) day = int((sdn - islamic_sdn(year,month,1)) + 1) return (year,month,day) - diff --git a/gramps2/src/RelLib/_Date.py b/gramps2/src/RelLib/_Date.py new file mode 100644 index 000000000..552f03e7c --- /dev/null +++ b/gramps2/src/RelLib/_Date.py @@ -0,0 +1,565 @@ +# +# Gramps - a GTK+/GNOME based genealogy program +# +# Copyright (C) 2000-2006 Donald N. Allingham +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# + +# $Id$ + +"Support for dates" + +__author__ = "Donald N. Allingham" +__version__ = "$Revision$" + +from gettext import gettext as _ +from _CalSdn import * + +#------------------------------------------------------------------------- +# +# DateError exception +# +#------------------------------------------------------------------------- +class DateError(Exception): + """Error used to report Date errors""" + def __init__(self,value=""): + Exception.__init__(self) + self.value = value + + def __str__(self): + return self.value + +#------------------------------------------------------------------------- +# +# Date class +# +#------------------------------------------------------------------------- +class Date: + """ + The core date handling class for GRAMPs. Supports partial dates, + compound dates and alternate calendars. + """ + + MOD_NONE = 0 + MOD_BEFORE = 1 + MOD_AFTER = 2 + MOD_ABOUT = 3 + MOD_RANGE = 4 + MOD_SPAN = 5 + MOD_TEXTONLY = 6 + + QUAL_NONE = 0 + QUAL_ESTIMATED = 1 + QUAL_CALCULATED= 2 + + CAL_GREGORIAN = 0 + CAL_JULIAN = 1 + CAL_HEBREW = 2 + CAL_FRENCH = 3 + CAL_PERSIAN = 4 + CAL_ISLAMIC = 5 + + EMPTY = (0,0,0,False) + + _POS_DAY = 0 + _POS_MON = 1 + _POS_YR = 2 + _POS_SL = 3 + _POS_RDAY = 4 + _POS_RMON = 5 + _POS_RYR = 6 + _POS_RSL = 7 + + _calendar_convert = [ + gregorian_sdn, + julian_sdn, + hebrew_sdn, + french_sdn, + persian_sdn, + islamic_sdn, + ] + + _calendar_change = [ + gregorian_ymd, + julian_ymd, + hebrew_ymd, + french_ymd, + persian_ymd, + islamic_ymd, + ] + + calendar_names = ["Gregorian", + "Julian", + "Hebrew", + "French Republican", + "Persian", + "Islamic"] + + + ui_calendar_names = [_("Gregorian"), + _("Julian"), + _("Hebrew"), + _("French Republican"), + _("Persian"), + _("Islamic")] + + def __init__(self,source=None): + """ + Creates a new Date instance. + """ + if source: + self.calendar = source.calendar + self.modifier = source.modifier + self.quality = source.quality + self.dateval = source.dateval + self.text = source.text + self.sortval = source.sortval + else: + self.calendar = Date.CAL_GREGORIAN + self.modifier = Date.MOD_NONE + self.quality = Date.QUAL_NONE + self.dateval = Date.EMPTY + self.text = u"" + self.sortval = 0 + + def serialize(self): + return (self.calendar,self.modifier,self.quality, + self.dateval,self.text,self.sortval) + + def unserialize(self,data): + (self.calendar,self.modifier,self.quality, + self.dateval,self.text,self.sortval) = data + return self + + def copy(self,source): + """ + Copy all the attributes of the given Date instance + to the present instance, without creating a new object. + """ + self.calendar = source.calendar + self.modifier = source.modifier + self.quality = source.quality + self.dateval = source.dateval + self.text = source.text + self.sortval = source.sortval + + def __cmp__(self,other): + """ + Comparison function. Allows the usage of equality tests. + This allows you do run statements like 'date1 <= date2' + """ + if isinstance(other,Date): + return cmp(self.sortval,other.sortval) + else: + return -1 + + def is_equal(self,other): + """ + Return 1 if the given Date instance is the same as the present + instance IN ALL REGARDS. Needed, because the __cmp__ only looks + at the sorting value, and ignores the modifiers/comments. + """ + if self.modifier == other.modifier \ + and self.modifier == Date.MOD_TEXTONLY: + value = self.text == other.text + else: + value = (self.calendar == other.calendar and + self.modifier == other.modifier and + self.quality == other.quality and + self.dateval == other.dateval) + return value + + def __str__(self): + """ + Produces a string representation of the Date object. If the + date is not valid, the text representation is displayed. If + the date is a range or a span, a string in the form of + 'YYYY-MM-DD - YYYY-MM-DD' is returned. Otherwise, a string in + the form of 'YYYY-MM-DD' is returned. + """ + if self.quality == Date.QUAL_ESTIMATED: + qual = "est " + elif self.quality == Date.QUAL_CALCULATED: + qual = "calc " + else: + qual = "" + + if self.modifier == Date.MOD_BEFORE: + pref = "bef " + elif self.modifier == Date.MOD_AFTER: + pref = "aft " + elif self.modifier == Date.MOD_ABOUT: + pref = "abt " + else: + pref = "" + + if self.calendar != Date.CAL_GREGORIAN: + cal = " (%s)" % Date.calendar_names[self.calendar] + else: + cal = "" + + + if self.modifier == Date.MOD_TEXTONLY: + val = self.text + elif self.modifier == Date.MOD_RANGE or self.modifier == Date.MOD_SPAN: + val = "%04d-%02d-%02d - %04d-%02d-%02d" % ( + self.dateval[Date._POS_YR],self.dateval[Date._POS_MON], + self.dateval[Date._POS_DAY],self.dateval[Date._POS_RYR], + self.dateval[Date._POS_RMON],self.dateval[Date._POS_RDAY]) + else: + val = "%04d-%02d-%02d" % ( + self.dateval[Date._POS_YR],self.dateval[Date._POS_MON], + self.dateval[Date._POS_DAY]) + return "%s%s%s%s" % (qual,pref,val,cal) + + def get_sort_value(self): + """ + Returns the sort value of Date object. If the value is a + text string, 0 is returned. Otherwise, the calculated sort + date is returned. The sort date is rebuilt on every assignment. + + The sort value is an integer representing the value. A date of + March 5, 1990 would have the value of 19900305. + """ + return self.sortval + + def get_modifier(self): + """ + Returns an integer indicating the calendar selected. The valid + values are:: + + MOD_NONE = no modifier (default) + MOD_BEFORE = before + MOD_AFTER = after + MOD_ABOUT = about + MOD_RANGE = date range + MOD_SPAN = date span + MOD_TEXTONLY = text only + """ + return self.modifier + + def set_modifier(self,val): + """ + Sets the modifier for the date. + """ + if val not in (Date.MOD_NONE,Date.MOD_BEFORE,Date.MOD_AFTER, + Date.MOD_ABOUT,Date.MOD_RANGE,Date.MOD_SPAN, + Date.MOD_TEXTONLY): + raise DateError("Invalid modifier") + self.modifier = val + + def get_quality(self): + """ + Returns an integer indicating the calendar selected. The valid + values are:: + + QUAL_NONE = normal (default) + QUAL_ESTIMATED = estimated + QUAL_CALCULATED = calculated + """ + return self.quality + + def set_quality(self,val): + """ + Sets the quality selected for the date. + """ + if val not in (Date.QUAL_NONE,Date.QUAL_ESTIMATED, + Date.QUAL_CALCULATED): + raise DateError("Invalid quality") + self.quality = val + + def get_calendar(self): + """ + Returns an integer indicating the calendar selected. The valid + values are:: + + CAL_GREGORIAN - Gregorian calendar + CAL_JULIAN - Julian calendar + CAL_HEBREW - Hebrew (Jewish) calendar + CAL_FRENCH - French Republican calendar + CAL_PERSIAN - Persian calendar + CAL_ISLAMIC - Islamic calendar + """ + return self.calendar + + def set_calendar(self,val): + """ + Sets the calendar selected for the date. + """ + if val not in (Date.CAL_GREGORIAN,Date.CAL_JULIAN,Date.CAL_HEBREW, + Date.CAL_FRENCH,Date.CAL_PERSIAN,Date.CAL_ISLAMIC): + raise DateError("Invalid calendar") + self.calendar = val + + def get_start_date(self): + """ + Returns a tuple representing the start date. If the date is a + compound date (range or a span), it is the first part of the + compound date. If the date is a text string, a tuple of + (0,0,0,False) is returned. Otherwise, a date of (DD,MM,YY,slash) + is returned. If slash is True, then the date is in the form of 1530/1. + """ + if self.modifier == Date.MOD_TEXTONLY: + val = Date.EMPTY + else: + val = self.dateval[0:4] + return val + + def get_stop_date(self): + """ + Returns a tuple representing the second half of a compound date. + If the date is not a compound date, (including text strings) a tuple + of (0,0,0,False) is returned. Otherwise, a date of (DD,MM,YY,slash) + is returned. If slash is True, then the date is in the form of 1530/1. + """ + if self.modifier == Date.MOD_RANGE or self.modifier == Date.MOD_SPAN: + val = self.dateval[4:8] + else: + val = Date.EMPTY + return val + + def _get_low_item(self,index): + if self.modifier == Date.MOD_TEXTONLY: + val = 0 + else: + val = self.dateval[index] + return val + + def _get_low_item_valid(self,index): + if self.modifier == Date.MOD_TEXTONLY: + val = False + else: + val = self.dateval[index] != 0 + return val + + def _get_high_item(self,index): + if self.modifier == Date.MOD_SPAN or self.modifier == Date.MOD_RANGE: + val = self.dateval[index] + else: + val = 0 + return val + + def get_year(self): + """ + Returns the year associated with the date. If the year is + not defined, a zero is returned. If the date is a compound + date, the lower date year is returned. + """ + return self._get_low_item(Date._POS_YR) + + def set_year(self,year): + """ + """ + self.dateval = self.dateval[0:2] + (year,) + self.dateval[3:] + self.calc_sort_value() + + def get_year_valid(self): + return self._get_low_item_valid(Date._POS_YR) + + def get_month(self): + """ + Returns the month associated with the date. If the month is + not defined, a zero is returned. If the date is a compound + date, the lower date month is returned. + """ + return self._get_low_item(Date._POS_MON) + + def get_month_valid(self): + return self._get_low_item_valid(Date._POS_MON) + + def get_day(self): + """ + Returns the day of the month associated with the date. If + the day is not defined, a zero is returned. If the date is + a compound date, the lower date day is returned. + """ + return self._get_low_item(Date._POS_DAY) + + def get_day_valid(self): + return self._get_low_item_valid(Date._POS_DAY) + + def get_valid(self): + """ Returns true if any part of the date is valid""" + return self.modifier != Date.MOD_TEXTONLY + + def get_incomplete(self): + pass + + def get_stop_year(self): + """ + Returns the day of the year associated with the second + part of a compound date. If the year is not defined, a zero + is returned. + """ + return self._get_high_item(Date._POS_RYR) + + def get_stop_month(self): + """ + Returns the month of the month associated with the second + part of a compound date. If the month is not defined, a zero + is returned. + """ + return self._get_high_item(Date._POS_RMON) + + def get_stop_day(self): + """ + Returns the day of the month associated with the second + part of a compound date. If the day is not defined, a zero + is returned. + """ + return self._get_high_item(Date._POS_RDAY) + + def get_high_year(self): + """ + Returns the high year estimate. For compound dates with non-zero + stop year, the stop year is returned. Otherwise, the start year + is returned. + """ + if self.is_compound(): + ret = self.get_stop_year() + if ret: + return ret + else: + return self.get_year() + + def get_text(self): + """ + Returns the text value associated with an invalid date. + """ + return self.text + + def set(self,quality,modifier,calendar,value,text=None): + """ + Sets the date to the specified value. Parameters are:: + + quality - The date quality for the date (see get_quality + for more information) + modified - The date modifier for the date (see get_modifier + for more information) + calendar - The calendar associated with the date (see + get_calendar for more information). + value - A tuple representing the date information. For a + non-compound date, the format is (DD,MM,YY,slash) + and for a compound date the tuple stores data as + (DD,MM,YY,slash1,DD,MM,YY,slash2) + text - A text string holding either the verbatim user input + or a comment relating to the date. + + The sort value is recalculated. + """ + + if modifier in (Date.MOD_NONE,Date.MOD_BEFORE, + Date.MOD_AFTER,Date.MOD_ABOUT) and len(value) < 4: + raise DateError("Invalid value. Should be: (DD,MM,YY,slash)") + if modifier in (Date.MOD_RANGE,Date.MOD_SPAN) and len(value) < 8: + raise DateError( + "Invalid value. Should be: (DD,MM,YY,slash1,DD,MM,YY,slash2)") + if modifier not in (Date.MOD_NONE,Date.MOD_BEFORE,Date.MOD_AFTER, + Date.MOD_ABOUT,Date.MOD_RANGE,Date.MOD_SPAN, + Date.MOD_TEXTONLY): + raise DateError("Invalid modifier") + if quality not in (Date.QUAL_NONE,Date.QUAL_ESTIMATED, + Date.QUAL_CALCULATED): + raise DateError("Invalid quality") + if calendar not in (Date.CAL_GREGORIAN,Date.CAL_JULIAN,Date.CAL_HEBREW, + Date.CAL_FRENCH,Date.CAL_PERSIAN,Date.CAL_ISLAMIC): + raise DateError("Invalid calendar") + + self.quality = quality + self.modifier = modifier + self.calendar = calendar + self.dateval = value + year = max(value[Date._POS_YR],1) + month = max(value[Date._POS_MON],1) + day = max(value[Date._POS_DAY],1) + if year == 0 and month == 0 and day == 0: + self.sortval = 0 + else: + self.sortval = Date._calendar_convert[calendar](year,month,day) + if text: + self.text = text + + def calc_sort_value(self): + year = max(self.dateval[Date._POS_YR],1) + month = max(self.dateval[Date._POS_MON],1) + day = max(self.dateval[Date._POS_DAY],1) + if year == 0 and month == 0 and day == 0: + self.sortval = 0 + else: + self.sortval = Date._calendar_convert[self.calendar](year,month,day) + + def convert_calendar(self,calendar): + """ + Converts the date from the current calendar to the specified + calendar. + """ + if calendar == self.calendar: + return + (y,m,d) = Date._calendar_change[calendar](self.sortval) + if self.is_compound(): + ry = max(self.dateval[Date._POS_RYR],1) + rm = max(self.dateval[Date._POS_RMON],1) + rd = max(self.dateval[_POS_RDAY],1) + sdn = Date._calendar_convert[self.calendar](ry,rm,rd) + (ny,nm,nd) = Date._calendar_change[calendar](sdn) + self.dateval = (d,m,y,self.dateval[Date._POS_SL], + nd,nm,ny,self.dateval[Date._POS_RSL]) + else: + self.dateval = (d,m,y,self.dateval[Date._POS_SL]) + self.calendar = calendar + + def set_as_text(self,text): + """ + Sets the day to a text string, and assigns the sort value + to zero. + """ + self.modifier = Date.MOD_TEXTONLY + self.text = text + self.sortval = 0 + + def set_text_value(self,text): + """ + Sets the text string to a given text. + """ + self.text = text + + def is_empty(self): + """ + Returns True if the date contains no information (empty text). + """ + return (self.modifier == Date.MOD_TEXTONLY and not self.text) or \ + (self.get_start_date()==Date.EMPTY + and self.get_stop_date()==Date.EMPTY) + + def is_compound(self): + """ + Returns True if the date is a date range or a date span. + """ + return self.modifier == Date.MOD_RANGE \ + or self.modifier == Date.MOD_SPAN + + def is_regular(self): + """ + Returns True if the date is a regular date. + + The regular date is a single exact date, i.e. not text-only, not + a range or a span, not estimated/calculated, not about/before/after + date, and having year, month, and day all non-zero. + """ + return self.modifier == Date.MOD_NONE \ + and self.quality == Date.QUAL_NONE \ + and self.get_year_valid() and self.get_month_valid() \ + and self.get_day_valid() diff --git a/gramps2/src/RelLib/_DateBase.py b/gramps2/src/RelLib/_DateBase.py index 556b8bfd9..bf21810d0 100644 --- a/gramps2/src/RelLib/_DateBase.py +++ b/gramps2/src/RelLib/_DateBase.py @@ -1,7 +1,7 @@ # # Gramps - a GTK+/GNOME based genealogy program # -# Copyright (C) 2000-2005 Donald N. Allingham +# Copyright (C) 2000-2006 Donald N. Allingham # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -29,7 +29,7 @@ DateBase class for GRAMPS # GRAMPS modules # #------------------------------------------------------------------------- -import Date +from _Date import Date #------------------------------------------------------------------------- # @@ -49,10 +49,23 @@ class DateBase: @type source: DateBase """ if source: - self.date = Date.Date(source.date) + self.date = Date(source.date) else: self.date = None + def serialize(self): + if self.date == None: + date = None + else: + date = self.date.serialize() + return date + + def unserialize(self,data): + if data == None: + self.date = None + else: + self.date = Date().unserialize(data) + # def set_date(self, date) : # """ # Sets the date of the DateBase instance. @@ -103,7 +116,7 @@ class DateBase: @rtype: L{Date} """ if not self.date: - self.date = Date.Date() + self.date = Date() return self.date def set_date_object(self,date): diff --git a/gramps2/src/RelLib/_Event.py b/gramps2/src/RelLib/_Event.py index 57819eb10..8a1aa4a6e 100644 --- a/gramps2/src/RelLib/_Event.py +++ b/gramps2/src/RelLib/_Event.py @@ -1,7 +1,7 @@ # # Gramps - a GTK+/GNOME based genealogy program # -# Copyright (C) 2000-2005 Donald N. Allingham +# Copyright (C) 2000-2006 Donald N. Allingham # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -142,9 +142,11 @@ class Event(PrimaryObject,SourceNote,MediaBase,DateBase,PlaceBase): be considered persistent. @rtype: tuple """ - return (self.handle, self.gramps_id, self.type, self.date, + return (self.handle, self.gramps_id, self.type, + DateBase.serialize(self), self.description, self.place, self.cause, - self.source_list, self.note, self.media_list, + SourceNote.serialize(self), + MediaBase.serialize(self), self.change, self.marker, self.private) def unserialize(self,data): @@ -156,9 +158,13 @@ class Event(PrimaryObject,SourceNote,MediaBase,DateBase,PlaceBase): Person object @type data: tuple """ - (self.handle, self.gramps_id, self.type, self.date, - self.description, self.place, self.cause, self.source_list, self.note, - self.media_list, self.change, self.marker, self.private) = data + (self.handle, self.gramps_id, self.type, date, + self.description, self.place, self.cause, sn, + media_list, self.change, self.marker, self.private) = data + + DateBase.unserialize(self,date) + MediaBase.unserialize(self,media_list) + SourceNote.unserialize(self,sn) def _has_handle_reference(self,classname,handle): if classname == 'Place': diff --git a/gramps2/src/RelLib/_EventRef.py b/gramps2/src/RelLib/_EventRef.py index 9f1786ff6..8447adf7c 100644 --- a/gramps2/src/RelLib/_EventRef.py +++ b/gramps2/src/RelLib/_EventRef.py @@ -1,7 +1,7 @@ # # Gramps - a GTK+/GNOME based genealogy program # -# Copyright (C) 2000-2005 Donald N. Allingham +# Copyright (C) 2000-2006 Donald N. Allingham # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -77,6 +77,14 @@ class EventRef(BaseObject,PrivacyBase,NoteBase): self.ref = None self.role = (EventRef.CUSTOM,"") + def serialize(self): + return (self.private,NoteBase.serialize(self),self.ref,self.role) + + def unserialize(self,data): + (self.private,nb,self.ref,self.role) = data + NoteBase.unserialize(self,nb) + return self + def get_text_data_list(self): """ Returns the list of all textual attributes of the object. diff --git a/gramps2/src/RelLib/_Family.py b/gramps2/src/RelLib/_Family.py index 5c4d67c7f..6fba6bccd 100644 --- a/gramps2/src/RelLib/_Family.py +++ b/gramps2/src/RelLib/_Family.py @@ -1,7 +1,7 @@ # # Gramps - a GTK+/GNOME based genealogy program # -# Copyright (C) 2000-2005 Donald N. Allingham +# Copyright (C) 2000-2006 Donald N. Allingham # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -109,10 +109,16 @@ class Family(PrimaryObject,SourceNote,MediaBase,AttributeBase): be considered persistent. @rtype: tuple """ - return (self.handle, self.gramps_id, self.father_handle, self.mother_handle, - self.child_list, self.type, self.event_ref_list, - self.media_list, self.attribute_list, self.lds_seal, - self.complete, self.source_list, self.note, + if self.lds_seal == None: + lds_seal = None + else: + lds_seal = self.lds_seal.serialize() + return (self.handle, self.gramps_id, self.father_handle, + self.mother_handle,self.child_list, self.type, + [er.serialize() for er in self.event_ref_list], + MediaBase.serialize(self), + AttributeBase.serialize(self), + lds_seal,SourceNote.serialize(self), self.change, self.marker, self.private) def unserialize(self, data): @@ -121,10 +127,15 @@ class Family(PrimaryObject,SourceNote,MediaBase,AttributeBase): back into the data in a Family structure. """ (self.handle, self.gramps_id, self.father_handle, self.mother_handle, - self.child_list, self.type, self.event_ref_list, - self.media_list, self.attribute_list, self.lds_seal, - self.complete, self.source_list, self.note, self.change, - self.marker, self.private) = data + self.child_list, self.type, + event_ref_list, media_list, attribute_list, lds_seal, sn, + self.change,self.marker, self.private) = data + + self.event_ref_list = [EventRef().unserialize(er) + for er in event_ref_list] + MediaBase.unserialize(self,media_list) + AttributeBase.unserialize(self,attribute_list) + SourceNote.unserialize(self,sn) def _has_handle_reference(self,classname,handle): if classname == 'Event': diff --git a/gramps2/src/RelLib/_LdsOrd.py b/gramps2/src/RelLib/_LdsOrd.py index 8a5d549ac..d979ebf9f 100644 --- a/gramps2/src/RelLib/_LdsOrd.py +++ b/gramps2/src/RelLib/_LdsOrd.py @@ -1,7 +1,7 @@ # # Gramps - a GTK+/GNOME based genealogy program # -# Copyright (C) 2000-2005 Donald N. Allingham +# Copyright (C) 2000-2006 Donald N. Allingham # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -61,6 +61,17 @@ class LdsOrd(SourceNote,DateBase,PlaceBase): self.temple = "" self.status = 0 + def serialize(self): + return (SourceNote.serialize(self), + DateBase.serialize(self),self.place, + self.famc,self.temple,self.status) + + def unserialize(self,data): + (sn,date,self.place, + self.famc,self.temple,self.status) = data + SourceNote.unserialize(self,sn) + DateBase.unserialize(self,date) + def get_text_data_list(self): """ Returns the list of all textual attributes of the object. diff --git a/gramps2/src/RelLib/_Location.py b/gramps2/src/RelLib/_Location.py index 48d31dbbb..48b49e9ea 100644 --- a/gramps2/src/RelLib/_Location.py +++ b/gramps2/src/RelLib/_Location.py @@ -1,7 +1,7 @@ # # Gramps - a GTK+/GNOME based genealogy program # -# Copyright (C) 2000-2005 Donald N. Allingham +# Copyright (C) 2000-2006 Donald N. Allingham # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -60,6 +60,14 @@ class Location(BaseObject,LocationBase): self.parish = "" self.county = "" + def serialize(self): + return (LocationBase.serialize(self),self.parish,self.county) + + def unserialize(self,data): + (lb,self.parish,self.county) = data + LocationBase.unserialize(self,lb) + return self + def get_text_data_list(self): """ Returns the list of all textual attributes of the object. diff --git a/gramps2/src/RelLib/_LocationBase.py b/gramps2/src/RelLib/_LocationBase.py index 73400fe1b..7670734cb 100644 --- a/gramps2/src/RelLib/_LocationBase.py +++ b/gramps2/src/RelLib/_LocationBase.py @@ -1,7 +1,7 @@ # # Gramps - a GTK+/GNOME based genealogy program # -# Copyright (C) 2000-2005 Donald N. Allingham +# Copyright (C) 2000-2006 Donald N. Allingham # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -52,6 +52,13 @@ class LocationBase: self.postal = "" self.phone = "" + def serialize(self): + return (self.city,self.state,self.country,self.postal,self.phone) + + def unserialize(self,data): + (self.city,self.state,self.country,self.postal,self.phone) = data + return self + def get_text_data_list(self): """ Returns the list of all textual attributes of the object. diff --git a/gramps2/src/RelLib/_MediaBase.py b/gramps2/src/RelLib/_MediaBase.py index 08732074f..bb0c67dac 100644 --- a/gramps2/src/RelLib/_MediaBase.py +++ b/gramps2/src/RelLib/_MediaBase.py @@ -1,7 +1,7 @@ # # Gramps - a GTK+/GNOME based genealogy program # -# Copyright (C) 2000-2005 Donald N. Allingham +# Copyright (C) 2000-2006 Donald N. Allingham # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -54,6 +54,12 @@ class MediaBase: else: self.media_list = [] + def serialize(self): + return [mref.serialize() for mref in self.media_list] + + def unserialize(self,data): + self.media_list = [MediaRef().unserialize(item) for item in data] + def add_media_reference(self,media_ref): """ Adds a L{MediaRef} instance to the object's media list. diff --git a/gramps2/src/RelLib/_MediaObject.py b/gramps2/src/RelLib/_MediaObject.py index a3092fdce..3a649250b 100644 --- a/gramps2/src/RelLib/_MediaObject.py +++ b/gramps2/src/RelLib/_MediaObject.py @@ -1,7 +1,7 @@ # # Gramps - a GTK+/GNOME based genealogy program # -# Copyright (C) 2000-2005 Donald N. Allingham +# Copyright (C) 2000-2006 Donald N. Allingham # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -69,11 +69,13 @@ class MediaObject(PrimaryObject,SourceNote,DateBase,AttributeBase): self.path = source.path self.mime = source.mime self.desc = source.desc + # FIXME: thumb is not currently being serialized! self.thumb = source.thumb else: self.path = "" self.mime = "" self.desc = "" + # FIXME: thumb is not currently being serialized! self.thumb = None def serialize(self): @@ -92,9 +94,11 @@ class MediaObject(PrimaryObject,SourceNote,DateBase,AttributeBase): be considered persistent. @rtype: tuple """ - return (self.handle, self.gramps_id, self.path, self.mime, - self.desc, self.attribute_list, self.source_list, self.note, - self.change, self.date, self.marker, self.private) + return (self.handle, self.gramps_id, self.path, self.mime, self.desc, + AttributeBase.serialize(self), + SourceNote.serialize(self), + self.change, + DateBase.serialize(self), self.marker, self.private) def unserialize(self,data): """ @@ -105,8 +109,12 @@ class MediaObject(PrimaryObject,SourceNote,DateBase,AttributeBase): @type data: tuple """ (self.handle, self.gramps_id, self.path, self.mime, self.desc, - self.attribute_list, self.source_list, self.note, self.change, - self.date, self.marker, self.private) = data + attribute_list, sn, self.change, + date, self.marker, self.private) = data + + AttributeBase.unserialize(self,attribute_list) + SourceNote.unserialize(self,sn) + DateBase.unserialize(self,date) def get_text_data_list(self): """ diff --git a/gramps2/src/RelLib/_MediaRef.py b/gramps2/src/RelLib/_MediaRef.py index 5c12fb105..3729bf0e4 100644 --- a/gramps2/src/RelLib/_MediaRef.py +++ b/gramps2/src/RelLib/_MediaRef.py @@ -1,7 +1,7 @@ # # Gramps - a GTK+/GNOME based genealogy program # -# Copyright (C) 2000-2005 Donald N. Allingham +# Copyright (C) 2000-2006 Donald N. Allingham # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -51,6 +51,17 @@ class MediaRef(PrivateSourceNote,AttributeBase): self.ref = None self.rect = None + def serialize(self): + return (PrivateSourceNote.serialize(self), + AttributeBase.serialize(self), + self.ref,self.rect) + + def unserialize(self,data): + (psn,attribute_list,self.ref,self.rect) = data + PrivateSourceNote.unserialize(self,psn) + AttributeBase.unserialize(self,attribute_list) + return self + def get_text_data_child_list(self): """ Returns the list of child objects that may carry textual data. diff --git a/gramps2/src/RelLib/_Name.py b/gramps2/src/RelLib/_Name.py index 08a8dff74..f73b3b48f 100644 --- a/gramps2/src/RelLib/_Name.py +++ b/gramps2/src/RelLib/_Name.py @@ -1,7 +1,7 @@ # # Gramps - a GTK+/GNOME based genealogy program # -# Copyright (C) 2000-2005 Donald N. Allingham +# Copyright (C) 2000-2006 Donald N. Allingham # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -93,6 +93,22 @@ class Name(PrivateSourceNote,DateBase): self.sort_as = self.DEF self.display_as = self.DEF + def serialize(self): + return (PrivateSourceNote.serialize(self), + DateBase.serialize(self), + self.first_name,self.surname,self.suffix,self.title, + self.type,self.prefix,self.patronymic,self.sname, + self.group_as,self.sort_as,self.display_as) + + def unserialize(self,data): + (psn,date, + self.first_name,self.surname,self.suffix,self.title, + self.type,self.prefix,self.patronymic,self.sname, + self.group_as,self.sort_as,self.display_as) = data + PrivateSourceNote.unserialize(self,psn) + DateBase.unserialize(self,date) + return self + def get_text_data_list(self): """ Returns the list of all textual attributes of the object. diff --git a/gramps2/src/RelLib/_Note.py b/gramps2/src/RelLib/_Note.py index f08b9a629..ce4610b95 100644 --- a/gramps2/src/RelLib/_Note.py +++ b/gramps2/src/RelLib/_Note.py @@ -1,7 +1,7 @@ # # Gramps - a GTK+/GNOME based genealogy program # -# Copyright (C) 2000-2005 Donald N. Allingham +# Copyright (C) 2000-2006 Donald N. Allingham # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -53,6 +53,13 @@ class Note(BaseObject): self.text = text self.format = 0 + def serialize(self): + return (self.text,self.format) + + def unserialize(self,data): + (self.text,self.format) = data + return self + def get_text_data_list(self): """ Returns the list of all textual attributes of the object. diff --git a/gramps2/src/RelLib/_NoteBase.py b/gramps2/src/RelLib/_NoteBase.py index 2b11794d1..6084701d4 100644 --- a/gramps2/src/RelLib/_NoteBase.py +++ b/gramps2/src/RelLib/_NoteBase.py @@ -1,7 +1,7 @@ # # Gramps - a GTK+/GNOME based genealogy program # -# Copyright (C) 2000-2005 Donald N. Allingham +# Copyright (C) 2000-2006 Donald N. Allingham # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -53,6 +53,19 @@ class NoteBase: else: self.note = None + def serialize(self): + if self.note == None: + note = None + else: + note = self.note.serialize() + return note + + def unserialize(self,data): + if data == None: + self.note = None + else: + self.note = Note().unserialize(data) + def set_note(self,text): """ Assigns the specified text to the associated note. diff --git a/gramps2/src/RelLib/_Person.py b/gramps2/src/RelLib/_Person.py index 876571e82..e3050a22d 100644 --- a/gramps2/src/RelLib/_Person.py +++ b/gramps2/src/RelLib/_Person.py @@ -1,7 +1,7 @@ # # Gramps - a GTK+/GNOME based genealogy program # -# Copyright (C) 2000-2005 Donald N. Allingham +# Copyright (C) 2000-2006 Donald N. Allingham # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -44,6 +44,7 @@ from _AddressBase import AddressBase from _UrlBase import UrlBase from _Name import Name from _EventRef import EventRef +from _LdsOrd import LdsOrd #------------------------------------------------------------------------- # @@ -94,27 +95,27 @@ class Person(PrimaryObject,SourceNote, data items have empty or null values, including the database handle. """ + PrimaryObject.__init__(self) + SourceNote.__init__(self) + MediaBase.__init__(self) + AttributeBase.__init__(self) + AddressBase.__init__(self) + UrlBase.__init__(self) + self.primary_name = Name() + self.event_ref_list = [] + self.family_list = [] + self.parent_family_list = [] + self.nickname = "" + self.alternate_names = [] + self.gender = Person.UNKNOWN + self.death_ref = None + self.birth_ref = None + self.lds_bapt = None + self.lds_endow = None + self.lds_seal = None + if data: self.unserialize(data) - else: - PrimaryObject.__init__(self) - SourceNote.__init__(self) - MediaBase.__init__(self) - AttributeBase.__init__(self) - AddressBase.__init__(self) - UrlBase.__init__(self) - self.primary_name = Name() - self.event_ref_list = [] - self.family_list = [] - self.parent_family_list = [] - self.nickname = "" - self.alternate_names = [] - self.gender = Person.UNKNOWN - self.death_ref = None - self.birth_ref = None - self.lds_bapt = None - self.lds_endow = None - self.lds_seal = None # We hold a reference to the GrampsDB so that we can maintain # its genderStats. It doesn't get set here, but from @@ -136,13 +137,40 @@ class Person(PrimaryObject,SourceNote, be considered persistent. @rtype: tuple """ + if self.birth_ref == None: + birth_ref = None + else: + birth_ref = self.birth_ref.serialize() + if self.death_ref == None: + death_ref = None + else: + death_ref = self.death_ref.serialize() + if self.lds_bapt == None: + lds_bapt = None + else: + lds_bapt = self.lds_bapt.serialize() + if self.lds_endow == None: + lds_endow = None + else: + lds_endow = self.lds_endow.serialize() + if self.lds_seal == None: + lds_seal = None + else: + lds_seal = self.lds_seal.serialize() + return (self.handle, self.gramps_id, self.gender, - self.primary_name, self.alternate_names, - unicode(self.nickname), self.death_ref, self.birth_ref, - self.event_ref_list, self.family_list, self.parent_family_list, - self.media_list, self.address_list, self.attribute_list, - self.urls, self.lds_bapt, self.lds_endow, self.lds_seal, - self.source_list, self.note, self.change, self.marker, + self.primary_name.serialize(), + [name.serialize() for name in self.alternate_names], + unicode(self.nickname), death_ref, birth_ref, + [er.serialize() for er in self.event_ref_list], + self.family_list,self.parent_family_list, + MediaBase.serialize(self), + AddressBase.serialize(self), + AttributeBase.serialize(self), + UrlBase.serialize(self), + lds_bapt, lds_endow, lds_seal, + SourceNote.serialize(self), + self.change, self.marker, self.private) def unserialize(self,data): @@ -154,13 +182,34 @@ class Person(PrimaryObject,SourceNote, Person object @type data: tuple """ - (self.handle, self.gramps_id, self.gender, self.primary_name, - self.alternate_names, self.nickname, self.death_ref, - self.birth_ref, self.event_ref_list, self.family_list, - self.parent_family_list, self.media_list, self.address_list, - self.attribute_list, self.urls, self.lds_bapt, self.lds_endow, - self.lds_seal, self.source_list, self.note, self.change, - self.marker, self.private) = (data + (False,))[0:23] + (self.handle, self.gramps_id, self.gender, primary_name, + alternate_names, self.nickname, death_ref, + birth_ref, event_ref_list, self.family_list, + self.parent_family_list, media_list, address_list, + attribute_list, urls, lds_bapt, lds_endow, + lds_seal, sn, self.change, + self.marker, self.private) = (data + (False,))[0:22] + + self.primary_name.unserialize(primary_name) + if death_ref: + self.death_ref = EventRef().unserialize(death_ref) + if birth_ref: + self.birth_ref = EventRef().unserialize(birth_ref) + if lds_bapt: + self.lds_bapt = LdsOrd().unserialize(lds_bapt) + if lds_endow: + self.lds_endow = LdsOrd().unserialize(lds_endow) + if lds_seal: + self.lds_seal = LdsOrd().unserialize(lds_seal) + self.alternate_names = [Name().unserialize(name) + for name in alternate_names] + self.event_ref_list = [EventRef().unserialize(er) + for er in event_ref_list] + MediaBase.unserialize(self,media_list) + AddressBase.unserialize(self,address_list) + AttributeBase.unserialize(self,attribute_list) + UrlBase.unserialize(self,urls) + SourceNote.unserialize(self,sn) def _has_handle_reference(self,classname,handle): if classname == 'Event': diff --git a/gramps2/src/RelLib/_Place.py b/gramps2/src/RelLib/_Place.py index 1a928162b..b920afb07 100644 --- a/gramps2/src/RelLib/_Place.py +++ b/gramps2/src/RelLib/_Place.py @@ -1,7 +1,7 @@ # # Gramps - a GTK+/GNOME based genealogy program # -# Copyright (C) 2000-2005 Donald N. Allingham +# Copyright (C) 2000-2006 Donald N. Allingham # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -63,9 +63,7 @@ class Place(PrimaryObject,SourceNote,MediaBase,UrlBase): self.lat = source.lat self.title = source.title self.main_loc = Location(source.main_loc) - self.alt_loc = [] - for loc in source.alt_loc: - self.alt_loc = Location(loc) + self.alt_loc = [Location(loc) for loc in source.alt_loc] else: self.long = "" self.lat = "" @@ -89,10 +87,17 @@ class Place(PrimaryObject,SourceNote,MediaBase,UrlBase): be considered persistent. @rtype: tuple """ + if self.main_loc == None: + main_loc = None + else: + main_loc = self.main_loc.serialize() + return (self.handle, self.gramps_id, self.title, self.long, self.lat, - self.main_loc, self.alt_loc, self.urls, self.media_list, - self.source_list, self.note, self.change, self.marker, - self.private) + main_loc, [al.serialize() for al in self.alt_loc], + UrlBase.serialize(self), + MediaBase.serialize(self), + SourceNote.serialize(self), + self.change, self.marker,self.private) def unserialize(self,data): """ @@ -104,10 +109,18 @@ class Place(PrimaryObject,SourceNote,MediaBase,UrlBase): @type data: tuple """ (self.handle, self.gramps_id, self.title, self.long, self.lat, - self.main_loc, self.alt_loc, self.urls, self.media_list, - self.source_list, self.note, self.change, self.marker, - self.private) = data - + main_loc, alt_loc, urls, media_list, sn, + self.change, self.marker, self.private) = data + + if main_loc == None: + self.main_loc = None + else: + self.main.loc = Location().unserialize(main_loc) + self.alt_loc = [Location().unserialize(al) for al in alt_loc] + UrlBase.unserialize(self,urls) + MediaBase.unserialize(self,media_list) + SourceNote.unserialize(self,sn) + def get_text_data_list(self): """ Returns the list of all textual attributes of the object. diff --git a/gramps2/src/RelLib/_PrivateSourceNote.py b/gramps2/src/RelLib/_PrivateSourceNote.py index 921760224..eb3f1ac70 100644 --- a/gramps2/src/RelLib/_PrivateSourceNote.py +++ b/gramps2/src/RelLib/_PrivateSourceNote.py @@ -1,7 +1,7 @@ # # Gramps - a GTK+/GNOME based genealogy program # -# Copyright (C) 2000-2005 Donald N. Allingham +# Copyright (C) 2000-2006 Donald N. Allingham # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -51,3 +51,10 @@ class PrivateSourceNote(SourceNote,PrivacyBase): """ SourceNote.__init__(self,source) PrivacyBase.__init__(self,source) + + def serialize(self): + return (self.private,SourceNote.serialize(self)) + + def unserialize(self,data): + (self.private,sn) = data + SourceNote.unserialize(self,sn) diff --git a/gramps2/src/RelLib/_RepoRef.py b/gramps2/src/RelLib/_RepoRef.py index 8af894136..fcafd64fb 100644 --- a/gramps2/src/RelLib/_RepoRef.py +++ b/gramps2/src/RelLib/_RepoRef.py @@ -1,7 +1,7 @@ # # Gramps - a GTK+/GNOME based genealogy program # -# Copyright (C) 2000-2005 Donald N. Allingham +# Copyright (C) 2000-2006 Donald N. Allingham # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -69,6 +69,14 @@ class RepoRef(BaseObject,NoteBase): self.call_number = "" self.media_type = (RepoRef.CUSTOM,"") + def serialize(self): + return (NoteBase.serialize(self), + self.ref,self.call_number,self.media_type) + + def unserialize(self,data): + (note,self.ref,self.call_number,self.media_type) = data + NoteBase.unserialize(self,note) + def get_text_data_list(self): """ Returns the list of all textual attributes of the object. diff --git a/gramps2/src/RelLib/_Repository.py b/gramps2/src/RelLib/_Repository.py index 9bd09bbf5..665ae44a1 100644 --- a/gramps2/src/RelLib/_Repository.py +++ b/gramps2/src/RelLib/_Repository.py @@ -1,7 +1,7 @@ # # Gramps - a GTK+/GNOME based genealogy program # -# Copyright (C) 2000-2005 Donald N. Allingham +# Copyright (C) 2000-2006 Donald N. Allingham # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -72,16 +72,22 @@ class Repository(PrimaryObject,NoteBase,AddressBase,UrlBase): def serialize(self): return (self.handle, self.gramps_id, self.type, unicode(self.name), - self.note, self.address_list, self.urls,self.marker, - self.private) + NoteBase.serialize(self), + AddressBase.serialize(self), + UrlBase.serialize(self), + self.marker, self.private) def unserialize(self,data): """ Converts the data held in a tuple created by the serialize method back into the data in an Repository structure. """ - (self.handle, self.gramps_id, self.type, self.name, self.note, - self.address_list, self.urls ,self.marker, self.private) = data + (self.handle, self.gramps_id, self.type, self.name, note, + address_list, urls ,self.marker, self.private) = data + + NoteBase.unserialize(self,note) + AddressBase.unserialize(self,address_list) + UrlBase.unserialize(self,urls) def get_text_data_list(self): """ diff --git a/gramps2/src/RelLib/_Source.py b/gramps2/src/RelLib/_Source.py index c817dbaae..146ac2bc1 100644 --- a/gramps2/src/RelLib/_Source.py +++ b/gramps2/src/RelLib/_Source.py @@ -1,7 +1,7 @@ # # Gramps - a GTK+/GNOME based genealogy program # -# Copyright (C) 2000-2005 Donald N. Allingham +# Copyright (C) 2000-2006 Donald N. Allingham # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -33,6 +33,7 @@ from _PrimaryObject import PrimaryObject from _MediaBase import MediaBase from _NoteBase import NoteBase from _Note import Note +from _RepoRef import RepoRef #------------------------------------------------------------------------- # @@ -58,9 +59,11 @@ class Source(PrimaryObject,MediaBase,NoteBase): def serialize(self): return (self.handle, self.gramps_id, unicode(self.title), unicode(self.author), unicode(self.pubinfo), - self.note, self.media_list, unicode(self.abbrev), - self.change,self.datamap,self.reporef_list, self.marker, - self.private) + NoteBase.serialize(self), + MediaBase.serialize(self), unicode(self.abbrev), + self.change,self.datamap, + [rr.serialize() for rr in self.reporef_list], + self.marker,self.private) def unserialize(self,data): """ @@ -68,9 +71,13 @@ class Source(PrimaryObject,MediaBase,NoteBase): back into the data in an Event structure. """ (self.handle, self.gramps_id, self.title, self.author, - self.pubinfo, self.note, self.media_list, - self.abbrev, self.change, self.datamap, self.reporef_list, + self.pubinfo, note, media_list, + self.abbrev, self.change, self.datamap, reporef_list, self.marker, self.private) = data + + NoteBase.unserialize(self,note) + MediaBase.unserialize(self,media_list) + self.reporef_list = [RepoRef().unserialize(rr) for rr in reporef_list] def get_text_data_list(self): """ @@ -79,10 +86,9 @@ class Source(PrimaryObject,MediaBase,NoteBase): @return: Returns the list of all textual attributes of the object. @rtype: list """ - return [self.title,self.author,self.pubinfo,self.abbrev,self.gramps_id]\ - + self.datamap.keys() + self.datamap.values() - - + return [self.title,self.author,self.pubinfo,self.abbrev, + self.gramps_id] + self.datamap.keys() + self.datamap.values() + def get_text_data_child_list(self): """ Returns the list of child objects that may carry textual data. diff --git a/gramps2/src/RelLib/_SourceNote.py b/gramps2/src/RelLib/_SourceNote.py index f61a3752b..4970ed5a8 100644 --- a/gramps2/src/RelLib/_SourceNote.py +++ b/gramps2/src/RelLib/_SourceNote.py @@ -1,7 +1,7 @@ # # Gramps - a GTK+/GNOME based genealogy program # -# Copyright (C) 2000-2005 Donald N. Allingham +# Copyright (C) 2000-2006 Donald N. Allingham # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -57,6 +57,16 @@ class SourceNote(BaseObject,NoteBase): else: self.source_list = [] + def serialize(self): + return (NoteBase.serialize(self), + [sref.serialize() for sref in self.source_list]) + + def unserialize(self,data): + (note,source_list) = data + NoteBase.unserialize(self,note) + self.source_list = [SourceRef().unserialize(item) + for item in source_list] + def add_source_reference(self,src_ref) : """ Adds a source reference to this object. diff --git a/gramps2/src/RelLib/_SourceRef.py b/gramps2/src/RelLib/_SourceRef.py index cf903fc13..aa8b2bbd5 100644 --- a/gramps2/src/RelLib/_SourceRef.py +++ b/gramps2/src/RelLib/_SourceRef.py @@ -1,7 +1,7 @@ # # Gramps - a GTK+/GNOME based genealogy program # -# Copyright (C) 2000-2005 Donald N. Allingham +# Copyright (C) 2000-2006 Donald N. Allingham # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -68,6 +68,18 @@ class SourceRef(BaseObject,DateBase,PrivacyBase,NoteBase): self.note = Note() self.text = "" + def serialize(self): + return (DateBase.serialize(self),self.private, + NoteBase.serialize(self), + self.confidence,self.ref,self.page,self.text) + + def unserialize(self,data): + (date,self.private,nb, + self.confidence,self.ref,self.page,self.text) = data + DateBase.unserialize(self,date) + NoteBase.unserialize(self,nb) + return self + def get_text_data_list(self): """ Returns the list of all textual attributes of the object. diff --git a/gramps2/src/RelLib/_Url.py b/gramps2/src/RelLib/_Url.py index 6b590e1a7..6db67db75 100644 --- a/gramps2/src/RelLib/_Url.py +++ b/gramps2/src/RelLib/_Url.py @@ -1,7 +1,7 @@ # # Gramps - a GTK+/GNOME based genealogy program # -# Copyright (C) 2000-2005 Donald N. Allingham +# Copyright (C) 2000-2006 Donald N. Allingham # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -68,6 +68,13 @@ class Url(BaseObject,PrivacyBase): self.desc = "" self.type = (Url.CUSTOM,"") + def serialize(self): + return (self.private,self.path,self.desc,self.type) + + def unserialize(self,data): + (self.private,self.path,self.desc,self.type) = data + return self + def get_text_data_list(self): """ Returns the list of all textual attributes of the object. diff --git a/gramps2/src/RelLib/_UrlBase.py b/gramps2/src/RelLib/_UrlBase.py index a74afe630..feefe30df 100644 --- a/gramps2/src/RelLib/_UrlBase.py +++ b/gramps2/src/RelLib/_UrlBase.py @@ -1,7 +1,7 @@ # # Gramps - a GTK+/GNOME based genealogy program # -# Copyright (C) 2000-2005 Donald N. Allingham +# Copyright (C) 2000-2006 Donald N. Allingham # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -55,6 +55,12 @@ class UrlBase: else: self.urls = [] + def serialize(self): + return [url.serialize() for url in self.urls] + + def unserialize(self,data): + self.urls = [Url().unserialize(item) for item in data] + def get_url_list(self): """ Returns the list of L{Url} instances associated with the object. diff --git a/gramps2/src/RelLib/__init__.py b/gramps2/src/RelLib/__init__.py index b22fb5969..2a705b33b 100644 --- a/gramps2/src/RelLib/__init__.py +++ b/gramps2/src/RelLib/__init__.py @@ -1,7 +1,7 @@ # # Gramps - a GTK+/GNOME based genealogy program # -# Copyright (C) 2000-2005 Donald N. Allingham +# Copyright (C) 2000-2006 Donald N. Allingham # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -25,6 +25,9 @@ __author__ = "Donald N. Allingham" __version__ = "$Revision$" +# Dates +from _Date import Date, DateError + # Secondary objects from _Address import Address from _Location import Location diff --git a/gramps2/src/ReportUtils.py b/gramps2/src/ReportUtils.py index 85be856fc..8c656628d 100644 --- a/gramps2/src/ReportUtils.py +++ b/gramps2/src/ReportUtils.py @@ -1,7 +1,7 @@ # # Gramps - a GTK+/GNOME based genealogy program # -# Copyright (C) 2000-2005 Donald N. Allingham +# Copyright (C) 2000-2006 Donald N. Allingham # # # This program is free software; you can redistribute it and/or modify @@ -30,7 +30,6 @@ A collection of utilities to aid in the generation of reports. # GRAMPS modules # #------------------------------------------------------------------------ -import Date import DateHandler import RelLib from NameDisplay import displayer as _nd @@ -1040,14 +1039,14 @@ def estimate_age(db, person, end_handle=None, start_handle=None): else: return high[2] - low[2] - if bstop == Date.EMPTY and dstop == Date.EMPTY: + if bstop == RelLib.Date.EMPTY and dstop == RelLib.Date.EMPTY: lower = _calc_diff(bstart,dstart) age = (lower, lower) - elif bstop == Date.EMPTY: + elif bstop == RelLib.Date.EMPTY: lower = _calc_diff(bstart,dstart) upper = _calc_diff(bstart,dstop) age = (lower,upper) - elif dstop == Date.EMPTY: + elif dstop == RelLib.Date.EMPTY: lower = _calc_diff(bstop,dstart) upper = _calc_diff(bstart,dstart) age = (lower,upper) @@ -1316,7 +1315,7 @@ def get_birth_death_strings(database,person,empty_date="",empty_place=""): bplace = database.get_place_from_handle(bplace_handle).get_title() bdate_obj = birth.get_date_object() bdate_full = bdate_obj and bdate_obj.get_day_valid() - bdate_mod = bdate_obj and bdate_obj.get_modifier() != Date.MOD_NONE + bdate_mod = bdate_obj and bdate_obj.get_modifier() != RelLib.Date.MOD_NONE death_ref = person.get_death_ref() if death_ref and death_ref.ref: @@ -1329,7 +1328,7 @@ def get_birth_death_strings(database,person,empty_date="",empty_place=""): dplace = database.get_place_from_handle(dplace_handle).get_title() ddate_obj = death.get_date_object() ddate_full = ddate_obj and ddate_obj.get_day_valid() - ddate_mod = ddate_obj and ddate_obj.get_modifier() != Date.MOD_NONE + ddate_mod = ddate_obj and ddate_obj.get_modifier() != RelLib.Date.MOD_NONE return (bdate,bplace,bdate_full,bdate_mod,ddate,dplace,ddate_full,ddate_mod) @@ -1594,7 +1593,7 @@ def married_str(database,person,spouse,event,endnotes=None, dobj = event.get_date_object() - if dobj.get_modifier() != Date.MOD_NONE: + if dobj.get_modifier() != RelLib.Date.MOD_NONE: date_full = 2 elif dobj and dobj.get_day_valid(): date_full = 1 @@ -1980,7 +1979,7 @@ def buried_str(database,person,person_name=None,empty_date="",empty_place=""): bplace = database.get_place_from_handle(bplace_handle).get_title() bdate_obj = burial.get_date_object() bdate_full = bdate_obj and bdate_obj.get_day_valid() - bdate_mod = bdate_obj and bdate_obj.get_modifier() != Date.MOD_NONE + bdate_mod = bdate_obj and bdate_obj.get_modifier() != RelLib.Date.MOD_NONE else: return text diff --git a/gramps2/src/RepositoryRefEdit.py b/gramps2/src/RepositoryRefEdit.py index fbcd645a4..c0ee763da 100644 --- a/gramps2/src/RepositoryRefEdit.py +++ b/gramps2/src/RepositoryRefEdit.py @@ -1,7 +1,7 @@ # # Gramps - a GTK+/GNOME based genealogy program # -# Copyright (C) 2000-2005 Donald N. Allingham +# Copyright (C) 2000-2006 Donald N. Allingham # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -46,7 +46,6 @@ import cPickle as pickle import const import Utils import RelLib -import Date import DateEdit import DateHandler import AutoComp diff --git a/gramps2/src/SelectChild.py b/gramps2/src/SelectChild.py index 02ee13b66..45b04e27b 100644 --- a/gramps2/src/SelectChild.py +++ b/gramps2/src/SelectChild.py @@ -2,7 +2,7 @@ # # Gramps - a GTK+/GNOME based genealogy program # -# Copyright (C) 2000-2005 Donald N. Allingham +# Copyright (C) 2000-2006 Donald N. Allingham # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -49,7 +49,6 @@ import PeopleModel import NameDisplay import AutoComp import GenericFilter -import Date import GrampsDisplay from QuestionDialog import ErrorDialog from WindowUtils import GladeIf @@ -337,7 +336,7 @@ class LikelyFilter(GenericFilter.Rule): person = db.get_person_from_handle(self.list[0]) if person.birth_handle: birth = db.get_event_from_handle(person.birth_handle) - dateobj = Date.Date(birth.date) + dateobj = RelLib.Date(birth.date) year = dateobj.get_year() dateobj.set_year(year+10) self.lower = dateobj.sortval diff --git a/gramps2/src/Sort.py b/gramps2/src/Sort.py index 8f828534e..7fd7066ab 100644 --- a/gramps2/src/Sort.py +++ b/gramps2/src/Sort.py @@ -1,7 +1,7 @@ # # Gramps - a GTK+/GNOME based genealogy program # -# Copyright (C) 2000-2005 Donald N. Allingham +# Copyright (C) 2000-2006 Donald N. Allingham # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -39,7 +39,7 @@ import locale # GRAMPS Modules # #------------------------------------------------------------------------- -import Date +from RelLib import Date from NameDisplay import displayer as _nd #------------------------------------------------------------------------- @@ -103,13 +103,13 @@ class Sort: if birth_handle1: date1 = self.database.get_event_from_handle(birth_handle1).get_date_object() else: - date1 = Date.Date() + date1 = Date() birth_handle2 = second.get_birth_handle() if birth_handle2: date2 = self.database.get_event_from_handle(birth_handle2).get_date_object() else: - date2 = Date.Date() + date2 = Date() dsv1 = date1.get_sort_value() dsv2 = date2.get_sort_value() diff --git a/gramps2/src/Sources.py b/gramps2/src/Sources.py index cdf9a6e74..1ed01ba77 100644 --- a/gramps2/src/Sources.py +++ b/gramps2/src/Sources.py @@ -1,7 +1,7 @@ # # Gramps - a GTK+/GNOME based genealogy program # -# Copyright (C) 2000-2005 Donald N. Allingham +# Copyright (C) 2000-2006 Donald N. Allingham # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -47,7 +47,6 @@ import cPickle as pickle import const import Utils import RelLib -import Date import DateEdit import DateHandler import GrampsDisplay @@ -402,7 +401,7 @@ class SourceEditor(DisplayState.ManagedWindow): self.date_entry_field.set_text(date_str) self.private.set_active(self.source_ref.get_privacy()) else: - self.date_obj = Date.Date() + self.date_obj = RelLib.Date() self.active_source = None date_stat = self.get_widget("date_stat") diff --git a/gramps2/src/Utils.py b/gramps2/src/Utils.py index 6bc3fe075..dc01a9045 100644 --- a/gramps2/src/Utils.py +++ b/gramps2/src/Utils.py @@ -1,7 +1,7 @@ # # Gramps - a GTK+/GNOME based genealogy program # -# Copyright (C) 2000-2005 Donald N. Allingham +# Copyright (C) 2000-2006 Donald N. Allingham # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -47,7 +47,6 @@ import gtk.gdk import const import GrampsMime import NameDisplay -import Date import RelLib import Errors @@ -791,7 +790,7 @@ def probably_alive(person,db,current_year=None,limit=0): # things are simple. if person.death_ref: death = db.get_event_from_handle(person.death_ref.ref) - if death.get_date_object().get_start_date() != Date.EMPTY: + if death.get_date_object().get_start_date() != RelLib.Date.EMPTY: death_year = death.get_date_object().get_year() if death_year - limit < current_year: return False @@ -804,7 +803,7 @@ def probably_alive(person,db,current_year=None,limit=0): RelLib.Event.CREMATION]: if not death_year: death_year = ev.get_date_object().get_year() - if ev.get_date_object().get_start_date() != Date.EMPTY: + if ev.get_date_object().get_start_date() != RelLib.Date.EMPTY: if ev.get_date_object().get_year() - limit < current_year: return False # For any other event of this person, check whether it happened @@ -817,7 +816,7 @@ def probably_alive(person,db,current_year=None,limit=0): # assume they are alive (we already know they are not dead). if person.birth_ref: birth = db.get_event_from_handle(person.birth_ref.ref) - if birth.get_date_object().get_start_date() != Date.EMPTY: + if birth.get_date_object().get_start_date() != RelLib.Date.EMPTY: if not birth_year: birth_year = birth.get_date_object().get_year() # Check whether the birth event is too old because the @@ -846,8 +845,8 @@ def probably_alive(person,db,current_year=None,limit=0): if child.birth_ref: child_birth = db.get_event_from_handle(child.birth_ref.ref) dobj = child_birth.get_date_object() - if dobj.get_start_date() != Date.EMPTY: - d = Date.Date(dobj) + if dobj.get_start_date() != RelLib.Date.EMPTY: + d = RelLib.Date(dobj) val = d.get_start_date() val = d.get_year() - years d.set_year(val) @@ -857,7 +856,7 @@ def probably_alive(person,db,current_year=None,limit=0): if child.death_ref: child_death = db.get_event_from_handle(child.death_ref.ref) dobj = child_death.get_date_object() - if dobj.get_start_date() != Date.EMPTY: + if dobj.get_start_date() != RelLib.Date.EMPTY: if not not_too_old (dobj,current_year): return True @@ -890,7 +889,7 @@ def probably_alive(person,db,current_year=None,limit=0): if father.birth_ref: father_birth = db.get_event_from_handle(father.birth_ref.ref) dobj = father_birth.get_date_object() - if dobj.get_start_date() != Date.EMPTY: + if dobj.get_start_date() != RelLib.Date.EMPTY: if not not_too_old (dobj,year - average_generation_gap): #print father.get_primary_name().get_name(), " father of ", person.get_primary_name().get_name(), " is too old by birth. birth year ", dobj.get_year(), " test year ", year - average_generation_gap return True @@ -901,7 +900,7 @@ def probably_alive(person,db,current_year=None,limit=0): if father.death_ref: father_death = db.get_event_from_handle(father.death_ref.ref) dobj = father_death.get_date_object() - if dobj.get_start_date() != Date.EMPTY: + if dobj.get_start_date() != RelLib.Date.EMPTY: if dobj.get_year() < year - average_generation_gap: #print father.get_primary_name().get_name(), " father of ", person.get_primary_name().get_name(), " is too old by death." return True @@ -915,7 +914,7 @@ def probably_alive(person,db,current_year=None,limit=0): if mother.birth_ref: mother_birth = db.get_event_from_handle(mother.birth_ref.ref) dobj = mother_birth.get_date_object() - if dobj.get_start_date() != Date.EMPTY: + if dobj.get_start_date() != RelLib.Date.EMPTY: if not not_too_old (dobj,year - average_generation_gap): #print mother.get_primary_name().get_name(), " mother of ", person.get_primary_name().get_name(), " is too old by birth. birth year ", dobj.get_year(), " test year ", year - average_generation_gap return True @@ -926,7 +925,7 @@ def probably_alive(person,db,current_year=None,limit=0): if mother.death_ref: mother_death = db.get_event_from_handle(mother.death_ref.ref) dobj = mother_death.get_date_object() - if dobj.get_start_date() != Date.EMPTY: + if dobj.get_start_date() != RelLib.Date.EMPTY: if dobj.get_year() < year - average_generation_gap: #print mother.get_primary_name().get_name(), " mother of ", person.get_primary_name().get_name(), " is too old by death." return True diff --git a/gramps2/src/dates/Date_de.py b/gramps2/src/dates/Date_de.py index 2d7ded010..09143b693 100644 --- a/gramps2/src/dates/Date_de.py +++ b/gramps2/src/dates/Date_de.py @@ -2,7 +2,7 @@ # # Gramps - a GTK+/GNOME based genealogy program # -# Copyright (C) 2004-2005 Donald N. Allingham +# Copyright (C) 2004-2006 Donald N. Allingham # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -37,7 +37,7 @@ import re # GRAMPS modules # #------------------------------------------------------------------------- -import Date +from RelLib import Date from DateParser import DateParser from DateDisplay import DateDisplay diff --git a/gramps2/src/dates/Date_es.py b/gramps2/src/dates/Date_es.py index 17d6bbec8..429f1eee4 100644 --- a/gramps2/src/dates/Date_es.py +++ b/gramps2/src/dates/Date_es.py @@ -2,7 +2,7 @@ # # Gramps - a GTK+/GNOME based genealogy program # -# Copyright (C) 2004-2005 Donald N. Allingham +# Copyright (C) 2004-2006 Donald N. Allingham # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -37,7 +37,7 @@ import re # GRAMPS modules # #------------------------------------------------------------------------- -import Date +from RelLib import Date from DateParser import DateParser from DateDisplay import DateDisplay diff --git a/gramps2/src/dates/Date_fi.py b/gramps2/src/dates/Date_fi.py index 6c7e4371d..65d5141b2 100644 --- a/gramps2/src/dates/Date_fi.py +++ b/gramps2/src/dates/Date_fi.py @@ -2,7 +2,7 @@ # # Gramps - a GTK+/GNOME based genealogy program # -# Copyright (C) 2004-2005 Donald N. Allingham +# Copyright (C) 2004-2006 Donald N. Allingham # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -37,7 +37,7 @@ import re # GRAMPS modules # #------------------------------------------------------------------------- -import Date +from RelLib import Date from DateParser import DateParser from DateDisplay import DateDisplay diff --git a/gramps2/src/dates/Date_fr.py b/gramps2/src/dates/Date_fr.py index e4312db25..2d7b8141e 100644 --- a/gramps2/src/dates/Date_fr.py +++ b/gramps2/src/dates/Date_fr.py @@ -2,7 +2,7 @@ # # Gramps - a GTK+/GNOME based genealogy program # -# Copyright (C) 2004-2005 Donald N. Allingham +# Copyright (C) 2004-2006 Donald N. Allingham # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -37,7 +37,7 @@ import re # GRAMPS modules # #------------------------------------------------------------------------- -import Date +from RelLib import Date from DateParser import DateParser from DateDisplay import DateDisplay diff --git a/gramps2/src/dates/Date_nl.py b/gramps2/src/dates/Date_nl.py index bd8b7f267..0d7151b31 100644 --- a/gramps2/src/dates/Date_nl.py +++ b/gramps2/src/dates/Date_nl.py @@ -2,7 +2,7 @@ # # Gramps - a GTK+/GNOME based genealogy program # -# Copyright (C) 2004-2005 Donald N. Allingham +# Copyright (C) 2004-2006 Donald N. Allingham # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -43,7 +43,7 @@ import re # GRAMPS modules # #------------------------------------------------------------------------- -import Date +from RelLib import Date from DateParser import DateParser from DateDisplay import DateDisplay diff --git a/gramps2/src/dates/Date_ru.py b/gramps2/src/dates/Date_ru.py index 15eaa5899..4f5b5b78e 100644 --- a/gramps2/src/dates/Date_ru.py +++ b/gramps2/src/dates/Date_ru.py @@ -2,7 +2,7 @@ # # Gramps - a GTK+/GNOME based genealogy program # -# Copyright (C) 2004-2005 Donald N. Allingham +# Copyright (C) 2004-2006 Donald N. Allingham # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -37,7 +37,7 @@ import re # GRAMPS modules # #------------------------------------------------------------------------- -import Date +from RelLib import Date from DateParser import DateParser from DateDisplay import DateDisplay diff --git a/gramps2/src/dates/Date_sv.py b/gramps2/src/dates/Date_sv.py index 3a3326bc7..04b1cdf19 100644 --- a/gramps2/src/dates/Date_sv.py +++ b/gramps2/src/dates/Date_sv.py @@ -2,7 +2,7 @@ # # Gramps - a GTK+/GNOME based genealogy program # -# Copyright (C) 2004-2005 Donald N. Allingham +# Copyright (C) 2004-2006 Donald N. Allingham # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -37,7 +37,7 @@ import re # GRAMPS modules # #------------------------------------------------------------------------- -import Date +from RelLib import Date from DateParser import DateParser from DateDisplay import DateDisplay diff --git a/gramps2/src/plugins/ExportVCalendar.py b/gramps2/src/plugins/ExportVCalendar.py index 3b680a09a..39aca20cb 100644 --- a/gramps2/src/plugins/ExportVCalendar.py +++ b/gramps2/src/plugins/ExportVCalendar.py @@ -2,7 +2,7 @@ # Gramps - a GTK+/GNOME based genealogy program # # Copyright (C) 2004 Martin Hawlisch -# Copyright (C) 2005 Donald N. Allingham +# Copyright (C) 2005-2006 Donald N. Allingham # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -46,7 +46,7 @@ import gtk.glade import GenericFilter import const import Utils -import Date +from RelLib import Date import Errors from gettext import gettext as _ from QuestionDialog import ErrorDialog diff --git a/gramps2/src/plugins/ExportVCard.py b/gramps2/src/plugins/ExportVCard.py index 2585c0378..4ea574fba 100644 --- a/gramps2/src/plugins/ExportVCard.py +++ b/gramps2/src/plugins/ExportVCard.py @@ -2,7 +2,7 @@ # Gramps - a GTK+/GNOME based genealogy program # # Copyright (C) 2004 Martin Hawlisch -# Copyright (C) 2005 Donald N. Allingham +# Copyright (C) 2005-2006 Donald N. Allingham # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -44,7 +44,7 @@ import gtk.glade #------------------------------------------------------------------------- import GenericFilter import const -import Date +from RelLib import Date import Errors from gettext import gettext as _ from QuestionDialog import ErrorDialog diff --git a/gramps2/src/plugins/ImportGeneWeb.py b/gramps2/src/plugins/ImportGeneWeb.py index 8cd5091bd..b164f8691 100644 --- a/gramps2/src/plugins/ImportGeneWeb.py +++ b/gramps2/src/plugins/ImportGeneWeb.py @@ -46,7 +46,6 @@ import gtk.glade #------------------------------------------------------------------------- import Errors import RelLib -import Date import const from QuestionDialog import ErrorDialog from DateHandler import parser as _dp @@ -56,15 +55,15 @@ _date_parse = re.compile('([~?<>]+)?([0-9/]+)([J|H|F])?(\.\.)?([0-9/]+)?([J|H|F] _text_parse = re.compile('0\((.*)\)') _mod_map = { - '>' : Date.MOD_AFTER, - '<' : Date.MOD_BEFORE, - '~' : Date.MOD_ABOUT, + '>' : RelLib.Date.MOD_AFTER, + '<' : RelLib.Date.MOD_BEFORE, + '~' : RelLib.Date.MOD_ABOUT, } _cal_map = { - 'J' : Date.CAL_JULIAN, - 'H' : Date.CAL_HEBREW, - 'F' : Date.CAL_FRENCH, + 'J' : RelLib.Date.CAL_JULIAN, + 'H' : RelLib.Date.CAL_HEBREW, + 'F' : RelLib.Date.CAL_FRENCH, } #------------------------------------------------------------------------- @@ -650,27 +649,27 @@ class GeneWebParser: def parse_date(self,field): if field == "0": return None - date = Date.Date() + date = RelLib.Date() matches = _text_parse.match(field) if matches: groups = matches.groups() date.set_as_text(groups[0]) - date.set_modifier(Date.MOD_TEXTONLY) + date.set_modifier(RelLib.Date.MOD_TEXTONLY) return date matches = _date_parse.match(field) if matches: groups = matches.groups() - mod = _mod_map.get(groups[0],Date.MOD_NONE) + mod = _mod_map.get(groups[0],RelLib.Date.MOD_NONE) if groups[3] == "..": - mod = Date.MOD_SPAN - cal2 = _cal_map.get(groups[5],Date.CAL_GREGORIAN) + mod = RelLib.Date.MOD_SPAN + cal2 = _cal_map.get(groups[5],RelLib.Date.CAL_GREGORIAN) sub2 = self.sub_date(groups[4]) else: sub2 = (0,0,0) - cal1 = _cal_map.get(groups[2],Date.CAL_GREGORIAN) + cal1 = _cal_map.get(groups[2],RelLib.Date.CAL_GREGORIAN) sub1 = self.sub_date(groups[1]) - date.set(Date.QUAL_NONE,mod, cal1, + date.set(RelLib.Date.QUAL_NONE,mod, cal1, (sub1[0],sub1[1],sub1[2],None,sub2[0],sub2[1],sub2[2],None)) return date else: diff --git a/gramps2/src/plugins/TestcaseGenerator.py b/gramps2/src/plugins/TestcaseGenerator.py index 700ba42bd..9beb13fe2 100644 --- a/gramps2/src/plugins/TestcaseGenerator.py +++ b/gramps2/src/plugins/TestcaseGenerator.py @@ -47,7 +47,6 @@ import gtk.glade # #------------------------------------------------------------------------- import Errors -import Date import RelLib import Tool import const @@ -647,61 +646,71 @@ class TestcaseGenerator(Tool.Tool): def generate_date_tests(self): dates = [] # first some valid dates - calendar = Date.CAL_GREGORIAN - for quality in (Date.QUAL_NONE, Date.QUAL_ESTIMATED, Date.QUAL_CALCULATED): - for modifier in (Date.MOD_NONE, Date.MOD_BEFORE, Date.MOD_AFTER, Date.MOD_ABOUT): + calendar = RelLib.Date.CAL_GREGORIAN + for quality in (RelLib.Date.QUAL_NONE, RelLib.Date.QUAL_ESTIMATED, + RelLib.Date.QUAL_CALCULATED): + for modifier in (RelLib.Date.MOD_NONE, RelLib.Date.MOD_BEFORE, + RelLib.Date.MOD_AFTER, RelLib.Date.MOD_ABOUT): for slash1 in (False,True): - d = Date.Date() + d = RelLib.Date() d.set(quality,modifier,calendar,(4,7,1789,slash1),"Text comment") dates.append( d) - for modifier in (Date.MOD_RANGE, Date.MOD_SPAN): + for modifier in (RelLib.Date.MOD_RANGE, RelLib.Date.MOD_SPAN): for slash1 in (False,True): for slash2 in (False,True): - d = Date.Date() + d = RelLib.Date() d.set(quality,modifier,calendar,(4,7,1789,slash1,5,8,1876,slash2),"Text comment") dates.append( d) - modifier = Date.MOD_TEXTONLY - d = Date.Date() - d.set(quality,modifier,calendar,Date.EMPTY,"This is a textual date") + modifier = RelLib.Date.MOD_TEXTONLY + d = RelLib.Date() + d.set(quality,modifier,calendar,RelLib.Date.EMPTY, + "This is a textual date") dates.append( d) # test invalid dates dateval = (4,7,1789,False,5,8,1876,False) for l in range(1,len(dateval)): - d = Date.Date() + d = RelLib.Date() try: - d.set(Date.QUAL_NONE,Date.MOD_NONE,Date.CAL_GREGORIAN,dateval[:l],"Text comment") + d.set(RelLib.Date.QUAL_NONE,RelLib.Date.MOD_NONE, + RelLib.Date.CAL_GREGORIAN,dateval[:l],"Text comment") dates.append( d) except Errors.DateError, e: d.set_as_text("Date identified value correctly as invalid.\n%s" % e) dates.append( d) except: - d = Date.Date() + d = RelLib.Date() d.set_as_text("Date.set Exception %s" % ("".join(traceback.format_exception(*sys.exc_info())),)) dates.append( d) for l in range(1,len(dateval)): - d = Date.Date() + d = RelLib.Date() try: - d.set(Date.QUAL_NONE,Date.MOD_SPAN,Date.CAL_GREGORIAN,dateval[:l],"Text comment") + d.set(RelLib.Date.QUAL_NONE,RelLib.Date.MOD_SPAN,RelLib.Date.CAL_GREGORIAN,dateval[:l],"Text comment") dates.append( d) except Errors.DateError, e: d.set_as_text("Date identified value correctly as invalid.\n%s" % e) dates.append( d) except: - d = Date.Date() + d = RelLib.Date() d.set_as_text("Date.set Exception %s" % ("".join(traceback.format_exception(*sys.exc_info())),)) dates.append( d) - d = Date.Date() - d.set(Date.QUAL_NONE,Date.MOD_NONE,Date.CAL_GREGORIAN,(44,7,1789,False),"Text comment") + d = RelLib.Date() + d.set(RelLib.Date.QUAL_NONE,RelLib.Date.MOD_NONE, + RelLib.Date.CAL_GREGORIAN,(44,7,1789,False),"Text comment") dates.append( d) - d = Date.Date() - d.set(Date.QUAL_NONE,Date.MOD_NONE,Date.CAL_GREGORIAN,(4,77,1789,False),"Text comment") + d = RelLib.Date() + d.set(RelLib.Date.QUAL_NONE,RelLib.Date.MOD_NONE, + RelLib.Date.CAL_GREGORIAN,(4,77,1789,False),"Text comment") dates.append( d) - d = Date.Date() - d.set(Date.QUAL_NONE,Date.MOD_SPAN,Date.CAL_GREGORIAN,(4,7,1789,False,55,8,1876,False),"Text comment") + d = RelLib.Date() + d.set(RelLib.Date.QUAL_NONE,RelLib.Date.MOD_SPAN, + RelLib.Date.CAL_GREGORIAN, + (4,7,1789,False,55,8,1876,False),"Text comment") dates.append( d) - d = Date.Date() - d.set(Date.QUAL_NONE,Date.MOD_SPAN,Date.CAL_GREGORIAN,(4,7,1789,False,5,88,1876,False),"Text comment") + d = RelLib.Date() + d.set(RelLib.Date.QUAL_NONE,RelLib.Date.MOD_SPAN, + RelLib.Date.CAL_GREGORIAN, + (4,7,1789,False,5,88,1876,False),"Text comment") dates.append( d) # now add them as birth to new persons @@ -721,16 +730,17 @@ class TestcaseGenerator(Tool.Tool): try: ndate = _dp.parse( datestr) if not ndate: - ndate = Date.Date() + ndate = RelLib.Date() ndate.set_as_text("DateParser None") except: - ndate = Date.Date() + ndate = RelLib.Date() ndate.set_as_text("DateParser Exception %s" % ("".join(traceback.format_exception(*sys.exc_info())),)) except: - ndate = Date.Date() + ndate = RelLib.Date() ndate.set_as_text("DateDisplay Exception: %s" % ("".join(traceback.format_exception(*sys.exc_info())),)) - if dateval.get_modifier() != Date.MOD_TEXTONLY and ndate.get_modifier() == Date.MOD_TEXTONLY: + if dateval.get_modifier() != RelLib.Date.MOD_TEXTONLY \ + and ndate.get_modifier() == RelLib.Date.MOD_TEXTONLY: # parser was unable to correctly parse the string ndate.set_as_text( "TEXTONLY: "+ndate.get_text()) @@ -1029,7 +1039,7 @@ class TestcaseGenerator(Tool.Tool): start = end - randint(0,100) year = randint(start,end) - ndate = Date.Date() + ndate = RelLib.Date() if randint(0,10) == 1: # Some get a textual date ndate.set_as_text( choice((self.rand_text(self.SHORT),"Unknown","??","Don't know","TODO!"))) @@ -1039,17 +1049,23 @@ class TestcaseGenerator(Tool.Tool): pass else: # regular dates - calendar = Date.CAL_GREGORIAN - quality = choice( (Date.QUAL_NONE, Date.QUAL_ESTIMATED, Date.QUAL_CALCULATED)) - modifier = choice( (Date.MOD_NONE, Date.MOD_BEFORE, Date.MOD_AFTER,\ - Date.MOD_ABOUT, Date.MOD_RANGE, Date.MOD_SPAN)) + calendar = RelLib.Date.CAL_GREGORIAN + quality = choice( (RelLib.Date.QUAL_NONE, + RelLib.Date.QUAL_ESTIMATED, + RelLib.Date.QUAL_CALCULATED)) + modifier = choice( (RelLib.Date.MOD_NONE, + RelLib.Date.MOD_BEFORE, + RelLib.Date.MOD_AFTER,\ + RelLib.Date.MOD_ABOUT, + RelLib.Date.MOD_RANGE, + RelLib.Date.MOD_SPAN)) day = randint(0,28) if day > 0: # avoid days without month month = randint(1,12) else: month = randint(0,12) - if modifier in (Date.MOD_RANGE, Date.MOD_SPAN): + if modifier in (RelLib.Date.MOD_RANGE, RelLib.Date.MOD_SPAN): day2 = randint(0,28) if day2 > 0: month2 = randint(1,12) diff --git a/gramps2/src/plugins/Verify.py b/gramps2/src/plugins/Verify.py index cee492ed6..647396890 100644 --- a/gramps2/src/plugins/Verify.py +++ b/gramps2/src/plugins/Verify.py @@ -1,7 +1,7 @@ # # Gramps - a GTK+/GNOME based genealogy program # -# Copyright (C) 2000-2005 Donald N. Allingham +# Copyright (C) 2000-2006 Donald N. Allingham # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -47,7 +47,6 @@ import GrampsDisplay #------------------------------------------------------------------------ import RelLib import Utils -import Date import Tool #------------------------------------------------------------------------- @@ -160,8 +159,8 @@ class Verify(Tool.Tool): event = self.db.get_event_from_handle(event_handle) dateObj = event.get_date_object() if dateObj: - if dateObj.get_calendar() != Date.CAL_GREGORIAN: - dateObj.set_calendar(Date.CAL_GREGORIAN) + if dateObj.get_calendar() != RelLib.Date.CAL_GREGORIAN: + dateObj.set_calendar(RelLib.Date.CAL_GREGORIAN) year = dateObj.get_year() return year diff --git a/gramps2/src/plugins/WriteGeneWeb.py b/gramps2/src/plugins/WriteGeneWeb.py index 59c7b32ba..7a64fd7ad 100644 --- a/gramps2/src/plugins/WriteGeneWeb.py +++ b/gramps2/src/plugins/WriteGeneWeb.py @@ -2,7 +2,7 @@ # Gramps - a GTK+/GNOME based genealogy program # # Copyright (C) 2004 Martin Hawlisch -# Copyright (C) 2004-2005 Donald N. Allingham +# Copyright (C) 2004-2006 Donald N. Allingham # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -47,7 +47,6 @@ import RelLib import GenericFilter import const import Utils -import Date import Errors from QuestionDialog import ErrorDialog @@ -528,19 +527,19 @@ class GeneWebWriter: (day,month,year,sl) = subdate cal_type = "" - if cal == Date.CAL_HEBREW: + if cal == RelLib.Date.CAL_HEBREW: cal_type = "H" - elif cal == Date.CAL_FRENCH: + elif cal == RelLib.Date.CAL_FRENCH: cal_type = "F" - elif cal == Date.CAL_JULIAN: + elif cal == RelLib.Date.CAL_JULIAN: cal_type = "J" mode_prefix = "" - if mode == Date.MOD_ABOUT: + if mode == RelLib.Date.MOD_ABOUT: mode_prefix = "~" - elif mode == Date.MOD_BEFORE: + elif mode == RelLib.Date.MOD_BEFORE: mode_prefix = "<" - elif mode == Date.MOD_AFTER: + elif mode == RelLib.Date.MOD_AFTER: mode_prefix = ">" if year > 0: @@ -563,9 +562,10 @@ class GeneWebWriter: elif not date.is_empty(): mod = date.get_modifier() cal = cal = date.get_calendar() - if mod == Date.MOD_SPAN or mod == Date.MOD_RANGE: - retval = "%s..%s" % (self.format_single_date(date.get_start_date(), cal,mod), - self.format_single_date(date.get_stop_date(),cal,mod)) + if mod == RelLib.Date.MOD_SPAN or mod == RelLib.Date.MOD_RANGE: + retval = "%s..%s" % ( + self.format_single_date(date.get_start_date(), cal,mod), + self.format_single_date(date.get_stop_date(),cal,mod)) else: retval = self.format_single_date(date.get_start_date(),cal,mod) return retval diff --git a/gramps2/src/plugins/rel_hu.py b/gramps2/src/plugins/rel_hu.py index 17bf4d59c..d5e5739aa 100644 --- a/gramps2/src/plugins/rel_hu.py +++ b/gramps2/src/plugins/rel_hu.py @@ -2,7 +2,7 @@ # # Gramps - a GTK+/GNOME based genealogy program # -# Copyright (C) 2003-2005 Donald N. Allingham +# Copyright (C) 2003-2006 Donald N. Allingham # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -31,7 +31,6 @@ #------------------------------------------------------------------------- import RelLib -import Date import Relationship from PluginMgr import register_relcalc import types @@ -155,7 +154,7 @@ class RelationshipCalculator(Relationship.RelationshipCalculator): other_birth_event = other_person.get_birth() other_birth_date = other_birth_event.get_date_object() if (orig_birth_date == "")or(other_birth_date == "") :return 0 - else :return Date.compare_dates(orig_birth_date,other_birth_date) + else :return RelLib.Date.compare_dates(orig_birth_date,other_birth_date) def get_age_brother (self,level):