* 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.


svn: r3556
This commit is contained in:
Alex Roitman 2004-09-19 15:17:57 +00:00
parent 4e43d89fe3
commit 894619e016
8 changed files with 140 additions and 73 deletions

View File

@ -1,3 +1,12 @@
2004-09-19 Alex Roitman <shura@alex.neuro.umn.edu>
* 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 <dallingham@users.sourceforge.net> 2004-09-18 Don Allingham <dallingham@users.sourceforge.net>
* src/GrampsInMemDB.py: new base class for in memory databases, such * src/GrampsInMemDB.py: new base class for in memory databases, such
as XML or GEDCOM as XML or GEDCOM

View File

@ -25,6 +25,13 @@ The AddrEdit module provides the AddressEditor class. This provides a
mechanism for the user to edit address information. mechanism for the user to edit address information.
""" """
#-------------------------------------------------------------------------
#
# Python modules
#
#-------------------------------------------------------------------------
from gettext import gettext as _
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
# GTK/Gnome modules # GTK/Gnome modules
@ -43,9 +50,8 @@ import Utils
import Date import Date
import RelLib import RelLib
import Sources import Sources
import Date
import DateEdit import DateEdit
from gettext import gettext as _
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
@ -108,6 +114,7 @@ class AddressEditor:
if self.addr: if self.addr:
self.srcreflist = self.addr.get_source_references() 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.addr_start.set_text(self.addr.get_date())
self.street.set_text(self.addr.get_street()) self.street.set_text(self.addr.get_street())
self.city.set_text(self.addr.get_city()) self.city.set_text(self.addr.get_city())
@ -124,6 +131,7 @@ class AddressEditor:
else: else:
self.flowed.set_active(1) self.flowed.set_active(1)
else: else:
self.addr_date_obj = Date.Date()
self.srcreflist = [] self.srcreflist = []
self.sourcetab = Sources.SourceTab(self.srcreflist,self, self.sourcetab = Sources.SourceTab(self.srcreflist,self,
@ -133,7 +141,10 @@ class AddressEditor:
self.top.get_widget('del_src')) self.top.get_widget('del_src'))
date_stat = self.top.get_widget("date_stat") 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({ self.top.signal_autoconnect({
"on_switch_page" : self.on_switch_page, "on_switch_page" : self.on_switch_page,
@ -193,7 +204,7 @@ class AddressEditor:
Called when the OK button is pressed. Gets data from the Called when the OK button is pressed. Gets data from the
form and updates the Address data structure. 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()) street = unicode(self.street.get_text())
city = unicode(self.city.get_text()) city = unicode(self.city.get_text())
state = unicode(self.state.get_text()) state = unicode(self.state.get_text())
@ -210,7 +221,7 @@ class AddressEditor:
self.parent.plist.append(self.addr) self.parent.plist.append(self.addr)
self.addr.set_source_reference_list(self.srcreflist) 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.callback(self.addr)
self.close(obj) self.close(obj)
@ -221,13 +232,11 @@ class AddressEditor:
set(data) set(data)
self.parent.lists_changed = 1 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""" """Compares the data items, and updates if necessary"""
d = Date.Date()
d.set(date)
if self.addr.get_date() != d.get_date(): if self.addr.get_date_object() != date_obj:
self.addr.set_date(date) self.addr.set_date_object(date_obj)
self.parent.lists_changed = 1 self.parent.lists_changed = 1
self.check(self.addr.get_street,self.addr.set_street,street) self.check(self.addr.get_street,self.addr.set_street,street)

View File

@ -120,6 +120,19 @@ class Date:
self.sortval = 0 self.sortval = 0
self.comment = u"" 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): def __cmp__(self,other):
""" """
Comparison function. Allows the usage of equality tests. Comparison function. Allows the usage of equality tests.

View File

@ -21,7 +21,7 @@
# $Id$ # $Id$
""" """
The DateEdit module provides classes. Date editing module for GRAMPS.
The DateEdit.DateEdit provides two visual feedback to the user via a pixamp 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 to indicate if the assocated GtkEntry box contains a valid date. Green
@ -59,8 +59,8 @@ import gobject
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
import Date import Date
import DateParser
import DateDisplay import DateDisplay
import DateHandler
import const import const
import Utils import Utils
@ -104,38 +104,65 @@ class DateEdit:
bad = gtk.gdk.pixbuf_new_from_file(const.bad_xpm) bad = gtk.gdk.pixbuf_new_from_file(const.bad_xpm)
caution = gtk.gdk.pixbuf_new_from_file(const.caution_xpm) caution = gtk.gdk.pixbuf_new_from_file(const.caution_xpm)
def __init__(self,text_obj,button_obj): def __init__(self,date_obj,text_obj,button_obj,parent_window=None):
"""Creates a connection between the text_obj and the pixmap_obj""" """
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.text_obj = text_obj
self.button_obj = button_obj self.button_obj = button_obj
self.parent_window = parent_window
self.pixmap_obj = button_obj.get_child() self.pixmap_obj = button_obj.get_child()
self.text_obj.connect('focus-out-event',self.check) self.text_obj.connect('focus-out-event',self.parse_and_check)
self.check(None,None)
self.button_obj.connect('clicked',self.invoke_date_editor) self.button_obj.connect('clicked',self.invoke_date_editor)
def set_calendar(self,cobj):
self.check(None,None)
def check(self,obj,val): self.text = unicode(self.text_obj.get_text())
"""Called with the text box loses focus. If the string contains a self.check()
valid date, sets the appropriate pixmap"""
text = unicode(self.text_obj.get_text()) def check(self):
self.checkval = self.dp.parse(text) """
if self.checkval.get_modifier() == Date.MOD_TEXTONLY: 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) self.pixmap_obj.set_from_pixbuf(DateEdit.bad)
# elif self.checkval.get_incomplete(): # elif self.checkval.get_incomplete():
# self.pixmap_obj.set_from_pixbuf(DateEdit.caution) # self.pixmap_obj.set_from_pixbuf(DateEdit.caution)
else: else:
self.pixmap_obj.set_from_pixbuf(DateEdit.good) 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): def invoke_date_editor(self,obj):
date_dialog = DateEditorDialog(self.checkval) """
the_date = date_dialog.get_date() Invokes Date Editor dialog when the user clicks the LED button.
self.text_obj.set_text(str(the_date)) If date was in fact built, sets the date_obj to the newly built
print "The date was built as follows:", the_date 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. 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. Initiate and display the dialog.
""" """
# Create self.date as a copy of the given Date object. # Create self.date as a copy of the given Date object.
self.date = Date.Date(date) 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 = gtk.glade.XML(const.dialogFile, "date_edit","gramps" )
self.top_window = self.top.get_widget('date_edit') 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 # The dialog is modal -- since dates don't have name, we don't
# want to have several open dialogs, since then the user will # want to have several open dialogs, since then the user will
# loose track of which is which. # loose track of which is which.
if parent_window:
self.top_window.set_transient_for(parent_window)
response = self.top_window.run() response = self.top_window.run()
self.top_window.destroy()
self.return_date = None
if response == gtk.RESPONSE_HELP: if response == gtk.RESPONSE_HELP:
# Here be help :-) # Here be help :-)
@ -231,18 +258,14 @@ class DateEditorDialog:
elif response == gtk.RESPONSE_OK: elif response == gtk.RESPONSE_OK:
(the_quality,the_modifier,the_calendar,the_value,the_text) = \ (the_quality,the_modifier,the_calendar,the_value,the_text) = \
self.build_date_from_ui() self.build_date_from_ui()
self.old_date.set( self.return_date = Date.Date(self.date)
self.return_date.set(
quality=the_quality, quality=the_quality,
modifier=the_modifier, modifier=the_modifier,
calendar=the_calendar, calendar=the_calendar,
value=the_value) value=the_value)
self.old_date.set_text_value(the_text) self.return_date.set_text_value(the_text)
self.top_window.destroy()
def get_date(self):
"""
Return the current date.
"""
return self.date
def build_date_from_ui(self): def build_date_from_ui(self):
""" """
@ -260,7 +283,6 @@ class DateEditorDialog:
text = self.text_entry.get_text() text = self.text_entry.get_text()
if modifier == Date.MOD_TEXTONLY: if modifier == Date.MOD_TEXTONLY:
date.set_as_text(self.text_entry.get_text())
return (Date.QUAL_NONE,Date.MOD_TEXTONLY,Date.CAL_GREGORIAN, return (Date.QUAL_NONE,Date.MOD_TEXTONLY,Date.CAL_GREGORIAN,
Date.EMPTY,text) Date.EMPTY,text)

View File

@ -55,7 +55,7 @@ import ListModel
import RelLib import RelLib
import Sources import Sources
import DateEdit import DateEdit
import DateParser import Date
import DateHandler import DateHandler
import TransTable 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_data_received',self.ad_drag_data_received)
self.addr_list.connect('drag_begin', self.ad_drag_begin) self.addr_list.connect('drag_begin', self.ad_drag_begin)
self.bdate_check = DateEdit.DateEdit(self.bdate, self.birth_date_object = self.birth.get_date_object()
self.get_widget("birth_stat")) self.death_date_object = self.death.get_date_object()
self.bdate_check.set_calendar(self.birth.get_date_object().get_calendar()) self.update_birth_death()
self.ddate_check = DateEdit.DateEdit(self.ddate, self.bdate_check = DateEdit.DateEdit(self.birth_date_object,
self.get_widget("death_stat")) self.bdate,
self.ddate_check.set_calendar(self.death.get_date_object().get_calendar()) 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({ self.top.signal_autoconnect({
"destroy_passed_object" : self.on_cancel_edit, "destroy_passed_object" : self.on_cancel_edit,
@ -425,8 +431,6 @@ class EditPerson:
"on_help_person_clicked" : self.on_help_clicked, "on_help_person_clicked" : self.on_help_clicked,
}) })
self.update_birth_death()
self.sourcetab = Sources.SourceTab(self.srcreflist,self, self.sourcetab = Sources.SourceTab(self.srcreflist,self,
self.top,self.window,self.slist, self.top,self.window,self.slist,
self.top.get_widget('add_src'), self.top.get_widget('add_src'),
@ -981,7 +985,7 @@ class EditPerson:
self.update_birth = 1 self.update_birth = 1
pname = self.person.get_primary_name().get_name() pname = self.person.get_primary_name().get_name()
event = self.birth 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()) def_placename = unicode(self.bplace.get_text())
p = self.get_place(self.bplace) p = self.get_place(self.bplace)
@ -999,7 +1003,7 @@ class EditPerson:
self.update_death = 1 self.update_death = 1
pname = self.person.get_primary_name().get_name() pname = self.person.get_primary_name().get_name()
event = self.death 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()) def_placename = unicode(self.dplace.get_text())
p = self.get_place(self.dplace) p = self.get_place(self.dplace)
@ -1087,8 +1091,8 @@ class EditPerson:
orig record""" orig record"""
surname = unicode(self.surname.get_text()) surname = unicode(self.surname.get_text())
self.birth.set_date(unicode(self.bdate.get_text())) self.birth.set_date_object(self.birth_date_object)
self.death.set_date(unicode(self.ddate.get_text())) self.death.set_date_object(self.death_date_object)
ntype = unicode(self.ntype_field.child.get_text()) ntype = unicode(self.ntype_field.child.get_text())
suffix = unicode(self.suffix.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.bplace.set_text(place_title(self.db,self.birth))
self.dplace.set_text(place_title(self.db,self.death)) self.dplace.set_text(place_title(self.db,self.death))
self.bdate.set_text(self.dd.display(self.birth.get_date_object())) self.bdate.set_text(self.dd.display(self.birth_date_object))
self.bdate_check.set_calendar(self.birth.get_date_object().get_calendar()) self.ddate.set_text(self.dd.display(self.death_date_object))
self.ddate.set_text(self.dd.display(self.death.get_date_object()))
self.ddate_check.set_calendar(self.death.get_date_object().get_calendar())
def on_update_attr_clicked(self,obj): def on_update_attr_clicked(self,obj):
import AttrEdit import AttrEdit
@ -1462,7 +1464,7 @@ class EditPerson:
name = self.pname 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)) self.birth.set_place_handle(self.get_place(self.bplace,1))
if idval != self.person.get_gramps_id(): 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()) new_order = self.reorder_child_list(self.person,f.get_child_handle_list())
f.set_child_handle_list(new_order) 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)) self.death.set_place_handle(self.get_place(self.dplace,1))
if self.orig_death == None: if self.orig_death == None:
@ -1709,10 +1711,12 @@ class EditPerson:
self.load_photo(None) self.load_photo(None)
def update_birth_info(self): def update_birth_info(self):
self.birth_date_object.copy(self.birth.get_date_object())
self.bdate.set_text(self.birth.get_date()) self.bdate.set_text(self.birth.get_date())
self.bplace.set_text(place_title(self.db,self.birth)) self.bplace.set_text(place_title(self.db,self.birth))
def update_death_info(self): def update_death_info(self):
self.death_date_object.copy(self.death.get_date_object())
self.ddate.set_text(self.death.get_date()) self.ddate.set_text(self.death.get_date())
self.dplace.set_text(place_title(self.db,self.death)) self.dplace.set_text(place_title(self.db,self.death))

View File

@ -20,7 +20,13 @@
# $Id$ # $Id$
#-------------------------------------------------------------------------
#
# Python modules
#
#-------------------------------------------------------------------------
from string import strip from string import strip
from gettext import gettext as _
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
@ -44,14 +50,11 @@ import GrampsCfg
import AutoComp import AutoComp
import RelLib import RelLib
import Date import Date
import DateParser
import DateHandler import DateHandler
import ImageSelect import ImageSelect
import DateEdit import DateEdit
from gettext import gettext as _
from QuestionDialog import WarningDialog from QuestionDialog import WarningDialog
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
# EventEditor class # EventEditor class
@ -194,7 +197,10 @@ class EventEditor:
self.event_menu.child.set_text(def_event) self.event_menu.child.set_text(def_event)
if def_placename: if def_placename:
self.place_field.set_text(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: if not event:
event = RelLib.Event() event = RelLib.Event()
@ -282,7 +288,7 @@ class EventEditor:
trans = self.db.transaction_begin() trans = self.db.transaction_begin()
ename = unicode(self.event_menu.child.get_text()) 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()) ecause = unicode(self.cause_field.get_text())
eplace_obj = self.get_place(self.place_field,trans) eplace_obj = self.get_place(self.place_field,trans)
buf = self.note_field.get_buffer() buf = self.note_field.get_buffer()

View File

@ -1723,6 +1723,8 @@ class Address(DataObj):
if provided""" if provided"""
DataObj.__init__(self,source) DataObj.__init__(self,source)
self.dd = DateHandler.create_display()
self.dp = DateHandler.create_parser()
if source: if source:
self.street = source.street self.street = source.street
self.city = source.city self.city = source.city
@ -1743,12 +1745,14 @@ class Address(DataObj):
def set_date(self,text): def set_date(self,text):
"""attempts to sets the date that the person lived at the address """attempts to sets the date that the person lived at the address
from the passed string""" from the passed string"""
self.date.set(text) self.date = self.dp.parse(text)
def get_date(self): def get_date(self):
"""returns a string representation of the date that the person """returns a string representation of the date that the person
lived at the address""" 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): def get_preferred_date(self):
"""returns a string representation of the date that the person """returns a string representation of the date that the person

View File

@ -30816,7 +30816,7 @@ Other</property>
<property name="xalign">0.5</property> <property name="xalign">0.5</property>
<property name="yalign">0.5</property> <property name="yalign">0.5</property>
<property name="xpad">0</property> <property name="xpad">0</property>
<property name="ypad">0</property> <property name="ypad">6</property>
</widget> </widget>
<packing> <packing>
<property name="padding">0</property> <property name="padding">0</property>