diff --git a/ChangeLog b/ChangeLog index a4285c2ed..9ae58242d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2005-12-20 Alex Roitman + * src/RelLib/__init__.py: More breaking up in RelLib; + * src/RelLib/Makefile.am: Ship new files; + * src/RelLib/ various files: add more files. + 2005-12-20 Richard Taylor * src/RelLib/_helper.py: removed get_backlink_handles * test/RelLib_Test.py: removed test for get_backlink_handles diff --git a/src/RelLib/Makefile.am b/src/RelLib/Makefile.am index a43af3ce4..920231974 100644 --- a/src/RelLib/Makefile.am +++ b/src/RelLib/Makefile.am @@ -6,18 +6,41 @@ pkgdatadir = $(datadir)/@PACKAGE@/RelLib pkgdata_PYTHON = \ + _AddressBase.py\ + _Address.py\ + _AttributeBase.py\ + _Attribute.py\ + _BaseObject.py\ + _DateBase.py\ + _Event.py\ + _EventRef.py\ + _Family.py\ + _GenderStats.py\ __init__.py\ - _helper.py\ - _secondary.py\ - Researcher.py\ - GenderStats.py\ - Person.py\ - Family.py\ - Event.py\ - Place.py\ - Source.py\ - MediaObject.py\ - Repository.py + _LdsOrd.py\ + _LocationBase.py\ + _Location.py\ + _MediaBase.py\ + _MediaObject.py\ + _MediaRef.py\ + _Name.py\ + _NoteBase.py\ + _Note.py\ + _Person.py\ + _PlaceBase.py\ + _Place.py\ + _PrimaryObject.py\ + _PrivacyBase.py\ + _PrivateSourceNote.py\ + _RepoRef.py\ + _Repository.py\ + _Researcher.py\ + _SourceNote.py\ + _Source.py\ + _SourceRef.py\ + _UrlBase.py\ + _Url.py\ + _Witness.py\ pkgpyexecdir = @pkgpyexecdir@/RelLib pkgpythondir = @pkgpythondir@/RelLib diff --git a/src/RelLib/_Address.py b/src/RelLib/_Address.py new file mode 100644 index 000000000..f55c0fc29 --- /dev/null +++ b/src/RelLib/_Address.py @@ -0,0 +1,95 @@ +# +# Gramps - a GTK+/GNOME based genealogy program +# +# Copyright (C) 2000-2005 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$ + +""" +Address class for GRAMPS +""" + +#------------------------------------------------------------------------- +# +# GRAMPS modules +# +#------------------------------------------------------------------------- +from _PrivateSourceNote import PrivateSourceNote +from _DateBase import DateBase +from _LocationBase import LocationBase + +#------------------------------------------------------------------------- +# +# Address for Person/Repository +# +#------------------------------------------------------------------------- +class Address(PrivateSourceNote,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) + DateBase.__init__(self,source) + LocationBase.__init__(self,source) + + if source: + self.street = source.street + else: + self.street = "" + + 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.street] + LocationBase.get_text_data_list() + #return [self.street,self.city,self.state,self.country, + # self.postal,self.phone,self.get_date()] + + 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_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_street(self,val): + """sets the street portion of the Address""" + self.street = val + + def get_street(self): + """returns the street portion of the Address""" + return self.street diff --git a/src/RelLib/_AddressBase.py b/src/RelLib/_AddressBase.py new file mode 100644 index 000000000..e99b116b6 --- /dev/null +++ b/src/RelLib/_AddressBase.py @@ -0,0 +1,102 @@ +# +# Gramps - a GTK+/GNOME based genealogy program +# +# Copyright (C) 2000-2005 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$ + +""" +AddressBase class for GRAMPS +""" + +#------------------------------------------------------------------------- +# +# GRAMPS modules +# +#------------------------------------------------------------------------- +from _Address import Address + +#------------------------------------------------------------------------- +# +# AddressBase classes +# +#------------------------------------------------------------------------- +class AddressBase: + """ + Base class for address-aware objects. + """ + + def __init__(self,source=None): + """ + Initialize a AddressBase. 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: AddressBase + """ + + if source: + self.address_list = [ Address(address) \ + for address in source.address_list ] + else: + self.address_list = [] + + def add_address(self,address): + """ + Adds the L{Address} instance to the object's list of addresses + + @param address: L{Address} instance to add to the object's address list + @type address: list + """ + self.address_list.append(address) + + def remove_address(self,address): + """ + Removes the specified L{Address} instance from the address list + If the instance does not exist in the list, the operation has + no effect. + + @param address: L{Address} instance to remove from the list + @type address: L{Address} + + @return: True if the address was removed, False if it was not in the list. + @rtype: bool + """ + if address in self.address_list: + self.address_list.remove(address) + return True + else: + return False + + def get_address_list(self): + """ + Returns the list of L{Address} instances associated with the object + + @return: Returns the list of L{Address} instances + @rtype: list + """ + return self.address_list + + def set_address_list(self,address_list): + """ + Assigns the passed list to the object's list of L{Address} instances. + @param address_list: List of L{Address} instances to be associated + with the object + @type address_list: list + """ + self.address_list = address_list diff --git a/src/RelLib/_Attribute.py b/src/RelLib/_Attribute.py new file mode 100644 index 000000000..581cd0e84 --- /dev/null +++ b/src/RelLib/_Attribute.py @@ -0,0 +1,123 @@ +# +# Gramps - a GTK+/GNOME based genealogy program +# +# Copyright (C) 2000-2005 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$ + +""" +Attribute class for GRAMPS +""" + +#------------------------------------------------------------------------- +# +# standard python modules +# +#------------------------------------------------------------------------- +from warnings import warn + +#------------------------------------------------------------------------- +# +# GRAMPS modules +# +#------------------------------------------------------------------------- +from _PrivateSourceNote import PrivateSourceNote + +#------------------------------------------------------------------------- +# +# Attribute for Person/Family/MediaObject/MediaRef +# +#------------------------------------------------------------------------- +class Attribute(PrivateSourceNote): + """Provides a simple key/value pair for describing properties. Used + by the Person and Family objects to store descriptive information.""" + + UNKNOWN = -1 + CUSTOM = 0 + CASTE = 1 + DESCRIPTION = 2 + ID = 3 + NATIONAL = 4 + NUM_CHILD = 5 + SSN = 6 + + def __init__(self,source=None): + """creates a new Attribute object, copying from the source if provided""" + PrivateSourceNote.__init__(self,source) + + if source: + self.type = source.type + self.value = source.value + else: + self.type = (Attribute.CUSTOM,"") + self.value = "" + + 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.value] + + 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_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_type(self,val): + """sets the type (or key) of the Attribute instance""" + if not type(val) == tuple: + warn( "set_type now takes a tuple", DeprecationWarning, 2) + # Wrapper for old API + # remove when transitition done. + if val in range(-1,7): + val = (val,'') + else: + val = (Attribute.CUSTOM,val) + self.type = val + + def get_type(self): + """returns the type (or key) or the Attribute instance""" + return self.type + + def set_value(self,val): + """sets the value of the Attribute instance""" + self.value = val + + def get_value(self): + """returns the value of the Attribute instance""" + return self.value diff --git a/src/RelLib/_AttributeBase.py b/src/RelLib/_AttributeBase.py new file mode 100644 index 000000000..a6a1407bd --- /dev/null +++ b/src/RelLib/_AttributeBase.py @@ -0,0 +1,104 @@ +# +# Gramps - a GTK+/GNOME based genealogy program +# +# Copyright (C) 2000-2005 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$ + +""" +AttributeBase class for GRAMPS +""" + +#------------------------------------------------------------------------- +# +# GRAMPS modules +# +#------------------------------------------------------------------------- +from _Attribute import Attribute + +#------------------------------------------------------------------------- +# +# AttributeBase class +# +#------------------------------------------------------------------------- +class AttributeBase: + """ + Base class for attribute-aware objects. + """ + + def __init__(self,source=None): + """ + Initialize a AttributeBase. 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: AttributeBase + """ + + if source: + self.attribute_list = [ Attribute(attribute) \ + for attribute in source.attribute_list ] + else: + self.attribute_list = [] + + def add_attribute(self,attribute): + """ + Adds the L{Attribute} instance to the object's list of attributes + + @param attribute: L{Attribute} instance to add. + @type attribute: L{Attribute} + """ + self.attribute_list.append(attribute) + + def remove_attribute(self,attribute): + """ + Removes the specified L{Attribute} instance from the attribute list + If the instance does not exist in the list, the operation has + no effect. + + @param attribute: L{Attribute} instance to remove from the list + @type attribute: L{Attribute} + + @return: True if the attribute was removed, False if it was not + in the list. + @rtype: bool + """ + if attribute in self.attribute_list: + self.attribute_list.remove(attribute) + return True + else: + return False + + def get_attribute_list(self): + """ + Returns the list of L{Attribute} instances associated with the object. + + @returns: Returns the list of L{Attribute} instances. + @rtype: list + """ + return self.attribute_list + + def set_attribute_list(self,attribute_list): + """ + Assigns the passed list to the Person's list of L{Attribute} instances. + + @param attribute_list: List of L{Attribute} instances to ba associated + with the Person + @type attribute_list: list + """ + self.attribute_list = attribute_list diff --git a/src/RelLib/_BaseObject.py b/src/RelLib/_BaseObject.py new file mode 100644 index 000000000..1922d6c6b --- /dev/null +++ b/src/RelLib/_BaseObject.py @@ -0,0 +1,200 @@ +# +# Gramps - a GTK+/GNOME based genealogy program +# +# Copyright (C) 2000-2005 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$ + +""" +Base Object class for GRAMPS +""" + +#------------------------------------------------------------------------- +# +# standard python modules +# +#------------------------------------------------------------------------- +import re + +#------------------------------------------------------------------------- +# +# Base Object +# +#------------------------------------------------------------------------- +class BaseObject: + """ + The BaseObject is the base class for all data objects in GRAMPS, + whether primary or not. Its main goal is to provide common capabilites + to all objects, such as searching through all available information. + """ + + def __init__(self): + """ + Initialize a BaseObject. + """ + pass + + def matches_string(self,pattern,case_sensitive=False): + """ + Returns True if any text data in the object or any of it's child + objects matches a given pattern. + + @param pattern: The pattern to match. + @type pattern: str + @param case_sensitive: Whether the match is case-sensitive. + @type case_sensitive: bool + @return: Returns whether any text data in the object or any of it's child objects matches a given pattern. + @rtype: bool + """ + # Run through its own items + patern_upper = pattern.upper() + for item in self.get_text_data_list(): + if not item: + continue + if case_sensitive: + if item.find(pattern) != -1: + return True + else: + if item.upper().find(patern_upper) != -1: + return True + + # Run through child objects + for obj in self.get_text_data_child_list(): + if obj.matches_string(pattern,case_sensitive): + return True + + return False + + def matches_regexp(self,pattern,case_sensitive=False): + """ + Returns True if any text data in the object or any of it's child + objects matches a given regular expression. + + @param pattern: The pattern to match. + @type pattern: str + @return: Returns whether any text data in the object or any of it's child objects matches a given regexp. + @rtype: bool + """ + + # Run through its own items + if case_sensitive: + pattern_obj = re.compile(pattern) + else: + pattern_obj = re.compile(pattern,re.IGNORECASE) + for item in self.get_text_data_list(): + if item and pattern_obj.match(item): + return True + + # Run through child objects + for obj in self.get_text_data_child_list(): + if obj.matches_regexp(pattern,case_sensitive): + return True + + return False + + 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 [] + + 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 + """ + return [] + + def get_referenced_handles(self): + """ + Returns the list of (classname,handle) tuples for all directly + referenced primary objects. + + @return: Returns the list of (classname,handle) tuples for referenced objects. + @rtype: list + """ + 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 [] + + def get_referenced_handles_recursively(self): + """ + Returns the list of (classname,handle) tuples for all referenced + primary objects, whether directly or through child objects. + + @return: Returns the list of (classname,handle) tuples for referenced objects. + @rtype: list + """ + ret = self.get_referenced_handles() + + # Run through child objects + for obj in self.get_handle_referents(): + ret += obj.get_referenced_handles_recursively() + + return ret + +class PrivacyBase: + """ + Base class for privacy-aware objects. + """ + + def __init__(self,source=None): + """ + Initialize a PrivacyBase. 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: PrivacyBase + """ + + if source: + self.private = source.private + else: + self.private = False + + def set_privacy(self,val): + """ + Sets or clears the privacy flag of the data + + @param val: value to assign to the privacy flag. True indicates that the + record is private, False indicates that it is public. + @type val: bool + """ + self.private = val + + def get_privacy(self): + """ + Returns the privacy level of the data. + + @returns: True indicates that the record is private + @rtype: bool + """ + return self.private diff --git a/src/RelLib/_DateBase.py b/src/RelLib/_DateBase.py new file mode 100644 index 000000000..556b8bfd9 --- /dev/null +++ b/src/RelLib/_DateBase.py @@ -0,0 +1,116 @@ +# +# Gramps - a GTK+/GNOME based genealogy program +# +# Copyright (C) 2000-2005 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$ + +""" +DateBase class for GRAMPS +""" + +#------------------------------------------------------------------------- +# +# GRAMPS modules +# +#------------------------------------------------------------------------- +import Date + +#------------------------------------------------------------------------- +# +# Base classes +# +#------------------------------------------------------------------------- +class DateBase: + """ + Base class for storing date information. + """ + + def __init__(self,source=None): + """ + Create a new DateBase, copying from source if not None + + @param source: Object used to initialize the new object + @type source: DateBase + """ + if source: + self.date = Date.Date(source.date) + else: + self.date = None + +# def set_date(self, date) : +# """ +# Sets the date of the DateBase instance. + +# The date is parsed into a L{Date} instance. + +# @param date: String representation of a date. The locale specific +# L{DateParser} is used to parse the string into a GRAMPS L{Date} +# object. +# @type date: str +# """ +# self.date = DateHandler.parser.parse(date) + +# def get_date(self) : +# """ +# Returns a string representation of the date of the DateBase instance. + +# This representation is based off the default date display format +# determined by the locale's L{DateDisplay} instance. + +# @return: Returns a string representing the DateBase date +# @rtype: str +# """ +# if self.date: +# return DateHandler.displayer.display(self.date) +# return u"" + +# def get_quote_date(self) : +# """ +# Returns a string representation of the date of the DateBase instance. + +# This representation is based off the default date display format +# determined by the locale's L{DateDisplay} instance. The date is +# enclosed in quotes if the L{Date} is not a valid date. + +# @return: Returns a string representing the DateBase date +# @rtype: str +# """ +# if self.date: +# return DateHandler.displayer.quote_display(self.date) +# return u"" + + def get_date_object(self): + """ + Returns the L{Date} object associated with the DateBase. + + @return: Returns a DateBase L{Date} instance. + @rtype: L{Date} + """ + if not self.date: + self.date = Date.Date() + return self.date + + def set_date_object(self,date): + """ + Sets the L{Date} object associated with the DateBase. + + @param date: L{Date} instance to be assigned to the DateBase + @type date: L{Date} + """ + self.date = date diff --git a/src/RelLib/Event.py b/src/RelLib/_Event.py similarity index 97% rename from src/RelLib/Event.py rename to src/RelLib/_Event.py index 4ccaa47d4..f72eb2ba8 100644 --- a/src/RelLib/Event.py +++ b/src/RelLib/_Event.py @@ -23,6 +23,7 @@ """ Event object for GRAMPS """ + #------------------------------------------------------------------------- # # standard python modules @@ -35,9 +36,17 @@ from warnings import warn # GRAMPS modules # #------------------------------------------------------------------------- -from _helper import PrimaryObject,SourceNote,MediaBase,DateBase,PlaceBase - +from _PrimaryObject import PrimaryObject +from _SourceNote import SourceNote +from _MediaBase import MediaBase +from _DateBase import DateBase +from _PlaceBase import PlaceBase +#------------------------------------------------------------------------- +# +# Event class +# +#------------------------------------------------------------------------- class Event(PrimaryObject,SourceNote,MediaBase,DateBase,PlaceBase): """ Introduction @@ -364,4 +373,3 @@ class Event(PrimaryObject,SourceNote,MediaBase,DateBase,PlaceBase): def set_ext_witness_list(self,witness_list): self.ext_witness_list = witness_list - diff --git a/src/RelLib/_EventRef.py b/src/RelLib/_EventRef.py new file mode 100644 index 000000000..9f1786ff6 --- /dev/null +++ b/src/RelLib/_EventRef.py @@ -0,0 +1,143 @@ +# +# Gramps - a GTK+/GNOME based genealogy program +# +# Copyright (C) 2000-2005 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$ + +""" +Event Reference class for GRAMPS +""" + +#------------------------------------------------------------------------- +# +# standard python modules +# +#------------------------------------------------------------------------- +from warnings import warn + +#------------------------------------------------------------------------- +# +# GRAMPS modules +# +#------------------------------------------------------------------------- +from _BaseObject import BaseObject +from _PrivacyBase import PrivacyBase +from _NoteBase import NoteBase + +#------------------------------------------------------------------------- +# +# Event References for Person/Family +# +#------------------------------------------------------------------------- +class EventRef(BaseObject,PrivacyBase,NoteBase): + """ + Event reference class. + + This class is for keeping information about how the person relates + to the refereneced event. + """ + + UNKNOWN = -1 + CUSTOM = 0 + PRIMARY = 1 + CLERGY = 2 + CELEBRANT = 3 + AIDE = 4 + BRIDE = 5 + GROOM = 6 + WITNESS = 7 + FAMILY = 8 + + def __init__(self,source=None): + """ + Creates a new EventRef instance, copying from the source if present. + """ + PrivacyBase.__init__(self) + NoteBase.__init__(self) + if source: + self.ref = source.ref + self.role = source.role_int + else: + self.ref = None + self.role = (EventRef.CUSTOM,"") + + def get_text_data_list(self): + """ + Returns the list of all textual attributes of the object. + + @return: Returns the list of all textual attributes of the object. + @rtype: list + """ + return [self.role_str] + + def get_text_data_child_list(self): + """ + Returns the list of child objects that may carry textual data. + + @return: Returns the list of child objects that may carry textual data. + @rtype: list + """ + if self.note: + return [self.note] + return [] + + def get_referenced_handles(self): + """ + Returns the list of (classname,handle) tuples for all directly + referenced primary objects. + + @return: Returns the list of (classname,handle) tuples for referenced objects. + @rtype: list + """ + if self.ref: + return [('Event',self.ref)] + else: + return [] + + def get_reference_handle(self): + """ + Returns the handle of the referred Event object. + """ + 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. + """ + return self.role + + def set_role(self,role): + """ + Sets the role according to the given argument. + """ + if not type(role) == tuple: + if role in range(-1,9): + warn( "set_role now takes a tuple", DeprecationWarning, 2) + # Wrapper for old API + # remove when transitition done. + role = (role,'') + else: + assert type(role) == tuple + self.role = role diff --git a/src/RelLib/Family.py b/src/RelLib/_Family.py similarity index 97% rename from src/RelLib/Family.py rename to src/RelLib/_Family.py index e0f933926..5c4d67c7f 100644 --- a/src/RelLib/Family.py +++ b/src/RelLib/_Family.py @@ -36,9 +36,17 @@ from warnings import warn # GRAMPS modules # #------------------------------------------------------------------------- -from _helper import PrimaryObject,SourceNote,MediaBase,AttributeBase -from _secondary import EventRef +from _PrimaryObject import PrimaryObject +from _SourceNote import SourceNote +from _MediaBase import MediaBase +from _AttributeBase import AttributeBase +from _EventRef import EventRef +#------------------------------------------------------------------------- +# +# Family class +# +#------------------------------------------------------------------------- class Family(PrimaryObject,SourceNote,MediaBase,AttributeBase): """ Introduction diff --git a/src/RelLib/GenderStats.py b/src/RelLib/_GenderStats.py similarity index 99% rename from src/RelLib/GenderStats.py rename to src/RelLib/_GenderStats.py index 898a625a8..487dca4f8 100644 --- a/src/RelLib/GenderStats.py +++ b/src/RelLib/_GenderStats.py @@ -29,7 +29,7 @@ Gender statistics kept in GRAMPS database. # GRAMPS modules # #------------------------------------------------------------------------- -from Person import Person +from _Person import Person #------------------------------------------------------------------------- # diff --git a/src/RelLib/_LdsOrd.py b/src/RelLib/_LdsOrd.py new file mode 100644 index 000000000..8a5d549ac --- /dev/null +++ b/src/RelLib/_LdsOrd.py @@ -0,0 +1,164 @@ +# +# Gramps - a GTK+/GNOME based genealogy program +# +# Copyright (C) 2000-2005 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$ + +""" +LDS Ordinance class for GRAMPS +""" + +#------------------------------------------------------------------------- +# +# GRAMPS modules +# +#------------------------------------------------------------------------- +from _SourceNote import SourceNote +from _DateBase import DateBase +from _PlaceBase import PlaceBase + +#------------------------------------------------------------------------- +# +# LDS Ordinance class +# +#------------------------------------------------------------------------- +class LdsOrd(SourceNote,DateBase,PlaceBase): + """ + Class that contains information about LDS Ordinances. LDS + ordinances are similar to events, but have very specific additional + information related to data collected by the Church of Jesus Christ + of Latter Day Saints (Morman church). The LDS church is the largest + source of genealogical information in the United States. + """ + def __init__(self,source=None): + """Creates a LDS Ordinance instance""" + SourceNote.__init__(self,source) + DateBase.__init__(self,source) + PlaceBase.__init__(self,source) + + if source: + self.famc = source.famc + self.temple = source.temple + self.status = source.status + else: + self.famc = None + self.temple = "" + self.status = 0 + + 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.temple] + #return [self.temple,self.get_date()] + + 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.place: + return [('Place',self.place)] + 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_family_handle(self,family): + """Sets the Family database handle associated with the LDS ordinance""" + self.famc = family + + def get_family_handle(self): + """Gets the Family database handle associated with the LDS ordinance""" + return self.famc + + def set_status(self,val): + """ + Sets the status of the LDS ordinance. The status is a text string + that matches a predefined set of strings.""" + self.status = val + + def get_status(self): + """Gets the status of the LDS ordinance""" + return self.status + + def set_temple(self,temple): + """Sets the temple assocated with the ordinance""" + self.temple = temple + + def get_temple(self): + """Gets the temple assocated with the ordinance""" + return self.temple + + def is_empty(self): + """Returns 1 if the ordidance is actually empty""" + if (self.famc or + (self.date and not self.date.is_empty()) or + self.temple or + self.status or + self.place): + return False + else: + return True + + def are_equal(self,other): + """returns 1 if the specified ordinance is the same as the instance""" + if other == None: + return self.is_empty() + if (self.famc != other.famc or + self.place != other.place or + self.status != other.status or + self.temple != other.temple or + not self.get_date_object().is_equal(other.get_date_object()) or + len(self.get_source_references()) != len(other.get_source_references())): + return False + + index = 0 + olist = other.get_source_references() + for a in self.get_source_references(): + if not a.are_equal(olist[index]): + return False + index += 1 + return True diff --git a/src/RelLib/_Location.py b/src/RelLib/_Location.py new file mode 100644 index 000000000..48d31dbbb --- /dev/null +++ b/src/RelLib/_Location.py @@ -0,0 +1,90 @@ +# +# Gramps - a GTK+/GNOME based genealogy program +# +# Copyright (C) 2000-2005 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$ + +""" +Location class for GRAMPS +""" + +#------------------------------------------------------------------------- +# +# GRAMPS modules +# +#------------------------------------------------------------------------- +from _BaseObject import BaseObject +from _LocationBase import LocationBase + +#------------------------------------------------------------------------- +# +# Location class for Places +# +#------------------------------------------------------------------------- +class Location(BaseObject,LocationBase): + """ + Provides information about a place. + + The data 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): + """ + Creates a Location object, copying from the source object if it exists. + """ + + BaseObject.__init__(self) + LocationBase.__init__(self,source) + if source: + self.parish = source.parish + self.county = source.county + else: + self.parish = "" + self.county = "" + + 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.parish,self.county] + LocationBase.get_text_data_list() + + def is_empty(self): + return not self.city and not self.county and not self.state and \ + not self.country and not self.postal and not self.phone + + 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): + """sets the county name of the Location object""" + self.county = data + + def get_county(self): + """returns the county name of the Location object""" + return self.county diff --git a/src/RelLib/_LocationBase.py b/src/RelLib/_LocationBase.py new file mode 100644 index 000000000..73400fe1b --- /dev/null +++ b/src/RelLib/_LocationBase.py @@ -0,0 +1,102 @@ +# +# Gramps - a GTK+/GNOME based genealogy program +# +# Copyright (C) 2000-2005 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$ + +""" +LocationBase class for GRAMPS +""" + +#------------------------------------------------------------------------- +# +# LocationBase class +# +#------------------------------------------------------------------------- +class LocationBase: + """ + Base class for all things Address. + """ + + def __init__(self,source=None): + """ + Creates a LocationBase object, + copying from the source object if it exists. + """ + if source: + self.city = source.city + self.state = source.state + self.country = source.country + self.postal = source.postal + self.phone = source.phone + else: + self.city = "" + self.state = "" + self.country = "" + self.postal = "" + self.phone = "" + + 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.city,self.state,self.country,self.postal,self.phone] + + def set_city(self,data): + """sets the city name of the LocationBase object""" + self.city = data + + def get_city(self): + """returns the city name of the LocationBase object""" + return self.city + + def set_postal_code(self,data): + """sets the postal code of the LocationBase object""" + self.postal = data + + def get_postal_code(self): + """returns the postal code of the LocationBase object""" + return self.postal + + def set_phone(self,data): + """sets the phone number of the LocationBase object""" + self.phone = data + + def get_phone(self): + """returns the phone number of the LocationBase object""" + return self.phone + + def set_state(self,data): + """sets the state name of the LocationBase object""" + self.state = data + + def get_state(self): + """returns the state name of the LocationBase object""" + return self.state + + def set_country(self,data): + """sets the country name of the LocationBase object""" + self.country = data + + def get_country(self): + """returns the country name of the LocationBase object""" + return self.country diff --git a/src/RelLib/_MediaBase.py b/src/RelLib/_MediaBase.py new file mode 100644 index 000000000..08732074f --- /dev/null +++ b/src/RelLib/_MediaBase.py @@ -0,0 +1,124 @@ +# +# Gramps - a GTK+/GNOME based genealogy program +# +# Copyright (C) 2000-2005 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$ + +""" +MediaBase class for GRAMPS +""" + +#------------------------------------------------------------------------- +# +# GRAMPS modules +# +#------------------------------------------------------------------------- +from _MediaRef import MediaRef + +#------------------------------------------------------------------------- +# +# MediaBase class +# +#------------------------------------------------------------------------- +class MediaBase: + """ + Base class for storing media references + """ + + def __init__(self,source=None): + """ + Create a new MediaBase, copying from source if not None + + @param source: Object used to initialize the new object + @type source: MediaBase + """ + + if source: + self.media_list = [ MediaRef(mref) for mref in source.media_list ] + else: + self.media_list = [] + + def add_media_reference(self,media_ref): + """ + Adds a L{MediaRef} instance to the object's media list. + + @param media_ref: L{MediaRef} instance to be added to the object's + media list. + @type media_ref: L{MediaRef} + """ + self.media_list.append(media_ref) + + def get_media_list(self): + """ + Returns the list of L{MediaRef} instances associated with the object. + + @returns: list of L{MediaRef} instances associated with the object + @rtype: list + """ + return self.media_list + + def set_media_list(self,media_ref_list): + """ + Sets the list of L{MediaRef} instances associated with the object. + It replaces the previous list. + + @param media_ref_list: list of L{MediaRef} instances to be assigned + to the object. + @type media_ref_list: list + """ + self.media_list = media_ref_list + + def has_media_reference(self,obj_handle) : + """ + Returns True if the object or any of it's child objects has reference + to this media object handle. + + @param obj_handle: The media handle to be checked. + @type obj_handle: str + @return: Returns whether the object or any of it's child objects has reference to this media handle. + @rtype: bool + """ + return obj_handle in [media_ref.ref for media_ref in self.media_list] + + def remove_media_references(self,obj_handle_list): + """ + Removes references to all media handles in the list. + + @param obj_handle_list: The list of media handles to be removed. + @type obj_handle_list: list + """ + new_media_list = [ media_ref for media_ref in self.media_list \ + if media_ref.ref not in obj_handle_list ] + self.media_list = new_media_list + + def replace_media_references(self,old_handle,new_handle): + """ + Replaces all references to old media handle with the new handle. + + @param old_handle: The media handle to be replaced. + @type old_handle: str + @param new_handle: The media handle to replace the old one with. + @type new_handle: str + """ + refs_list = [ media_ref.ref for media_ref in self.media_list ] + n_replace = refs_list.count(old_handle) + for ix_replace in xrange(n_replace): + ix = refs_list.index(old_handle) + self.media_list[ix].ref = new_handle + refs_list[ix] = new_handle diff --git a/src/RelLib/MediaObject.py b/src/RelLib/_MediaObject.py similarity index 94% rename from src/RelLib/MediaObject.py rename to src/RelLib/_MediaObject.py index efceb59a0..a3092fdce 100644 --- a/src/RelLib/MediaObject.py +++ b/src/RelLib/_MediaObject.py @@ -36,9 +36,16 @@ import os # GRAMPS modules # #------------------------------------------------------------------------- -from _helper import PrimaryObject,SourceNote,DateBase,AttributeBase - +from _PrimaryObject import PrimaryObject +from _SourceNote import SourceNote +from _DateBase import DateBase +from _AttributeBase import AttributeBase +#------------------------------------------------------------------------- +# +# MediaObject class +# +#------------------------------------------------------------------------- class MediaObject(PrimaryObject,SourceNote,DateBase,AttributeBase): """ Containter for information about an image file, including location, @@ -175,4 +182,3 @@ class MediaObject(PrimaryObject,SourceNote,DateBase,AttributeBase): def get_description(self): """returns the description of the image""" return self.desc - diff --git a/src/RelLib/_MediaRef.py b/src/RelLib/_MediaRef.py new file mode 100644 index 000000000..5c12fb105 --- /dev/null +++ b/src/RelLib/_MediaRef.py @@ -0,0 +1,110 @@ +# +# Gramps - a GTK+/GNOME based genealogy program +# +# Copyright (C) 2000-2005 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$ + +""" +Media Reference class for GRAMPS +""" + +#------------------------------------------------------------------------- +# +# GRAMPS modules +# +#------------------------------------------------------------------------- +from _PrivateSourceNote import PrivateSourceNote +from _AttributeBase import AttributeBase + +#------------------------------------------------------------------------- +# +# MediaObject References for Person/Place/Source +# +#------------------------------------------------------------------------- +class MediaRef(PrivateSourceNote,AttributeBase): + """Media reference class""" + def __init__(self,source=None): + + PrivateSourceNote.__init__(self,source) + AttributeBase.__init__(self,source) + + if source: + self.ref = source.ref + self.rect = source.rect + else: + self.ref = None + self.rect = None + + 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.attribute_list + self.source_list + if self.note: + check_list.append(self.note) + return check_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 self.attribute_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 [('MediaObject',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.attribute_list + self.source_list + + def set_rectangle(self,coord): + """Sets subection of an image""" + self.rect = coord + + 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 diff --git a/src/RelLib/_Name.py b/src/RelLib/_Name.py new file mode 100644 index 000000000..1c8e2ddd5 --- /dev/null +++ b/src/RelLib/_Name.py @@ -0,0 +1,366 @@ +# +# Gramps - a GTK+/GNOME based genealogy program +# +# Copyright (C) 2000-2005 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$ + +""" +Name class for GRAMPS +""" + +#------------------------------------------------------------------------- +# +# standard python modules +# +#------------------------------------------------------------------------- +from warnings import warn + +#------------------------------------------------------------------------- +# +# GRAMPS modules +# +#------------------------------------------------------------------------- +from _PrivateSourceNote import PrivateSourceNote +from _DateBase import DateBase + +#------------------------------------------------------------------------- +# +# Personal Name +# +#------------------------------------------------------------------------- +class Name(PrivateSourceNote,DateBase): + """ + Provides name information about a person. + + A person may have more that one name throughout his or her life. + """ + + DEF = 0 # locale default + LNFN = 1 # last name first name [patronymic] + FNLN = 2 # first name last name + PTFN = 3 # patronymic last name + FN = 4 # first name + + UNKNOWN = -1 + CUSTOM = 0 + AKA = 1 + BIRTH = 2 + MARRIED = 3 + + def __init__(self,source=None): + """creates a new Name instance, copying from the source if provided""" + PrivateSourceNote.__init__(self,source) + DateBase.__init__(self,source) + + if source: + self.first_name = source.first_name + self.surname = source.surname + self.suffix = source.suffix + self.title = source.title + self.type = source.type + self.prefix = source.prefix + self.patronymic = source.patronymic + self.sname = source.sname + self.group_as = source.group_as + self.sort_as = source.sort_as + self.display_as = source.display_as + else: + self.first_name = "" + self.surname = "" + self.suffix = "" + self.title = "" + self.type = (Name.BIRTH,"") + self.prefix = "" + self.patronymic = "" + self.sname = '@' + self.group_as = "" + self.sort_as = self.DEF + self.display_as = self.DEF + + 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.first_name,self.surname,self.suffix,self.title, + self.type[1],self.prefix,self.patronymic] + #return [self.first_name,self.surname,self.suffix,self.title, + # self.type[1],self.prefix,self.patronymic,self.get_date()] + + 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_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_group_as(self,name): + """ + Sets the grouping name for a person. Normally, this is the person's + surname. However, some locales group equivalent names (e.g. Ivanova + and Ivanov in Russian are usually considered equivalent. + """ + if name == self.surname: + self.group_as = "" + else: + self.group_as = name + + def get_group_as(self): + """ + Returns the grouping name, which is used to group equivalent surnames. + """ + return self.group_as + + def get_group_name(self): + """ + Returns the grouping name, which is used to group equivalent surnames. + """ + if self.group_as: + return self.group_as + else: + return self.surname + + def set_sort_as(self,value): + """ + Specifies the sorting method for the specified name. Typically the + locale's default should be used. However, there may be names where + a specific sorting structure is desired for a name. + """ + self.sort_as = value + + def get_sort_as(self): + """ + Returns the selected sorting method for the name. The options are + DEF (default for the current locale), LNFN (last name, first name), + or FNLN (first name, last name). + """ + return self.sort_as + + def set_display_as(self,value): + """ + Specifies the display format for the specified name. Typically the + locale's default should be used. However, there may be names where + a specific display format is desired for a name. + """ + self.display_as = value + + def get_display_as(self): + """ + Returns the selected display format for the name. The options are + DEF (default for the current locale), LNFN (last name, first name), + or FNLN (first name, last name). + """ + return self.display_as + + def get_surname_prefix(self): + """ + Returns the prefix (or article) of a surname. The prefix is not + used for sorting or grouping. + """ + return self.prefix + + def set_surname_prefix(self,val): + """ + Sets the prefix (or article) of a surname. Examples of articles + would be 'de' or 'van'. + """ + self.prefix = val + + def set_type(self,the_type): + """sets the type of the Name instance""" + if not type(the_type) == tuple: + if the_type in [UNKNOWN,CUSTOM,AKA,BIRTH,MARRIED]: + warn( "set_type now takes a tuple", DeprecationWarning, 2) + # Wrapper for old API + # remove when transitition done. + the_type = (the_type,'') + else: + assert type(the_type) == tuple + self.type = the_type + + def get_type(self): + """returns the type of the Name instance""" + return self.type + + def build_sort_name(self): + if self.surname: + self.sname = "%-25s%-30s%s" % (self.surname,self.first_name,self.suffix) + else: + self.sname = "@" + + def set_first_name(self,name): + """sets the given name for the Name instance""" + self.first_name = name + self.build_sort_name() + + def set_patronymic(self,name): + """sets the patronymic name for the Name instance""" + self.patronymic = name + self.build_sort_name() + + def set_surname(self,name): + """sets the surname (or last name) for the Name instance""" + self.surname = name + self.build_sort_name() + + def set_suffix(self,name): + """sets the suffix (such as Jr., III, etc.) for the Name instance""" + self.suffix = name + self.build_sort_name() + + def get_sort_name(self): + return self.sname + + def get_first_name(self): + """returns the given name for the Name instance""" + return self.first_name + + def get_patronymic(self): + """returns the patronymic name for the Name instance""" + return self.patronymic + + def get_surname(self): + """returns the surname (or last name) for the Name instance""" + return self.surname + + def get_upper_surname(self): + """returns the surname (or last name) for the Name instance""" + return self.surname.upper() + + def get_suffix(self): + """returns the suffix for the Name instance""" + return self.suffix + + def set_title(self,title): + """sets the title (Dr., Reverand, Captain) for the Name instance""" + self.title = title + + def get_title(self): + """returns the title for the Name instance""" + return self.title + + def get_name(self): + """returns a name string built from the components of the Name + instance, in the form of surname, Firstname""" + + if self.patronymic: + first = "%s %s" % (self.first_name, self.patronymic) + else: + first = self.first_name + if self.suffix: + if self.prefix: + return "%s %s, %s %s" % (self.prefix, self.surname, first, self.suffix) + else: + return "%s, %s %s" % (self.surname, first, self.suffix) + else: + if self.prefix: + return "%s %s, %s" % (self.prefix,self.surname, first) + else: + return "%s, %s" % (self.surname, first) + + def get_upper_name(self): + """returns a name string built from the components of the Name + instance, in the form of surname, Firstname""" + + if self.patronymic: + first = "%s %s" % (self.first_name, self.patronymic) + else: + first = self.first_name + if self.suffix: + if self.prefix: + return "%s %s, %s %s" % (self.prefix.upper(), self.surname.upper(), first, self.suffix) + else: + return "%s, %s %s" % (self.surname.upper(), first, self.suffix) + else: + if self.prefix: + return "%s %s, %s" % (self.prefix.upper(), self.surname.upper(), first) + else: + return "%s, %s" % (self.surname.upper(), first) + + def get_regular_name(self): + """returns a name string built from the components of the Name + instance, in the form of Firstname surname""" + if self.patronymic: + first = "%s %s" % (self.first_name, self.patronymic) + else: + first = self.first_name + if (self.suffix == ""): + if self.prefix: + return "%s %s %s" % (first, self.prefix, self.surname) + else: + return "%s %s" % (first, self.surname) + else: + if self.prefix: + return "%s %s %s, %s" % (first, self.prefix, self.surname, self.suffix) + else: + return "%s %s, %s" % (first, self.surname, self.suffix) + + def is_equal(self,other): + """ + compares to names to see if they are equal, return 0 if they + are not + """ + if self.first_name != other.first_name: + return False + if self.surname != other.surname: + return False + if self.patronymic != other.patronymic: + return False + if self.prefix != other.prefix: + return False + if self.suffix != other.suffix: + return False + if self.title != other.title: + return False + if self.type != other.type: + return False + if self.private != other.private: + return False + if self.get_note() != other.get_note(): + return False + if (self.date and other.date and not self.date.is_equal(other.date)) \ + or (self.date and not other.date) \ + or (not self.date and other.date): + return False + if len(self.get_source_references()) != len(other.get_source_references()): + return False + index = 0 + olist = other.get_source_references() + for a in self.get_source_references(): + if not a.are_equal(olist[index]): + return True + index += 1 + return True diff --git a/src/RelLib/_Note.py b/src/RelLib/_Note.py new file mode 100644 index 000000000..f08b9a629 --- /dev/null +++ b/src/RelLib/_Note.py @@ -0,0 +1,110 @@ +# +# Gramps - a GTK+/GNOME based genealogy program +# +# Copyright (C) 2000-2005 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$ + +""" +Note class for GRAMPS +""" + +#------------------------------------------------------------------------- +# +# GRAMPS modules +# +#------------------------------------------------------------------------- +from _BaseObject import BaseObject + +#------------------------------------------------------------------------- +# +# Class for notes used throughout the majority of GRAMPS objects +# +#------------------------------------------------------------------------- +class Note(BaseObject): + """ + Introduction + ============ + The Note class defines a text note. The note may be preformatted + or 'flowed', which indicates that it text string is considered + to be in paragraphs, separated by newlines. + """ + + def __init__(self,text = ""): + """ + Creates a new Note object, initializing from the passed string. + """ + BaseObject.__init__(self) + self.text = text + self.format = 0 + + 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.text] + + def set(self,text): + """ + Sets the text associated with the note to the passed string. + + @param text: Text string defining the note contents. + @type text: str + """ + self.text = text + + def get(self): + """ + Return the text string associated with the note. + @returns: Returns the text string defining the note contents. + @rtype: str + """ + return self.text + + def append(self,text): + """ + Appends the specified text to the text associated with the note. + + @param text: Text string to be appended to the note. + @type text: str + """ + self.text = self.text + text + + def set_format(self,format): + """ + Sets the format of the note to the passed value. The value can + either indicate Flowed or Preformatted. + + @param format: 0 indicates Flowed, 1 indicates Preformated + @type format: int + """ + self.format = format + + def get_format(self): + """ + Returns the format of the note. The value can either indicate + Flowed or Preformatted. + + @returns: 0 indicates Flowed, 1 indicates Preformated + @rtype: int + """ + return self.format + diff --git a/src/RelLib/_NoteBase.py b/src/RelLib/_NoteBase.py new file mode 100644 index 000000000..2b11794d1 --- /dev/null +++ b/src/RelLib/_NoteBase.py @@ -0,0 +1,121 @@ +# +# Gramps - a GTK+/GNOME based genealogy program +# +# Copyright (C) 2000-2005 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$ + +""" +NoteBase class for GRAMPS +""" + +#------------------------------------------------------------------------- +# +# GRAMPS modules +# +#------------------------------------------------------------------------- +from _Note import Note + +#------------------------------------------------------------------------- +# +# NoteBase class +# +#------------------------------------------------------------------------- +class NoteBase: + """ + Base class for storing notes. + """ + def __init__(self,source=None): + """ + Create a new NoteBase, copying from source if not None + + @param source: Object used to initialize the new object + @type source: NoteBase + """ + + if source and source.note: + self.note = Note(source.note.get()) + else: + self.note = None + + def set_note(self,text): + """ + Assigns the specified text to the associated note. + + @param text: Text of the note + @type text: str + """ + if not self.note: + self.note = Note() + self.note.set(text) + + def get_note(self): + """ + Returns the text of the current note. + + @returns: the text of the current note + @rtype: str + """ + if self.note: + return self.note.get() + return "" + + def set_note_format(self,val): + """ + Sets the note's format to the given value. The format indicates + whether the text is flowed (wrapped) or preformatted. + + @param val: True indicates the text is flowed + @type val: bool + """ + if self.note: + self.note.set_format(val) + + def get_note_format(self): + """ + Returns the current note's format + + @returns: True indicates that the note should be flowed (wrapped) + @rtype: bool + """ + if self.note == None: + return False + else: + return self.note.get_format() + + def set_note_object(self,note_obj): + """ + Replaces the current L{Note} object associated with the object + + @param note_obj: New L{Note} object to be assigned + @type note_obj: L{Note} + """ + self.note = note_obj + + def get_note_object(self): + """ + Returns the L{Note} instance associated with the object. + + @returns: L{Note} object assocated with the object + @rtype: L{Note} + """ + return self.note + + def unique_note(self): + """Creates a unique instance of the current note""" + self.note = Note(self.note.get()) diff --git a/src/RelLib/Person.py b/src/RelLib/_Person.py similarity index 98% rename from src/RelLib/Person.py rename to src/RelLib/_Person.py index 5b92b317c..876571e82 100644 --- a/src/RelLib/Person.py +++ b/src/RelLib/_Person.py @@ -36,11 +36,20 @@ from warnings import warn # GRAMPS modules # #------------------------------------------------------------------------- -from _helper import PrimaryObject,SourceNote,MediaBase,\ - AttributeBase,AddressBase,UrlBase -from _secondary import Name,EventRef - +from _PrimaryObject import PrimaryObject +from _SourceNote import SourceNote +from _MediaBase import MediaBase +from _AttributeBase import AttributeBase +from _AddressBase import AddressBase +from _UrlBase import UrlBase +from _Name import Name +from _EventRef import EventRef +#------------------------------------------------------------------------- +# +# Person class +# +#------------------------------------------------------------------------- class Person(PrimaryObject,SourceNote, MediaBase,AttributeBase,AddressBase,UrlBase): """ diff --git a/src/RelLib/Place.py b/src/RelLib/_Place.py similarity index 89% rename from src/RelLib/Place.py rename to src/RelLib/_Place.py index 83ffc718e..1a928162b 100644 --- a/src/RelLib/Place.py +++ b/src/RelLib/_Place.py @@ -29,9 +29,17 @@ Place object for GRAMPS # GRAMPS modules # #------------------------------------------------------------------------- -from _helper import PrimaryObject,SourceNote,MediaBase,UrlBase -from _secondary import Location +from _PrimaryObject import PrimaryObject +from _SourceNote import SourceNote +from _MediaBase import MediaBase +from _UrlBase import UrlBase +from _Location import Location +#------------------------------------------------------------------------- +# +# Place class +# +#------------------------------------------------------------------------- class Place(PrimaryObject,SourceNote,MediaBase,UrlBase): """ Contains information related to a place, including multiple address @@ -252,20 +260,25 @@ class Place(PrimaryObject,SourceNote,MediaBase,UrlBase): self.alt_loc.append(location) def get_display_info(self): - """Gets the display information associated with the object. This includes - the information that is used for display and for sorting. Returns a list - consisting of 13 strings. These are: Place Title, Place ID, Main Location - Parish, Main Location County, Main Location City, Main Location State/Province, - Main Location Country, upper case Place Title, upper case Parish, upper - case city, upper case county, upper case state, upper case country""" + """ + Gets the display information associated with the object. + + This includes the information that is used for display and for sorting. + Returns a list consisting of 13 strings. These are: + Place Title, Place ID, Main Location Parish, Main Location County, + Main Location City, Main Location State/Province, + Main Location Country, upper case Place Title, upper case Parish, + upper case city, upper case county, upper case state, + upper case country + """ if self.main_loc: - return [self.title,self.gramps_id,self.main_loc.parish,self.main_loc.city, - self.main_loc.county,self.main_loc.state,self.main_loc.country, + return [self.title,self.gramps_id,self.main_loc.parish, + self.main_loc.city,self.main_loc.county, + self.main_loc.state,self.main_loc.country, self.title.upper(), self.main_loc.parish.upper(), self.main_loc.city.upper(), self.main_loc.county.upper(), self.main_loc.state.upper(), self.main_loc.country.upper()] else: return [self.title,self.gramps_id,'','','','','', self.title.upper(), '','','','',''] - diff --git a/src/RelLib/_PlaceBase.py b/src/RelLib/_PlaceBase.py new file mode 100644 index 000000000..8de3185ba --- /dev/null +++ b/src/RelLib/_PlaceBase.py @@ -0,0 +1,66 @@ +# +# Gramps - a GTK+/GNOME based genealogy program +# +# Copyright (C) 2000-2005 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$ + +""" +PlaceBase class for GRAMPS +""" + +#------------------------------------------------------------------------- +# +# PlaceBase class +# +#------------------------------------------------------------------------- +class PlaceBase: + """ + Base class for place-aware objects. + """ + def __init__(self,source=None): + """ + Initialize a PlaceBase. 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: PlaceBase + """ + if source: + self.place = source.place + else: + self.place = "" + + def set_place_handle(self,place_handle): + """ + Sets the database handle for L{Place} associated with the object. + + @param place_handle: L{Place} database handle + @type place_handle: str + """ + self.place = place_handle + + def get_place_handle(self): + """ + Returns the database handle of the L{Place} assocated with + the Event. + + @returns: L{Place} database handle + @rtype: str + """ + return self.place diff --git a/src/RelLib/_PrimaryObject.py b/src/RelLib/_PrimaryObject.py new file mode 100644 index 000000000..0c8c6f2c0 --- /dev/null +++ b/src/RelLib/_PrimaryObject.py @@ -0,0 +1,222 @@ +# +# Gramps - a GTK+/GNOME based genealogy program +# +# Copyright (C) 2000-2005 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$ + +""" +Primary Object class for GRAMPS +""" + +#------------------------------------------------------------------------- +# +# standard python modules +# +#------------------------------------------------------------------------- +import time +import locale + +#------------------------------------------------------------------------- +# +# GRAMPS modules +# +#------------------------------------------------------------------------- +from _BaseObject import BaseObject +from _PrivacyBase import PrivacyBase +from _SourceNote import SourceNote +from _MediaBase import MediaBase + +#------------------------------------------------------------------------- +# +# Localized constants +# +#------------------------------------------------------------------------- +_date_format = locale.nl_langinfo(locale.D_T_FMT) +_codeset = locale.nl_langinfo(locale.CODESET) + +#------------------------------------------------------------------------- +# +# Primary Object class +# +#------------------------------------------------------------------------- +class PrimaryObject(BaseObject,PrivacyBase): + """ + The PrimaryObject is the base class for all primary objects in the + database. Primary objects are the core objects in the database. + Each object has a database handle and a GRAMPS ID value. The database + handle is used as the record number for the database, and the GRAMPS + ID is the user visible version. + """ + + MARKER_NONE = -1 + MARKER_CUSTOM = 0 + MARKER_COMPLETE = 1 + MARKER_TODO = 2 + + def __init__(self,source=None): + """ + Initialize a PrimaryObject. If source is None, both the ID and handle + are assigned as empty strings. If 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: PrimaryObject + """ + BaseObject.__init__(self) + PrivacyBase.__init__(self,source) + if source: + self.gramps_id = source.gramps_id + self.handle = source.handle + self.change = source.change + self.marker = source.marker + else: + self.gramps_id = None + self.handle = None + self.change = 0 + self.marker = (PrimaryObject.MARKER_NONE,"") + + def get_change_time(self): + """ + Returns the time that the data was last changed. The value + in the format returned by the time.time() command. + + @returns: Time that the data was last changed. The value + in the format returned by the time.time() command. + @rtype: int + """ + return self.change + + def get_change_display(self): + """ + Returns the string representation of the last change time. + + @returns: string representation of the last change time. + @rtype: str + + """ + if self.change: + return unicode(time.strftime(_date_format, + time.localtime(self.change)), + _codeset) + else: + return '' + + def set_handle(self,handle): + """ + Sets the database handle for the primary object + + @param handle: object database handle + @type handle: str + """ + self.handle = handle + + def get_handle(self): + """ + Returns the database handle for the primary object + + @returns: database handle associated with the object + @rtype: str + """ + return self.handle + + def set_gramps_id(self,gramps_id): + """ + Sets the GRAMPS ID for the primary object + + @param gramps_id: GRAMPS ID + @type gramps_id: str + """ + self.gramps_id = gramps_id + + def get_gramps_id(self): + """ + Returns the GRAMPS ID for the primary object + + @returns: GRAMPS ID associated with the object + @rtype: str + """ + return self.gramps_id + + def has_handle_reference(self,classname,handle): + """ + Returns True if the object has reference to a given handle + of given primary object type. + + @param classname: The name of the primary object class. + @type classname: str + @param handle: The handle to be checked. + @type handle: str + @return: Returns whether the object has reference to this handle of this object type. + @rtype: bool + """ + if classname == 'Source' and isinstance(self,SourceNote): + return self.has_source_reference(handle) + elif classname == 'MediaObject' and isinstance(self,MediaBase): + return self.has_media_reference(handle) + else: + return self._has_handle_reference(classname,handle) + + def remove_handle_references(self,classname,handle_list): + """ + Removes all references in this object to object handles in the list. + + @param classname: The name of the primary object class. + @type classname: str + @param handle_list: The list of handles to be removed. + @type handle_list: str + """ + if classname == 'Source' and isinstance(self,SourceNote): + self.remove_source_references(handle_list) + elif classname == 'MediaObject' and isinstance(self,MediaBase): + self.remove_media_references(handle_list) + else: + self._remove_handle_references(classname,handle_list) + + def replace_handle_reference(self,classname,old_handle,new_handle): + """ + Replaces all references to old handle with those to the new handle. + + @param classname: The name of the primary object class. + @type classname: str + @param old_handle: The handle to be replaced. + @type old_handle: str + @param new_handle: The handle to replace the old one with. + @type new_handle: str + """ + if classname == 'Source' and isinstance(self,SourceNote): + self.replace_source_references(old_handle,new_handle) + elif classname == 'MediaObject' and isinstance(self,MediaBase): + self.replace_media_references(old_handle,new_handle) + else: + self._replace_handle_reference(classname,old_handle,new_handle) + + def _has_handle_reference(self,classname,handle): + return False + + def _remove_handle_references(self,classname,handle_list): + pass + + def _replace_handle_reference(self,classname,old_handle,new_handle): + pass + + def set_marker(self,marker): + self.marker = marker + + def get_marker(self): + return self.marker diff --git a/src/RelLib/_PrivacyBase.py b/src/RelLib/_PrivacyBase.py new file mode 100644 index 000000000..58a591939 --- /dev/null +++ b/src/RelLib/_PrivacyBase.py @@ -0,0 +1,68 @@ +# +# Gramps - a GTK+/GNOME based genealogy program +# +# Copyright (C) 2000-2005 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$ + +""" +PrivacyBase Object class for GRAMPS +""" + +#------------------------------------------------------------------------- +# +# PrivacyBase Object +# +#------------------------------------------------------------------------- +class PrivacyBase: + """ + Base class for privacy-aware objects. + """ + + def __init__(self,source=None): + """ + Initialize a PrivacyBase. 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: PrivacyBase + """ + + if source: + self.private = source.private + else: + self.private = False + + def set_privacy(self,val): + """ + Sets or clears the privacy flag of the data + + @param val: value to assign to the privacy flag. True indicates that the + record is private, False indicates that it is public. + @type val: bool + """ + self.private = val + + def get_privacy(self): + """ + Returns the privacy level of the data. + + @returns: True indicates that the record is private + @rtype: bool + """ + return self.private diff --git a/src/RelLib/_PrivateSourceNote.py b/src/RelLib/_PrivateSourceNote.py new file mode 100644 index 000000000..921760224 --- /dev/null +++ b/src/RelLib/_PrivateSourceNote.py @@ -0,0 +1,53 @@ +# +# Gramps - a GTK+/GNOME based genealogy program +# +# Copyright (C) 2000-2005 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$ + +""" +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) diff --git a/src/RelLib/_RepoRef.py b/src/RelLib/_RepoRef.py new file mode 100644 index 000000000..3bd9ffa8d --- /dev/null +++ b/src/RelLib/_RepoRef.py @@ -0,0 +1,121 @@ +# +# Gramps - a GTK+/GNOME based genealogy program +# +# Copyright (C) 2000-2005 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$ + +""" +Repository Reference class for GRAMPS +""" + +#------------------------------------------------------------------------- +# +# GRAMPS modules +# +#------------------------------------------------------------------------- +from _BaseObject import BaseObject +from _NoteBase import NoteBase + +#------------------------------------------------------------------------- +# +# Repository Reference for Sources +# +#------------------------------------------------------------------------- +class RepoRef(BaseObject,NoteBase): + """ + Repository reference class. + """ + + UNKNOWN = -1 + CUSTOM = 0 + AUDIO = 1 + BOOK = 2 + CARD = 3 + ELECTRONIC = 4 + FICHE = 5 + FILM = 6 + MAGAZINE = 7 + MANUSCRIPT = 8 + MAP = 9 + NEWSPAPER = 10 + PHOTO = 11 + TOMBSTONE = 12 + VIDEO = 13 + + def __init__(self,source=None): + NoteBase.__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 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.call_number,self.media_type[1]] + + def get_text_data_child_list(self): + """ + Returns the list of child objects that may carry textual data. + + @return: Returns the list of child objects that may carry textual data. + @rtype: list + """ + if self.note: + return [self.note] + return [] + + def get_referenced_handles(self): + """ + Returns the list of (classname,handle) tuples for all directly + referenced primary objects. + + @return: Returns the list of (classname,handle) tuples for referenced objects. + @rtype: list + """ + if self.ref: + return [('Repository',self.ref)] + 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 + + def get_call_number(self): + return self.call_number + + def get_media_type(self): + return self.media_type + + def set_media_type(self,media_type): + self.media_type = media_type diff --git a/src/RelLib/Repository.py b/src/RelLib/_Repository.py similarity index 94% rename from src/RelLib/Repository.py rename to src/RelLib/_Repository.py index c1d4ae388..9bd09bbf5 100644 --- a/src/RelLib/Repository.py +++ b/src/RelLib/_Repository.py @@ -36,8 +36,16 @@ from warnings import warn # GRAMPS modules # #------------------------------------------------------------------------- -from _helper import PrimaryObject,NoteBase,AddressBase,UrlBase +from _PrimaryObject import PrimaryObject +from _NoteBase import NoteBase +from _AddressBase import AddressBase +from _UrlBase import UrlBase +#------------------------------------------------------------------------- +# +# Repository class +# +#------------------------------------------------------------------------- class Repository(PrimaryObject,NoteBase,AddressBase,UrlBase): """A location where collections of Sources are found""" diff --git a/src/RelLib/Researcher.py b/src/RelLib/_Researcher.py similarity index 98% rename from src/RelLib/Researcher.py rename to src/RelLib/_Researcher.py index 649144fb4..06aad3547 100644 --- a/src/RelLib/Researcher.py +++ b/src/RelLib/_Researcher.py @@ -29,7 +29,7 @@ Researcher informaiton for GRAMPS. # GRAMPS modules # #------------------------------------------------------------------------- -from _helper import LocationBase +from _LocationBase import LocationBase #------------------------------------------------------------------------- # diff --git a/src/RelLib/Source.py b/src/RelLib/_Source.py similarity index 96% rename from src/RelLib/Source.py rename to src/RelLib/_Source.py index 075406e6b..fd325c837 100644 --- a/src/RelLib/Source.py +++ b/src/RelLib/_Source.py @@ -29,9 +29,16 @@ Source object for GRAMPS # GRAMPS modules # #------------------------------------------------------------------------- -from _helper import PrimaryObject,MediaBase,NoteBase -from _secondary import Note +from _PrimaryObject import PrimaryObject +from _MediaBase import MediaBase +from _NoteBase import NoteBase +from _Note import Note +#------------------------------------------------------------------------- +# +# Source class +# +#------------------------------------------------------------------------- class Source(PrimaryObject,MediaBase,NoteBase): """A record of a source of information""" diff --git a/src/RelLib/_SourceNote.py b/src/RelLib/_SourceNote.py new file mode 100644 index 000000000..f61a3752b --- /dev/null +++ b/src/RelLib/_SourceNote.py @@ -0,0 +1,153 @@ +# +# Gramps - a GTK+/GNOME based genealogy program +# +# Copyright (C) 2000-2005 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 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 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 diff --git a/src/RelLib/_SourceRef.py b/src/RelLib/_SourceRef.py new file mode 100644 index 000000000..bcbf8e121 --- /dev/null +++ b/src/RelLib/_SourceRef.py @@ -0,0 +1,151 @@ +# +# Gramps - a GTK+/GNOME based genealogy program +# +# Copyright (C) 2000-2005 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$ + +""" +Source Reference class for GRAMPS +""" + +#------------------------------------------------------------------------- +# +# GRAMPS modules +# +#------------------------------------------------------------------------- +from _BaseObject import BaseObject +from _DateBase import DateBase +from _PrivacyBase import PrivacyBase +from _NoteBase import NoteBase + +#------------------------------------------------------------------------- +# +# Source References for all primary objects +# +#------------------------------------------------------------------------- +class SourceRef(BaseObject,DateBase,PrivacyBase,NoteBase): + """Source reference, containing detailed information about how a + referenced source relates to it""" + + CONF_VERY_HIGH = 4 + CONF_HIGH = 3 + CONF_NORMAL = 2 + CONF_LOW = 1 + CONF_VERY_LOW = 0 + + def __init__(self,source=None): + """creates a new SourceRef, copying from the source if present""" + BaseObject.__init__(self) + DateBase.__init__(self,source) + PrivacyBase.__init__(self,source) + NoteBase.__init__(self,source) + 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 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.page,self.text] + #return [self.page,self.text,self.get_date()] + + 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 + """ + return [self.note] + + 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 [('Source',self.ref)] + else: + return [] + + def set_confidence_level(self,val): + """Sets the confidence level""" + self.confidence = val + + def get_confidence_level(self): + """Returns the confidence level""" + return self.confidence + + def set_base_handle(self,ref): + """sets the Source instance to which the SourceRef refers""" + self.ref = ref + + def get_base_handle(self): + """returns the Source instance to which the SourceRef refers""" + return self.ref + + def set_page(self,page): + """sets the page indicator of the SourceRef""" + self.page = page + + def get_page(self): + """gets the page indicator of the SourceRef""" + return self.page + + def set_text(self,text): + """sets the text related to the SourceRef""" + self.text = text + + def get_text(self): + """returns the text related to the SourceRef""" + return self.text + + def are_equal(self,other): + """returns True if the passed SourceRef is equal to the current""" + if self.ref and other.ref: + if self.page != other.page: + return False + if not self.get_date_object().is_equal(other.get_date_object()): + return False + if self.get_text() != other.get_text(): + return False + if self.get_note() != other.get_note(): + return False + if self.confidence != other.confidence: + return False + return True + elif not self.ref and not other.ref: + return True + else: + return False diff --git a/src/RelLib/_Url.py b/src/RelLib/_Url.py new file mode 100644 index 000000000..6b590e1a7 --- /dev/null +++ b/src/RelLib/_Url.py @@ -0,0 +1,128 @@ +# +# Gramps - a GTK+/GNOME based genealogy program +# +# Copyright (C) 2000-2005 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$ + +""" +Url class for GRAMPS +""" + +#------------------------------------------------------------------------- +# +# standard python modules +# +#------------------------------------------------------------------------- +from warnings import warn + +#------------------------------------------------------------------------- +# +# GRAMPS modules +# +#------------------------------------------------------------------------- +from _BaseObject import BaseObject +from _PrivacyBase import PrivacyBase + +#------------------------------------------------------------------------- +# +# Url for Person/Place/Repository +# +#------------------------------------------------------------------------- +class Url(BaseObject,PrivacyBase): + """Contains information related to internet Uniform Resource Locators, + allowing gramps to store information about internet resources""" + + UNKNOWN = -1 + CUSTOM = 0 + EMAIL = 1 + WEB_HOME = 2 + WEB_SEARCH = 3 + WEB_FTP = 4 + + def __init__(self,source=None): + """creates a new URL instance, copying from the source if present""" + BaseObject.__init__(self) + PrivacyBase.__init__(self,source) + if source: + self.path = source.path + self.desc = source.desc + self.type = source.type + else: + self.path = "" + self.desc = "" + self.type = (Url.CUSTOM,"") + + 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.path,self.desc] + + def set_path(self,path): + """sets the URL path""" + self.path = path + + def get_path(self): + """returns the URL path""" + return self.path + + def set_description(self,description): + """sets the description of the URL""" + self.desc = description + + def get_description(self): + """returns the description of the URL""" + return self.desc + + def set_type(self,the_type): + """ + @param type: descriptive type of the Url + @type type: str + """ + if not type(the_type) == tuple: + warn( "set_type now takes a tuple", DeprecationWarning, 2) + # Wrapper for old API + # remove when transitition done. + if the_type in range(-1,5): + the_type = (the_type,'') + else: + the_type = (Url.CUSTOM,the_type) + self.type = the_type + + def get_type(self): + """ + @returns: the descriptive type of the Url + @rtype: str + """ + return self.type + + 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 + if self.type != other.type: + return 0 + return 1 diff --git a/src/RelLib/_UrlBase.py b/src/RelLib/_UrlBase.py new file mode 100644 index 000000000..a74afe630 --- /dev/null +++ b/src/RelLib/_UrlBase.py @@ -0,0 +1,103 @@ +# +# Gramps - a GTK+/GNOME based genealogy program +# +# Copyright (C) 2000-2005 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$ + +""" +UrlBase class for GRAMPS +""" + +#------------------------------------------------------------------------- +# +# GRAMPS modules +# +#------------------------------------------------------------------------- +from _Url import Url + +#------------------------------------------------------------------------- +# +# UrlBase classes +# +#------------------------------------------------------------------------- +class UrlBase: + """ + Base class for url-aware objects. + """ + + def __init__(self,source=None): + """ + Initialize an UrlBase. 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: UrlBase + """ + + if source: + self.urls = [ Url(url) for url in source.urls ] + else: + self.urls = [] + + def get_url_list(self): + """ + Returns the list of L{Url} instances associated with the object. + + @returns: List of L{Url} instances + @rtype: list + """ + return self.urls + + def set_url_list(self,url_list): + """ + Sets the list of L{Url} instances to passed the list. + + @param url_list: List of L{Url} instances + @type url_list: list + """ + self.urls = url_list + + def add_url(self,url): + """ + Adds a L{Url} instance to the object's list of L{Url} instances + + @param url: L{Url} instance to be added to the Person's list of + related web sites. + @type url: L{Url} + """ + self.urls.append(url) + + + def remove_url(self,url): + """ + Removes the specified L{Url} instance from the url list + If the instance does not exist in the list, the operation has + no effect. + + @param attribute: L{Url} instance to remove from the list + @type attribute: L{Url} + + @return: True if the url was removed, False if it was not in the list. + @rtype: bool + """ + if url in self.urls: + self.urls.remove(url) + return True + else: + return False diff --git a/src/RelLib/_Witness.py b/src/RelLib/_Witness.py new file mode 100644 index 000000000..49c6b3519 --- /dev/null +++ b/src/RelLib/_Witness.py @@ -0,0 +1,35 @@ +# +# Gramps - a GTK+/GNOME based genealogy program +# +# Copyright (C) 2000-2005 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$ + +""" +Witness class for GRAMPS +""" + +#------------------------------------------------------------------------- +# +# Witness class +# +#------------------------------------------------------------------------- +class Witness(BaseObject,PrivacyBase): + # FIXME: this class is only present to enable db upgrade + def __init__(self): + pass diff --git a/src/RelLib/__init__.py b/src/RelLib/__init__.py index 0fbc62c0d..3f666e8b6 100644 --- a/src/RelLib/__init__.py +++ b/src/RelLib/__init__.py @@ -25,13 +25,28 @@ __author__ = "Donald N. Allingham" __version__ = "$Revision$" -from _secondary import * -from Person import Person -from Family import Family -from Event import Event -from Place import Place -from Source import Source -from MediaObject import MediaObject -from Repository import Repository -from GenderStats import GenderStats -from Researcher import Researcher +# Secondary objects +from _Address import Address +from _Location import Location +from _Attribute import Attribute +from _EventRef import EventRef +from _LdsOrd import LdsOrd +from _MediaRef import MediaRef +from _Name import Name +from _Note import Note +from _RepoRef import RepoRef +from _SourceRef import SourceRef +from _Url import Url + +# Primary objects +from _Person import Person +from _Family import Family +from _Event import Event +from _Place import Place +from _Source import Source +from _MediaObject import MediaObject +from _Repository import Repository + +# These are actually metadata +from _GenderStats import GenderStats +from _Researcher import Researcher diff --git a/src/RelLib/_helper.py b/src/RelLib/_helper.py deleted file mode 100644 index d6126f75d..000000000 --- a/src/RelLib/_helper.py +++ /dev/null @@ -1,1073 +0,0 @@ -# -# Gramps - a GTK+/GNOME based genealogy program -# -# Copyright (C) 2000-2005 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$ - -""" -The helper classes for GRAMPS objects -""" - -#------------------------------------------------------------------------- -# -# standard python modules -# -#------------------------------------------------------------------------- -import time -import re -import locale - -#------------------------------------------------------------------------- -# -# GRAMPS modules -# -#------------------------------------------------------------------------- -import Date - -#------------------------------------------------------------------------- -# -# Localized constants -# -#------------------------------------------------------------------------- -_date_format = locale.nl_langinfo(locale.D_T_FMT) -_codeset = locale.nl_langinfo(locale.CODESET) - -#------------------------------------------------------------------------- -# -# Base classes -# -#------------------------------------------------------------------------- -class BaseObject: - """ - The BaseObject is the base class for all data objects in GRAMPS, - whether primary or not. Its main goal is to provide common capabilites - to all objects, such as searching through all available information. - """ - - def __init__(self): - """ - Initialize a BaseObject. - """ - pass - - def matches_string(self,pattern,case_sensitive=False): - """ - Returns True if any text data in the object or any of it's child - objects matches a given pattern. - - @param pattern: The pattern to match. - @type pattern: str - @param case_sensitive: Whether the match is case-sensitive. - @type case_sensitive: bool - @return: Returns whether any text data in the object or any of it's child objects matches a given pattern. - @rtype: bool - """ - # Run through its own items - patern_upper = pattern.upper() - for item in self.get_text_data_list(): - if not item: - continue - if case_sensitive: - if item.find(pattern) != -1: - return True - else: - if item.upper().find(patern_upper) != -1: - return True - - # Run through child objects - for obj in self.get_text_data_child_list(): - if obj.matches_string(pattern,case_sensitive): - return True - - return False - - def matches_regexp(self,pattern,case_sensitive=False): - """ - Returns True if any text data in the object or any of it's child - objects matches a given regular expression. - - @param pattern: The pattern to match. - @type pattern: str - @return: Returns whether any text data in the object or any of it's child objects matches a given regexp. - @rtype: bool - """ - - # Run through its own items - if case_sensitive: - pattern_obj = re.compile(pattern) - else: - pattern_obj = re.compile(pattern,re.IGNORECASE) - for item in self.get_text_data_list(): - if item and pattern_obj.match(item): - return True - - # Run through child objects - for obj in self.get_text_data_child_list(): - if obj.matches_regexp(pattern,case_sensitive): - return True - - return False - - 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 [] - - 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 - """ - return [] - - def get_referenced_handles(self): - """ - Returns the list of (classname,handle) tuples for all directly - referenced primary objects. - - @return: Returns the list of (classname,handle) tuples for referenced objects. - @rtype: list - """ - 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 [] - - def get_referenced_handles_recursively(self): - """ - Returns the list of (classname,handle) tuples for all referenced - primary objects, whether directly or through child objects. - - @return: Returns the list of (classname,handle) tuples for referenced objects. - @rtype: list - """ - ret = self.get_referenced_handles() - - # Run through child objects - for obj in self.get_handle_referents(): - ret += obj.get_referenced_handles_recursively() - - return ret - -class PrivacyBase: - """ - Base class for privacy-aware objects. - """ - - def __init__(self,source=None): - """ - Initialize a PrivacyBase. 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: PrivacyBase - """ - - if source: - self.private = source.private - else: - self.private = False - - def set_privacy(self,val): - """ - Sets or clears the privacy flag of the data - - @param val: value to assign to the privacy flag. True indicates that the - record is private, False indicates that it is public. - @type val: bool - """ - self.private = val - - def get_privacy(self): - """ - Returns the privacy level of the data. - - @returns: True indicates that the record is private - @rtype: bool - """ - return self.private - -class PrimaryObject(BaseObject,PrivacyBase): - """ - The PrimaryObject is the base class for all primary objects in the - database. Primary objects are the core objects in the database. - Each object has a database handle and a GRAMPS ID value. The database - handle is used as the record number for the database, and the GRAMPS - ID is the user visible version. - """ - - MARKER_NONE = -1 - MARKER_CUSTOM = 0 - MARKER_COMPLETE = 1 - MARKER_TODO = 2 - - def __init__(self,source=None): - """ - Initialize a PrimaryObject. If source is None, both the ID and handle - are assigned as empty strings. If 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: PrimaryObject - """ - BaseObject.__init__(self) - PrivacyBase.__init__(self,source) - if source: - self.gramps_id = source.gramps_id - self.handle = source.handle - self.change = source.change - self.marker = source.marker - else: - self.gramps_id = None - self.handle = None - self.change = 0 - self.marker = (PrimaryObject.MARKER_NONE,"") - - def get_change_time(self): - """ - Returns the time that the data was last changed. The value - in the format returned by the time.time() command. - - @returns: Time that the data was last changed. The value - in the format returned by the time.time() command. - @rtype: int - """ - return self.change - - def get_change_display(self): - """ - Returns the string representation of the last change time. - - @returns: string representation of the last change time. - @rtype: str - - """ - if self.change: - return unicode(time.strftime(_date_format, - time.localtime(self.change)), - _codeset) - else: - return '' - - def set_handle(self,handle): - """ - Sets the database handle for the primary object - - @param handle: object database handle - @type handle: str - """ - self.handle = handle - - def get_handle(self): - """ - Returns the database handle for the primary object - - @returns: database handle associated with the object - @rtype: str - """ - return self.handle - - def set_gramps_id(self,gramps_id): - """ - Sets the GRAMPS ID for the primary object - - @param gramps_id: GRAMPS ID - @type gramps_id: str - """ - self.gramps_id = gramps_id - - def get_gramps_id(self): - """ - Returns the GRAMPS ID for the primary object - - @returns: GRAMPS ID associated with the object - @rtype: str - """ - return self.gramps_id - - def has_handle_reference(self,classname,handle): - """ - Returns True if the object has reference to a given handle - of given primary object type. - - @param classname: The name of the primary object class. - @type classname: str - @param handle: The handle to be checked. - @type handle: str - @return: Returns whether the object has reference to this handle of this object type. - @rtype: bool - """ - if classname == 'Source' and isinstance(self,SourceNote): - return self.has_source_reference(handle) - elif classname == 'MediaObject' and isinstance(self,MediaBase): - return self.has_media_reference(handle) - else: - return self._has_handle_reference(classname,handle) - - def remove_handle_references(self,classname,handle_list): - """ - Removes all references in this object to object handles in the list. - - @param classname: The name of the primary object class. - @type classname: str - @param handle_list: The list of handles to be removed. - @type handle_list: str - """ - if classname == 'Source' and isinstance(self,SourceNote): - self.remove_source_references(handle_list) - elif classname == 'MediaObject' and isinstance(self,MediaBase): - self.remove_media_references(handle_list) - else: - self._remove_handle_references(classname,handle_list) - - def replace_handle_reference(self,classname,old_handle,new_handle): - """ - Replaces all references to old handle with those to the new handle. - - @param classname: The name of the primary object class. - @type classname: str - @param old_handle: The handle to be replaced. - @type old_handle: str - @param new_handle: The handle to replace the old one with. - @type new_handle: str - """ - if classname == 'Source' and isinstance(self,SourceNote): - self.replace_source_references(old_handle,new_handle) - elif classname == 'MediaObject' and isinstance(self,MediaBase): - self.replace_media_references(old_handle,new_handle) - else: - self._replace_handle_reference(classname,old_handle,new_handle) - - def _has_handle_reference(self,classname,handle): - return False - - def _remove_handle_references(self,classname,handle_list): - pass - - def _replace_handle_reference(self,classname,old_handle,new_handle): - pass - - def set_marker(self,marker): - self.marker = marker - - def get_marker(self): - return self.marker - -class NoteBase: - """ - Base class for storing notes. - """ - def __init__(self,source=None): - """ - Create a new NoteBase, copying from source if not None - - @param source: Object used to initialize the new object - @type source: NoteBase - """ - - if source and source.note: - self.note = Note(source.note.get()) - else: - self.note = None - - def set_note(self,text): - """ - Assigns the specified text to the associated note. - - @param text: Text of the note - @type text: str - """ - if not self.note: - self.note = Note() - self.note.set(text) - - def get_note(self): - """ - Returns the text of the current note. - - @returns: the text of the current note - @rtype: str - """ - if self.note: - return self.note.get() - return "" - - def set_note_format(self,val): - """ - Sets the note's format to the given value. The format indicates - whether the text is flowed (wrapped) or preformatted. - - @param val: True indicates the text is flowed - @type val: bool - """ - if self.note: - self.note.set_format(val) - - def get_note_format(self): - """ - Returns the current note's format - - @returns: True indicates that the note should be flowed (wrapped) - @rtype: bool - """ - if self.note == None: - return False - else: - return self.note.get_format() - - def set_note_object(self,note_obj): - """ - Replaces the current L{Note} object associated with the object - - @param note_obj: New L{Note} object to be assigned - @type note_obj: L{Note} - """ - self.note = note_obj - - def get_note_object(self): - """ - Returns the L{Note} instance associated with the object. - - @returns: L{Note} object assocated with the object - @rtype: L{Note} - """ - return self.note - - def unique_note(self): - """Creates a unique instance of the current note""" - self.note = Note(self.note.get()) - -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 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 MediaBase: - """ - Base class for storing media references - """ - - def __init__(self,source=None): - """ - Create a new MediaBase, copying from source if not None - - @param source: Object used to initialize the new object - @type source: MediaBase - """ - - if source: - self.media_list = [ MediaRef(mref) for mref in source.media_list ] - else: - self.media_list = [] - - def add_media_reference(self,media_ref): - """ - Adds a L{MediaRef} instance to the object's media list. - - @param media_ref: L{MediaRef} instance to be added to the object's - media list. - @type media_ref: L{MediaRef} - """ - self.media_list.append(media_ref) - - def get_media_list(self): - """ - Returns the list of L{MediaRef} instances associated with the object. - - @returns: list of L{MediaRef} instances associated with the object - @rtype: list - """ - return self.media_list - - def set_media_list(self,media_ref_list): - """ - Sets the list of L{MediaRef} instances associated with the object. - It replaces the previous list. - - @param media_ref_list: list of L{MediaRef} instances to be assigned - to the object. - @type media_ref_list: list - """ - self.media_list = media_ref_list - - def has_media_reference(self,obj_handle) : - """ - Returns True if the object or any of it's child objects has reference - to this media object handle. - - @param obj_handle: The media handle to be checked. - @type obj_handle: str - @return: Returns whether the object or any of it's child objects has reference to this media handle. - @rtype: bool - """ - return obj_handle in [media_ref.ref for media_ref in self.media_list] - - def remove_media_references(self,obj_handle_list): - """ - Removes references to all media handles in the list. - - @param obj_handle_list: The list of media handles to be removed. - @type obj_handle_list: list - """ - new_media_list = [ media_ref for media_ref in self.media_list \ - if media_ref.ref not in obj_handle_list ] - self.media_list = new_media_list - - def replace_media_references(self,old_handle,new_handle): - """ - Replaces all references to old media handle with the new handle. - - @param old_handle: The media handle to be replaced. - @type old_handle: str - @param new_handle: The media handle to replace the old one with. - @type new_handle: str - """ - refs_list = [ media_ref.ref for media_ref in self.media_list ] - n_replace = refs_list.count(old_handle) - for ix_replace in xrange(n_replace): - ix = refs_list.index(old_handle) - self.media_list[ix].ref = new_handle - refs_list[ix] = new_handle - -class DateBase: - """ - Base class for storing date information. - """ - - def __init__(self,source=None): - """ - Create a new DateBase, copying from source if not None - - @param source: Object used to initialize the new object - @type source: DateBase - """ - if source: - self.date = Date.Date(source.date) - else: - self.date = None - -# def set_date(self, date) : -# """ -# Sets the date of the DateBase instance. - -# The date is parsed into a L{Date} instance. - -# @param date: String representation of a date. The locale specific -# L{DateParser} is used to parse the string into a GRAMPS L{Date} -# object. -# @type date: str -# """ -# self.date = DateHandler.parser.parse(date) - -# def get_date(self) : -# """ -# Returns a string representation of the date of the DateBase instance. - -# This representation is based off the default date display format -# determined by the locale's L{DateDisplay} instance. - -# @return: Returns a string representing the DateBase date -# @rtype: str -# """ -# if self.date: -# return DateHandler.displayer.display(self.date) -# return u"" - -# def get_quote_date(self) : -# """ -# Returns a string representation of the date of the DateBase instance. - -# This representation is based off the default date display format -# determined by the locale's L{DateDisplay} instance. The date is -# enclosed in quotes if the L{Date} is not a valid date. - -# @return: Returns a string representing the DateBase date -# @rtype: str -# """ -# if self.date: -# return DateHandler.displayer.quote_display(self.date) -# return u"" - - def get_date_object(self): - """ - Returns the L{Date} object associated with the DateBase. - - @return: Returns a DateBase L{Date} instance. - @rtype: L{Date} - """ - if not self.date: - self.date = Date.Date() - return self.date - - def set_date_object(self,date): - """ - Sets the L{Date} object associated with the DateBase. - - @param date: L{Date} instance to be assigned to the DateBase - @type date: L{Date} - """ - self.date = date - -class AttributeBase: - """ - Base class for attribute-aware objects. - """ - - def __init__(self,source=None): - """ - Initialize a AttributeBase. 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: AttributeBase - """ - - if source: - self.attribute_list = [ Attribute(attribute) \ - for attribute in source.attribute_list ] - else: - self.attribute_list = [] - - def add_attribute(self,attribute): - """ - Adds the L{Attribute} instance to the object's list of attributes - - @param attribute: L{Attribute} instance to add. - @type attribute: L{Attribute} - """ - self.attribute_list.append(attribute) - - def remove_attribute(self,attribute): - """ - Removes the specified L{Attribute} instance from the attribute list - If the instance does not exist in the list, the operation has - no effect. - - @param attribute: L{Attribute} instance to remove from the list - @type attribute: L{Attribute} - - @return: True if the attribute was removed, False if it was not - in the list. - @rtype: bool - """ - if attribute in self.attribute_list: - self.attribute_list.remove(attribute) - return True - else: - return False - - def get_attribute_list(self): - """ - Returns the list of L{Attribute} instances associated with the object. - - @returns: Returns the list of L{Attribute} instances. - @rtype: list - """ - return self.attribute_list - - def set_attribute_list(self,attribute_list): - """ - Assigns the passed list to the Person's list of L{Attribute} instances. - - @param attribute_list: List of L{Attribute} instances to ba associated - with the Person - @type attribute_list: list - """ - self.attribute_list = attribute_list - -class AddressBase: - """ - Base class for address-aware objects. - """ - - def __init__(self,source=None): - """ - Initialize a AddressBase. 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: AddressBase - """ - - if source: - self.address_list = [ Address(address) \ - for address in source.address_list ] - else: - self.address_list = [] - - def add_address(self,address): - """ - Adds the L{Address} instance to the object's list of addresses - - @param address: L{Address} instance to add to the object's address list - @type address: list - """ - self.address_list.append(address) - - def remove_address(self,address): - """ - Removes the specified L{Address} instance from the address list - If the instance does not exist in the list, the operation has - no effect. - - @param address: L{Address} instance to remove from the list - @type address: L{Address} - - @return: True if the address was removed, False if it was not in the list. - @rtype: bool - """ - if address in self.address_list: - self.address_list.remove(address) - return True - else: - return False - - def get_address_list(self): - """ - Returns the list of L{Address} instances associated with the object - - @return: Returns the list of L{Address} instances - @rtype: list - """ - return self.address_list - - def set_address_list(self,address_list): - """ - Assigns the passed list to the object's list of L{Address} instances. - @param address_list: List of L{Address} instances to be associated - with the object - @type address_list: list - """ - self.address_list = address_list - -class UrlBase: - """ - Base class for url-aware objects. - """ - - def __init__(self,source=None): - """ - Initialize an UrlBase. 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: UrlBase - """ - - if source: - self.urls = [ Url(url) for url in source.urls ] - else: - self.urls = [] - - def get_url_list(self): - """ - Returns the list of L{Url} instances associated with the object. - - @returns: List of L{Url} instances - @rtype: list - """ - return self.urls - - def set_url_list(self,url_list): - """ - Sets the list of L{Url} instances to passed the list. - - @param url_list: List of L{Url} instances - @type url_list: list - """ - self.urls = url_list - - def add_url(self,url): - """ - Adds a L{Url} instance to the object's list of L{Url} instances - - @param url: L{Url} instance to be added to the Person's list of - related web sites. - @type url: L{Url} - """ - self.urls.append(url) - - - def remove_url(self,url): - """ - Removes the specified L{Url} instance from the url list - If the instance does not exist in the list, the operation has - no effect. - - @param attribute: L{Url} instance to remove from the list - @type attribute: L{Url} - - @return: True if the url was removed, False if it was not in the list. - @rtype: bool - """ - if url in self.urls: - self.urls.remove(url) - return True - else: - return False - -class PlaceBase: - """ - Base class for place-aware objects. - """ - def __init__(self,source=None): - """ - Initialize a PlaceBase. 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: PlaceBase - """ - if source: - self.place = source.place - else: - self.place = "" - - def set_place_handle(self,place_handle): - """ - Sets the database handle for L{Place} associated with the object. - - @param place_handle: L{Place} database handle - @type place_handle: str - """ - self.place = place_handle - - def get_place_handle(self): - """ - Returns the database handle of the L{Place} assocated with - the Event. - - @returns: L{Place} database handle - @rtype: str - """ - return self.place - -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) - -class LocationBase: - """ - Base class for all things Address. - """ - - def __init__(self,source=None): - """ - Creates a LocationBase object, - copying from the source object if it exists. - """ - if source: - self.city = source.city - self.state = source.state - self.country = source.country - self.postal = source.postal - self.phone = source.phone - else: - self.city = "" - self.state = "" - self.country = "" - self.postal = "" - self.phone = "" - - 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.city,self.state,self.country,self.postal,self.phone] - - def set_city(self,data): - """sets the city name of the LocationBase object""" - self.city = data - - def get_city(self): - """returns the city name of the LocationBase object""" - return self.city - - def set_postal_code(self,data): - """sets the postal code of the LocationBase object""" - self.postal = data - - def get_postal_code(self): - """returns the postal code of the LocationBase object""" - return self.postal - - def set_phone(self,data): - """sets the phone number of the LocationBase object""" - self.phone = data - - def get_phone(self): - """returns the phone number of the LocationBase object""" - return self.phone - - def set_state(self,data): - """sets the state name of the LocationBase object""" - self.state = data - - def get_state(self): - """returns the state name of the LocationBase object""" - return self.state - - def set_country(self,data): - """sets the country name of the LocationBase object""" - self.country = data - - def get_country(self): - """returns the country name of the LocationBase object""" - return self.country - -class Witness(BaseObject,PrivacyBase): - # FIXME: this class is only present to enable db upgrade - def __init__(self): - pass diff --git a/src/RelLib/_secondary.py b/src/RelLib/_secondary.py deleted file mode 100644 index 96617065c..000000000 --- a/src/RelLib/_secondary.py +++ /dev/null @@ -1,1241 +0,0 @@ -# -# Gramps - a GTK+/GNOME based genealogy program -# -# Copyright (C) 2000-2005 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$ - -""" -Secondary (non-primary) objects for GRAMPS -""" - -#------------------------------------------------------------------------- -# -# standard python modules -# -#------------------------------------------------------------------------- -from warnings import warn - -#------------------------------------------------------------------------- -# -# GRAMPS modules -# -#------------------------------------------------------------------------- -from _helper import * - -#------------------------------------------------------------------------- -# -# Class for notes used throughout the majority of GRAMPS objects -# -#------------------------------------------------------------------------- -class Note(BaseObject): - """ - Introduction - ============ - The Note class defines a text note. The note may be preformatted - or 'flowed', which indicates that it text string is considered - to be in paragraphs, separated by newlines. - """ - - def __init__(self,text = ""): - """ - Creates a new Note object, initializing from the passed string. - """ - BaseObject.__init__(self) - self.text = text - self.format = 0 - - 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.text] - - def set(self,text): - """ - Sets the text associated with the note to the passed string. - - @param text: Text string defining the note contents. - @type text: str - """ - self.text = text - - def get(self): - """ - Return the text string associated with the note. - @returns: Returns the text string defining the note contents. - @rtype: str - """ - return self.text - - def append(self,text): - """ - Appends the specified text to the text associated with the note. - - @param text: Text string to be appended to the note. - @type text: str - """ - self.text = self.text + text - - def set_format(self,format): - """ - Sets the format of the note to the passed value. The value can - either indicate Flowed or Preformatted. - - @param format: 0 indicates Flowed, 1 indicates Preformated - @type format: int - """ - self.format = format - - def get_format(self): - """ - Returns the format of the note. The value can either indicate - Flowed or Preformatted. - - @returns: 0 indicates Flowed, 1 indicates Preformated - @rtype: int - """ - return self.format - -#------------------------------------------------------------------------- -# -# Personal Name -# -#------------------------------------------------------------------------- -class Name(PrivateSourceNote,DateBase): - """ - Provides name information about a person. - - A person may have more that one name throughout his or her life. - """ - - DEF = 0 # locale default - LNFN = 1 # last name first name [patronymic] - FNLN = 2 # first name last name - PTFN = 3 # patronymic last name - FN = 4 # first name - - UNKNOWN = -1 - CUSTOM = 0 - AKA = 1 - BIRTH = 2 - MARRIED = 3 - - def __init__(self,source=None): - """creates a new Name instance, copying from the source if provided""" - PrivateSourceNote.__init__(self,source) - DateBase.__init__(self,source) - - if source: - self.first_name = source.first_name - self.surname = source.surname - self.suffix = source.suffix - self.title = source.title - self.type = source.type - self.prefix = source.prefix - self.patronymic = source.patronymic - self.sname = source.sname - self.group_as = source.group_as - self.sort_as = source.sort_as - self.display_as = source.display_as - else: - self.first_name = "" - self.surname = "" - self.suffix = "" - self.title = "" - self.type = (Name.BIRTH,"") - self.prefix = "" - self.patronymic = "" - self.sname = '@' - self.group_as = "" - self.sort_as = self.DEF - self.display_as = self.DEF - - 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.first_name,self.surname,self.suffix,self.title, - self.type[1],self.prefix,self.patronymic] - #return [self.first_name,self.surname,self.suffix,self.title, - # self.type[1],self.prefix,self.patronymic,self.get_date()] - - 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_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_group_as(self,name): - """ - Sets the grouping name for a person. Normally, this is the person's - surname. However, some locales group equivalent names (e.g. Ivanova - and Ivanov in Russian are usually considered equivalent. - """ - if name == self.surname: - self.group_as = "" - else: - self.group_as = name - - def get_group_as(self): - """ - Returns the grouping name, which is used to group equivalent surnames. - """ - return self.group_as - - def get_group_name(self): - """ - Returns the grouping name, which is used to group equivalent surnames. - """ - if self.group_as: - return self.group_as - else: - return self.surname - - def set_sort_as(self,value): - """ - Specifies the sorting method for the specified name. Typically the - locale's default should be used. However, there may be names where - a specific sorting structure is desired for a name. - """ - self.sort_as = value - - def get_sort_as(self): - """ - Returns the selected sorting method for the name. The options are - DEF (default for the current locale), LNFN (last name, first name), - or FNLN (first name, last name). - """ - return self.sort_as - - def set_display_as(self,value): - """ - Specifies the display format for the specified name. Typically the - locale's default should be used. However, there may be names where - a specific display format is desired for a name. - """ - self.display_as = value - - def get_display_as(self): - """ - Returns the selected display format for the name. The options are - DEF (default for the current locale), LNFN (last name, first name), - or FNLN (first name, last name). - """ - return self.display_as - - def get_surname_prefix(self): - """ - Returns the prefix (or article) of a surname. The prefix is not - used for sorting or grouping. - """ - return self.prefix - - def set_surname_prefix(self,val): - """ - Sets the prefix (or article) of a surname. Examples of articles - would be 'de' or 'van'. - """ - self.prefix = val - - def set_type(self,the_type): - """sets the type of the Name instance""" - if not type(the_type) == tuple: - if the_type in [UNKNOWN,CUSTOM,AKA,BIRTH,MARRIED]: - warn( "set_type now takes a tuple", DeprecationWarning, 2) - # Wrapper for old API - # remove when transitition done. - the_type = (the_type,'') - else: - assert type(the_type) == tuple - self.type = the_type - - def get_type(self): - """returns the type of the Name instance""" - return self.type - - def build_sort_name(self): - if self.surname: - self.sname = "%-25s%-30s%s" % (self.surname,self.first_name,self.suffix) - else: - self.sname = "@" - - def set_first_name(self,name): - """sets the given name for the Name instance""" - self.first_name = name - self.build_sort_name() - - def set_patronymic(self,name): - """sets the patronymic name for the Name instance""" - self.patronymic = name - self.build_sort_name() - - def set_surname(self,name): - """sets the surname (or last name) for the Name instance""" - self.surname = name - self.build_sort_name() - - def set_suffix(self,name): - """sets the suffix (such as Jr., III, etc.) for the Name instance""" - self.suffix = name - self.build_sort_name() - - def get_sort_name(self): - return self.sname - - def get_first_name(self): - """returns the given name for the Name instance""" - return self.first_name - - def get_patronymic(self): - """returns the patronymic name for the Name instance""" - return self.patronymic - - def get_surname(self): - """returns the surname (or last name) for the Name instance""" - return self.surname - - def get_upper_surname(self): - """returns the surname (or last name) for the Name instance""" - return self.surname.upper() - - def get_suffix(self): - """returns the suffix for the Name instance""" - return self.suffix - - def set_title(self,title): - """sets the title (Dr., Reverand, Captain) for the Name instance""" - self.title = title - - def get_title(self): - """returns the title for the Name instance""" - return self.title - - def get_name(self): - """returns a name string built from the components of the Name - instance, in the form of surname, Firstname""" - - if self.patronymic: - first = "%s %s" % (self.first_name, self.patronymic) - else: - first = self.first_name - if self.suffix: - if self.prefix: - return "%s %s, %s %s" % (self.prefix, self.surname, first, self.suffix) - else: - return "%s, %s %s" % (self.surname, first, self.suffix) - else: - if self.prefix: - return "%s %s, %s" % (self.prefix,self.surname, first) - else: - return "%s, %s" % (self.surname, first) - - def get_upper_name(self): - """returns a name string built from the components of the Name - instance, in the form of surname, Firstname""" - - if self.patronymic: - first = "%s %s" % (self.first_name, self.patronymic) - else: - first = self.first_name - if self.suffix: - if self.prefix: - return "%s %s, %s %s" % (self.prefix.upper(), self.surname.upper(), first, self.suffix) - else: - return "%s, %s %s" % (self.surname.upper(), first, self.suffix) - else: - if self.prefix: - return "%s %s, %s" % (self.prefix.upper(), self.surname.upper(), first) - else: - return "%s, %s" % (self.surname.upper(), first) - - def get_regular_name(self): - """returns a name string built from the components of the Name - instance, in the form of Firstname surname""" - if self.patronymic: - first = "%s %s" % (self.first_name, self.patronymic) - else: - first = self.first_name - if (self.suffix == ""): - if self.prefix: - return "%s %s %s" % (first, self.prefix, self.surname) - else: - return "%s %s" % (first, self.surname) - else: - if self.prefix: - return "%s %s %s, %s" % (first, self.prefix, self.surname, self.suffix) - else: - return "%s %s, %s" % (first, self.surname, self.suffix) - - def is_equal(self,other): - """ - compares to names to see if they are equal, return 0 if they - are not - """ - if self.first_name != other.first_name: - return False - if self.surname != other.surname: - return False - if self.patronymic != other.patronymic: - return False - if self.prefix != other.prefix: - return False - if self.suffix != other.suffix: - return False - if self.title != other.title: - return False - if self.type != other.type: - return False - if self.private != other.private: - return False - if self.get_note() != other.get_note(): - return False - if (self.date and other.date and not self.date.is_equal(other.date)) \ - or (self.date and not other.date) \ - or (not self.date and other.date): - return False - if len(self.get_source_references()) != len(other.get_source_references()): - return False - index = 0 - olist = other.get_source_references() - for a in self.get_source_references(): - if not a.are_equal(olist[index]): - return True - index += 1 - return True - -#------------------------------------------------------------------------- -# -# Attribute for Person/Family/MediaObject/MediaRef -# -#------------------------------------------------------------------------- -class Attribute(PrivateSourceNote): - """Provides a simple key/value pair for describing properties. Used - by the Person and Family objects to store descriptive information.""" - - UNKNOWN = -1 - CUSTOM = 0 - CASTE = 1 - DESCRIPTION = 2 - ID = 3 - NATIONAL = 4 - NUM_CHILD = 5 - SSN = 6 - - def __init__(self,source=None): - """creates a new Attribute object, copying from the source if provided""" - PrivateSourceNote.__init__(self,source) - - if source: - self.type = source.type - self.value = source.value - else: - self.type = (Attribute.CUSTOM,"") - self.value = "" - - 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.value] - - 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_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_type(self,val): - """sets the type (or key) of the Attribute instance""" - if not type(val) == tuple: - warn( "set_type now takes a tuple", DeprecationWarning, 2) - # Wrapper for old API - # remove when transitition done. - if val in range(-1,7): - val = (val,'') - else: - val = (Attribute.CUSTOM,val) - self.type = val - - def get_type(self): - """returns the type (or key) or the Attribute instance""" - return self.type - - def set_value(self,val): - """sets the value of the Attribute instance""" - self.value = val - - def get_value(self): - """returns the value of the Attribute instance""" - return self.value - -#------------------------------------------------------------------------- -# -# Address for Person/Repository -# -#------------------------------------------------------------------------- -class Address(PrivateSourceNote,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) - DateBase.__init__(self,source) - LocationBase.__init__(self,source) - - if source: - self.street = source.street - else: - self.street = "" - - 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.street] + LocationBase.get_text_data_list() - #return [self.street,self.city,self.state,self.country, - # self.postal,self.phone,self.get_date()] - - 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_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_street(self,val): - """sets the street portion of the Address""" - self.street = val - - def get_street(self): - """returns the street portion of the Address""" - return self.street - -#------------------------------------------------------------------------- -# -# Location class for Places -# -#------------------------------------------------------------------------- -class Location(BaseObject,LocationBase): - """ - Provides information about a place. - - The data 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): - """ - Creates a Location object, copying from the source object if it exists. - """ - - BaseObject.__init__(self) - LocationBase.__init__(self,source) - if source: - self.parish = source.parish - self.county = source.county - else: - self.parish = "" - self.county = "" - - 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.parish,self.county] + LocationBase.get_text_data_list() - - def is_empty(self): - return not self.city and not self.county and not self.state and \ - not self.country and not self.postal and not self.phone - - 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): - """sets the county name of the Location object""" - self.county = data - - def get_county(self): - """returns the county name of the Location object""" - return self.county - -#------------------------------------------------------------------------- -# -# Url for Person/Place/Repository -# -#------------------------------------------------------------------------- -class Url(BaseObject,PrivacyBase): - """Contains information related to internet Uniform Resource Locators, - allowing gramps to store information about internet resources""" - - UNKNOWN = -1 - CUSTOM = 0 - EMAIL = 1 - WEB_HOME = 2 - WEB_SEARCH = 3 - WEB_FTP = 4 - - def __init__(self,source=None): - """creates a new URL instance, copying from the source if present""" - BaseObject.__init__(self) - PrivacyBase.__init__(self,source) - if source: - self.path = source.path - self.desc = source.desc - self.type = source.type - else: - self.path = "" - self.desc = "" - self.type = (Url.CUSTOM,"") - - 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.path,self.desc] - - def set_path(self,path): - """sets the URL path""" - self.path = path - - def get_path(self): - """returns the URL path""" - return self.path - - def set_description(self,description): - """sets the description of the URL""" - self.desc = description - - def get_description(self): - """returns the description of the URL""" - return self.desc - - def set_type(self,the_type): - """ - @param type: descriptive type of the Url - @type type: str - """ - if not type(the_type) == tuple: - warn( "set_type now takes a tuple", DeprecationWarning, 2) - # Wrapper for old API - # remove when transitition done. - if the_type in range(-1,5): - the_type = (the_type,'') - else: - the_type = (Url.CUSTOM,the_type) - self.type = the_type - - def get_type(self): - """ - @returns: the descriptive type of the Url - @rtype: str - """ - return self.type - - 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 - if self.type != other.type: - return 0 - return 1 - -#------------------------------------------------------------------------- -# -# LDS Ordinance class -# -#------------------------------------------------------------------------- -class LdsOrd(SourceNote,DateBase,PlaceBase): - """ - Class that contains information about LDS Ordinances. LDS - ordinances are similar to events, but have very specific additional - information related to data collected by the Church of Jesus Christ - of Latter Day Saints (Morman church). The LDS church is the largest - source of genealogical information in the United States. - """ - def __init__(self,source=None): - """Creates a LDS Ordinance instance""" - SourceNote.__init__(self,source) - DateBase.__init__(self,source) - PlaceBase.__init__(self,source) - - if source: - self.famc = source.famc - self.temple = source.temple - self.status = source.status - else: - self.famc = None - self.temple = "" - self.status = 0 - - 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.temple] - #return [self.temple,self.get_date()] - - 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.place: - return [('Place',self.place)] - 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_family_handle(self,family): - """Sets the Family database handle associated with the LDS ordinance""" - self.famc = family - - def get_family_handle(self): - """Gets the Family database handle associated with the LDS ordinance""" - return self.famc - - def set_status(self,val): - """ - Sets the status of the LDS ordinance. The status is a text string - that matches a predefined set of strings.""" - self.status = val - - def get_status(self): - """Gets the status of the LDS ordinance""" - return self.status - - def set_temple(self,temple): - """Sets the temple assocated with the ordinance""" - self.temple = temple - - def get_temple(self): - """Gets the temple assocated with the ordinance""" - return self.temple - - def is_empty(self): - """Returns 1 if the ordidance is actually empty""" - if (self.famc or - (self.date and not self.date.is_empty()) or - self.temple or - self.status or - self.place): - return False - else: - return True - - def are_equal(self,other): - """returns 1 if the specified ordinance is the same as the instance""" - if other == None: - return self.is_empty() - if (self.famc != other.famc or - self.place != other.place or - self.status != other.status or - self.temple != other.temple or - not self.get_date_object().is_equal(other.get_date_object()) or - len(self.get_source_references()) != len(other.get_source_references())): - return False - - index = 0 - olist = other.get_source_references() - for a in self.get_source_references(): - if not a.are_equal(olist[index]): - return False - index += 1 - return True - -#------------------------------------------------------------------------- -# -# Event References for Person/Family -# -#------------------------------------------------------------------------- -class EventRef(BaseObject,PrivacyBase,NoteBase): - """ - Event reference class. - - This class is for keeping information about how the person relates - to the refereneced event. - """ - - UNKNOWN = -1 - CUSTOM = 0 - PRIMARY = 1 - CLERGY = 2 - CELEBRANT = 3 - AIDE = 4 - BRIDE = 5 - GROOM = 6 - WITNESS = 7 - FAMILY = 8 - - def __init__(self,source=None): - """ - Creates a new EventRef instance, copying from the source if present. - """ - PrivacyBase.__init__(self) - NoteBase.__init__(self) - if source: - self.ref = source.ref - self.role = source.role_int - else: - self.ref = None - self.role = (EventRef.CUSTOM,"") - - def get_text_data_list(self): - """ - Returns the list of all textual attributes of the object. - - @return: Returns the list of all textual attributes of the object. - @rtype: list - """ - return [self.role_str] - - def get_text_data_child_list(self): - """ - Returns the list of child objects that may carry textual data. - - @return: Returns the list of child objects that may carry textual data. - @rtype: list - """ - if self.note: - return [self.note] - return [] - - def get_referenced_handles(self): - """ - Returns the list of (classname,handle) tuples for all directly - referenced primary objects. - - @return: Returns the list of (classname,handle) tuples for referenced objects. - @rtype: list - """ - if self.ref: - return [('Event',self.ref)] - else: - return [] - - def get_reference_handle(self): - """ - Returns the handle of the referred Event object. - """ - 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. - """ - return self.role - - def set_role(self,role): - """ - Sets the role according to the given argument. - """ - if not type(role) == tuple: - if role in range(-1,9): - warn( "set_role now takes a tuple", DeprecationWarning, 2) - # Wrapper for old API - # remove when transitition done. - role = (role,'') - else: - assert type(role) == tuple - self.role = role - -#------------------------------------------------------------------------- -# -# Source References for all primary objects -# -#------------------------------------------------------------------------- -class SourceRef(BaseObject,DateBase,PrivacyBase,NoteBase): - """Source reference, containing detailed information about how a - referenced source relates to it""" - - CONF_VERY_HIGH = 4 - CONF_HIGH = 3 - CONF_NORMAL = 2 - CONF_LOW = 1 - CONF_VERY_LOW = 0 - - def __init__(self,source=None): - """creates a new SourceRef, copying from the source if present""" - BaseObject.__init__(self) - DateBase.__init__(self,source) - PrivacyBase.__init__(self,source) - NoteBase.__init__(self,source) - 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 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.page,self.text] - #return [self.page,self.text,self.get_date()] - - 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 - """ - return [self.note] - - 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 [('Source',self.ref)] - else: - return [] - - def set_confidence_level(self,val): - """Sets the confidence level""" - self.confidence = val - - def get_confidence_level(self): - """Returns the confidence level""" - return self.confidence - - def set_base_handle(self,ref): - """sets the Source instance to which the SourceRef refers""" - self.ref = ref - - def get_base_handle(self): - """returns the Source instance to which the SourceRef refers""" - return self.ref - - def set_page(self,page): - """sets the page indicator of the SourceRef""" - self.page = page - - def get_page(self): - """gets the page indicator of the SourceRef""" - return self.page - - def set_text(self,text): - """sets the text related to the SourceRef""" - self.text = text - - def get_text(self): - """returns the text related to the SourceRef""" - return self.text - - def are_equal(self,other): - """returns True if the passed SourceRef is equal to the current""" - if self.ref and other.ref: - if self.page != other.page: - return False - if not self.get_date_object().is_equal(other.get_date_object()): - return False - if self.get_text() != other.get_text(): - return False - if self.get_note() != other.get_note(): - return False - if self.confidence != other.confidence: - return False - return True - elif not self.ref and not other.ref: - return True - else: - return False - -#------------------------------------------------------------------------- -# -# MediaObject References for Person/Place/Source -# -#------------------------------------------------------------------------- -class MediaRef(PrivateSourceNote,AttributeBase): - """Media reference class""" - def __init__(self,source=None): - - PrivateSourceNote.__init__(self,source) - AttributeBase.__init__(self,source) - - if source: - self.ref = source.ref - self.rect = source.rect - else: - self.ref = None - self.rect = None - - 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.attribute_list + self.source_list - if self.note: - check_list.append(self.note) - return check_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 self.attribute_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 [('MediaObject',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.attribute_list + self.source_list - - def set_rectangle(self,coord): - """Sets subection of an image""" - self.rect = coord - - 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 - -class RepoRef(BaseObject,NoteBase): - """ - Repository reference class. - """ - - UNKNOWN = -1 - CUSTOM = 0 - AUDIO = 1 - BOOK = 2 - CARD = 3 - ELECTRONIC = 4 - FICHE = 5 - FILM = 6 - MAGAZINE = 7 - MANUSCRIPT = 8 - MAP = 9 - NEWSPAPER = 10 - PHOTO = 11 - TOMBSTONE = 12 - VIDEO = 13 - - def __init__(self,source=None): - NoteBase.__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 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.call_number,self.media_type[1]] - - def get_text_data_child_list(self): - """ - Returns the list of child objects that may carry textual data. - - @return: Returns the list of child objects that may carry textual data. - @rtype: list - """ - if self.note: - return [self.note] - return [] - - def get_referenced_handles(self): - """ - Returns the list of (classname,handle) tuples for all directly - referenced primary objects. - - @return: Returns the list of (classname,handle) tuples for referenced objects. - @rtype: list - """ - if self.ref: - return [('Repository',self.ref)] - 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 - - def get_call_number(self): - return self.call_number - - def get_media_type(self): - return self.media_type - - def set_media_type(self,media_type): - self.media_type = media_type -