diff --git a/gramps2/ChangeLog b/gramps2/ChangeLog index 50ff07e70..8736849e0 100644 --- a/gramps2/ChangeLog +++ b/gramps2/ChangeLog @@ -1,3 +1,12 @@ +2004-09-19 Alex Roitman + * src/DateEdit.py: Take date object as an argument and work with it. + * src/AddrEdit.py: Use date object instead of text. + * src/EditPerson.py: Use date object instead of text. + * src/EventEdit.py: Use date object instead of text. + * src/gramps.glade: Minor cleanup. + * src/Date.py (copy): Add method. + * src/RelLib.py (Address): Correct the use of dates. + 2004-09-18 Don Allingham * src/GrampsInMemDB.py: new base class for in memory databases, such as XML or GEDCOM diff --git a/gramps2/src/AddrEdit.py b/gramps2/src/AddrEdit.py index 045e53ed4..bace48cad 100644 --- a/gramps2/src/AddrEdit.py +++ b/gramps2/src/AddrEdit.py @@ -25,6 +25,13 @@ The AddrEdit module provides the AddressEditor class. This provides a mechanism for the user to edit address information. """ +#------------------------------------------------------------------------- +# +# Python modules +# +#------------------------------------------------------------------------- +from gettext import gettext as _ + #------------------------------------------------------------------------- # # GTK/Gnome modules @@ -43,9 +50,8 @@ import Utils import Date import RelLib import Sources - +import Date import DateEdit -from gettext import gettext as _ #------------------------------------------------------------------------- # @@ -108,6 +114,7 @@ class AddressEditor: if self.addr: self.srcreflist = self.addr.get_source_references() + self.addr_date_obj = Date.Date(self.addr.get_date_object()) self.addr_start.set_text(self.addr.get_date()) self.street.set_text(self.addr.get_street()) self.city.set_text(self.addr.get_city()) @@ -124,6 +131,7 @@ class AddressEditor: else: self.flowed.set_active(1) else: + self.addr_date_obj = Date.Date() self.srcreflist = [] self.sourcetab = Sources.SourceTab(self.srcreflist,self, @@ -133,7 +141,10 @@ class AddressEditor: self.top.get_widget('del_src')) date_stat = self.top.get_widget("date_stat") - self.date_check = DateEdit.DateEdit(self.addr_start,date_stat) + self.date_check = DateEdit.DateEdit(self.addr_date_obj, + self.addr_start, + date_stat, + self.window) self.top.signal_autoconnect({ "on_switch_page" : self.on_switch_page, @@ -193,7 +204,7 @@ class AddressEditor: Called when the OK button is pressed. Gets data from the form and updates the Address data structure. """ - date = unicode(self.addr_start.get_text()) + date_obj = self.addr_date_obj street = unicode(self.street.get_text()) city = unicode(self.city.get_text()) state = unicode(self.state.get_text()) @@ -210,7 +221,7 @@ class AddressEditor: self.parent.plist.append(self.addr) self.addr.set_source_reference_list(self.srcreflist) - self.update(date,street,city,state,country,postal,phone,note,format,priv) + self.update(date_obj,street,city,state,country,postal,phone,note,format,priv) self.callback(self.addr) self.close(obj) @@ -221,13 +232,11 @@ class AddressEditor: set(data) self.parent.lists_changed = 1 - def update(self,date,street,city,state,country,postal,phone,note,format,priv): + def update(self,date_obj,street,city,state,country,postal,phone,note,format,priv): """Compares the data items, and updates if necessary""" - d = Date.Date() - d.set(date) - if self.addr.get_date() != d.get_date(): - self.addr.set_date(date) + if self.addr.get_date_object() != date_obj: + self.addr.set_date_object(date_obj) self.parent.lists_changed = 1 self.check(self.addr.get_street,self.addr.set_street,street) diff --git a/gramps2/src/Date.py b/gramps2/src/Date.py index 79ccf49f3..34b172d26 100644 --- a/gramps2/src/Date.py +++ b/gramps2/src/Date.py @@ -120,6 +120,19 @@ class Date: self.sortval = 0 self.comment = u"" + 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 + self.comment = source.comment + def __cmp__(self,other): """ Comparison function. Allows the usage of equality tests. diff --git a/gramps2/src/DateEdit.py b/gramps2/src/DateEdit.py index d60854497..7d8f635f1 100644 --- a/gramps2/src/DateEdit.py +++ b/gramps2/src/DateEdit.py @@ -21,7 +21,7 @@ # $Id$ """ -The DateEdit module provides classes. +Date editing module for GRAMPS. The DateEdit.DateEdit provides two visual feedback to the user via a pixamp to indicate if the assocated GtkEntry box contains a valid date. Green @@ -59,8 +59,8 @@ import gobject # #------------------------------------------------------------------------- import Date -import DateParser import DateDisplay +import DateHandler import const import Utils @@ -104,38 +104,65 @@ class DateEdit: bad = gtk.gdk.pixbuf_new_from_file(const.bad_xpm) caution = gtk.gdk.pixbuf_new_from_file(const.caution_xpm) - def __init__(self,text_obj,button_obj): - """Creates a connection between the text_obj and the pixmap_obj""" + def __init__(self,date_obj,text_obj,button_obj,parent_window=None): + """ + Creates a connection between the date_obj, text_obj and the pixmap_obj. + Assigns callbacks to parse and change date when the text + in text_obj is changed, and to invoke Date Editor when the LED + button_obj is pressed. + """ - self.dp = DateParser.DateParser() + self.dp = DateHandler.create_parser() + self.dd = DateHandler.create_display() + self.date_obj = date_obj self.text_obj = text_obj self.button_obj = button_obj + self.parent_window = parent_window + self.pixmap_obj = button_obj.get_child() - self.text_obj.connect('focus-out-event',self.check) - self.check(None,None) + self.text_obj.connect('focus-out-event',self.parse_and_check) self.button_obj.connect('clicked',self.invoke_date_editor) - - def set_calendar(self,cobj): - self.check(None,None) - def check(self,obj,val): - """Called with the text box loses focus. If the string contains a - valid date, sets the appropriate pixmap""" + self.text = unicode(self.text_obj.get_text()) + self.check() - text = unicode(self.text_obj.get_text()) - self.checkval = self.dp.parse(text) - if self.checkval.get_modifier() == Date.MOD_TEXTONLY: + def check(self): + """ + 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(DateEdit.bad) # elif self.checkval.get_incomplete(): # self.pixmap_obj.set_from_pixbuf(DateEdit.caution) else: self.pixmap_obj.set_from_pixbuf(DateEdit.good) - + + def parse_and_check(self,obj,val): + """ + Called with the text box loses focus. Parses the text and calls + the check() method ONLY if the text has changed. + """ + + text = unicode(self.text_obj.get_text()) + if text != self.text: + self.text = text + self.date_obj.copy(self.dp.parse(text)) + self.check() + def invoke_date_editor(self,obj): - date_dialog = DateEditorDialog(self.checkval) - the_date = date_dialog.get_date() - self.text_obj.set_text(str(the_date)) - print "The date was built as follows:", the_date + """ + Invokes Date Editor dialog when the user clicks the LED button. + If date was in fact built, sets the date_obj to the newly built + date. + """ + date_dialog = DateEditorDialog(self.date_obj,self.parent_window) + the_date = date_dialog.return_date + if the_date: + self.date_obj.copy(the_date) + self.text_obj.set_text(self.dd.display(self.date_obj)) + print "The date was built as follows:", self.date_obj + else: + print "Cancel was pressed, date not changed." #------------------------------------------------------------------------- # @@ -148,16 +175,13 @@ class DateEditorDialog: limitations of parsing and/or underlying structure of Date. """ - def __init__(self,date): + def __init__(self,date,parent_window=None): """ Initiate and display the dialog. """ # Create self.date as a copy of the given Date object. self.date = Date.Date(date) - # Keep the given Date object safe as self.old_date - # until we're happy with modifying and want to commit. - self.old_date = date self.top = gtk.glade.XML(const.dialogFile, "date_edit","gramps" ) self.top_window = self.top.get_widget('date_edit') @@ -222,8 +246,11 @@ class DateEditorDialog: # The dialog is modal -- since dates don't have name, we don't # want to have several open dialogs, since then the user will # loose track of which is which. + if parent_window: + self.top_window.set_transient_for(parent_window) response = self.top_window.run() - self.top_window.destroy() + + self.return_date = None if response == gtk.RESPONSE_HELP: # Here be help :-) @@ -231,18 +258,14 @@ class DateEditorDialog: elif response == gtk.RESPONSE_OK: (the_quality,the_modifier,the_calendar,the_value,the_text) = \ self.build_date_from_ui() - self.old_date.set( + self.return_date = Date.Date(self.date) + self.return_date.set( quality=the_quality, modifier=the_modifier, calendar=the_calendar, value=the_value) - self.old_date.set_text_value(the_text) - - def get_date(self): - """ - Return the current date. - """ - return self.date + self.return_date.set_text_value(the_text) + self.top_window.destroy() def build_date_from_ui(self): """ @@ -260,7 +283,6 @@ class DateEditorDialog: text = self.text_entry.get_text() if modifier == Date.MOD_TEXTONLY: - date.set_as_text(self.text_entry.get_text()) return (Date.QUAL_NONE,Date.MOD_TEXTONLY,Date.CAL_GREGORIAN, Date.EMPTY,text) diff --git a/gramps2/src/EditPerson.py b/gramps2/src/EditPerson.py index 7e0272994..7fee9ddf4 100644 --- a/gramps2/src/EditPerson.py +++ b/gramps2/src/EditPerson.py @@ -55,7 +55,7 @@ import ListModel import RelLib import Sources import DateEdit -import DateParser +import Date import DateHandler import TransTable @@ -374,13 +374,19 @@ class EditPerson: self.addr_list.connect('drag_data_received',self.ad_drag_data_received) self.addr_list.connect('drag_begin', self.ad_drag_begin) - self.bdate_check = DateEdit.DateEdit(self.bdate, - self.get_widget("birth_stat")) - self.bdate_check.set_calendar(self.birth.get_date_object().get_calendar()) + self.birth_date_object = self.birth.get_date_object() + self.death_date_object = self.death.get_date_object() + self.update_birth_death() - self.ddate_check = DateEdit.DateEdit(self.ddate, - self.get_widget("death_stat")) - self.ddate_check.set_calendar(self.death.get_date_object().get_calendar()) + self.bdate_check = DateEdit.DateEdit(self.birth_date_object, + self.bdate, + self.get_widget("birth_stat"), + self.window) + + self.ddate_check = DateEdit.DateEdit(self.death_date_object, + self.ddate, + self.get_widget("death_stat"), + self.window) self.top.signal_autoconnect({ "destroy_passed_object" : self.on_cancel_edit, @@ -425,8 +431,6 @@ class EditPerson: "on_help_person_clicked" : self.on_help_clicked, }) - self.update_birth_death() - self.sourcetab = Sources.SourceTab(self.srcreflist,self, self.top,self.window,self.slist, self.top.get_widget('add_src'), @@ -981,7 +985,7 @@ class EditPerson: self.update_birth = 1 pname = self.person.get_primary_name().get_name() event = self.birth - event.set_date(unicode(self.bdate.get_text())) + event.set_date_object(Date.Date(self.birth_date_object)) def_placename = unicode(self.bplace.get_text()) p = self.get_place(self.bplace) @@ -999,7 +1003,7 @@ class EditPerson: self.update_death = 1 pname = self.person.get_primary_name().get_name() event = self.death - event.set_date(unicode(self.ddate.get_text())) + event.set_date_object(Date.Date(self.death_date_object)) def_placename = unicode(self.dplace.get_text()) p = self.get_place(self.dplace) @@ -1087,8 +1091,8 @@ class EditPerson: orig record""" surname = unicode(self.surname.get_text()) - self.birth.set_date(unicode(self.bdate.get_text())) - self.death.set_date(unicode(self.ddate.get_text())) + self.birth.set_date_object(self.birth_date_object) + self.death.set_date_object(self.death_date_object) ntype = unicode(self.ntype_field.child.get_text()) suffix = unicode(self.suffix.get_text()) @@ -1215,10 +1219,8 @@ class EditPerson: self.bplace.set_text(place_title(self.db,self.birth)) self.dplace.set_text(place_title(self.db,self.death)) - self.bdate.set_text(self.dd.display(self.birth.get_date_object())) - self.bdate_check.set_calendar(self.birth.get_date_object().get_calendar()) - self.ddate.set_text(self.dd.display(self.death.get_date_object())) - self.ddate_check.set_calendar(self.death.get_date_object().get_calendar()) + self.bdate.set_text(self.dd.display(self.birth_date_object)) + self.ddate.set_text(self.dd.display(self.death_date_object)) def on_update_attr_clicked(self,obj): import AttrEdit @@ -1462,7 +1464,7 @@ class EditPerson: name = self.pname - self.birth.set_date(unicode(self.bdate.get_text())) + self.birth.set_date_object(self.birth_date_object) self.birth.set_place_handle(self.get_place(self.bplace,1)) if idval != self.person.get_gramps_id(): @@ -1532,7 +1534,7 @@ class EditPerson: new_order = self.reorder_child_list(self.person,f.get_child_handle_list()) f.set_child_handle_list(new_order) - self.death.set_date(unicode(self.ddate.get_text())) + self.death.set_date_object(self.death_date_object) self.death.set_place_handle(self.get_place(self.dplace,1)) if self.orig_death == None: @@ -1709,10 +1711,12 @@ class EditPerson: self.load_photo(None) def update_birth_info(self): + self.birth_date_object.copy(self.birth.get_date_object()) self.bdate.set_text(self.birth.get_date()) self.bplace.set_text(place_title(self.db,self.birth)) def update_death_info(self): + self.death_date_object.copy(self.death.get_date_object()) self.ddate.set_text(self.death.get_date()) self.dplace.set_text(place_title(self.db,self.death)) diff --git a/gramps2/src/EventEdit.py b/gramps2/src/EventEdit.py index 1bf8fdbce..ee3cc8b11 100644 --- a/gramps2/src/EventEdit.py +++ b/gramps2/src/EventEdit.py @@ -20,7 +20,13 @@ # $Id$ +#------------------------------------------------------------------------- +# +# Python modules +# +#------------------------------------------------------------------------- from string import strip +from gettext import gettext as _ #------------------------------------------------------------------------- # @@ -44,14 +50,11 @@ import GrampsCfg import AutoComp import RelLib import Date -import DateParser import DateHandler import ImageSelect - import DateEdit -from gettext import gettext as _ - from QuestionDialog import WarningDialog + #------------------------------------------------------------------------- # # EventEditor class @@ -194,7 +197,10 @@ class EventEditor: self.event_menu.child.set_text(def_event) if def_placename: self.place_field.set_text(def_placename) - self.date_check = DateEdit.DateEdit(self.date_field,self.top.get_widget("date_stat")) + self.date_check = DateEdit.DateEdit(self.date, + self.date_field, + self.top.get_widget("date_stat"), + self.window) if not event: event = RelLib.Event() @@ -282,7 +288,7 @@ class EventEditor: trans = self.db.transaction_begin() ename = unicode(self.event_menu.child.get_text()) - self.date = self.dp.parse(unicode(self.date_field.get_text())) + #self.date = self.dp.parse(unicode(self.date_field.get_text())) ecause = unicode(self.cause_field.get_text()) eplace_obj = self.get_place(self.place_field,trans) buf = self.note_field.get_buffer() diff --git a/gramps2/src/RelLib.py b/gramps2/src/RelLib.py index 8bef341ca..df4cb241d 100644 --- a/gramps2/src/RelLib.py +++ b/gramps2/src/RelLib.py @@ -1723,6 +1723,8 @@ class Address(DataObj): if provided""" DataObj.__init__(self,source) + self.dd = DateHandler.create_display() + self.dp = DateHandler.create_parser() if source: self.street = source.street self.city = source.city @@ -1743,12 +1745,14 @@ class Address(DataObj): def set_date(self,text): """attempts to sets the date that the person lived at the address from the passed string""" - self.date.set(text) + self.date = self.dp.parse(text) def get_date(self): """returns a string representation of the date that the person lived at the address""" - return self.date.get_date() + if self.date: + return self.dd.display(self.date) + return u"" def get_preferred_date(self): """returns a string representation of the date that the person diff --git a/gramps2/src/gramps.glade b/gramps2/src/gramps.glade index f0ac59a3f..37c5cbc50 100644 --- a/gramps2/src/gramps.glade +++ b/gramps2/src/gramps.glade @@ -30816,7 +30816,7 @@ Other 0.5 0.5 0 - 0 + 6 0