* src/EditPerson.py: Support for event references.

* src/FamilyView.py: Support for event references.
* src/ListBox.py: Support for event references.
* src/PedView.py: Support for event references.
* src/RelLib.py: Support for event references.


svn: r4700
This commit is contained in:
Alex Roitman 2005-05-27 05:07:26 +00:00
parent d29b4c8ffc
commit 33396348db
6 changed files with 208 additions and 146 deletions

View File

@ -1,6 +1,12 @@
2005-05-26 Alex Roitman <shura@gramps-project.org>
* src/RelLib.py (EventRef): Add class.
* src/EditPerson.py: Support for event references.
* src/FamilyView.py: Support for event references.
* src/ListBox.py: Support for event references.
* src/PedView.py: Support for event references.
* src/RelLib.py: Support for event references.
2005-05-26 Martin Hawlisch <Martin.Hawlisch@gmx.de>
* src/plugins/TestcaseGenerator.py: Add place, media and source
references.

View File

@ -201,8 +201,8 @@ class EditPerson:
self.prefix_label.set_text(_('Patronymic:'))
self.prefix_label.set_use_underline(True)
self.birth_handle = person.get_birth_handle()
self.death_handle = person.get_death_handle()
self.birth_ref = person.get_birth_ref()
self.death_ref = person.get_death_ref()
self.pname = RelLib.Name(person.get_primary_name())
@ -226,7 +226,7 @@ class EditPerson:
# event display
self.event_box = ListBox.EventListBox(
self, self.person, self.event_list, events_label,
self, self.person, self.event_ref_list, events_label,
[event_add_btn,event_edit_btn,event_delete_btn])
self.attr_box = ListBox.AttrListBox(
@ -848,20 +848,20 @@ class EditPerson:
self.person.set_attribute_list(self.attr_box.data)
self.person.set_address_list(self.addr_box.data)
self.person.set_birth_handle(None)
self.person.set_death_handle(None)
elist = self.event_box.data[:]
for event in elist:
if event.get_name() == "Birth":
self.person.set_birth_handle(event.get_handle())
self.event_box.data.remove(event)
if event.get_name() == "Death":
self.person.set_death_handle(event.get_handle())
self.event_box.data.remove(event)
elist = []
for val in self.event_box.data:
elist.append(val.get_handle())
self.person.set_event_list(elist)
self.person.set_birth_ref(None)
self.person.set_death_ref(None)
eref_list = self.event_box.data[:]
for event_ref in eref_list:
if event_ref and event_ref.ref:
event = self.db.get_event_from_handle(event_ref.ref)
if event.get_name() == "Birth":
self.person.set_birth_ref(event_ref)
self.event_box.data.remove(event_ref)
if event.get_name() == "Death":
self.person.set_death_ref(event_ref)
self.event_box.data.remove(event_ref)
eref_list = [event_ref for event_ref in self.event_box.data]
self.person.set_event_ref_list(eref_list)
def on_apply_person_clicked(self,obj):
@ -1193,8 +1193,8 @@ class EditPerson:
for i in range(len(list)):
child_handle = list[i]
child = self.db.get_person_from_handle(child_handle)
if child.get_birth_handle():
event = self.db.get_event_from_handle(child.get_birth_handle())
if child.get_birth_ref():
event = self.db.get_event_from_handle(child.get_birth_ref().ref)
child_date = event.get_date_object().get_sort_value()
else:
continue
@ -1213,9 +1213,9 @@ class EditPerson:
return(list)
# Build the person's date string once
event_handle = person.get_birth_handle()
if event_handle:
event = self.db.get_event_from_handle(event_handle)
event_ref = person.get_birth_ref()
if event_ref:
event = self.db.get_event_from_handle(event_ref.ref)
person_bday = event.get_date_object().get_sort_value()
else:
person_bday = 0
@ -1226,9 +1226,9 @@ class EditPerson:
target = index
for i in range(index-1, -1, -1):
other = self.db.get_person_from_handle(list[i])
event_handle = other.get_birth_handle()
if event_handle:
event = self.db.get_event_from_handle(event_handle)
event_ref = other.get_birth_ref()
if event_ref:
event = self.db.get_event_from_handle(event_ref.ref)
other_bday = event.get_date_object().get_sort_value()
if other_bday == 0:
continue;
@ -1241,9 +1241,9 @@ class EditPerson:
if (target == index):
for i in range(index, len(list)):
other = self.db.get_person_from_handle(list[i])
event_handle = other.get_birth_handle()
if event_handle:
event = self.db.get_event_from_handle(event_handle)
event_ref = other.get_birth_ref()
if event_ref:
event = self.db.get_event_from_handle(event_ref.ref)
other_bday = event.get_date_object().get_sort_value()
if other_bday == "99999999":
continue;

View File

@ -977,10 +977,16 @@ class FamilyView:
return
person = self.person
bhandle = person.get_birth_handle()
dhandle = person.get_death_handle()
bd = self.parent.db.get_event_from_handle(bhandle)
dd = self.parent.db.get_event_from_handle(dhandle)
bref = person.get_birth_ref()
dref = person.get_death_ref()
if bref:
bd = self.parent.db.get_event_from_handle(bref.ref)
else:
bd = None
if dref:
dd = self.parent.db.get_event_from_handle(dref.ref)
else:
dd = None
if bd and dd:
n = "%s [%s]\n\t%s %s\n\t%s %s " % (
@ -1596,10 +1602,10 @@ class FamilyView:
for i in range(len(list)):
child_handle = list[i]
child = self.parent.db.get_person_from_handle(child_handle)
birth_handle = child.get_birth_handle()
birth = self.parent.db.get_event_from_handle(birth_handle)
if not birth:
birth_ref = child.get_birth_ref()
if not birth_ref:
continue
birth = self.parent.db.get_event_from_handle(birth_ref.ref)
child_date = birth.get_date_object().get_sort_value()
if child_date == 0:
continue

View File

@ -245,14 +245,14 @@ class EventListBox(ReorderListBox):
self.trans = TransTable.TransTable(self.titles)
self.data = []
if person.get_birth_handle():
event = parent.db.get_event_from_handle(person.get_birth_handle())
if person.get_birth_ref():
event = parent.db.get_event_from_handle(person.get_birth_ref().ref)
self.data.append(event)
if person.get_death_handle():
event = parent.db.get_event_from_handle(person.get_death_handle())
if person.get_death_ref():
event = parent.db.get_event_from_handle(person.get_death_ref().ref)
self.data.append(event)
for val in person.get_event_list():
self.data.append(parent.db.get_event_from_handle(val))
for event_ref in person.get_event_ref_list():
self.data.append(parent.db.get_event_from_handle(event_ref.ref))
eventnames = const.personalEvents

View File

@ -717,16 +717,18 @@ class PedigreeView:
name = NameDisplay.displayer.display(person)
if line_count < 3:
return name
birth = self.db.get_event_from_handle( person.get_birth_handle())
birth_ref = person.get_birth_ref()
bd=""
bp=""
if birth:
if birth_ref:
birth = self.db.get_event_from_handle(birth_ref.ref)
bd = birth.get_date()
bp = self.get_place_name(birth.get_place_handle())
death = self.db.get_event_from_handle( person.get_death_handle())
death_ref = person.get_death_ref()
dd=""
dp=""
if death:
if death_ref:
death = self.db.get_event_from_handle(death_ref.ref)
dd = death.get_date()
dp = self.get_place_name(death.get_place_handle())
if line_count < 5:
@ -800,12 +802,13 @@ def build_detail_string(db,person):
return u"\n%s %s" % (label,ed)
birth_handle = person.get_birth_handle()
if birth_handle:
detail_text += format_event(db, _BORN, db.get_event_from_handle(birth_handle))
birth_ref = person.get_birth_ref()
if birth_ref:
detail_text += format_event(db, _BORN,
db.get_event_from_handle(birth_ref.ref))
else:
for event_handle in person.get_event_list():
event = db.get_event_from_handle(event_handle)
for event_ref in person.get_event_ref_list():
event = db.get_event_from_handle(event_ref.ref)
if event and event.get_name() == "Baptism":
detail_text += format_event(db, _BAPT, event)
break
@ -813,12 +816,13 @@ def build_detail_string(db,person):
detail_text += format_event(db, _CHRI, event)
break
death_handle = person.get_death_handle()
if death_handle:
detail_text += format_event(db, _DIED, db.get_event_from_handle(death_handle))
death_ref = person.get_death_ref()
if death_ref:
detail_text += format_event(db, _DIED,
db.get_event_from_handle(death_ref.ref))
else:
for event_handle in person.get_event_list():
event = db.get_event_from_handle(event_handle)
for event_ref in person.get_event_ref_list():
event = db.get_event_from_handle(event_ref.ref)
if event and event.get_name() == "Burial":
detail_text += format_event(db, _BURI, event)
break

View File

@ -918,14 +918,14 @@ class Person(PrimaryObject,PrivateSourceNote,MediaBase,AttributeBase):
MediaBase.__init__(self)
AttributeBase.__init__(self)
self.primary_name = Name()
self.event_list = []
self.event_ref_list = []
self.family_list = []
self.parent_family_list = []
self.nickname = ""
self.alternate_names = []
self.gender = Person.UNKNOWN
self.death_handle = None
self.birth_handle = None
self.death_ref = None
self.birth_ref = None
self.address_list = []
self.urls = []
self.lds_bapt = None
@ -956,8 +956,8 @@ class Person(PrimaryObject,PrivateSourceNote,MediaBase,AttributeBase):
"""
return (self.handle, self.gramps_id, self.gender,
self.primary_name, self.alternate_names,
unicode(self.nickname), self.death_handle, self.birth_handle,
self.event_list, self.family_list, self.parent_family_list,
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.complete, self.source_list, self.note, self.change,
@ -973,8 +973,8 @@ class Person(PrimaryObject,PrivateSourceNote,MediaBase,AttributeBase):
@type data: tuple
"""
(self.handle, self.gramps_id, self.gender, self.primary_name,
self.alternate_names, self.nickname, self.death_handle,
self.birth_handle, self.event_list, self.family_list,
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.complete, self.source_list, self.note,
@ -982,7 +982,10 @@ class Person(PrimaryObject,PrivateSourceNote,MediaBase,AttributeBase):
def _has_handle_reference(self,classname,handle):
if classname == 'Event':
return handle in self.event_list + [self.birth_handle,self.death_handle]
return handle in [ref.ref for ref in
self.event_ref_list + [self.birth_ref,
self.death_ref]
if ref]
elif classname == 'Family':
return handle in self.family_list + \
[item[0] for item in self.parent_family_list ]
@ -994,13 +997,13 @@ class Person(PrimaryObject,PrivateSourceNote,MediaBase,AttributeBase):
def _remove_handle_references(self,classname,handle_list):
if classname == 'Event':
new_list = [ handle for handle in self.event_list \
if handle not in handle_list ]
self.event_list = new_list
if self.death_handle and self.death_handle in handle_list:
self.death_handle = None
if self.birth_handle and self.birth_handle in handle_list:
self.birth_handle = None
new_list = [ ref for ref in self.event_ref_list \
if ref and ref.ref not in handle_list ]
self.event_ref_list = new_list
if self.death_ref and self.death_ref.ref in handle_list:
self.death_ref = None
if self.birth_ref and self.birth_ref.ref in handle_list:
self.birth_ref = None
elif classname == 'Family':
new_list = [ handle for handle in self.family_list \
if handle not in handle_list ]
@ -1015,13 +1018,15 @@ class Person(PrimaryObject,PrivateSourceNote,MediaBase,AttributeBase):
def _replace_handle_reference(self,classname,old_handle,new_handle):
if classname == 'Event':
while old_handle in self.event_list:
ix = self.event_list.index(old_handle)
self.event_list[ix] = new_handle
if self.death_handle and self.death_handle == old_handle:
self.death_handle = new_handle
if self.birth_handle and self.birth_handle == old_handle:
self.birth_handle = new_handle
handle_list = [ref.ref for ref in self.event_ref_list]
while old_handle in handle_list:
ix = handle_list.index(old_handle)
self.event_ref_list[ix].ref = new_handle
handle_list[ix] = ''
if self.death_ref and self.death_ref.ref == old_handle:
self.death_ref.ref = new_handle
if self.birth_ref and self.birth_ref.ref == old_handle:
self.birth_ref.ref = new_handle
elif classname == 'Family':
while old_handle in self.family_list:
ix = self.family_list.index(old_handle)
@ -1084,9 +1089,9 @@ class Person(PrimaryObject,PrivateSourceNote,MediaBase,AttributeBase):
@rtype: list
"""
ret = []
ret += [('Event',handle) for handle in
self.event_list + [self.birth_handle,self.death_handle]
if handle]
ret += [('Event',ref.ref) for ref in
self.event_ref_list + [self.birth_ref,self.death_ref]
if ref]
ret += [('Family',handle) for handle in self.family_list
+ [item[0] for item in self.parent_family_list]]
return ret
@ -1250,80 +1255,83 @@ class Person(PrimaryObject,PrivateSourceNote,MediaBase,AttributeBase):
"""
return self.gender
def set_birth_handle(self,event_handle):
def set_birth_ref(self,event_ref):
"""
Assigns the birth event to the Person object. This is accomplished
by assigning the handle of a valid L{Event} in the current database.
by assigning the L{EventRef} of the birth event in the current
database.
@param event_handle: handle of the L{Event} to be associated with
@param event_ref: the L{EventRef} object associated with
the Person's birth.
@type event_handle: str
@type event_handle: EventRef
"""
self.birth_handle = event_handle
self.birth_ref = event_ref
def set_death_handle(self,event_handle):
def set_death_ref(self,event_ref):
"""
Assigns the death event to the Person object. This is accomplished
by assigning the handle of a valid L{Event} in the current database.
by assigning the L{EventRef} of the death event in the current
database.
@param event_handle: handle of the L{Event} to be associated with
@param event_ref: the L{EventRef} object associated with
the Person's death.
@type event_handle: str
@type event_handle: EventRef
"""
self.death_handle = event_handle
self.death_ref = event_ref
def get_birth_handle(self):
def get_birth_ref(self):
"""
Returns the database handle for the Person's birth event. This
Returns the L{EventRef} for Person's birth event. This
should correspond to an L{Event} in the database's L{Event} list.
@returns: Returns the birth L{Event} handle or None if no birth
@returns: Returns the birth L{EventRef} or None if no birth
L{Event} has been assigned.
@rtype: str
@rtype: EventRef
"""
return self.birth_handle
return self.birth_ref
def get_death_handle(self):
def get_death_ref(self):
"""
Returns the database handle for the Person's death event. This
Returns the L{EventRef} for the Person's death event. This
should correspond to an L{Event} in the database's L{Event} list.
@returns: Returns the death L{Event} handle or None if no death
@returns: Returns the death L{EventRef} or None if no death
L{Event} has been assigned.
@rtype: str
@rtype: event_ref
"""
return self.death_handle
return self.death_ref
def add_event_handle(self,event_handle):
def add_event_ref(self,event_ref):
"""
Adds the L{Event} to the Person instance's L{Event} list. This is
accomplished by assigning the handle of a valid L{Event} in the
current database.
Adds the L{EventRef} to the Person instance's L{EventRef} list.
This is accomplished by assigning the L{EventRef} of a valid
L{Event} in the current database.
@param event_handle: handle of the L{Event} to be added to the
Person's L{Event} list.
@type event_handle: str
@param event_ref: the L{EventRef} to be added to the
Person's L{EventRef} list.
@type event_ref: EventRef
"""
self.event_list.append(event_handle)
self.event_ref_list.append(event_ref)
def get_event_list(self):
def get_event_ref_list(self):
"""
Returns the list of handles associated with L{Event} instances.
Returns the list of L{EventRef} objects associated with L{Event}
instances.
@returns: Returns the list of L{Event} handles associated with
@returns: Returns the list of L{EventRef} objects associated with
the Person instance.
@rtype: list
"""
return self.event_list
return self.event_ref_list
def set_event_list(self,event_list):
def set_event_ref_list(self,event_ref_list):
"""
Sets the Person instance's L{Event} list to the passed list.
Sets the Person instance's L{EventRef} list to the passed list.
@param event_list: List of valid L{Event} handles
@type event_list: list
@param event_ref_list: List of valid L{EventRef} objects
@type event_ref_list: list
"""
self.event_list = event_list
self.event_ref_list = event_ref_list
def add_family_handle(self,family_handle):
"""
@ -1697,7 +1705,7 @@ class Family(PrimaryObject,SourceNote,MediaBase,AttributeBase):
self.mother_handle = None
self.child_list = []
self.type = Family.MARRIED
self.event_list = []
self.event_ref_list = []
self.lds_seal = None
self.complete = 0
@ -1718,7 +1726,7 @@ class Family(PrimaryObject,SourceNote,MediaBase,AttributeBase):
@rtype: tuple
"""
return (self.handle, self.gramps_id, self.father_handle, self.mother_handle,
self.child_list, self.type, self.event_list,
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)
@ -1729,13 +1737,13 @@ 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_list,
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) = data
def _has_handle_reference(self,classname,handle):
if classname == 'Event':
return handle in self.event_list
return handle in [ref.ref for ref in self.event_ref_list]
elif classname == 'Person':
return handle in self.child_list + [self.father_handle,self.mother_handle]
elif classname == 'Place':
@ -1744,9 +1752,9 @@ class Family(PrimaryObject,SourceNote,MediaBase,AttributeBase):
def _remove_handle_references(self,classname,handle_list):
if classname == 'Event':
new_list = [ handle for handle in self.event_list \
if handle not in handle_list ]
self.event_list = new_list
new_list = [ ref for ref in self.event_ref_list \
if ref.ref not in handle_list ]
self.event_ref_list = new_list
elif classname == 'Person':
new_list = [ handle for handle in self.child_list \
if handle not in handle_list ]
@ -1761,9 +1769,11 @@ class Family(PrimaryObject,SourceNote,MediaBase,AttributeBase):
def _replace_handle_reference(self,classname,old_handle,new_handle):
if classname == 'Event':
while old_handle in self.event_list:
ix = self.event_list.index(old_handle)
self.event_list[ix] = new_handle
handle_list = [ref.ref for ref in self.event_ref_list]
while old_handle in handle_list:
ix = handle_list(old_handle)
self.event_ref_list[ix].ref = new_handle
handle_list[ix] = ''
elif classname == 'Person':
while old_handle in self.child_list:
ix = self.child_list.index(old_handle)
@ -1818,7 +1828,7 @@ class Family(PrimaryObject,SourceNote,MediaBase,AttributeBase):
@rtype: list
"""
ret = []
ret += [('Event',handle) for handle in self.event_list]
ret += [('Event',ref.ref) for ref in self.event_ref_list]
ret += [('Person',handle) for handle in
self.child_list + [self.father_handle,self.mother_handle]
if handle]
@ -1999,36 +2009,37 @@ class Family(PrimaryObject,SourceNote,MediaBase,AttributeBase):
"""
self.child_list = child_list
def add_event_handle(self,event_handle):
def add_event_ref(self,event_ref):
"""
Adds the L{Event} to the Family instance's L{Event} list. This is
accomplished by assigning the handle of a valid L{Event} in the
current database.
Adds the L{EventRef} to the Family instance's L{EventRef} list.
This is accomplished by assigning the L{EventRef} for the valid
L{Event}in the current database.
@param event_handle: handle of the L{Event} to be added to the
Person's L{Event} list.
@type event_handle: str
@param event_ref: the L{EventRef} to be added to the
Person's L{EventRef} list.
@type event_ref: EventRef
"""
self.event_list.append(event_handle)
self.event_ref_list.append(event_ref)
def get_event_list(self) :
def get_event_ref_list(self) :
"""
Returns the list of handles associated with L{Event} instances.
Returns the list of L{EventRef} objects associated with L{Event}
instances.
@returns: Returns the list of L{Event} handles associated with
@returns: Returns the list of L{EventRef} objects associated with
the Family instance.
@rtype: list
"""
return self.event_list
return self.event_ref_list
def set_event_list(self,event_list) :
def set_event_ref_list(self,event_ref_list) :
"""
Sets the Family instance's L{Event} list to the passed list.
Sets the Family instance's L{EventRef} list to the passed list.
@param event_list: List of valid L{Event} handles
@type event_list: list
@param event_ref_list: List of valid L{EventRef} objects
@type event_ref_list: list
"""
self.event_list = event_list
self.event_ref_list = event_ref_list
class Event(PrimaryObject,PrivateSourceNote,MediaBase,DateBase,PlaceBase):
"""
@ -4024,7 +4035,7 @@ class SourceRef(BaseObject,DateBase,PrivacyBase,NoteBase):
else:
return False
class EventRef:
class EventRef(BaseObject,PrivacyBase,NoteBase):
"""
Event reference class.
@ -4046,6 +4057,8 @@ class EventRef:
"""
Creates a new EventRef instance, copying from the source if present.
"""
PrivacyBase.__init__(self)
NoteBase.__init__(self)
if source:
self.ref = source.ref
self.role_int = source.role_int
@ -4055,6 +4068,39 @@ class EventRef:
self.role_int = self.ROLE_CUSTOM
self.role_str = ""
def get_text_data_list(self):
"""
Returns the list of all textual attributes of the object.
@return: Returns the list of all textual attributes of the object.
@rtype: list
"""
return [self.role_str]
def get_text_data_child_list(self):
"""
Returns the list of child objects that may carry textual data.
@return: Returns the list of child objects that may carry textual data.
@rtype: list
"""
if self.note:
return [self.note]
return []
def get_referenced_handles(self):
"""
Returns the list of (classname,handle) tuples for all directly
referenced primary objects.
@return: Returns the list of (classname,handle) tuples for referenced objects.
@rtype: list
"""
if self.ref:
return [('Event',self.ref)]
else:
return []
def get_reference_handle(self):
"""
Returns the handle of the referred Event object.