Add ChildRef class, reorganize RelLib.

svn: r6320
This commit is contained in:
Alex Roitman 2006-04-13 03:15:22 +00:00
parent 0eb3838f92
commit 7a61396025
38 changed files with 696 additions and 469 deletions

View File

@ -2,6 +2,7 @@
* src/plugins/GraphViz.py: Add graph preview based on mime (Bug 1449796)
2006-04-12 Alex Roitman <shura@gramps-project.org>
* various: Add ChildRef class, reorganize RelLib.
* src/plugins/Check.py (Check.__init__): Typo.
2006-04-11 Alex Roitman <shura@gramps-project.org>

View File

@ -699,8 +699,9 @@ class FamilyView(PageView.PersonNavView):
if family:
person = self.dbstate.db.get_person_from_handle(self.dbstate.active.handle)
GrampsDb.add_child_to_family(family, child, (RelLib.Person.CHILD_BIRTH,'')
(RelLib.Person.CHILD_BIRTH,''))
GrampsDb.add_child_to_family(family, child,
(RelLib.ChildRef.CHILD_BIRTH,'')
(RelLib.ChildRef.CHILD_BIRTH,''))
def add_parent_family(self, obj, event, handle):
if event.type == gtk.gdk.BUTTON_PRESS and event.button == 1:

View File

@ -1121,8 +1121,8 @@ class PedigreeView(PageView.PersonNavView):
else:
return
if family_handle:
mrel = m != RelLib.Person.CHILD_BIRTH
frel = f != RelLib.Person.CHILD_BIRTH
mrel = m != RelLib.ChildRef.CHILD_BIRTH
frel = f != RelLib.ChildRef.CHILD_BIRTH
family = self.db.get_family_from_handle(family_handle)
if family != None:

View File

@ -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
@ -799,10 +799,11 @@ class EditFamily(EditPrimary):
for handle in self.obj.get_child_handle_list():
child = self.db.get_person_from_handle(handle)
# fix - relationships need to be extracted from the list
child.add_parent_family_handle(self.obj.handle,
(RelLib.Person.CHILD_BIRTH,''),
(RelLib.Person.CHILD_BIRTH,''),
)
child.add_parent_family_handle(
self.obj.handle,
(RelLib.ChildRef.CHILD_BIRTH,''),
(RelLib.ChildRef.CHILD_BIRTH,''),
)
self.db.commit_person(child,trans)
self.db.add_family(self.obj,trans)
@ -838,10 +839,11 @@ class EditFamily(EditPrimary):
# add the family from children which have been addedna
for handle in new_set.difference(orig_set):
person = self.db.get_person_from_handle(handle)
person.add_parent_family_handle(self.obj.handle,
(RelLib.Person.CHILD_BIRTH,''),
(RelLib.Person.CHILD_BIRTH,''),
)
person.add_parent_family_handle(
self.obj.handle,
(RelLib.ChildRef.CHILD_BIRTH,''),
(RelLib.ChildRef.CHILD_BIRTH,''),
)
self.db.commit_person(person,trans)
if self.object_is_empty():

View File

@ -1448,8 +1448,8 @@ class HaveAltFamilies(Rule):
def apply(self,db,person):
for (fam,rel1,rel2) in person.get_parent_family_handle_list():
if rel1 == RelLib.Person.CHILD_ADOPTED \
or rel2 == RelLib.Person.CHILD_ADOPTED:
if rel1 == RelLib.ChildRef.CHILD_ADOPTED \
or rel2 == RelLib.ChildRef.CHILD_ADOPTED:
return True
return False

View File

@ -33,12 +33,12 @@ import RelLib
#
#-------------------------------------------------------------------------
child_relations = (
(RelLib.Person.CHILD_BIRTH , "Birth"),
(RelLib.Person.CHILD_ADOPTED , "Adopted"),
(RelLib.Person.CHILD_STEPCHILD , "Stepchild"),
(RelLib.Person.CHILD_SPONSORED , "Sponsored"),
(RelLib.Person.CHILD_FOSTER , "Foster"),
(RelLib.Person.CHILD_UNKNOWN , "Unknown"),
(RelLib.ChildRef.CHILD_BIRTH , "Birth"),
(RelLib.ChildRef.CHILD_ADOPTED , "Adopted"),
(RelLib.ChildRef.CHILD_STEPCHILD , "Stepchild"),
(RelLib.ChildRef.CHILD_SPONSORED , "Sponsored"),
(RelLib.ChildRef.CHILD_FOSTER , "Foster"),
(RelLib.ChildRef.CHILD_UNKNOWN , "Unknown"),
)
events = (
@ -175,7 +175,7 @@ url_types = (
# mapping from the tuple collection to the appropriate CUSTOM integer
custom_types = {
child_relations : RelLib.Person.CHILD_CUSTOM,
child_relations : RelLib.ChildRef.CHILD_CUSTOM,
events : RelLib.Event.CUSTOM,
attributes : RelLib.Attribute.CUSTOM,
family_relations : RelLib.Family.CUSTOM,

View File

@ -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
@ -118,8 +118,10 @@ def remove_child_from_family(db, person_handle, family_handle, trans=None):
db.transaction_commit(trans,_("Remove child from family"))
def add_child_to_family(db, family, child, mrel=(RelLib.Person.CHILD_BIRTH,''),
frel=(RelLib.Person.CHILD_BIRTH,''), trans=None):
def add_child_to_family(db, family, child,
mrel=(RelLib.ChildRef.CHILD_BIRTH,''),
frel=(RelLib.ChildRef.CHILD_BIRTH,''),
trans=None):
family.add_child_handle(child.handle)
child.add_parent_family_handle(family.handle, mrel, frel )

View File

@ -128,16 +128,16 @@ file_systems = {
"SMBFS" : _('Networked Windows file system')
}
rel_types = ((RelLib.Person.CHILD_BIRTH,''),
(RelLib.Person.CHILD_UNKNOWN,''),
(RelLib.Person.CHILD_NONE,''))
rel_types = ((RelLib.ChildRef.CHILD_BIRTH,''),
(RelLib.ChildRef.CHILD_UNKNOWN,''),
(RelLib.ChildRef.CHILD_NONE,''))
pedi_type = {
'birth' : (RelLib.Person.CHILD_BIRTH,''),
'natural': (RelLib.Person.CHILD_BIRTH,''),
'step' : (RelLib.Person.CHILD_ADOPTED,''),
'adopted': (RelLib.Person.CHILD_ADOPTED,''),
'foster' : (RelLib.Person.CHILD_FOSTER,''),
'birth' : (RelLib.ChildRef.CHILD_BIRTH,''),
'natural': (RelLib.ChildRef.CHILD_BIRTH,''),
'step' : (RelLib.ChildRef.CHILD_ADOPTED,''),
'adopted': (RelLib.ChildRef.CHILD_ADOPTED,''),
'foster' : (RelLib.ChildRef.CHILD_FOSTER,''),
}
lds_status = {
@ -1045,8 +1045,8 @@ class GedcomParser:
self.barf(level+1)
def parse_ftw_relations(self,level):
mrel = (RelLib.Person.CHILD_BIRTH,'')
frel = (RelLib.Person.CHILD_BIRTH,'')
mrel = (RelLib.ChildRef.CHILD_BIRTH,'')
frel = (RelLib.ChildRef.CHILD_BIRTH,'')
while True:
matches = self.get_next()
@ -1055,17 +1055,17 @@ class GedcomParser:
return (mrel,frel)
# FTW
elif matches[1] == TOKEN__FREL:
frel = pedi_type.get(matches[2].lower(),(RelLib.Person.CHILD_BIRTH,''))
frel = pedi_type.get(matches[2].lower(),(RelLib.ChildRef.CHILD_BIRTH,''))
# FTW
elif matches[1] == TOKEN__MREL:
mrel = pedi_type.get(matches[2].lower(),(RelLib.Person.CHILD_BIRTH,''))
mrel = pedi_type.get(matches[2].lower(),(RelLib.ChildRef.CHILD_BIRTH,''))
elif matches[1] == TOKEN_ADOP:
mrel = (RelLib.Person.CHILD_ADOPTED,'')
frel = (RelLib.Person.CHILD_ADOPTED,'')
mrel = (RelLib.ChildRef.CHILD_ADOPTED,'')
frel = (RelLib.ChildRef.CHILD_ADOPTED,'')
# Legacy
elif matches[1] == TOKEN__STAT:
mrel = (RelLib.Person.CHILD_BIRTH,'')
frel = (RelLib.Person.CHILD_BIRTH,'')
mrel = (RelLib.ChildRef.CHILD_BIRTH,'')
frel = (RelLib.ChildRef.CHILD_BIRTH,'')
# Legacy _PREF
elif matches[1][0] == TOKEN_UNKNOWN:
pass
@ -1239,7 +1239,7 @@ class GedcomParser:
return None
def parse_famc_type(self,level,person):
ftype = (RelLib.Person.CHILD_BIRTH,'')
ftype = (RelLib.ChildRef.CHILD_BIRTH,'')
note = ""
while True:
matches = self.get_next()
@ -1566,8 +1566,8 @@ class GedcomParser:
self.barf(level+1)
def parse_adopt_famc(self,level):
mrel = RelLib.Person.CHILD_ADOPTED
frel = RelLib.Person.CHILD_ADOPTED
mrel = RelLib.ChildRef.CHILD_ADOPTED
frel = RelLib.ChildRef.CHILD_ADOPTED
while True:
matches = self.get_next()
if int(matches[0]) < level:
@ -1575,9 +1575,9 @@ class GedcomParser:
return (mrel,frel)
elif matches[1] == TOKEN_ADOP:
if matches[2] == "HUSB":
mrel = RelLib.Person.CHILD_BIRTH
mrel = RelLib.ChildRef.CHILD_BIRTH
elif matches[2] == "WIFE":
frel = RelLib.Person.CHILD_BIRTH
frel = RelLib.ChildRef.CHILD_BIRTH
else:
self.barf(level+1)
return None
@ -2104,8 +2104,8 @@ class GedcomParser:
else:
if ftype in rel_types:
state.person.add_parent_family_handle(
handle, (RelLib.Person.CHILD_BIRTH,''),
(RelLib.Person.CHILD_BIRTH,''))
handle, (RelLib.ChildRef.CHILD_BIRTH,''),
(RelLib.ChildRef.CHILD_BIRTH,''))
else:
if state.person.get_main_parents_family_handle() == handle:
state.person.set_main_parent_family_handle(None)

View File

@ -932,8 +932,8 @@ class GedcomWriter:
for f in person.get_parent_family_handle_list():
mrel = f[1]
frel = f[2]
if (mrel == RelLib.Person.CHILD_ADOPTED or
frel == RelLib.Person.CHILD_ADOPTED):
if (mrel == RelLib.ChildRef.CHILD_ADOPTED or
frel == RelLib.ChildRef.CHILD_ADOPTED):
fam = f[0]
break
if fam:
@ -976,8 +976,8 @@ class GedcomWriter:
for f in person.get_parent_family_handle_list():
mrel = f[1]
frel = f[2]
if (mrel == RelLib.Person.CHILD_ADOPTED or
frel == RelLib.Person.CHILD_ADOPTED):
if (mrel == RelLib.ChildRef.CHILD_ADOPTED or
frel == RelLib.ChildRef.CHILD_ADOPTED):
fam = f[0]
break
if fam:
@ -1061,7 +1061,7 @@ class GedcomWriter:
if self.flist.has_key(family[0]):
self.writeln("1 FAMC @%s@" % self.fid(family[0]))
if self.adopt == GedcomInfo.ADOPT_PEDI:
if family[1] == RelLib.Person.CHILD_ADOPTED:
if family[1] == RelLib.ChildRef.CHILD_ADOPTED:
self.writeln("2 PEDI Adopted")
for family_handle in person.get_family_handle_list():

View File

@ -414,12 +414,12 @@ class XmlWriter:
self.write_url_list(person.get_url_list(),index+1)
for alt in person.get_parent_family_handle_list():
if alt[1][0] != RelLib.Person.CHILD_BIRTH:
if alt[1][0] != RelLib.ChildRef.CHILD_BIRTH:
mrel=' mrel="%s"' % _ConstXML.str_for_xml(
_ConstXML.child_relations,alt[1])
else:
mrel=''
if alt[2][0] != RelLib.Person.CHILD_BIRTH:
if alt[2][0] != RelLib.ChildRef.CHILD_BIRTH:
frel=' frel="%s"' % _ConstXML.str_for_xml(
_ConstXML.child_relations,alt[2])
else:

View File

@ -44,7 +44,10 @@ pkgdata_PYTHON = \
_SourceRef.py\
_UrlBase.py\
_Url.py\
_Witness.py
_Witness.py\
_SourceBase.py\
_RefBase.py\
_ChildRef.py
pkgpyexecdir = @pkgpyexecdir@/RelLib
pkgpythondir = @pkgpythondir@/RelLib

View File

@ -29,7 +29,9 @@ Address class for GRAMPS
# GRAMPS modules
#
#-------------------------------------------------------------------------
from _PrivateSourceNote import PrivateSourceNote
from _PrivacyBase import PrivacyBase
from _SourceBase import SourceBase
from _NoteBase import NoteBase
from _DateBase import DateBase
from _LocationBase import LocationBase
@ -38,13 +40,15 @@ from _LocationBase import LocationBase
# Address for Person/Repository
#
#-------------------------------------------------------------------------
class Address(PrivateSourceNote,DateBase,LocationBase):
class Address(PrivacyBase,SourceBase,NoteBase,DateBase,LocationBase):
"""Provides address information."""
def __init__(self,source=None):
"""Creates a new Address instance, copying from the source
if provided"""
PrivateSourceNote.__init__(self,source)
PrivacyBase.__init__(self,source)
SourceBase.__init__(self,source)
NoteBase.__init__(self,source)
DateBase.__init__(self,source)
LocationBase.__init__(self,source)
@ -54,15 +58,19 @@ class Address(PrivateSourceNote,DateBase,LocationBase):
self.street = ""
def serialize(self):
return (PrivateSourceNote.serialize(self),
return (PrivacyBase.serialize(self),
SourceBase.serialize(self),
NoteBase.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,
(privacy,source_list,note,date,self.city,self.state,
self.country,self.postal,self.phone,self.street) = data
PrivateSourceNote.unserialize(self,psn)
PrivacyBase.unserialize(self,privacy)
SourceBase.unserialize(self,source_list)
NoteBase.unserialize(self,note)
DateBase.unserialize(self,date)
return self

View File

@ -36,14 +36,16 @@ from warnings import warn
# GRAMPS modules
#
#-------------------------------------------------------------------------
from _PrivateSourceNote import PrivateSourceNote
from _PrivacyBase import PrivacyBase
from _SourceBase import SourceBase
from _NoteBase import NoteBase
#-------------------------------------------------------------------------
#
# Attribute for Person/Family/MediaObject/MediaRef
#
#-------------------------------------------------------------------------
class Attribute(PrivateSourceNote):
class Attribute(PrivacyBase,SourceBase,NoteBase):
"""Provides a simple key/value pair for describing properties. Used
by the Person and Family objects to store descriptive information."""
@ -57,8 +59,12 @@ class Attribute(PrivateSourceNote):
SSN = 6
def __init__(self,source=None):
"""creates a new Attribute object, copying from the source if provided"""
PrivateSourceNote.__init__(self,source)
"""
Creates a new Attribute object, copying from the source if provided.
"""
PrivacyBase.__init__(self,source)
SourceBase.__init__(self,source)
NoteBase.__init__(self,source)
if source:
self.type = source.type
@ -68,12 +74,16 @@ class Attribute(PrivateSourceNote):
self.value = ""
def serialize(self):
return (PrivateSourceNote.serialize(self),
return (PrivacyBase.serialize(self),
SourceBase.serialize(self),
NoteBase.serialize(self),
self.type,self.value)
def unserialize(self,data):
(psn,self.type,self.value) = data
PrivateSourceNote.unserialize(self,psn)
(privacy,source_list,note,self.type,self.value) = data
PrivateBase.unserialize(self,privacy)
SourceBase.unserialize(self,source_list)
NoteBase.unserialize(self,note)
return self
def get_text_data_list(self):

147
src/RelLib/_ChildRef.py Normal file
View File

@ -0,0 +1,147 @@
#
# Gramps - a GTK+/GNOME based genealogy program
#
# Copyright (C) 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: _EventRef.py 6194 2006-03-22 23:03:57Z dallingham $
"""
Child Reference class for GRAMPS.
"""
#-------------------------------------------------------------------------
#
# GRAMPS modules
#
#-------------------------------------------------------------------------
from _BaseObject import BaseObject
from _PrivacyBase import PrivacyBase
from _SourceBase import SourceBase
from _NoteBase import NoteBase
from _RefBase import RefBase
#-------------------------------------------------------------------------
#
# Person References for Person/Family
#
#-------------------------------------------------------------------------
class ChildRef(BaseObject,PrivacyBase,SourceBase,NoteBase,RefBase):
"""
Person reference class.
This class is for keeping information about how the person relates
to another person from the database, if not through family.
Examples would be: godparent, friend, etc.
"""
CHILD_NONE = 0
CHILD_BIRTH = 1
CHILD_ADOPTED = 2
CHILD_STEPCHILD = 3
CHILD_SPONSORED = 4
CHILD_FOSTER = 5
CHILD_UNKNOWN = 6
CHILD_CUSTOM = 7
def __init__(self,source=None):
BaseObject.__init__(self)
PrivacyBase.__init__(self,source)
SourceBase.__init__(self,source)
NoteBase.__init__(self,source)
RefBase.__init__(self)
if source:
self.frel = source.frel
self.mrel = source.mrel
else:
self.frel = (ChildRef.CHILD_BIRTH,'')
self.mrel = (ChildRef.CHILD_BIRTH,'')
def serialize(self):
return (PrivacyBase.serialize(self),
SourceBase.serialize(self),
NoteBase.serialize(self),
RefBase.__init__(self),
self.frel,self.mrel)
def unserialize(self,data):
(privacy,source_list,note,ref,self.frel,self.mrel) = data
PrivateBase.unserialize(self,privacy)
SourceBase.unserialize(self,source_list)
NoteBase.unserialize(self,note)
RefBase.unserialize(self,ref)
return self
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.rel]
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
"""
check_list = self.source_list
if self.note:
check_list.append(self.note)
return check_list
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 [('Person',self.ref)]
else:
return []
def get_handle_referents(self):
"""
Returns the list of child objects which may, directly or through
their children, reference primary objects..
@return: Returns the list of objects refereincing primary objects.
@rtype: list
"""
return self.source_list
def set_mother_relation(self,rel):
"""Sets relation between the person and mother"""
self.mrel = rel
def get_mother_relation(self):
"""Returns the relation between the person and mother"""
return self.mrel
def set_father_relation(self,frel):
"""Sets relation between the person and father"""
self.fmrel = rel
def get_father_relation(self):
"""Returns the relation between the person and father"""
return self.frel

View File

@ -37,7 +37,8 @@ from warnings import warn
#
#-------------------------------------------------------------------------
from _PrimaryObject import PrimaryObject
from _SourceNote import SourceNote
from _SourceBase import SourceBase
from _NoteBase import NoteBase
from _MediaBase import MediaBase
from _DateBase import DateBase
from _PlaceBase import PlaceBase
@ -47,7 +48,7 @@ from _PlaceBase import PlaceBase
# Event class
#
#-------------------------------------------------------------------------
class Event(PrimaryObject,SourceNote,MediaBase,DateBase,PlaceBase):
class Event(PrimaryObject,SourceBase,NoteBase,MediaBase,DateBase,PlaceBase):
"""
Introduction
============
@ -112,7 +113,8 @@ class Event(PrimaryObject,SourceNote,MediaBase,DateBase,PlaceBase):
"""
PrimaryObject.__init__(self,source)
SourceNote.__init__(self,source)
SourceBase.__init__(self,source)
NoteBase.__init__(self,source)
MediaBase.__init__(self,source)
DateBase.__init__(self,source)
PlaceBase.__init__(self,source)
@ -145,7 +147,8 @@ class Event(PrimaryObject,SourceNote,MediaBase,DateBase,PlaceBase):
return (self.handle, self.gramps_id, self.type,
DateBase.serialize(self),
self.description, self.place, self.cause,
SourceNote.serialize(self),
SourceBase.serialize(self),
NoteBase.serialize(self),
MediaBase.serialize(self),
self.change, self.marker, self.private)
@ -159,12 +162,13 @@ class Event(PrimaryObject,SourceNote,MediaBase,DateBase,PlaceBase):
@type data: tuple
"""
(self.handle, self.gramps_id, self.type, date,
self.description, self.place, self.cause, sn,
self.description, self.place, self.cause, source_list, note,
media_list, self.change, self.marker, self.private) = data
DateBase.unserialize(self,date)
MediaBase.unserialize(self,media_list)
SourceNote.unserialize(self,sn)
SourceBase.unserialize(self,source_list)
Note.unserialize(self,note)
def _has_handle_reference(self,classname,handle):
if classname == 'Place':

View File

@ -39,13 +39,14 @@ from warnings import warn
from _BaseObject import BaseObject
from _PrivacyBase import PrivacyBase
from _NoteBase import NoteBase
from _RefBase import RefBase
#-------------------------------------------------------------------------
#
# Event References for Person/Family
#
#-------------------------------------------------------------------------
class EventRef(BaseObject,PrivacyBase,NoteBase):
class EventRef(BaseObject,PrivacyBase,NoteBase,RefBase):
"""
Event reference class.
@ -71,19 +72,25 @@ class EventRef(BaseObject,PrivacyBase,NoteBase):
BaseObject.__init__(self)
PrivacyBase.__init__(self)
NoteBase.__init__(self)
RefBase.__init__(self)
if source:
self.ref = source.ref
self.role = source.role_int
self.role = source.role
else:
self.ref = None
self.role = (EventRef.CUSTOM,"")
def serialize(self):
return (self.private,NoteBase.serialize(self),self.ref,self.role)
return (
PrivacyBase.serialize(self),
NoteBase.serialize(self),
Refbase.serialize(self),
self.role
)
def unserialize(self,data):
(self.private,nb,self.ref,self.role) = data
NoteBase.unserialize(self,nb)
(privacy,note,ref,self.role) = data
PrivacyBase.unserialize(self,privacy)
NoteBase.unserialize(self,note)
RefBase.unserialize(self,ref)
return self
def get_text_data_list(self):
@ -119,18 +126,6 @@ class EventRef(BaseObject,PrivacyBase,NoteBase):
else:
return []
def get_reference_handle(self):
"""
Returns the handle of the referred Event object.
"""
return self.ref
def set_reference_handle(self,handle):
"""
Sets the handle of the referred Event object.
"""
self.ref = handle
def get_role(self):
"""
Returns the tuple corresponding to the preset role.

View File

@ -37,7 +37,8 @@ from warnings import warn
#
#-------------------------------------------------------------------------
from _PrimaryObject import PrimaryObject
from _SourceNote import SourceNote
from _SourceBase import SourceBase
from _NoteBase import NoteBase
from _MediaBase import MediaBase
from _AttributeBase import AttributeBase
from _EventRef import EventRef
@ -48,7 +49,8 @@ from _LdsOrdBase import LdsOrdBase
# Family class
#
#-------------------------------------------------------------------------
class Family(PrimaryObject,SourceNote,MediaBase,AttributeBase,LdsOrdBase):
class Family(PrimaryObject,SourceBase,NoteBase,MediaBase,AttributeBase,
LdsOrdBase):
"""
Introduction
============
@ -83,7 +85,8 @@ class Family(PrimaryObject,SourceNote,MediaBase,AttributeBase,LdsOrdBase):
handle.
"""
PrimaryObject.__init__(self)
SourceNote.__init__(self)
SourceBase.__init__(self)
NoteBase.__init__(self)
MediaBase.__init__(self)
AttributeBase.__init__(self)
LdsOrdBase.__init__(self)
@ -121,7 +124,8 @@ class Family(PrimaryObject,SourceNote,MediaBase,AttributeBase,LdsOrdBase):
MediaBase.serialize(self),
AttributeBase.serialize(self),
LdsOrdBase.serialize(self),
SourceNote.serialize(self),
SourceBase.serialize(self),
NoteBase.serialize(self),
self.change, self.marker, self.private)
def unserialize(self, data):
@ -130,15 +134,16 @@ class Family(PrimaryObject,SourceNote,MediaBase,AttributeBase,LdsOrdBase):
back into the data in a Family structure.
"""
(self.handle, self.gramps_id, self.father_handle, self.mother_handle,
self.child_list, self.type,
event_ref_list, media_list, attribute_list, lds_seal_list, sn,
self.change,self.marker, self.private) = data
self.child_list, self.type, event_ref_list, media_list,
attribute_list, lds_seal_list, source_list, note,
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)
SourceBase.unserialize(self,source_list)
NoteBase.unserialize(self,note)
LdsOrdBase.unserialize(self,lds_seal_list)
def _has_handle_reference(self,classname,handle):

View File

@ -29,7 +29,8 @@ LDS Ordinance class for GRAMPS
# GRAMPS modules
#
#-------------------------------------------------------------------------
from _SourceNote import SourceNote
from _SourceBase import SourceBase
from _NoteBase import NoteBase
from _DateBase import DateBase
from _PlaceBase import PlaceBase
from _PrivacyBase import PrivacyBase
@ -39,7 +40,7 @@ from _PrivacyBase import PrivacyBase
# LDS Ordinance class
#
#-------------------------------------------------------------------------
class LdsOrd(SourceNote,DateBase,PlaceBase,PrivacyBase):
class LdsOrd(SourceBase,NoteBase,DateBase,PlaceBase,PrivacyBase):
"""
Class that contains information about LDS Ordinances. LDS
ordinances are similar to events, but have very specific additional
@ -70,7 +71,8 @@ class LdsOrd(SourceNote,DateBase,PlaceBase,PrivacyBase):
def __init__(self,source=None):
"""Creates a LDS Ordinance instance"""
SourceNote.__init__(self,source)
SourceBase.__init__(self,source)
NoteBase.__init__(self,source)
DateBase.__init__(self,source)
PlaceBase.__init__(self,source)
PrivacyBase.__init__(self,source)
@ -87,15 +89,17 @@ class LdsOrd(SourceNote,DateBase,PlaceBase,PrivacyBase):
self.status = 0
def serialize(self):
return (SourceNote.serialize(self),
return (SourceBase.serialize(self),
NoteBase.serialize(self),
DateBase.serialize(self),
self.type,self.place,
self.famc,self.temple,self.status)
def unserialize(self,data):
(sn,date,self.type,self.place,
(source_list,note,date,self.type,self.place,
self.famc,self.temple,self.status) = data
SourceNote.unserialize(self,sn)
SourceBase.unserialize(self,source_list)
NoteBase.unserialize(self,note)
DateBase.unserialize(self,date)
return self

View File

@ -37,7 +37,8 @@ import os
#
#-------------------------------------------------------------------------
from _PrimaryObject import PrimaryObject
from _SourceNote import SourceNote
from _SourceBase import SourceBase
from _NoteBase import NoteBase
from _DateBase import DateBase
from _AttributeBase import AttributeBase
@ -46,7 +47,7 @@ from _AttributeBase import AttributeBase
# MediaObject class
#
#-------------------------------------------------------------------------
class MediaObject(PrimaryObject,SourceNote,DateBase,AttributeBase):
class MediaObject(PrimaryObject,SourceBase,NoteBase,DateBase,AttributeBase):
"""
Containter for information about an image file, including location,
description and privacy
@ -61,7 +62,8 @@ class MediaObject(PrimaryObject,SourceNote,DateBase,AttributeBase):
@type source: MediaObject
"""
PrimaryObject.__init__(self,source)
SourceNote.__init__(self,source)
SourceBase.__init__(self,source)
NoteBase.__init__(self,source)
DateBase.__init__(self,source)
AttributeBase.__init__(self,source)
@ -96,7 +98,8 @@ class MediaObject(PrimaryObject,SourceNote,DateBase,AttributeBase):
"""
return (self.handle, self.gramps_id, self.path, self.mime, self.desc,
AttributeBase.serialize(self),
SourceNote.serialize(self),
SourceBase.serialize(self),
NoteBase.serialize(self),
self.change,
DateBase.serialize(self), self.marker, self.private)
@ -109,11 +112,12 @@ class MediaObject(PrimaryObject,SourceNote,DateBase,AttributeBase):
@type data: tuple
"""
(self.handle, self.gramps_id, self.path, self.mime, self.desc,
attribute_list, sn, self.change,
attribute_list, source_list, note, self.change,
date, self.marker, self.private) = data
AttributeBase.unserialize(self,attribute_list)
SourceNote.unserialize(self,sn)
SourceBase.unserialize(self,source_list)
NoteBase.unserialize(self,note)
DateBase.unserialize(self,date)
def get_text_data_list(self):

View File

@ -29,7 +29,11 @@ Media Reference class for GRAMPS
# GRAMPS modules
#
#-------------------------------------------------------------------------
from _PrivateSourceNote import PrivateSourceNote
from _BaseObject import BaseObject
from _PrivacyBase import PrivacyBase
from _SourceBase import SourceBase
from _NoteBase import NoteBase
from _RefBase import RefBase
from _AttributeBase import AttributeBase
#-------------------------------------------------------------------------
@ -37,29 +41,38 @@ from _AttributeBase import AttributeBase
# MediaObject References for Person/Place/Source
#
#-------------------------------------------------------------------------
class MediaRef(PrivateSourceNote,AttributeBase):
class MediaRef(BaseObject,PrivacyBase,SourceBase,NoteBase,RefBase,
AttributeBase):
"""Media reference class"""
def __init__(self,source=None):
PrivateSourceNote.__init__(self,source)
BaseObject.__init__(self)
PrivacyBase.__init__(self,source)
SourceBase.__init__(self,source)
NoteBase.__init__(self,source)
RefBase.__init__(self)
AttributeBase.__init__(self,source)
if source:
self.ref = source.ref
self.rect = source.rect
else:
self.ref = None
self.rect = None
def serialize(self):
return (PrivateSourceNote.serialize(self),
return (PrivacyBase.serialize(self),
SourceBase.serialize(self),
NoteBase.serialize(self),
AttributeBase.serialize(self),
self.ref,self.rect)
Refbase.serialize(self),
self.rect)
def unserialize(self,data):
(psn,attribute_list,self.ref,self.rect) = data
PrivateSourceNote.unserialize(self,psn)
(privacy,source_list,note,attribute_list,ref,self.rect) = data
PrivateBase.unserialize(self,privacy)
SourceBase.unserialize(self,source_list)
NoteBase.unserialize(self,note)
AttributeBase.unserialize(self,attribute_list)
RefBase.unserialize(self,ref)
return self
def get_text_data_child_list(self):
@ -113,9 +126,3 @@ class MediaRef(PrivateSourceNote,AttributeBase):
def get_rectangle(self):
"""Returns the subsection of an image"""
return self.rect
def set_reference_handle(self,obj_id):
self.ref = obj_id
def get_reference_handle(self):
return self.ref

View File

@ -36,7 +36,9 @@ from warnings import warn
# GRAMPS modules
#
#-------------------------------------------------------------------------
from _PrivateSourceNote import PrivateSourceNote
from _PrivacyBase import PrivacyBase
from _SourceBase import SourceBase
from _NoteBase import NoteBase
from _DateBase import DateBase
#-------------------------------------------------------------------------
@ -44,7 +46,7 @@ from _DateBase import DateBase
# Personal Name
#
#-------------------------------------------------------------------------
class Name(PrivateSourceNote,DateBase):
class Name(PrivacyBase,SourceBase,NoteBase,DateBase):
"""
Provides name information about a person.
@ -66,12 +68,18 @@ class Name(PrivateSourceNote,DateBase):
def __init__(self,source=None,data=None):
"""creates a new Name instance, copying from the source if provided"""
if data:
(psn,date,
(privacy,source_list,note,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
PrivateBase.unserialize(self,privacy)
SourceBase.unserialize(self,source_list)
NoteBase.unserialize(self,note)
DateBase.unserialize(self,date)
elif source:
PrivateSourceNote.__init__(self,source)
PrivacyBase.__init__(self,source)
SourceBase.__init__(self,source)
NoteBase.__init__(self,source)
DateBase.__init__(self,source)
self.first_name = source.first_name
self.surname = source.surname
@ -85,7 +93,9 @@ class Name(PrivateSourceNote,DateBase):
self.sort_as = source.sort_as
self.display_as = source.display_as
else:
PrivateSourceNote.__init__(self,source)
PrivacyBase.__init__(self,source)
SourceBase.__init__(self,source)
NoteBase.__init__(self,source)
DateBase.__init__(self,source)
self.first_name = ""
self.surname = ""
@ -100,18 +110,22 @@ class Name(PrivateSourceNote,DateBase):
self.display_as = self.DEF
def serialize(self):
return (PrivateSourceNote.serialize(self),
return (PrivacyBase.serialize(self),
SourceBase.serialize(self),
NoteBase.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,
(privacy,source_list,note,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)
PrivateBase.unserialize(self,privacy)
SourceBase.unserialize(self,source_list)
NoteBase.unserialize(self,note)
DateBase.unserialize(self,date)
return self

View File

@ -37,7 +37,8 @@ from warnings import warn
#
#-------------------------------------------------------------------------
from _PrimaryObject import PrimaryObject
from _SourceNote import SourceNote
from _SourceBase import SourceBase
from _NoteBase import NoteBase
from _MediaBase import MediaBase
from _AttributeBase import AttributeBase
from _AddressBase import AddressBase
@ -52,8 +53,8 @@ from _PersonRef import PersonRef
# Person class
#
#-------------------------------------------------------------------------
class Person(PrimaryObject, SourceNote,
MediaBase, AttributeBase, AddressBase, UrlBase, LdsOrdBase):
class Person(PrimaryObject,SourceBase,NoteBase,MediaBase,
AttributeBase,AddressBase,UrlBase,LdsOrdBase):
"""
Introduction
============
@ -81,15 +82,6 @@ class Person(PrimaryObject, SourceNote,
MALE = 1
FEMALE = 0
CHILD_NONE = 0
CHILD_BIRTH = 1
CHILD_ADOPTED = 2
CHILD_STEPCHILD = 3
CHILD_SPONSORED = 4
CHILD_FOSTER = 5
CHILD_UNKNOWN = 6
CHILD_CUSTOM = 7
def __init__(self, data=None):
"""
Creates a new Person instance. After initialization, most
@ -97,7 +89,8 @@ class Person(PrimaryObject, SourceNote,
handle.
"""
PrimaryObject.__init__(self)
SourceNote.__init__(self)
SourceBase.__init__(self)
NoteBase.__init__(self)
MediaBase.__init__(self)
AttributeBase.__init__(self)
AddressBase.__init__(self)
@ -163,11 +156,12 @@ class Person(PrimaryObject, SourceNote,
AttributeBase.serialize(self), # 13
UrlBase.serialize(self), # 14
LdsOrdBase.serialize(self), # 15
SourceNote.serialize(self), # 16
self.change, # 17
self.marker, # 18
self.private, # 19
[pr.serialize() for pr in self.person_ref_list] # 20
SourceBase.serialize(self), # 16
NoteBase.serialize(self), # 17
self.change, # 18
self.marker, # 19
self.private, # 20
[pr.serialize() for pr in self.person_ref_list] # 21
)
def unserialize(self, data):
@ -196,11 +190,12 @@ class Person(PrimaryObject, SourceNote,
attribute_list, # 13
urls, # 14
lds_ord_list, # 15
sn, # 16
self.change, # 17
self.marker, # 18
self.private, # 19
person_ref_list, # 20
source_list, # 16
note, # 17
self.change, # 18
self.marker, # 19
self.private, # 20
person_ref_list, # 21
) = data
self.primary_name.unserialize(primary_name)
@ -219,7 +214,8 @@ class Person(PrimaryObject, SourceNote,
AddressBase.unserialize(self, address_list)
AttributeBase.unserialize(self, attribute_list)
UrlBase.unserialize(self, urls)
SourceNote.unserialize(self, sn)
SourceBase.unserialize(self, source_list)
NoteBase.unserialize(self, note)
def _has_handle_reference(self, classname, handle):
if classname == 'Event':
@ -230,8 +226,7 @@ class Person(PrimaryObject, SourceNote,
elif classname == 'Person':
return handle in [ref.ref for ref in self.person_ref_list]
elif classname == 'Family':
return handle in self.family_list + \
[item[0] for item in self.parent_family_list ]
return handle in (self.family_list + self.parent_family_list)
elif classname == 'Place':
return handle in self.lds_ord_list
return False
@ -253,8 +248,8 @@ class Person(PrimaryObject, SourceNote,
new_list = [ handle for handle in self.family_list \
if handle not in handle_list ]
self.family_list = new_list
new_list = [ item for item in self.parent_family_list \
if item[0] not in handle_list ]
new_list = [ handle for handle in self.parent_family_list \
if handle not in handle_list ]
self.parent_family_list = new_list
elif classname == 'Place':
for ordinance in self.lds_ord_list:
@ -283,13 +278,9 @@ class Person(PrimaryObject, SourceNote,
ix = self.family_list.index(old_handle)
self.family_list[ix] = new_handle
new_list = []
for item in self.parent_family_list:
if item[0] == old_handle:
new_list.append((new_handle, item[1], item[2]))
else:
new_list.append(item)
self.parent_family_list = new_list
while old_handle in self.parent_family_list:
ix = self.parent_family_list.index(old_handle)
self.parent_family_list[ix] = new_handle
elif classname == 'Place':
for ordinance in self.lds_ord_list:
if ordinance.place == old_handle:
@ -338,8 +329,8 @@ class Person(PrimaryObject, SourceNote,
@return: Returns the list of (classname, handle) tuples for referenced objects.
@rtype: list
"""
return [('Family', handle) for handle in self.family_list
+ [item[0] for item in self.parent_family_list]]
return [('Family', handle) for handle in
(self.family_list + self.parent_family_list)]
def get_handle_referents(self):
"""
@ -684,7 +675,7 @@ class Person(PrimaryObject, SourceNote,
"""
return self.parent_family_list
def add_parent_family_handle(self, family_handle, mrel, frel):
def add_parent_family_handle(self, family_handle):
"""
Adds the L{Family} handle to the Person instance's list of
families in which it is a child. This is accomplished by
@ -698,29 +689,7 @@ class Person(PrimaryObject, SourceNote,
@param family_handle: handle of the L{Family} to be added to the
Person's L{Family} list.
@type family_handle: str
@param mrel: relationship between the Person and its mother
@type mrel: tuple
@param frel: relationship between the Person and its father
@type frel: tuple
"""
if not type(mrel) == tuple:
if mrel in range(0, 8):
warn( "add_parent_family_handle now takes a tuple",
DeprecationWarning, 2)
# Wrapper for old API
# remove when transitition done.
mrel = (mrel, '')
else:
assert type(mrel) == tuple
if not type(frel) == tuple:
if frel in range(0, 8):
warn( "add_parent_family_handle now takes a tuple",
DeprecationWarning, 2)
# Wrapper for old API
# remove when transitition done.
frel = (frel, '')
else:
assert type(frel) == tuple
self.parent_family_list.append((family_handle, mrel, frel))
def clear_parent_family_handle_list(self):
@ -744,52 +713,11 @@ class Person(PrimaryObject, SourceNote,
list.
@rtype: tuple
"""
for f in self.parent_family_list[:]:
if f[0] == family_handle:
self.parent_family_list.remove(f)
return f
if family_handle in self.parent_family_list:
self.parent_family_list.remove(family_handle)
return True
else:
return None
def change_parent_family_handle(self, family_handle, mrel, frel):
"""
Changes the relationships of the L{Family} handle in the Person
instance's list of families in which it is a child. The handle
is assumed to already be in the list.
@param family_handle: handle of the L{Family} to be added to the
Person's L{Family} list.
@type family_handle: str
@param mrel: relationship between the Person and its mother
@type mrel: tuple
@param frel: relationship between the Person and its father
@type frel: tuple
"""
index=0
for f in self.parent_family_list[:]:
if f[0] == family_handle:
self.parent_family_list[index] = (family_handle, mrel, frel)
return True
index += 1
return False
def get_parent_family(self, family_handle):
"""
Finds the L{Family} and relationships associated with passed
family_handle.
@param family_handle: L{Family} handle used to search the parent
family list.
@type family_handle: str
@return: Returns a tuple consisting of the L{Family} handle, the
mother relationship, and father relationship
@rtype: tuple
"""
for f in self.parent_family_list:
if f[0] == family_handle:
return f
else:
return None
return False
def set_main_parent_family_handle(self, family_handle):
"""
@ -805,9 +733,9 @@ class Person(PrimaryObject, SourceNote,
@return: Returns True if the assignment has successful
@rtype: bool
"""
f = self.remove_parent_family_handle(family_handle)
if f:
self.parent_family_list = [f] + self.parent_family_list
if family_handle in self.parent_family_list:
self.parent_family_list.remove(family_handle)
self.parent_family_list = [family_handle] + self.parent_family_list
return True
else:
return False
@ -824,7 +752,7 @@ class Person(PrimaryObject, SourceNote,
if len(self.parent_family_list) == 0:
return None
else:
return self.parent_family_list[0][0]
return self.parent_family_list[0]
def add_person_ref(self,person_ref):
"""

View File

@ -29,14 +29,18 @@ Person Reference class for GRAMPS.
# GRAMPS modules
#
#-------------------------------------------------------------------------
from _PrivateSourceNote import PrivateSourceNote
from _BaseObject import BaseObject
from _PrivacyBase import PrivacyBase
from _SourceBase import SourceBase
from _NoteBase import NoteBase
from _RefBase import RefBase
#-------------------------------------------------------------------------
#
# Person References for Person/Family
#
#-------------------------------------------------------------------------
class PersonRef(PrivateSourceNote):
class PersonRef(BaseObject,PrivacyBase,SourceBase,NoteBase,RefBase):
"""
Person reference class.
@ -46,20 +50,29 @@ class PersonRef(PrivateSourceNote):
"""
def __init__(self,source=None):
PrivateSourceNote.__init__(self,source)
BaseObject.__init__(self)
PrivacyBase.__init__(self,source)
SourceBase.__init__(self,source)
NoteBase.__init__(self,source)
RefBase.__init__(self)
if source:
self.ref = source.ref
self.rel = source.rel
else:
self.ref = None
self.rel = ''
def serialize(self):
return (PrivateSourceNote.serialize(self),self.ref,self.rel)
return (PrivacyBase.serialize(self),
SourceBase.serialize(self),
NoteBase.serialize(self),
RefBase.__init__(self),
self.rel)
def unserialize(self,data):
(psn,self.ref,self.rel) = data
PrivateSourceNote.unserialize(self,psn)
(privacy,source_list,note,ref,self.rel) = data
PrivateBase.unserialize(self,privacy)
SourceBase.unserialize(self,source_list)
NoteBase.unserialize(self,note)
RefBase.unserialize(self,ref)
return self
def get_text_data_list(self):
@ -113,9 +126,3 @@ class PersonRef(PrivateSourceNote):
def get_relation(self):
"""Returns the relation to a person"""
return self.rel
def set_reference_handle(self,obj_id):
self.ref = obj_id
def get_reference_handle(self):
return self.ref

View File

@ -30,7 +30,8 @@ Place object for GRAMPS
#
#-------------------------------------------------------------------------
from _PrimaryObject import PrimaryObject
from _SourceNote import SourceNote
from _SourceBase import SourceBase
from _NoteBase import NoteBase
from _MediaBase import MediaBase
from _UrlBase import UrlBase
from _Location import Location
@ -40,7 +41,7 @@ from _Location import Location
# Place class
#
#-------------------------------------------------------------------------
class Place(PrimaryObject,SourceNote,MediaBase,UrlBase):
class Place(PrimaryObject,SourceBase,NoteBase,MediaBase,UrlBase):
"""
Contains information related to a place, including multiple address
information (since place names can change with time), longitude, latitude,
@ -55,7 +56,8 @@ class Place(PrimaryObject,SourceNote,MediaBase,UrlBase):
@type source: Place
"""
PrimaryObject.__init__(self,source)
SourceNote.__init__(self,source)
SourceBase.__init__(self,source)
NoteBase.__init__(self,source)
MediaBase.__init__(self,source)
UrlBase.__init__(self,source)
if source:
@ -96,7 +98,8 @@ class Place(PrimaryObject,SourceNote,MediaBase,UrlBase):
main_loc, [al.serialize() for al in self.alt_loc],
UrlBase.serialize(self),
MediaBase.serialize(self),
SourceNote.serialize(self),
SourceBase.serialize(self),
NoteBase.serialize(self),
self.change, self.marker,self.private)
def unserialize(self,data):
@ -109,7 +112,7 @@ class Place(PrimaryObject,SourceNote,MediaBase,UrlBase):
@type data: tuple
"""
(self.handle, self.gramps_id, self.title, self.long, self.lat,
main_loc, alt_loc, urls, media_list, sn,
main_loc, alt_loc, urls, media_list, source_list, note,
self.change, self.marker, self.private) = data
if main_loc == None:
@ -119,7 +122,8 @@ class Place(PrimaryObject,SourceNote,MediaBase,UrlBase):
self.alt_loc = [Location().unserialize(al) for al in alt_loc]
UrlBase.unserialize(self,urls)
MediaBase.unserialize(self,media_list)
SourceNote.unserialize(self,sn)
SourceBase.unserialize(self,source_list)
NoteBase.unserialize(self,note)
def get_text_data_list(self):
"""

View File

@ -39,7 +39,7 @@ import GrampsLocale
#-------------------------------------------------------------------------
from _BaseObject import BaseObject
from _PrivacyBase import PrivacyBase
from _SourceNote import SourceNote
from _SourceBase import SourceBase
from _MediaBase import MediaBase
#-------------------------------------------------------------------------
@ -163,7 +163,7 @@ class PrimaryObject(BaseObject,PrivacyBase):
@return: Returns whether the object has reference to this handle of this object type.
@rtype: bool
"""
if classname == 'Source' and isinstance(self,SourceNote):
if classname == 'Source' and isinstance(self,SourceBase):
return self.has_source_reference(handle)
elif classname == 'MediaObject' and isinstance(self,MediaBase):
return self.has_media_reference(handle)
@ -179,7 +179,7 @@ class PrimaryObject(BaseObject,PrivacyBase):
@param handle_list: The list of handles to be removed.
@type handle_list: str
"""
if classname == 'Source' and isinstance(self,SourceNote):
if classname == 'Source' and isinstance(self,SourceBase):
self.remove_source_references(handle_list)
elif classname == 'MediaObject' and isinstance(self,MediaBase):
self.remove_media_references(handle_list)
@ -197,7 +197,7 @@ class PrimaryObject(BaseObject,PrivacyBase):
@param new_handle: The handle to replace the old one with.
@type new_handle: str
"""
if classname == 'Source' and isinstance(self,SourceNote):
if classname == 'Source' and isinstance(self,SourceBase):
self.replace_source_references(old_handle,new_handle)
elif classname == 'MediaObject' and isinstance(self,MediaBase):
self.replace_media_references(old_handle,new_handle)

View File

@ -48,6 +48,13 @@ class PrivacyBase:
else:
self.private = False
def serialize(self):
return self.private
def unserialize(self,data):
self.private = data
return self
def set_privacy(self,val):
"""
Sets or clears the privacy flag of the data

View File

@ -24,37 +24,12 @@
PrivateSourceNote class for GRAMPS
"""
#-------------------------------------------------------------------------
#
# GRAMPS modules
#
#-------------------------------------------------------------------------
from _SourceNote import SourceNote
from _PrivacyBase import PrivacyBase
#-------------------------------------------------------------------------
#
# PrivateSourceNote class
#
#-------------------------------------------------------------------------
class PrivateSourceNote(SourceNote,PrivacyBase):
"""
Same as SourceNote, plus the privacy capabilities.
"""
def __init__(self,source=None):
"""
Initialize a PrivateSourceNote. If the source is not None, then object
is initialized from values of the source object.
@param source: Object used to initialize the new object
@type source: PrivateSourceNote
"""
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)
# FIXME: this class is only present to enable db upgrade
def __init__(self):
pass

66
src/RelLib/_RefBase.py Normal file
View File

@ -0,0 +1,66 @@
#
# Gramps - a GTK+/GNOME based genealogy program
#
# Copyright (C) 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: _EventRef.py 6194 2006-03-22 23:03:57Z dallingham $
"""
Base Reference class for GRAMPS.
"""
#-------------------------------------------------------------------------
#
# RefBase class
#
#-------------------------------------------------------------------------
class RefBase:
"""
Base reference class to manage references to other objects.
Any *Ref class should derive from this class.
"""
def __init__(self,source=None):
if source:
self.ref = source.ref
else:
self.ref = None
def serialize(self):
return self.ref
def unserialize(self,data):
self.ref = str(data)
return self
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
"""
assert False, "Must be overridden in the derived class"
def set_reference_handle(self,val):
self.ref = val
def get_reference_handle(self):
return self.ref

View File

@ -31,13 +31,14 @@ Repository Reference class for GRAMPS
#-------------------------------------------------------------------------
from _BaseObject import BaseObject
from _NoteBase import NoteBase
from _RefBase import RefBase
#-------------------------------------------------------------------------
#
# Repository Reference for Sources
#
#-------------------------------------------------------------------------
class RepoRef(BaseObject,NoteBase):
class RepoRef(BaseObject,NoteBase,RefBase):
"""
Repository reference class.
"""
@ -59,23 +60,26 @@ class RepoRef(BaseObject,NoteBase):
VIDEO = 13
def __init__(self,source=None):
BaseObject.__init__(self)
NoteBase.__init__(self)
RefBase.__init__(self)
if source:
self.ref = source.ref
self.call_number = source.call_number
self.media_type = source.media_type
else:
self.ref = None
self.call_number = ""
self.media_type = (RepoRef.CUSTOM,"")
def serialize(self):
return (NoteBase.serialize(self),
self.ref,self.call_number,self.media_type)
return (
NoteBase.serialize(self),
Refbase.serialize(self),
self.call_number,self.media_type)
def unserialize(self,data):
(note,self.ref,self.call_number,self.media_type) = data
(note,ref,self.call_number,self.media_type) = data
NoteBase.unserialize(self,note)
RefBase.unserialize(self,ref)
return self
def get_text_data_list(self):
@ -111,12 +115,6 @@ class RepoRef(BaseObject,NoteBase):
else:
return []
def set_reference_handle(self,ref):
self.ref = ref
def get_reference_handle(self):
return self.ref
def set_call_number(self,number):
self.call_number = number

155
src/RelLib/_SourceBase.py Normal file
View File

@ -0,0 +1,155 @@
#
# Gramps - a GTK+/GNOME based genealogy program
#
# Copyright (C) 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: _SourceNote.py 5875 2006-02-03 22:03:53Z rshura $
"""
SourceBase class for GRAMPS
"""
#-------------------------------------------------------------------------
#
# GRAMPS modules
#
#-------------------------------------------------------------------------
from _SourceRef import SourceRef
#-------------------------------------------------------------------------
#
# SourceBase classes
#
#-------------------------------------------------------------------------
class SourceBase:
"""
Base class for storing source references
"""
def __init__(self,source=None):
"""
Create a new SourceBase, copying from source if not None
@param source: Object used to initialize the new object
@type source: SourceBase
"""
if source:
self.source_list = [SourceRef(sref) for sref in source.source_list]
else:
self.source_list = []
def serialize(self):
return [sref.serialize() for sref in self.source_list]
def unserialize(self,data):
self.source_list = [SourceRef().unserialize(item) for item in data]
def add_source_reference(self,src_ref) :
"""
Adds a source reference to this object.
@param src_ref: The source reference to be added to the
SourceNote's list of source references.
@type src_ref: L{SourceRef}
"""
self.source_list.append(src_ref)
def get_source_references(self) :
"""
Returns the list of source references associated with the object.
@return: Returns the list of L{SourceRef} objects assocated with
the object.
@rtype: list
"""
return self.source_list
def get_sourcref_child_list(self):
"""
Returns the list of child secondary objects that may refer sources.
@return: Returns the list of child secondary child objects that may refer sources.
@rtype: list
"""
return []
def has_source_reference(self,src_handle) :
"""
Returns True if the object or any of it's child objects has reference
to this source handle.
@param src_handle: The source handle to be checked.
@type src_handle: str
@return: Returns whether the object or any of it's child objects has reference to this source handle.
@rtype: bool
"""
for src_ref in self.source_list:
# Using direct access here, not the getter method -- efficiency!
if src_ref.ref == src_handle:
return True
for item in self.get_sourcref_child_list():
if item.has_source_reference(src_handle):
return True
return False
def remove_source_references(self,src_handle_list):
"""
Removes references to all source handles in the list
in this object and all child objects.
@param src_handle_list: The list of source handles to be removed.
@type src_handle_list: list
"""
new_source_list = [ src_ref for src_ref in self.source_list \
if src_ref.ref not in src_handle_list ]
self.source_list = new_source_list
for item in self.get_sourcref_child_list():
item.remove_source_references(src_handle_list)
def replace_source_references(self,old_handle,new_handle):
"""
Replaces references to source handles in the list
in this object and all child objects.
@param old_handle: The source handle to be replaced.
@type old_handle: str
@param new_handle: The source handle to replace the old one with.
@type new_handle: str
"""
refs_list = [ src_ref.ref for src_ref in self.source_list ]
n_replace = refs_list.count(old_handle)
for ix_replace in xrange(n_replace):
ix = refs_list.index(old_handle)
self.source_list[ix].ref = new_handle
refs_list[ix] = new_handle
for item in self.get_sourcref_child_list():
item.replace_source_references(old_handle,new_handle)
def set_source_reference_list(self,src_ref_list) :
"""
Assigns the passed list to the object's list of source references.
@param src_ref_list: List of source references to ba associated
with the object
@type src_ref_list: list of L{SourceRef} instances
"""
self.source_list = src_ref_list

View File

@ -24,140 +24,12 @@
SourceNote class for GRAMPS
"""
#-------------------------------------------------------------------------
#
# GRAMPS modules
#
#-------------------------------------------------------------------------
from _BaseObject import BaseObject
from _NoteBase import NoteBase
from _SourceRef import SourceRef
#-------------------------------------------------------------------------
#
# SourceNote classes
#
#-------------------------------------------------------------------------
class SourceNote(BaseObject,NoteBase):
"""
Base class for storing source references and notes
"""
def __init__(self,source=None):
"""
Create a new SourceNote, copying from source if not None
@param source: Object used to initialize the new object
@type source: SourceNote
"""
BaseObject.__init__(self)
NoteBase.__init__(self,source)
if source:
self.source_list = [SourceRef(sref) for sref in source.source_list]
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.
@param src_ref: The source reference to be added to the
SourceNote's list of source references.
@type src_ref: L{SourceRef}
"""
self.source_list.append(src_ref)
def get_source_references(self) :
"""
Returns the list of source references associated with the object.
@return: Returns the list of L{SourceRef} objects assocated with
the object.
@rtype: list
"""
return self.source_list
def get_sourcref_child_list(self):
"""
Returns the list of child secondary objects that may refer sources.
@return: Returns the list of child secondary child objects that may refer sources.
@rtype: list
"""
return []
def has_source_reference(self,src_handle) :
"""
Returns True if the object or any of it's child objects has reference
to this source handle.
@param src_handle: The source handle to be checked.
@type src_handle: str
@return: Returns whether the object or any of it's child objects has reference to this source handle.
@rtype: bool
"""
for src_ref in self.source_list:
# Using direct access here, not the getter method -- efficiency!
if src_ref.ref == src_handle:
return True
for item in self.get_sourcref_child_list():
if item.has_source_reference(src_handle):
return True
return False
def remove_source_references(self,src_handle_list):
"""
Removes references to all source handles in the list
in this object and all child objects.
@param src_handle_list: The list of source handles to be removed.
@type src_handle_list: list
"""
new_source_list = [ src_ref for src_ref in self.source_list \
if src_ref.ref not in src_handle_list ]
self.source_list = new_source_list
for item in self.get_sourcref_child_list():
item.remove_source_references(src_handle_list)
def replace_source_references(self,old_handle,new_handle):
"""
Replaces references to source handles in the list
in this object and all child objects.
@param old_handle: The source handle to be replaced.
@type old_handle: str
@param new_handle: The source handle to replace the old one with.
@type new_handle: str
"""
refs_list = [ src_ref.ref for src_ref in self.source_list ]
n_replace = refs_list.count(old_handle)
for ix_replace in xrange(n_replace):
ix = refs_list.index(old_handle)
self.source_list[ix].ref = new_handle
refs_list[ix] = new_handle
for item in self.get_sourcref_child_list():
item.replace_source_references(old_handle,new_handle)
def set_source_reference_list(self,src_ref_list) :
"""
Assigns the passed list to the object's list of source references.
@param src_ref_list: List of source references to ba associated
with the object
@type src_ref_list: list of L{SourceRef} instances
"""
self.source_list = src_ref_list
class SourceNote:
# FIXME: this class is only present to enable db upgrade
def __init__(self):
pass

View File

@ -33,6 +33,7 @@ from _BaseObject import BaseObject
from _DateBase import DateBase
from _PrivacyBase import PrivacyBase
from _NoteBase import NoteBase
from _RefBase import RefBase
from _Note import Note
#-------------------------------------------------------------------------
@ -40,7 +41,7 @@ from _Note import Note
# Source References for all primary objects
#
#-------------------------------------------------------------------------
class SourceRef(BaseObject,DateBase,PrivacyBase,NoteBase):
class SourceRef(BaseObject,DateBase,PrivacyBase,NoteBase,RefBase):
"""Source reference, containing detailed information about how a
referenced source relates to it"""
@ -56,28 +57,31 @@ class SourceRef(BaseObject,DateBase,PrivacyBase,NoteBase):
DateBase.__init__(self,source)
PrivacyBase.__init__(self,source)
NoteBase.__init__(self,source)
RefBase.__init__(self)
if source:
self.confidence = source.confidence
self.ref = source.ref
self.page = source.page
self.text = source.text
else:
self.confidence = SourceRef.CONF_NORMAL
self.ref = None
self.page = ""
self.note = Note()
self.text = ""
def serialize(self):
return (DateBase.serialize(self),self.private,
return (DateBase.serialize(self),
PrivacyBase.serialize(self),
NoteBase.serialize(self),
self.confidence,self.ref,self.page,self.text)
self.confidence,
Refbase.serialize(self),
self.page,self.text)
def unserialize(self,data):
(date,self.private,nb,
self.confidence,self.ref,self.page,self.text) = data
(date,privacy,note,
self.confidence,ref,self.page,self.text) = data
DateBase.unserialize(self,date)
NoteBase.unserialize(self,nb)
PrivacyBase.unserialize(self,privacy)
NoteBase.unserialize(self,note)
RefBase.unserialize(self,ref)
return self
def get_text_data_list(self):

View File

@ -41,6 +41,7 @@ from _RepoRef import RepoRef
from _SourceRef import SourceRef
from _Url import Url
from _Witness import Witness
from _ChildRef import ChildRef
# Primary objects
from _PrimaryObject import PrimaryObject

View File

@ -72,17 +72,17 @@ def format_gender( type):
return gender.get(type[0],_("Invalid"))
child_relations = {
RelLib.Person.CHILD_NONE : _("None"),
RelLib.Person.CHILD_BIRTH : _("Birth"),
RelLib.Person.CHILD_ADOPTED : _("Adopted"),
RelLib.Person.CHILD_STEPCHILD : _("Stepchild"),
RelLib.Person.CHILD_SPONSORED : _("Sponsored"),
RelLib.Person.CHILD_FOSTER : _("Foster"),
RelLib.Person.CHILD_UNKNOWN : _("Unknown"),
RelLib.Person.CHILD_CUSTOM : _("Custom"),
RelLib.ChildRef.CHILD_NONE : _("None"),
RelLib.ChildRef.CHILD_BIRTH : _("Birth"),
RelLib.ChildRef.CHILD_ADOPTED : _("Adopted"),
RelLib.ChildRef.CHILD_STEPCHILD : _("Stepchild"),
RelLib.ChildRef.CHILD_SPONSORED : _("Sponsored"),
RelLib.ChildRef.CHILD_FOSTER : _("Foster"),
RelLib.ChildRef.CHILD_UNKNOWN : _("Unknown"),
RelLib.ChildRef.CHILD_CUSTOM : _("Custom"),
}
def format_child_relation( type):
if type[0] == RelLib.Person.CHILD_CUSTOM:
if type[0] == RelLib.ChildRef.CHILD_CUSTOM:
return type[1]
return child_relations.get(type[0],_("Invalid id %d ('%s')")%type)

View File

@ -248,8 +248,8 @@ class GraphViz:
family = self.database.get_family_from_handle(family_handle)
father_handle = family.get_father_handle()
mother_handle = family.get_mother_handle()
fadopted = frel != RelLib.Person.CHILD_BIRTH
madopted = mrel != RelLib.Person.CHILD_BIRTH
fadopted = frel != RelLib.ChildRef.CHILD_BIRTH
madopted = mrel != RelLib.ChildRef.CHILD_BIRTH
famid = family.get_gramps_id().replace('-','_')
if (self.show_families and
(father_handle and person_dict.has_key(father_handle) or

View File

@ -263,7 +263,10 @@ class GeneWebParser:
if child:
self.current_family.add_child_handle(child.get_handle())
self.db.commit_family(self.current_family,self.trans)
child.add_parent_family_handle(self.current_family.get_handle(),RelLib.Person.CHILD_REL_BIRTH,RelLib.Person.CHILD_REL_BIRTH)
child.add_parent_family_handle(
self.current_family.get_handle(),
RelLib.ChildRef.CHILD_REL_BIRTH,
RelLib.ChildRef.CHILD_REL_BIRTH)
if self.current_child_birthplace_handle:
birth_handle = child.get_birth_handle()
birth = self.db.get_event_from_handle(birth_handle)

View File

@ -1764,7 +1764,7 @@ class IndividualPage(BasePage):
val)
else:
of.write(nameof(person,self.exclude_private))
if rel != RelLib.Person.CHILD_BIRTH:
if rel != RelLib.ChildRef.CHILD_BIRTH:
of.write('&nbsp;&nbsp;&nbsp;(%s)' % Utils.format_child_relation(rel))
of.write('</td>\n')

View File

@ -520,7 +520,7 @@ class TestcaseGenerator(Tool.Tool):
person2.add_family_handle(fam_h)
self.db.commit_person(person2,self.trans)
child = self.db.get_person_from_handle(child_h)
child.add_parent_family_handle(fam_h,(RelLib.Person.CHILD_BIRTH,''),(RelLib.Person.CHILD_BIRTH,''))
child.add_parent_family_handle(fam_h,(RelLib.ChildRef.CHILD_BIRTH,''),(RelLib.ChildRef.CHILD_BIRTH,''))
self.db.commit_person(child,self.trans)
self.commit_transaction() # COMMIT TRANSACTION STEP
@ -901,10 +901,10 @@ class TestcaseGenerator(Tool.Tool):
fam.add_child_handle(child_h)
self.db.commit_family(fam,self.trans)
child = self.db.get_person_from_handle(child_h)
rel1 = (RelLib.Person.CHILD_BIRTH,'')
rel1 = (RelLib.ChildRef.CHILD_BIRTH,'')
if randint(0,2) == 1:
rel1 = self.rand_type(Utils.child_relations)
rel2 = (RelLib.Person.CHILD_BIRTH,'')
rel2 = (RelLib.ChildRef.CHILD_BIRTH,'')
if randint(0,2) == 1:
rel2 = self.rand_type(Utils.child_relations)
child.add_parent_family_handle(fam_h, rel1, rel2)
@ -952,10 +952,10 @@ class TestcaseGenerator(Tool.Tool):
person2 = self.db.get_person_from_handle(person2_h)
person2.add_family_handle(fam_h)
self.db.commit_person(person2,self.trans)
rel1 = (RelLib.Person.CHILD_BIRTH,'')
rel1 = (RelLib.ChildRef.CHILD_BIRTH,'')
if randint(0,2) == 1:
rel1 = self.rand_type(Utils.child_relations)
rel2 = (RelLib.Person.CHILD_BIRTH,'')
rel2 = (RelLib.ChildRef.CHILD_BIRTH,'')
if randint(0,2) == 1:
rel2 = self.rand_type(Utils.child_relations)
child.add_parent_family_handle(fam_h, rel1, rel2)