gramps/src/RelLib.py

1954 lines
58 KiB
Python
Raw Normal View History

2001-05-13 07:26:57 +05:30
#
# Gramps - a GTK+/GNOME based genealogy program
#
# Copyright (C) 2000 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
#
2001-09-07 08:09:30 +05:30
"""The core library of the gramps database"""
__author__ = "Don Allingham"
from re import compile
from Date import Date, compare_dates
from string import strip
2001-05-13 07:26:57 +05:30
2001-09-07 08:09:30 +05:30
CONF_VERY_HIGH = 4
CONF_HIGH = 3
CONF_NORMAL = 2
CONF_LOW = 1
CONF_VERY_LOW = 0
_id_reg = compile("%\d+d")
2001-09-07 08:09:30 +05:30
class SourceNote:
"""Base class for storing source references and notes"""
def __init__(self,source=None):
2001-09-07 08:09:30 +05:30
"""Create a new SourceNote, copying from source if not None"""
self.source_list = []
if source:
if len(source.source_list) > 0:
for sref in source.source_list:
self.source_list.append(SourceRef(sref))
if source.note:
self.note = Note(source.note.get())
else:
self.note = None
2001-09-07 08:09:30 +05:30
else:
self.note = None
def addSourceRef(self,id) :
2001-09-07 08:09:30 +05:30
"""Set the source reference"""
self.source_list.append(id)
2001-09-07 08:09:30 +05:30
def getSourceRefList(self) :
2001-09-07 08:09:30 +05:30
"""Return the source reference"""
return self.source_list
def setSourceRefList(self,list) :
"""Replaces the source reference"""
self.source_list = list
2001-09-07 08:09:30 +05:30
def setNote(self,text):
"""Set the note to the given text"""
if self.note == None:
self.note = Note()
self.note.set(text)
def getNote(self):
"""Return the current note"""
if self.note == None:
return ""
else:
return self.note.get()
def setNoteObj(self,obj):
"""Change the note object instance to obj"""
self.note = obj
def getNoteObj(self):
"""Return in note instance, not just the text"""
return self.note
class DataObj(SourceNote):
2001-10-04 09:52:41 +05:30
"""Base class for data elements, providing source, note, and privacy data"""
2001-09-07 08:09:30 +05:30
def __init__(self,source=None):
"""Create a new DataObj, copying data from a source object if provided"""
SourceNote.__init__(self,source)
if source:
self.private = source.private
else:
self.private = 0
def setPrivacy(self,val):
"""Sets or clears the privacy flag of the data"""
self.private = val
def getPrivacy(self):
"""Returns the privacy level of the data"""
return self.private
class Place(SourceNote):
"""Contains information related to a place, including multiple address
information (since place names can change with time), longitude, latitude,
a collection of images and URLs, a note and a source"""
def __init__(self,source=None):
"""Creates a new Place object.
source - Object to copy. If none supplied, create an empty place object"""
SourceNote.__init__(self,source)
if source:
self.long = source.log
self.lat = source.lat
self.title = source.title
self.main_loc = Location(source.main_loc)
self.alt_loc = []
for loc in source.alt_loc:
self.alt_loc = Location(loc)
self.id = source.id
self.urls = []
for u in source.urls:
self.urls.append(Url(u))
self.photoList = []
for photo in source.photoList:
self.photoList.append(ObjectRef(photo))
else:
self.long = ""
self.lat = ""
self.title = ""
self.main_loc = Location()
self.alt_loc = []
self.id = ""
self.urls = []
self.photoList = []
def getUrlList(self):
2001-09-07 08:09:30 +05:30
"""Return the list of URLs"""
return self.urls
def setUrlList(self,list):
2001-09-07 08:09:30 +05:30
"""Replace the current URL list with the new one"""
self.urls = list
def addUrl(self,url):
2001-09-07 08:09:30 +05:30
"""Add a URL to the URL list"""
self.urls.append(url)
def setId(self,id):
2001-09-07 08:09:30 +05:30
"""Sets the gramps ID for the place object"""
self.id = id
def getId(self):
2001-09-07 08:09:30 +05:30
"""Returns the gramps ID for the place object"""
return self.id
def set_title(self,name):
2001-09-07 08:09:30 +05:30
"""Sets the title of the place object"""
self.title = name
def get_title(self):
2001-09-07 08:09:30 +05:30
"""Returns the title of the place object"""
return self.title
def set_longitude(self,long):
2001-09-07 08:09:30 +05:30
"""Sets the longitude of the place"""
self.long = long
def get_longitude(self):
2001-09-07 08:09:30 +05:30
"""Returns the longitude of the place"""
return self.long
def set_latitude(self,long):
2001-09-07 08:09:30 +05:30
"""Sets the latitude of the place"""
self.lat = long
def get_latitude(self):
2001-09-07 08:09:30 +05:30
"""Returns the latitude of the place"""
return self.lat
def get_main_location(self):
2001-09-07 08:09:30 +05:30
"""Returns the Location object representing the primary information"""
return self.main_loc
def set_main_location(self,loc):
2001-09-07 08:09:30 +05:30
"""Assigns the main location to the Location object passed"""
self.main_loc = loc
def get_alternate_locations(self):
2001-09-07 08:09:30 +05:30
"""Returns a list of alternate location information objects"""
return self.alt_loc
def set_alternate_locations(self,list):
2001-09-07 08:09:30 +05:30
"""Replaces the current alternate location list with the new one"""
self.alt_loc = list
def add_alternate_locations(self,loc):
2001-09-07 08:09:30 +05:30
"""Adds a Location to the alternate location list"""
if loc not in self.alt_loc:
self.alt_loc.append(loc)
def addPhoto(self,photo):
2001-09-07 08:09:30 +05:30
"""Adds a Photo object to the place object's image list"""
self.photoList.append(photo)
def getPhotoList(self):
2001-09-07 08:09:30 +05:30
"""Returns the list of Photo objects"""
return self.photoList
def setPhotoList(self,list):
"""Sets the list of Photo objects"""
self.photoList = list
class Researcher:
2001-09-07 08:09:30 +05:30
"""Contains the information about the owner of the database"""
def __init__(self):
2001-09-07 08:09:30 +05:30
"""Initializes the Researcher object"""
self.name = ""
self.addr = ""
self.city = ""
self.state = ""
self.country = ""
self.postal = ""
self.phone = ""
self.email = ""
def getName(self):
2001-09-07 08:09:30 +05:30
"""returns the database owner's name"""
return self.name
def getAddress(self):
2001-09-07 08:09:30 +05:30
"""returns the database owner's address"""
return self.addr
def getCity(self):
2001-09-07 08:09:30 +05:30
"""returns the database owner's city"""
return self.city
def getState(self):
2001-09-07 08:09:30 +05:30
"""returns the database owner's state"""
return self.state
def getCountry(self):
2001-09-07 08:09:30 +05:30
"""returns the database owner's country"""
return self.country
def getPostalCode(self):
2001-09-07 08:09:30 +05:30
"""returns the database owner's postal code"""
return self.postal
def getPhone(self):
2001-09-07 08:09:30 +05:30
"""returns the database owner's phone number"""
return self.phone
def getEmail(self):
2001-09-07 08:09:30 +05:30
"""returns the database owner's email"""
return self.email
def set(self,name,addr,city,state,country,postal,phone,email):
2001-09-07 08:09:30 +05:30
"""sets the information about the database owner"""
self.name = strip(name)
self.addr = strip(addr)
self.city = strip(city)
self.state = strip(state)
self.country = strip(country)
self.postal = strip(postal)
self.phone = strip(phone)
self.email = strip(email)
class Location:
2001-09-07 08:09:30 +05:30
"""Provides information about a place, including city, county, state,
and country. Multiple Location objects can represent the same place,
since names of citys, countys, states, and even countries can change
with time"""
def __init__(self,source=None):
2001-09-07 08:09:30 +05:30
"""creates a Location object, copying from the source object if it exists"""
if source:
self.city = source.city
self.parish = source.parish
self.county = source.county
self.state = source.state
self.country = source.country
else:
self.city = ""
self.parish = ""
self.county = ""
self.state = ""
self.country = ""
2001-10-24 06:54:18 +05:30
def is_empty(self):
return self.city == "" and self.county == "" and self.state == "" and self.country == ""
def set_city(self,data):
2001-09-07 08:09:30 +05:30
"""sets the city name of the Location object"""
self.city = data
def get_city(self):
2001-09-07 08:09:30 +05:30
"""returns the city name of the Location object"""
return self.city
def set_parish(self,data):
"""sets the religious parish name"""
self.parish = data
def get_parish(self):
"""gets the religious parish name"""
return self.parish
def set_county(self,data):
2001-09-07 08:09:30 +05:30
"""sets the county name of the Location object"""
self.county = data
def get_county(self):
2001-09-07 08:09:30 +05:30
"""returns the county name of the Location object"""
return self.county
def set_state(self,data):
2001-09-07 08:09:30 +05:30
"""sets the state name of the Location object"""
self.state = data
def get_state(self):
2001-09-07 08:09:30 +05:30
"""returns the state name of the Location object"""
return self.state
def set_country(self,data):
2001-09-07 08:09:30 +05:30
"""sets the country name of the Location object"""
self.country = data
def get_country(self):
2001-09-07 08:09:30 +05:30
"""returns the country name of the Location object"""
return self.country
class Note:
2001-09-07 08:09:30 +05:30
"""Provides general text information"""
def __init__(self,text = ""):
2001-09-07 08:09:30 +05:30
"""create a new Note object from the passed string"""
self.text = text
def set(self,text):
2001-09-07 08:09:30 +05:30
"""set the note contents to the passed string"""
self.text = text
def get(self):
2001-09-07 08:09:30 +05:30
"""return the note contents"""
return self.text
2001-10-08 08:40:06 +05:30
class Photo(SourceNote):
2001-09-07 08:09:30 +05:30
"""Containter for information about an image file, including location,
description and privacy"""
def __init__(self,source=None):
2001-09-07 08:09:30 +05:30
"""Create a new Photo object, copying from the source if provided"""
2001-10-08 08:40:06 +05:30
SourceNote.__init__(self,source)
2001-10-07 08:28:29 +05:30
self.attrlist = []
if source:
self.path = source.path
self.mime = source.mime
self.local = source.local
self.desc = source.desc
self.id = source.id
2001-10-07 08:28:29 +05:30
for attr in source.attrlist:
self.attrlist.append(Attribute(attr))
else:
self.id = ""
self.local = 0
self.path = ""
self.mime = ""
self.desc = ""
2001-05-13 07:26:57 +05:30
def setLocal(self,val):
"""set or clear the local flag"""
self.local = val
def getLocal(self):
"""return the local flag"""
return self.local
def setId(self,id):
"""Sets the gramps ID for the place object"""
self.id = id
def getId(self):
"""Returns the gramps ID for the place object"""
return self.id
def setMimeType(self,type):
self.mime = type
def getMimeType(self):
return self.mime
2001-05-13 07:26:57 +05:30
def setPath(self,path):
2001-09-07 08:09:30 +05:30
"""set the file path to the passed path"""
2001-05-13 07:26:57 +05:30
self.path = path
def getPath(self):
2001-09-07 08:09:30 +05:30
"""return the file path"""
2001-05-13 07:26:57 +05:30
return self.path
def setDescription(self,text):
2001-09-07 08:09:30 +05:30
"""sets the description of the image"""
2001-05-13 07:26:57 +05:30
self.desc = text
def getDescription(self):
2001-09-07 08:09:30 +05:30
"""returns the description of the image"""
2001-05-13 07:26:57 +05:30
return self.desc
2001-10-07 08:28:29 +05:30
def addAttribute(self,attr):
2001-09-07 08:09:30 +05:30
"""Adds a propery to the Photo object. This is not used by gramps,
but provides a means for XML users to attach other properties to
the image"""
2001-10-07 08:28:29 +05:30
self.attrlist.append(attr)
2001-07-16 07:36:31 +05:30
2001-10-07 08:28:29 +05:30
def getAttributeList(self):
2001-09-07 08:09:30 +05:30
"""returns the property list associated with the image"""
2001-10-07 08:28:29 +05:30
return self.attrlist
2001-07-16 07:36:31 +05:30
def setAttributeList(self,list):
self.attrlist = list
class ObjectRef:
def __init__(self,source=None):
self.attrlist = []
if source:
self.private = source.private
self.ref = source.ref
self.note = Note(source.note)
for attr in source.attrlist:
self.attrlist.append(Attribute(attr))
else:
self.private = 0
self.ref = None
self.note = None
def setPrivacy(self,val):
"""Sets or clears the privacy flag of the data"""
self.private = val
def getPrivacy(self):
"""Returns the privacy level of the data"""
return self.private
def setReference(self,obj):
self.ref = obj
def getReference(self):
return self.ref
def setNote(self,text):
"""Set the note to the given text"""
if self.note == None:
self.note = Note()
self.note.set(text)
def getNote(self):
"""Return the current note"""
if self.note == None:
return ""
else:
return self.note.get()
def setNoteObj(self,obj):
"""Change the note object instance to obj"""
self.note = obj
def getNoteObj(self):
"""Return in note instance, not just the text"""
return self.note
def addAttribute(self,attr):
"""Adds a propery to the Photo object. This is not used by gramps,
but provides a means for XML users to attach other properties to
the image"""
self.attrlist.append(attr)
def getAttributeList(self):
"""returns the property list associated with the image"""
return self.attrlist
def setAttributeList(self,list):
"""sets the property list associated with the image"""
self.attrlist = list
2001-09-07 08:09:30 +05:30
class Attribute(DataObj):
"""Provides a simple key/value pair for describing properties. Used
by the Person and Family objects to store descriptive information."""
def __init__(self,source=None):
2001-09-07 08:09:30 +05:30
"""creates a new Attribute object, copying from the source if provided"""
DataObj.__init__(self,source)
if source:
self.type = source.type
self.value = source.value
else:
self.type = ""
self.value = ""
2001-05-13 07:26:57 +05:30
def setType(self,val):
2001-09-07 08:09:30 +05:30
"""sets the type (or key) of the Attribute instance"""
2001-05-13 07:26:57 +05:30
self.type = val
def getType(self):
2001-09-07 08:09:30 +05:30
"""returns the type (or key) or the Attribute instance"""
2001-05-13 07:26:57 +05:30
return self.type
def setValue(self,val):
2001-09-07 08:09:30 +05:30
"""sets the value of the Attribute instance"""
2001-05-13 07:26:57 +05:30
self.value = val
def getValue(self):
2001-09-07 08:09:30 +05:30
"""returns the value of the Attribute instance"""
2001-05-13 07:26:57 +05:30
return self.value
2001-09-07 08:09:30 +05:30
class Address(DataObj):
"""Provides address information for a person"""
def __init__(self,source=None):
2001-09-07 08:09:30 +05:30
"""Creates a new Address instance, copying from the source if provided"""
DataObj.__init__(self,source)
if source:
self.street = source.street
self.city = source.city
self.state = source.state
self.country = source.country
self.postal = source.postal
self.date = Date(source.date)
else:
self.street = ""
self.city = ""
self.state = ""
self.country = ""
self.postal = ""
self.date = Date()
2001-05-13 07:26:57 +05:30
def setDate(self,text):
2001-09-07 08:09:30 +05:30
"""attempts to sets the date that the person lived at the address
from the passed string"""
self.date.set(text)
2001-05-13 07:26:57 +05:30
def getDate(self):
2001-09-07 08:09:30 +05:30
"""returns a string representation of the date that the person
lived at the address"""
return self.date.getDate()
2001-05-13 07:26:57 +05:30
def getDateObj(self):
2001-09-07 08:09:30 +05:30
"""returns the Date object associated with the Address"""
return self.date
2001-05-13 07:26:57 +05:30
def setStreet(self,val):
2001-09-07 08:09:30 +05:30
"""sets the street portion of the Address"""
2001-05-13 07:26:57 +05:30
self.street = val
def getStreet(self):
2001-09-07 08:09:30 +05:30
"""returns the street portion of the Address"""
2001-05-13 07:26:57 +05:30
return self.street
def setCity(self,val):
2001-09-07 08:09:30 +05:30
"""sets the city portion of the Address"""
2001-05-13 07:26:57 +05:30
self.city = val
def getCity(self):
2001-09-07 08:09:30 +05:30
"""returns the city portion of the Address"""
2001-05-13 07:26:57 +05:30
return self.city
def setState(self,val):
2001-09-07 08:09:30 +05:30
"""sets the state portion of the Address"""
2001-05-13 07:26:57 +05:30
self.state = val
def getState(self):
2001-09-07 08:09:30 +05:30
"""returns the state portion of the Address"""
2001-05-13 07:26:57 +05:30
return self.state
def setCountry(self,val):
2001-09-07 08:09:30 +05:30
"""sets the country portion of the Address"""
2001-05-13 07:26:57 +05:30
self.country = val
def getCountry(self):
2001-09-07 08:09:30 +05:30
"""returns the country portion of the Address"""
2001-05-13 07:26:57 +05:30
return self.country
def setPostal(self,val):
2001-09-07 08:09:30 +05:30
"""sets the postal code of the Address"""
2001-05-13 07:26:57 +05:30
self.postal = val
def getPostal(self):
2001-09-07 08:09:30 +05:30
"""returns the postal code of the Address"""
2001-05-13 07:26:57 +05:30
return self.postal
2001-09-07 08:09:30 +05:30
class Name(DataObj):
"""Provides name information about a person. A person may have more
that one name throughout his or her life."""
def __init__(self,source=None):
2001-09-07 08:09:30 +05:30
"""creates a new Name instance, copying from the source if provided"""
DataObj.__init__(self,source)
if source:
self.FirstName = source.FirstName
self.Surname = source.Surname
self.Suffix = source.Suffix
self.Title = source.Title
else:
self.FirstName = ""
self.Surname = ""
self.Suffix = ""
self.Title = ""
2001-05-13 07:26:57 +05:30
def setFirstName(self,name):
2001-09-07 08:09:30 +05:30
"""sets the given name for the Name instance"""
2001-05-13 07:26:57 +05:30
self.FirstName = name
def setSurname(self,name):
2001-09-07 08:09:30 +05:30
"""sets the surname (or last name) for the Name instance"""
2001-05-13 07:26:57 +05:30
self.Surname = name
def setSuffix(self,name):
2001-09-07 08:09:30 +05:30
"""sets the suffix (such as Jr., III, etc.) for the Name instance"""
2001-05-13 07:26:57 +05:30
self.Suffix = name
def getFirstName(self):
2001-09-07 08:09:30 +05:30
"""returns the given name for the Name instance"""
2001-05-13 07:26:57 +05:30
return self.FirstName
def getSurname(self):
2001-09-07 08:09:30 +05:30
"""returns the surname (or last name) for the Name instance"""
2001-05-13 07:26:57 +05:30
return self.Surname
def getSuffix(self):
2001-09-07 08:09:30 +05:30
"""returns the suffix for the Name instance"""
2001-05-13 07:26:57 +05:30
return self.Suffix
def setTitle(self,title):
2001-09-07 08:09:30 +05:30
"""sets the title (Dr., Reverand, Captain) for the Name instance"""
2001-05-13 07:26:57 +05:30
self.Title = title
def getTitle(self):
2001-09-07 08:09:30 +05:30
"""returns the title for the Name instance"""
2001-05-13 07:26:57 +05:30
return self.Title
def getName(self):
2001-09-07 08:09:30 +05:30
"""returns a name string built from the components of the Name instance,
in the form of Surname, Firstname"""
2001-05-13 07:26:57 +05:30
if (self.Suffix == ""):
return "%s, %s" % (self.Surname, self.FirstName)
else:
return "%s, %s %s" % (self.Surname, self.FirstName, self.Suffix)
def getRegularName(self):
2001-09-07 08:09:30 +05:30
"""returns a name string built from the components of the Name instance,
in the form of Firstname Surname"""
2001-05-13 07:26:57 +05:30
if (self.Suffix == ""):
return "%s %s" % (self.FirstName, self.Surname)
else:
return "%s %s, %s" % (self.FirstName, self.Surname, self.Suffix)
def are_equal(self,other):
2001-09-07 08:09:30 +05:30
"""compares to names to see if they are equal, return 0 if they are not"""
if self.FirstName != other.FirstName:
return 0
if self.Surname != other.Surname:
return 0
if self.Suffix != other.Suffix:
return 0
if self.Title != other.Title:
return 0
if self.private != other.private:
return 0
if self.getNote() != other.getNote():
return 0
if len(self.getSourceRefList()) != len(other.getSourceRefList()):
return 0
index = 0
olist = other.getSourceRefList()
for a in self.getSourceRefList():
if not a.are_equal(olist[index]):
return 0
index = index + 1
return 1
2001-05-13 07:26:57 +05:30
class Url:
2001-09-07 08:09:30 +05:30
"""Contains information related to internet Uniform Resource Locators,
allowing gramps to store information about internet resources"""
2001-05-13 07:26:57 +05:30
def __init__(self,source=None):
2001-09-07 08:09:30 +05:30
"""creates a new URL instance, copying from the source if present"""
if source:
self.path = source.path
self.desc = source.desc
self.private = source.private
else:
self.path = ""
self.desc = ""
self.private = 0
def setPrivacy(self,val):
2001-09-07 08:09:30 +05:30
"""sets the privacy flag for the URL instance"""
self.private = val
def getPrivacy(self):
2001-09-07 08:09:30 +05:30
"""returns the privacy flag for the URL instance"""
return self.private
2001-05-13 07:26:57 +05:30
def set_path(self,path):
2001-09-07 08:09:30 +05:30
"""sets the URL path"""
2001-05-13 07:26:57 +05:30
self.path = path
def get_path(self):
2001-09-07 08:09:30 +05:30
"""returns the URL path"""
2001-05-13 07:26:57 +05:30
return self.path
def set_description(self,description):
2001-09-07 08:09:30 +05:30
"""sets the description of the URL"""
2001-05-13 07:26:57 +05:30
self.desc = description
def get_description(self):
2001-09-07 08:09:30 +05:30
"""returns the description of the URL"""
2001-05-13 07:26:57 +05:30
return self.desc
def are_equal(self,other):
"""returns 1 if the specified URL is the same as the instance"""
if other == None:
return 0
if self.path != other.path:
return 0
if self.desc != other.desc:
return 0
return 1
2001-05-13 07:26:57 +05:30
class Person:
2001-09-07 08:09:30 +05:30
"""Represents an individual person in the gramps database"""
unknown = 2
2001-05-13 07:26:57 +05:30
male = 1
female = 0
def __init__(self):
2001-09-07 08:09:30 +05:30
"""creates a new Person instance"""
self.id = ""
self.PrimaryName = None
2001-05-13 07:26:57 +05:30
self.EventList = []
self.FamilyList = []
self.AltFamilyList = []
self.MainFamily = None
self.photoList = []
self.nickname = ""
self.alternateNames = []
self.gender = 2
self.death = None
self.birth = None
2001-05-13 07:26:57 +05:30
self.addressList = []
self.attributeList = []
self.urls = []
self.note = None
2001-05-13 07:26:57 +05:30
self.paf_uid = ""
2001-08-06 08:30:01 +05:30
self.position = None
self.ancestor = None
2001-05-13 07:26:57 +05:30
2001-09-07 08:09:30 +05:30
def setPrimaryName(self,name):
"""sets the primary name of the Person to the specified Name instance"""
self.PrimaryName = name
2001-05-13 07:26:57 +05:30
2001-09-07 08:09:30 +05:30
def getPrimaryName(self):
"""returns the Name instance marked as the Person's primary name"""
if not self.PrimaryName:
self.PrimaryName = Name()
2001-05-13 07:26:57 +05:30
return self.PrimaryName
2001-09-07 08:09:30 +05:30
def setPafUid(self,val):
"""sets Personal Ancestral File UID value"""
self.paf_uid = val
2001-05-13 07:26:57 +05:30
def getPafUid(self) :
2001-09-07 08:09:30 +05:30
"""returns the Personal Ancestral File UID value"""
2001-05-13 07:26:57 +05:30
return self.paf_uid
def getAlternateNames(self):
2001-09-07 08:09:30 +05:30
"""returns the list of alternate Names"""
2001-05-13 07:26:57 +05:30
return self.alternateNames
def setAlternateNames(self,list):
2001-09-07 08:09:30 +05:30
"""changes the list of alternate names to the passed list"""
self.alternateNames = list
2001-05-13 07:26:57 +05:30
def addAlternateName(self,name):
2001-09-07 08:09:30 +05:30
"""adds an alternate Name instance to the list"""
2001-05-13 07:26:57 +05:30
self.alternateNames.append(name)
def getUrlList(self):
2001-09-07 08:09:30 +05:30
"""returns the list of URL instances"""
2001-05-13 07:26:57 +05:30
return self.urls
def setUrlList(self,list):
2001-09-07 08:09:30 +05:30
"""sets the list of URL instances to list"""
self.urls = list
2001-05-13 07:26:57 +05:30
def addUrl(self,url):
2001-09-07 08:09:30 +05:30
"""adds a URL instance to the list"""
2001-05-13 07:26:57 +05:30
self.urls.append(url)
2001-09-07 08:09:30 +05:30
def setId(self,id):
"""sets the gramps ID for the Person"""
self.id = str(id)
2001-05-13 07:26:57 +05:30
2001-09-07 08:09:30 +05:30
def getId(self):
"""returns the gramps ID for the Person"""
2001-05-13 07:26:57 +05:30
return self.id
2001-09-07 08:09:30 +05:30
def setNickName(self,name):
"""sets the nickname for the Person"""
2001-05-13 07:26:57 +05:30
self.nickname = name
def getNickName(self) :
2001-09-07 08:09:30 +05:30
"""returns the nickname for the Person"""
2001-05-13 07:26:57 +05:30
return self.nickname
def setGender(self,val) :
2001-09-07 08:09:30 +05:30
"""sets the gender of the Person"""
2001-05-13 07:26:57 +05:30
self.gender = val
def getGender(self) :
2001-09-07 08:09:30 +05:30
"""returns the gender of the Person"""
2001-05-13 07:26:57 +05:30
return self.gender
def setBirth(self,event) :
2001-09-07 08:09:30 +05:30
"""sets the birth event to the passed event"""
2001-05-13 07:26:57 +05:30
self.birth = event
def setDeath(self,event) :
2001-09-07 08:09:30 +05:30
"""sets the death event to the passed event"""
2001-05-13 07:26:57 +05:30
self.death = event
def getBirth(self) :
2001-09-07 08:09:30 +05:30
"""returns the birth event"""
if self.birth == None:
self.birth = Event()
self.birth.name = "Birth"
2001-05-13 07:26:57 +05:30
return self.birth
def getDeath(self) :
2001-09-07 08:09:30 +05:30
"""returns the death event"""
if self.death == None:
self.death = Event()
self.death.name = "Death"
2001-05-13 07:26:57 +05:30
return self.death
def addPhoto(self,photo):
2001-09-07 08:09:30 +05:30
"""adds a Photo instance to the image list"""
2001-05-13 07:26:57 +05:30
self.photoList.append(photo)
def getPhotoList(self):
2001-09-07 08:09:30 +05:30
"""returns the list of Photos"""
2001-05-13 07:26:57 +05:30
return self.photoList
def setPhotoList(self,list):
"""Sets the list of Photo objects"""
self.photoList = list
2001-09-07 08:09:30 +05:30
def addEvent(self,event):
"""adds an Event to the event list"""
2001-05-13 07:26:57 +05:30
self.EventList.append(event)
2001-09-07 08:09:30 +05:30
def getEventList(self):
"""returns the list of Event instances"""
2001-05-13 07:26:57 +05:30
return self.EventList
2001-09-07 08:09:30 +05:30
def setEventList(self,list):
"""sets the event list to the passed list"""
self.EventList = list
2001-09-07 08:09:30 +05:30
def addFamily(self,family):
"""adds the specified Family instance to the list of
families/marriages/partnerships in which the person is a
parent or spouse"""
2001-05-13 07:26:57 +05:30
self.FamilyList.append(family)
def getFamilyList(self) :
2001-09-07 08:09:30 +05:30
"""returns the list of Family instances in which the
person is a parent or spouse"""
2001-05-13 07:26:57 +05:30
return self.FamilyList
def removeFamily(self,family):
2001-09-07 08:09:30 +05:30
"""removes the specified Family instance from the list
of marriages/partnerships"""
2001-05-13 07:26:57 +05:30
index = 0
for fam in self.FamilyList:
if fam == family:
del self.FamilyList[index]
return
index = index + 1
2001-09-07 08:09:30 +05:30
def addAddress(self,address):
"""adds the Address instance to the list of addresses"""
2001-05-13 07:26:57 +05:30
self.addressList.append(address)
def removeAddress(self,address):
2001-09-07 08:09:30 +05:30
"""removes the Address instance from the list of addresses"""
2001-05-13 07:26:57 +05:30
index = 0
for addr in self.addressList:
if addr == address:
del self.addressList[index]
return
index = index + 1
2001-09-07 08:09:30 +05:30
def getAddressList(self):
"""returns the list of addresses"""
2001-05-13 07:26:57 +05:30
return self.addressList
2001-09-07 08:09:30 +05:30
def setAddressList(self,list):
"""sets the address list to the specified list"""
self.addressList = list
2001-09-07 08:09:30 +05:30
def addAttribute(self,attribute):
"""adds an Attribute instance to the attribute list"""
2001-05-13 07:26:57 +05:30
self.attributeList.append(attribute)
def removeAttribute(self,attribute):
2001-09-07 08:09:30 +05:30
"""removes the specified Attribute instance from the attribute list"""
2001-05-13 07:26:57 +05:30
index = 0
for attr in self.attributeList:
if attr == attribute:
del self.attributeList[index]
return
index = index + 1
2001-09-07 08:09:30 +05:30
def getAttributeList(self):
"""returns the attribute list"""
2001-05-13 07:26:57 +05:30
return self.attributeList
2001-09-07 08:09:30 +05:30
def setAttributeList(self,list):
"""sets the attribute list to the specified list"""
self.attributeList = list
2001-09-07 08:09:30 +05:30
def getAltFamilyList(self):
"""returns the list of alternate Family instances, in which the Person
is a child of the family, but not a natural child of both parents"""
2001-05-13 07:26:57 +05:30
return self.AltFamilyList
2001-09-07 08:09:30 +05:30
def addAltFamily(self,family,mrel,frel):
"""adds a Family to the alternate family list, indicating the relationship
to the mother (mrel) and the father (frel)"""
self.AltFamilyList.append((family,mrel,frel))
2001-05-13 07:26:57 +05:30
def removeAltFamily(self,family):
2001-09-07 08:09:30 +05:30
"""removes a Family instance from the alternate family list"""
2001-05-13 07:26:57 +05:30
index = 0
for fam in self.AltFamilyList:
if fam[0] == family:
del self.AltFamilyList[index]
return
index = index + 1
2001-09-07 08:09:30 +05:30
def setMainFamily(self,family):
"""sets the main Family of the Person, the Family in which the
Person is a natural born child"""
2001-05-13 07:26:57 +05:30
self.MainFamily = family
2001-09-07 08:09:30 +05:30
def getMainFamily(self):
"""returns the main Family of the Person, the Family in which the
Person is a natural born child"""
2001-05-13 07:26:57 +05:30
return self.MainFamily
2001-09-07 08:09:30 +05:30
def setNote(self,text):
"""sets the note attached to the Person to the passed text"""
if self.note == None:
self.note = Note()
2001-09-07 08:09:30 +05:30
self.note.set(text)
2001-05-13 07:26:57 +05:30
def getNote(self) :
2001-09-07 08:09:30 +05:30
"""returns the text of the note attached to the Person"""
if self.note == None:
return ""
else:
return self.note.get()
2001-09-07 08:09:30 +05:30
def setNoteObj(self,note):
"""sets the Note instance attached to the Person"""
self.note = note
def getNoteObj(self):
2001-09-07 08:09:30 +05:30
"""returns the Note instance attached to the Person"""
if self.note == None:
self.note = Note()
2001-05-13 07:26:57 +05:30
return self.note
2001-08-06 08:30:01 +05:30
def setPosition(self,pos):
2001-09-07 08:09:30 +05:30
"""sets a graphical location pointer for graphic display (x,y)"""
2001-08-06 08:30:01 +05:30
self.position = pos
def getPosition(self):
2001-09-07 08:09:30 +05:30
"""returns a graphical location pointer for graphic display (x,y)"""
2001-08-06 08:30:01 +05:30
return self.position
def setAncestor(self, value):
"""set ancestor flag and recurse"""
self.ancestor = value
family = self.MainFamily
if family:
if family.Father:
family.Father.setAncestor(value)
if (family.Mother):
family.Mother.setAncestor(value)
def getAncestor(self):
return self.ancestor
2001-09-07 08:09:30 +05:30
class Event(DataObj):
"""Event record, recording the event type, description, place, and date
of a particular event"""
def __init__(self,source=None):
2001-09-07 08:09:30 +05:30
"""creates a new Event instance, copying from the source if present"""
DataObj.__init__(self,source)
if source:
self.place = source.place
self.date = Date(source.date)
self.description = source.description
self.name = source.name
2001-10-04 09:52:41 +05:30
self.cause = source.cause
else:
self.place = None
self.date = None
self.description = ""
self.name = ""
2001-10-04 09:52:41 +05:30
self.cause = ""
2001-05-13 07:26:57 +05:30
def set(self,name,date,place,description):
2001-09-07 08:09:30 +05:30
"""sets the name, date, place, and description of an Event instance"""
2001-05-13 07:26:57 +05:30
self.name = name
self.place = place
self.description = description
self.setDate(date)
def are_equal(self,other):
2001-09-07 08:09:30 +05:30
"""returns 1 if the spdcified event is the same as the instance"""
2001-05-13 07:26:57 +05:30
if other == None:
return 0
if self.name != other.name:
return 0
if self.place != other.place:
return 0
if compare_dates(self.getDateObj(),other.getDateObj()):
return 0
if self.description != other.description:
return 0
2001-10-04 09:52:41 +05:30
if self.cause != other.cause:
return 0
if self.private != other.private:
return 0
if len(self.getSourceRefList()) != len(other.getSourceRefList()):
return 0
index = 0
olist = other.getSourceRefList()
for a in self.getSourceRefList():
if not a.are_equal(olist[index]):
return 0
index = index + 1
return 1
2001-05-13 07:26:57 +05:30
2001-09-07 08:09:30 +05:30
def setName(self,name):
"""sets the name of the Event"""
2001-05-13 07:26:57 +05:30
self.name = name
2001-09-07 08:09:30 +05:30
def getName(self):
"""returns the name of the Event"""
2001-05-13 07:26:57 +05:30
return self.name
2001-09-07 08:09:30 +05:30
def setPlace(self,place):
"""sets the Place instance of the Event"""
2001-05-13 07:26:57 +05:30
self.place = place
2001-09-07 08:09:30 +05:30
def getPlace(self):
"""returns the Place instance of the Event"""
2001-05-13 07:26:57 +05:30
return self.place
2001-10-04 09:52:41 +05:30
def setCause(self,cause):
"""sets the cause of the Event"""
self.cause = cause
def getCause(self):
"""returns the cause of the Event"""
return self.cause
2001-09-07 08:09:30 +05:30
def getPlaceName(self):
"""returns the title of the Place associated with the Event"""
if self.place:
return self.place.get_title()
else:
return ""
2001-09-07 08:09:30 +05:30
def setDescription(self,description):
"""sets the description of the Event instance"""
2001-05-13 07:26:57 +05:30
self.description = description
def getDescription(self) :
2001-09-07 08:09:30 +05:30
"""returns the description of the Event instance"""
2001-05-13 07:26:57 +05:30
return self.description
def setDate(self, date) :
2001-09-07 08:09:30 +05:30
"""attempts to sets the date of the Event instance"""
if not self.date:
self.date = Date()
self.date.set(date)
2001-05-13 07:26:57 +05:30
def getDate(self) :
2001-09-07 08:09:30 +05:30
"""returns a string representation of the date of the Event instance"""
if self.date:
return self.date.getDate()
return ""
2001-05-13 07:26:57 +05:30
def getQuoteDate(self) :
2001-09-07 08:09:30 +05:30
"""returns a string representation of the date of the Event instance,
enclosing the results in quotes if it is not a valid date"""
if self.date:
return self.date.getQuoteDate()
return ""
2001-09-07 08:09:30 +05:30
def getDateObj(self):
"""returns the Date object associated with the Event"""
if not self.date:
self.date = Date()
2001-05-13 07:26:57 +05:30
return self.date
def getSaveDate(self) :
2001-09-07 08:09:30 +05:30
"""returns the date of the Event in the form wanted by gramps XML save"""
if self.date:
return self.date.getSaveDate()
return ""
2001-05-13 07:26:57 +05:30
class Family:
2001-09-07 08:09:30 +05:30
"""Represents a family unit in the gramps database"""
2001-05-13 07:26:57 +05:30
def __init__(self):
2001-09-07 08:09:30 +05:30
"""creates a new Family instance"""
2001-05-13 07:26:57 +05:30
self.Father = None
self.Mother = None
self.Children = []
self.Marriage = None
self.Divorce = None
self.type = "Married"
2001-05-13 07:26:57 +05:30
self.EventList = []
self.id = ""
2001-05-13 07:26:57 +05:30
self.photoList = []
self.note = Note()
2001-06-03 04:26:04 +05:30
self.attributeList = []
self.position = None
def setPosition(self,pos):
2001-09-07 08:09:30 +05:30
"""sets a graphical location pointer for graphic display (x,y)"""
self.position = pos
def getPosition(self):
2001-09-07 08:09:30 +05:30
"""returns a graphical location pointer for graphic display (x,y)"""
return self.position
2001-06-03 04:26:04 +05:30
def addAttribute(self,attribute) :
2001-09-07 08:09:30 +05:30
"""adds an Attribute instance to the attribute list"""
2001-06-03 04:26:04 +05:30
self.attributeList.append(attribute)
def removeAttribute(self,attribute):
2001-09-07 08:09:30 +05:30
"""removes the specified Attribute instance from the attribute list"""
2001-06-03 04:26:04 +05:30
index = 0
for attr in self.attributeList:
if attr == attribute:
del self.attributeList[index]
return
index = index + 1
def getAttributeList(self) :
2001-09-07 08:09:30 +05:30
"""returns the attribute list"""
2001-06-03 04:26:04 +05:30
return self.attributeList
def setAttributeList(self,list) :
2001-09-07 08:09:30 +05:30
"""sets the attribute list to the specified list"""
self.attributeList = list
def getNote(self):
2001-09-07 08:09:30 +05:30
"""returns the text of the note attached to the Family"""
return self.note.get()
def setNote(self,text):
2001-09-07 08:09:30 +05:30
"""sets the note attached to the Family to the passed text"""
self.note.set(text)
def getNoteObj(self):
2001-09-07 08:09:30 +05:30
"""returns the Note instance attached to the Family"""
return self.note
def setNoteObj(self,obj):
2001-09-07 08:09:30 +05:30
"""sets the Note instance attached to the Family"""
self.note = obj
2001-05-13 07:26:57 +05:30
def setId(self,id) :
2001-09-07 08:09:30 +05:30
"""sets the gramps ID for the Family"""
self.id = str(id)
2001-05-13 07:26:57 +05:30
def getId(self) :
2001-09-07 08:09:30 +05:30
"""returns the gramps ID for the Family"""
2001-05-13 07:26:57 +05:30
return self.id
def setRelationship(self,type):
2001-09-07 08:09:30 +05:30
"""assigns a string indicating the relationship between the
father and the mother"""
self.type = type
def getRelationship(self):
2001-09-07 08:09:30 +05:30
"""returns a string indicating the relationship between the
father and the mother"""
return self.type
2001-05-13 07:26:57 +05:30
def setFather(self,person):
2001-09-07 08:09:30 +05:30
"""sets the father of the Family to the specfied Person"""
update = self.someChildIsAncestor()
if update and self.Father:
self.Father.setAncestor(0)
self.Father = person
if update and self.Father:
self.Father.setAncestor(1)
2001-05-13 07:26:57 +05:30
def getFather(self):
2001-09-07 08:09:30 +05:30
"""returns the father of the Family"""
2001-05-13 07:26:57 +05:30
return self.Father
def setMother(self,person):
2001-09-07 08:09:30 +05:30
"""sets the mother of the Family to the specfied Person"""
update = self.someChildIsAncestor()
if self.Mother and update:
self.Mother.setAncestor(0)
self.Mother = person
if update and self.Mother:
self.Mother.setAncestor(1)
2001-05-13 07:26:57 +05:30
def getMother(self):
2001-09-07 08:09:30 +05:30
"""returns the mother of the Family"""
2001-05-13 07:26:57 +05:30
return self.Mother
def addChild(self,person):
2001-09-07 08:09:30 +05:30
"""adds the specfied Person as a child of the Family, adding it
to the child list"""
2001-05-13 07:26:57 +05:30
if person not in self.Children:
self.Children.append(person)
if person.ancestor:
if self.Father:
self.Father.setAncestor(1)
if (self.Mother):
self.Mother.setAncestor(1)
2001-05-13 07:26:57 +05:30
def removeChild(self,person):
2001-09-07 08:09:30 +05:30
"""removes the specified Person from the child list"""
self.Children.remove(person)
if person.ancestor:
if self.Father:
self.Father.setAncestor(0)
if (self.Mother):
self.Mother.setAncestor(0)
2001-05-13 07:26:57 +05:30
def getChildList(self):
2001-09-07 08:09:30 +05:30
"""returns the list of children"""
2001-05-13 07:26:57 +05:30
return self.Children
def setChildList(self, list):
"""sets the list of children"""
self.Children = list
2001-05-13 07:26:57 +05:30
def getMarriage(self):
2001-09-07 08:09:30 +05:30
"""returns the marriage event of the Family. Obsolete"""
for e in self.EventList:
if e.getName() == "Marriage":
return e
return None
2001-05-13 07:26:57 +05:30
def getDivorce(self):
2001-09-07 08:09:30 +05:30
"""returns the divorce event of the Family. Obsolete"""
for e in self.EventList:
if e.getName() == "Divorce":
return e
return None
2001-05-13 07:26:57 +05:30
2001-09-07 08:09:30 +05:30
def addEvent(self,event):
"""adds an Event to the event list"""
2001-05-13 07:26:57 +05:30
self.EventList.append(event)
def getEventList(self) :
2001-09-07 08:09:30 +05:30
"""returns the list of Event instances"""
2001-05-13 07:26:57 +05:30
return self.EventList
def setEventList(self,list) :
2001-09-07 08:09:30 +05:30
"""sets the event list to the passed list"""
self.EventList = list
2001-05-13 07:26:57 +05:30
def addPhoto(self,photo):
2001-09-07 08:09:30 +05:30
"""Adds a Photo object to the Family instance's image list"""
2001-05-13 07:26:57 +05:30
self.photoList.append(photo)
def getPhotoList(self):
2001-09-07 08:09:30 +05:30
"""Returns the list of Photo objects"""
2001-05-13 07:26:57 +05:30
return self.photoList
def setPhotoList(self,list):
"""Sets the list of Photo objects"""
self.photoList = list
def someChildIsAncestor(self):
for child in self.Children:
if (child.ancestor):
return 1
return None
class Source:
2001-09-07 08:09:30 +05:30
"""A record of a source of information"""
2001-05-13 07:26:57 +05:30
def __init__(self):
2001-09-07 08:09:30 +05:30
"""creates a new Source instance"""
2001-05-13 07:26:57 +05:30
self.title = ""
self.author = ""
self.pubinfo = ""
self.callno = ""
self.note = Note()
self.photoList = []
self.id = ""
2001-05-13 07:26:57 +05:30
def setId(self,newId):
2001-09-07 08:09:30 +05:30
"""sets the gramps' ID for the Source instance"""
self.id = str(newId)
2001-05-13 07:26:57 +05:30
def getId(self):
2001-09-07 08:09:30 +05:30
"""returns the gramps' ID of the Source instance"""
2001-05-13 07:26:57 +05:30
return self.id
def addPhoto(self,photo):
2001-09-07 08:09:30 +05:30
"""Adds a Photo object to the Source instance's image list"""
self.photoList.append(photo)
def getPhotoList(self):
2001-09-07 08:09:30 +05:30
"""Returns the list of Photo objects"""
return self.photoList
def setPhotoList(self,list):
"""Sets the list of Photo objects"""
self.photoList = list
2001-05-13 07:26:57 +05:30
def setTitle(self,title):
2001-09-07 08:09:30 +05:30
"""sets the title of the Source"""
2001-05-13 07:26:57 +05:30
self.title = title
def getTitle(self):
2001-09-07 08:09:30 +05:30
"""returns the title of the Source"""
2001-05-13 07:26:57 +05:30
return self.title
def setNote(self,text):
2001-09-07 08:09:30 +05:30
"""sets the text of the note attached to the Source"""
self.note.set(text)
def getNote(self):
2001-09-07 08:09:30 +05:30
"""returns the text of the note attached to the Source"""
return self.note.get()
def setNoteObj(self,obj):
2001-09-07 08:09:30 +05:30
"""sets the Note instance attached to the Source"""
self.note = obj
def getNoteObj(self):
2001-09-07 08:09:30 +05:30
"""returns the Note instance attached to the Source"""
return self.note
2001-05-13 07:26:57 +05:30
def setAuthor(self,author):
2001-09-07 08:09:30 +05:30
"""sets the author of the Source"""
2001-05-13 07:26:57 +05:30
self.author = author
def getAuthor(self):
2001-09-07 08:09:30 +05:30
"""returns the author of the Source"""
2001-05-13 07:26:57 +05:30
return self.author
def setPubInfo(self,text):
2001-09-07 08:09:30 +05:30
"""sets the publication information of the Source"""
2001-05-13 07:26:57 +05:30
self.pubinfo = text
def getPubInfo(self):
2001-09-07 08:09:30 +05:30
"""returns the publication information of the Source"""
2001-05-13 07:26:57 +05:30
return self.pubinfo
def setCallNumber(self,val):
2001-09-07 08:09:30 +05:30
"""sets the call number (or some identification indicator)
of the Source"""
2001-05-13 07:26:57 +05:30
self.callno = val
def getCallNumber(self):
2001-09-07 08:09:30 +05:30
"""returns the call number (or some identification indicator)
of the Source"""
2001-05-13 07:26:57 +05:30
return self.callno
class SourceRef:
2001-09-07 08:09:30 +05:30
"""Source reference, containing detailed information about how a
referenced source relates to it"""
def __init__(self,source=None):
2001-09-07 08:09:30 +05:30
"""creates a new SourceRef, copying from the source if present"""
if source:
2001-10-04 09:52:41 +05:30
self.confidence = source.confidence
self.ref = source.ref
self.page = source.page
self.date = Date(source.date)
self.comments = Note(source.comments.get())
self.text = source.text
else:
2001-10-04 09:52:41 +05:30
self.confidence = CONF_NORMAL
self.ref = None
self.page = ""
self.date = Date()
self.comments = Note()
self.text = ""
2001-05-13 07:26:57 +05:30
2001-10-04 09:52:41 +05:30
def setConfidence(self,val):
"""Sets the confidence level"""
self.confidence = val
def getConfidence(self):
"""Returns the confidence level"""
return self.confidence
2001-05-13 07:26:57 +05:30
def setBase(self,ref):
2001-09-07 08:09:30 +05:30
"""sets the Source instance to which the SourceRef refers"""
2001-05-13 07:26:57 +05:30
self.ref = ref
def getBase(self):
2001-09-07 08:09:30 +05:30
"""returns the Source instance to which the SourceRef refers"""
2001-05-13 07:26:57 +05:30
return self.ref
def setDate(self,date):
2001-09-07 08:09:30 +05:30
"""sets the Date instance of the SourceRef"""
2001-05-13 07:26:57 +05:30
self.date = date
def getDate(self):
2001-09-07 08:09:30 +05:30
"""returns the Date instance of the SourceRef"""
2001-05-13 07:26:57 +05:30
return self.date
def setPage(self,page):
2001-09-07 08:09:30 +05:30
"""sets the page indicator of the SourceRef"""
2001-05-13 07:26:57 +05:30
self.page = page
def getPage(self):
2001-09-07 08:09:30 +05:30
"""gets the page indicator of the SourceRef"""
2001-05-13 07:26:57 +05:30
return self.page
def setText(self,text):
2001-09-07 08:09:30 +05:30
"""sets the text related to the SourceRef"""
2001-05-13 07:26:57 +05:30
self.text = text
def getText(self):
2001-09-07 08:09:30 +05:30
"""returns the text related to the SourceRef"""
2001-05-13 07:26:57 +05:30
return self.text
def setNoteObj(self,note):
2001-09-07 08:09:30 +05:30
"""Change the Note instance to obj"""
self.comments = note
2001-05-13 07:26:57 +05:30
def setComments(self,comments):
2001-09-07 08:09:30 +05:30
"""sets the comments about the SourceRef"""
self.comments.set(comments)
def getComments(self):
2001-09-07 08:09:30 +05:30
"""returns the comments about the SourceRef"""
return self.comments.get()
def are_equal(self,other):
2001-09-07 08:09:30 +05:30
"""returns 1 if the passed SourceRef is equal to the current"""
if self.ref and other.ref:
if self.page != other.page:
return 0
if compare_dates(self.date,other.date) != 0:
return 0
if self.getText() != other.getText():
return 0
if self.getComments() != other.getComments():
return 0
2001-10-04 09:52:41 +05:30
if self.confidence != other.confidence:
return 0
return 1
elif not self.ref and not other.ref:
return 1
else:
return 0
2001-05-13 07:26:57 +05:30
#-------------------------------------------------------------------------
#
#
#
#-------------------------------------------------------------------------
class RelDataBase:
2001-09-07 08:09:30 +05:30
"""Gramps database object"""
2001-05-13 07:26:57 +05:30
def __init__(self):
2001-09-07 08:09:30 +05:30
"""creates a new RelDataBase"""
2001-05-13 07:26:57 +05:30
self.new()
self.iprefix = "I%d"
self.sprefix = "S%d"
self.oprefix = "O%d"
self.pprefix = "P%d"
self.fprefix = "F%d"
def set_iprefix(self,val):
if _id_reg.search(val):
self.iprefix = val
else:
self.iprefix = val + "%d"
def set_sprefix(self,val):
if _id_reg.search(val):
self.sprefix = val
else:
self.sprefix = val + "%d"
def set_oprefix(self,val):
if _id_reg.search(val):
self.oprefix = val
else:
self.oprefix = val + "%d"
def set_pprefix(self,val):
if _id_reg.search(val):
self.pprefix = val
else:
self.pprefix = val + "%d"
def set_fprefix(self,val):
if _id_reg.search(val):
self.fprefix = val
else:
self.fprefix = val + "%d"
2001-05-13 07:26:57 +05:30
def new(self):
2001-09-07 08:09:30 +05:30
"""initializes the RelDataBase to empty values"""
2001-05-13 07:26:57 +05:30
self.personMap = {}
self.familyMap = {}
self.sourceMap = {}
self.placeMap = {}
self.objectMap = {}
2001-05-13 07:26:57 +05:30
self.smapIndex = 0
self.pmapIndex = 0
self.fmapIndex = 0
self.lmapIndex = 0
self.omapIndex = 0
2001-05-13 07:26:57 +05:30
self.default = None
self.owner = Researcher()
self.bookmarks = []
self.path = ""
self.place2title = {}
2001-05-13 07:26:57 +05:30
def getBookmarks(self):
2001-09-07 08:09:30 +05:30
"""returns the list of Person instances in the bookmarks"""
return self.bookmarks
2001-05-13 07:26:57 +05:30
def clean_bookmarks(self):
2001-09-07 08:09:30 +05:30
"""cleans up the bookmark list, removing empty slots"""
2001-05-13 07:26:57 +05:30
new_bookmarks = []
for person in self.bookmarks:
new_bookmarks.append(person)
self.bookmarks = new_bookmarks
def setResearcher(self,owner):
2001-09-07 08:09:30 +05:30
"""sets the information about the owner of the database"""
2001-05-13 07:26:57 +05:30
self.owner.set(owner.getName(),owner.getAddress(),owner.getCity(),\
owner.getState(),owner.getCountry(),\
owner.getPostalCode(),owner.getPhone(),owner.getEmail())
def getResearcher(self):
2001-09-07 08:09:30 +05:30
"""returns the Researcher instance, providing information about
the owner of the database"""
2001-05-13 07:26:57 +05:30
return self.owner
def setDefaultPerson(self,person):
2001-09-07 08:09:30 +05:30
"""sets the default Person to the passed instance"""
if (self.default):
self.default.setAncestor(0)
2001-05-13 07:26:57 +05:30
self.default = person
self.default.setAncestor(1)
2001-05-13 07:26:57 +05:30
def getDefaultPerson(self):
2001-09-07 08:09:30 +05:30
"""returns the default Person of the database"""
2001-05-13 07:26:57 +05:30
return self.default
def getPersonMap(self):
2001-09-07 08:09:30 +05:30
"""returns a map of gramps's IDs to Person instances"""
2001-05-13 07:26:57 +05:30
return self.personMap
def setPersonMap(self,map):
2001-09-07 08:09:30 +05:30
"""sets the map of gramps's IDs to Person instances"""
2001-05-13 07:26:57 +05:30
self.personMap = map
def getPlaceMap(self):
2001-09-07 08:09:30 +05:30
"""returns a map of gramps's IDs to Place instances"""
return self.placeMap
def setPlaceMap(self,map):
2001-09-07 08:09:30 +05:30
"""sets the map of gramps's IDs to Place instances"""
self.placeMap = map
2001-05-13 07:26:57 +05:30
def getFamilyMap(self):
2001-09-07 08:09:30 +05:30
"""returns a map of gramps's IDs to Family instances"""
2001-05-13 07:26:57 +05:30
return self.familyMap
def setFamilyMap(self,map):
2001-09-07 08:09:30 +05:30
"""sets the map of gramps's IDs to Family instances"""
2001-05-13 07:26:57 +05:30
self.familyMap = map
2001-09-07 08:09:30 +05:30
def getSourceMap(self):
"""returns a map of gramps's IDs to Source instances"""
return self.sourceMap
def getObjectMap(self):
"""returns a map of gramps's IDs to Object instances"""
return self.objectMap
2001-05-13 07:26:57 +05:30
def getSavePath(self):
2001-09-07 08:09:30 +05:30
"""returns the save path of the file, or "" if one does not exist"""
2001-05-13 07:26:57 +05:30
return self.path
def setSavePath(self,path):
2001-09-07 08:09:30 +05:30
"""sets the save path for the database"""
2001-05-13 07:26:57 +05:30
self.path = path
def getPersonEventTypes(self):
2001-09-07 08:09:30 +05:30
"""returns a list of all Event types assocated with Person
instances in the database"""
2001-05-13 07:26:57 +05:30
map = {}
for person in self.personMap.values():
for event in person.getEventList():
map[event.getName()] = 1
return map.keys()
def getPersonAttributeTypes(self):
2001-09-07 08:09:30 +05:30
"""returns a list of all Attribute types assocated with Person
instances in the database"""
2001-05-13 07:26:57 +05:30
map = {}
for person in self.personMap.values():
for attr in person.getAttributeList():
map[attr.getType()] = 1
return map.keys()
2001-06-03 04:26:04 +05:30
def getFamilyAttributeTypes(self):
2001-09-07 08:09:30 +05:30
"""returns a list of all Attribute types assocated with Family
instances in the database"""
2001-06-03 04:26:04 +05:30
map = {}
for family in self.familyMap.values():
for attr in family.getAttributeList():
map[attr.getType()] = 1
return map.keys()
2001-07-03 22:44:17 +05:30
def getFamilyEventTypes(self):
2001-09-07 08:09:30 +05:30
"""returns a list of all Event types assocated with Family
instances in the database"""
2001-07-03 22:44:17 +05:30
map = {}
for family in self.familyMap.values():
for attr in family.getEventList():
map[attr.getName()] = 1
return map.keys()
def getPlaces(self):
2001-09-07 08:09:30 +05:30
"""returns a list of Place instances"""
return self.placeMap.values()
def getFamilyRelationTypes(self):
2001-09-07 08:09:30 +05:30
"""returns a list of all relationship types assocated with Family
instances in the database"""
map = {}
for family in self.familyMap.values():
map[family.getRelationship()] = 1
return map.keys()
2001-09-07 08:09:30 +05:30
def addPerson(self,person):
"""adds a Person to the database, assigning a gramps' ID"""
index = self.iprefix % self.pmapIndex
2001-09-07 08:09:30 +05:30
while self.personMap.has_key(index):
self.pmapIndex = self.pmapIndex + 1
index = self.iprefix % self.pmapIndex
2001-09-07 08:09:30 +05:30
person.setId(index)
self.personMap[index] = person
self.pmapIndex = self.pmapIndex + 1
return index
2001-05-13 07:26:57 +05:30
def findPerson(self,idVal,map):
2001-09-07 08:09:30 +05:30
"""finds a Person in the database using the idVal and map
variables to translate between the external ID and gramps'
internal ID. If no such Person exists, a new Person instance
is created.
idVal - external ID number
map - map build by findPerson of external to gramp's IDs"""
idVal = str(idVal)
2001-05-13 07:26:57 +05:30
if map.has_key(idVal):
person = self.personMap[map[idVal]]
else:
person = Person()
map[idVal] = self.addPerson(person)
return person
def addPersonNoMap(self,person,id):
2001-09-07 08:09:30 +05:30
"""adds a Person to the database if the gramps' ID is known"""
id = str(id)
2001-05-13 07:26:57 +05:30
person.setId(id)
self.personMap[id] = person
2001-07-16 07:36:31 +05:30
self.pmapIndex = self.pmapIndex+1
2001-05-13 07:26:57 +05:30
return id
def findPersonNoMap(self,idVal):
2001-09-07 08:09:30 +05:30
"""finds a Person in the database from the passed gramps' ID.
If no such Person exists, a new Person is added to the database."""
val = str(idVal)
2001-05-13 07:26:57 +05:30
if self.personMap.has_key(val):
person = self.personMap[val]
else:
person = Person()
self.addPersonNoMap(person,val)
return person
def addSource(self,source):
2001-09-07 08:09:30 +05:30
"""adds a Source instance to the database, assigning it a gramps'
ID number"""
index = self.sprefix % self.smapIndex
2001-07-16 07:36:31 +05:30
while self.sourceMap.has_key(index):
self.smapIndex = self.smapIndex + 1
index = self.sprefix % self.smapIndex
2001-05-13 07:26:57 +05:30
source.setId(index)
self.sourceMap[index] = source
self.smapIndex = self.smapIndex + 1
return index
2001-09-07 08:09:30 +05:30
def findSource(self,idVal,map):
"""finds a Source in the database using the idVal and map
variables to translate between the external ID and gramps'
internal ID. If no such Source exists, a new Source instance
is created.
idVal - external ID number
map - map build by findSource of external to gramp's IDs"""
idVal = str(idVal)
if map.has_key(idVal):
source = self.sourceMap[map[idVal]]
else:
source = Source()
map[idVal] = self.addSource(source)
return source
def addSourceNoMap(self,source,index):
"""adds a Source to the database if the gramps' ID is known"""
index = str(index)
source.setId(index)
self.sourceMap[index] = source
self.smapIndex = self.smapIndex + 1
return index
def findSourceNoMap(self,idVal):
"""finds a Source in the database from the passed gramps' ID.
If no such Source exists, a new Source is added to the database."""
val = str(idVal)
if self.sourceMap.has_key(val):
source = self.sourceMap[val]
else:
source = Source()
self.addSourceNoMap(source,val)
return source
def addObject(self,object):
"""adds an Object instance to the database, assigning it a gramps'
ID number"""
index = self.oprefix % self.omapIndex
while self.objectMap.has_key(index):
self.omapIndex = self.omapIndex + 1
index = self.oprefix % self.omapIndex
object.setId(index)
self.objectMap[index] = object
self.omapIndex = self.omapIndex + 1
return index
def findObject(self,idVal,map):
"""finds an Object in the database using the idVal and map
variables to translate between the external ID and gramps'
internal ID. If no such Object exists, a new Object instance
is created.
idVal - external ID number
map - map build by findObject of external to gramp's IDs"""
idVal = str(idVal)
if map.has_key(idVal):
object = self.objectMap[map[idVal]]
else:
object = Photo()
map[idVal] = self.addObject(object)
return object
def addObjectNoMap(self,object,index):
"""adds an Object to the database if the gramps' ID is known"""
index = str(index)
object.setId(index)
self.objectMap[index] = object
self.omapIndex = self.omapIndex + 1
return index
def findObjectNoMap(self,idVal):
"""finds an Object in the database from the passed gramps' ID.
If no such Source exists, a new Source is added to the database."""
val = str(idVal)
if self.objectMap.has_key(val):
object = self.objectMap[val]
else:
object = Photo()
self.addObjectNoMap(object,val)
return object
def addPlace(self,place):
2001-09-07 08:09:30 +05:30
"""adds a Place instance to the database, assigning it a gramps'
ID number"""
index = self.pprefix % self.lmapIndex
while self.placeMap.has_key(index):
self.lmapIndex = self.lmapIndex + 1
index = self.pprefix % self.lmapIndex
place.setId(index)
self.placeMap[index] = place
self.lmapIndex = self.lmapIndex + 1
return index
def findPlace(self,idVal,map):
2001-09-07 08:09:30 +05:30
"""finds a Place in the database using the idVal and map
variables to translate between the external ID and gramps'
internal ID. If no such Place exists, a new Place instance
is created.
idVal - external ID number
map - map build by findPlace of external to gramp's IDs"""
idVal = str(idVal)
if map.has_key(idVal):
place = self.placeMap[map[idVal]]
else:
2001-09-01 22:43:15 +05:30
place = Place()
map[idVal] = self.addPlace(place)
return place
def addPlaceNoMap(self,place,index):
2001-09-07 08:09:30 +05:30
"""adds a Place to the database if the gramps' ID is known"""
index = str(index)
place.setId(index)
self.placeMap[index] = place
self.lmapIndex = self.lmapIndex + 1
return index
def findPlaceNoMap(self,idVal):
2001-09-07 08:09:30 +05:30
"""finds a Place in the database from the passed gramps' ID.
If no such Place exists, a new Place is added to the database."""
val = str(idVal)
if self.placeMap.has_key(val):
place = self.placeMap[val]
else:
place = Place()
self.addPlaceNoMap(place,val)
return place
2001-05-13 07:26:57 +05:30
def newFamily(self):
2001-09-07 08:09:30 +05:30
"""adds a Family to the database, assigning a gramps' ID"""
index = self.fprefix % self.fmapIndex
2001-07-16 07:36:31 +05:30
while self.familyMap.has_key(index):
self.fmapIndex = self.fmapIndex + 1
index = self.fprefix % self.fmapIndex
2001-05-13 07:26:57 +05:30
self.fmapIndex = self.fmapIndex + 1
family = Family()
2001-07-16 07:36:31 +05:30
family.setId(index)
self.familyMap[index] = family
2001-05-13 07:26:57 +05:30
return family
def newFamilyNoMap(self,id):
2001-09-07 08:09:30 +05:30
"""finds a Family in the database from the passed gramps' ID.
If no such Family exists, a new Family is added to the database."""
2001-05-13 07:26:57 +05:30
family = Family()
id = str(id)
2001-05-13 07:26:57 +05:30
family.setId(id)
self.familyMap[id] = family
2001-07-16 07:36:31 +05:30
self.fmapIndex = self.fmapIndex + 1
2001-05-13 07:26:57 +05:30
return family
def findFamily(self,idVal,map):
2001-09-07 08:09:30 +05:30
"""finds a Family in the database using the idVal and map
variables to translate between the external ID and gramps'
internal ID. If no such Family exists, a new Family instance
is created.
idVal - external ID number
map - map build by findFamily of external to gramp's IDs"""
idVal = str(idVal)
2001-05-13 07:26:57 +05:30
if map.has_key(idVal):
family = self.familyMap[map[idVal]]
else:
family = self.newFamily()
map[idVal] = family.getId()
return family
def findFamilyNoMap(self,idVal):
2001-09-07 08:09:30 +05:30
"""finds a Family in the database from the passed gramps' ID.
If no such Family exists, a new Family is added to the database."""
val = str(idVal)
2001-05-13 07:26:57 +05:30
if self.familyMap.has_key(val):
family = self.familyMap[val]
else:
family = self.newFamilyNoMap(val)
return family
def deleteFamily(self,family):
2001-09-07 08:09:30 +05:30
"""deletes the Family instance from the database"""
2001-05-13 07:26:57 +05:30
if self.familyMap.has_key(family.getId()):
del self.familyMap[family.getId()]