2005-12-21 02:18:18 +05:30
|
|
|
#
|
|
|
|
# Gramps - a GTK+/GNOME based genealogy program
|
|
|
|
#
|
2007-02-20 06:09:10 +05:30
|
|
|
# Copyright (C) 2000-2007 Donald N. Allingham
|
2005-12-21 02:18:18 +05:30
|
|
|
#
|
|
|
|
# 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
|
|
|
|
"""
|
|
|
|
|
2007-01-08 07:19:33 +05:30
|
|
|
__revision__ = "$Revision$"
|
|
|
|
|
2005-12-21 02:18:18 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# standard python modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
import time
|
2005-12-30 09:27:31 +05:30
|
|
|
import GrampsLocale
|
2005-12-21 02:18:18 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# GRAMPS modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2007-02-20 06:09:10 +05:30
|
|
|
from _BasicPrimaryObject import BasicPrimaryObject
|
2006-04-13 08:45:22 +05:30
|
|
|
from _SourceBase import SourceBase
|
2005-12-21 02:18:18 +05:30
|
|
|
from _MediaBase import MediaBase
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Localized constants
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2005-12-30 09:27:31 +05:30
|
|
|
_codeset = GrampsLocale.codeset
|
2005-12-21 02:18:18 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Primary Object class
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2007-02-20 06:09:10 +05:30
|
|
|
class PrimaryObject(BasicPrimaryObject):
|
2005-12-21 02:18:18 +05:30
|
|
|
"""
|
|
|
|
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.
|
|
|
|
"""
|
|
|
|
|
2007-01-08 07:19:33 +05:30
|
|
|
def __init__(self, source=None):
|
2005-12-21 02:18:18 +05:30
|
|
|
"""
|
2007-02-20 06:09:10 +05:30
|
|
|
Initialize a PrimaryObject. If source is None, both the ID and handle
|
2005-12-21 02:18:18 +05:30
|
|
|
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
|
|
|
|
"""
|
2007-02-20 06:09:10 +05:30
|
|
|
BasicPrimaryObject.__init__(self, source)
|
2005-12-21 02:18:18 +05:30
|
|
|
|
2007-01-08 07:19:33 +05:30
|
|
|
def has_handle_reference(self, classname, handle):
|
2005-12-21 02:18:18 +05:30
|
|
|
"""
|
|
|
|
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
|
|
|
|
"""
|
2007-01-08 07:19:33 +05:30
|
|
|
if classname == 'Source' and isinstance(self, SourceBase):
|
2005-12-21 02:18:18 +05:30
|
|
|
return self.has_source_reference(handle)
|
2007-01-08 07:19:33 +05:30
|
|
|
elif classname == 'MediaObject' and isinstance(self, MediaBase):
|
2005-12-21 02:18:18 +05:30
|
|
|
return self.has_media_reference(handle)
|
|
|
|
else:
|
2007-01-08 07:19:33 +05:30
|
|
|
return self._has_handle_reference(classname, handle)
|
2005-12-21 02:18:18 +05:30
|
|
|
|
2007-01-08 07:19:33 +05:30
|
|
|
def remove_handle_references(self, classname, handle_list):
|
2005-12-21 02:18:18 +05:30
|
|
|
"""
|
|
|
|
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
|
|
|
|
"""
|
2007-01-08 07:19:33 +05:30
|
|
|
if classname == 'Source' and isinstance(self, SourceBase):
|
2005-12-21 02:18:18 +05:30
|
|
|
self.remove_source_references(handle_list)
|
2007-01-08 07:19:33 +05:30
|
|
|
elif classname == 'MediaObject' and isinstance(self, MediaBase):
|
2005-12-21 02:18:18 +05:30
|
|
|
self.remove_media_references(handle_list)
|
|
|
|
else:
|
2007-01-08 07:19:33 +05:30
|
|
|
self._remove_handle_references(classname, handle_list)
|
2005-12-21 02:18:18 +05:30
|
|
|
|
2007-01-08 07:19:33 +05:30
|
|
|
def replace_handle_reference(self, classname, old_handle, new_handle):
|
2005-12-21 02:18:18 +05:30
|
|
|
"""
|
|
|
|
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
|
|
|
|
"""
|
2007-01-08 07:19:33 +05:30
|
|
|
if classname == 'Source' and isinstance(self, SourceBase):
|
|
|
|
self.replace_source_references(old_handle, new_handle)
|
|
|
|
elif classname == 'MediaObject' and isinstance(self, MediaBase):
|
|
|
|
self.replace_media_references(old_handle, new_handle)
|
2005-12-21 02:18:18 +05:30
|
|
|
else:
|
2007-01-08 07:19:33 +05:30
|
|
|
self._replace_handle_reference(classname, old_handle, new_handle)
|
2005-12-21 02:18:18 +05:30
|
|
|
|
2007-01-08 07:19:33 +05:30
|
|
|
def _has_handle_reference(self, classname, handle):
|
|
|
|
"""
|
|
|
|
returns True if the handle is referenced by the object
|
|
|
|
"""
|
2005-12-21 02:18:18 +05:30
|
|
|
return False
|
|
|
|
|
2007-01-08 07:19:33 +05:30
|
|
|
def _remove_handle_references(self, classname, handle_list):
|
|
|
|
"""
|
|
|
|
removes the handle references from the object
|
|
|
|
"""
|
2005-12-21 02:18:18 +05:30
|
|
|
pass
|
|
|
|
|
2007-01-08 07:19:33 +05:30
|
|
|
def _replace_handle_reference(self, classname, old_handle, new_handle):
|
|
|
|
"""
|
|
|
|
replaces the handle reference with the new reference
|
|
|
|
"""
|
2005-12-21 02:18:18 +05:30
|
|
|
pass
|
|
|
|
|
2007-01-08 07:19:33 +05:30
|
|
|
def set_marker(self, marker):
|
2006-04-21 05:33:27 +05:30
|
|
|
self.marker.set(marker)
|
2005-12-21 02:18:18 +05:30
|
|
|
|
|
|
|
def get_marker(self):
|
|
|
|
return self.marker
|