2007-02-20 06:09:10 +05:30
|
|
|
#
|
|
|
|
# Gramps - a GTK+/GNOME based genealogy program
|
|
|
|
#
|
|
|
|
# Copyright (C) 2000-2007 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$
|
|
|
|
|
|
|
|
"""
|
2008-02-24 19:25:55 +05:30
|
|
|
Basic Primary Object class for GRAMPS.
|
2007-02-20 06:09:10 +05:30
|
|
|
"""
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# standard python modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
import time
|
2007-10-10 09:11:44 +05:30
|
|
|
import locale
|
2007-02-20 06:09:10 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# GRAMPS modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2008-02-24 19:25:55 +05:30
|
|
|
from gen.lib.baseobj import BaseObject
|
|
|
|
from gen.lib.privacybase import PrivacyBase
|
|
|
|
from gen.lib.markertype import MarkerType
|
|
|
|
from gen.lib.srcbase import SourceBase
|
|
|
|
from gen.lib.mediabase import MediaBase
|
2007-02-20 06:09:10 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Localized constants
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2007-10-10 09:11:44 +05:30
|
|
|
try:
|
|
|
|
CODESET = locale.nl_langinfo(locale.CODESET)
|
|
|
|
except:
|
|
|
|
CODESET = locale.getpreferredencoding()
|
2007-02-20 06:09:10 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Basic Primary Object class
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
class BasicPrimaryObject(BaseObject, PrivacyBase):
|
|
|
|
"""
|
|
|
|
The BasicPrimaryObject is the base class for Note objects.
|
2008-02-24 19:25:55 +05:30
|
|
|
|
2007-02-20 06:09:10 +05:30
|
|
|
It is also the base class for the PrimaryObject class.
|
|
|
|
|
|
|
|
The PrimaryObject is the base class for all other 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.
|
|
|
|
"""
|
|
|
|
|
|
|
|
def __init__(self, source=None):
|
|
|
|
"""
|
2008-02-24 19:25:55 +05:30
|
|
|
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.
|
2007-02-20 06:09:10 +05:30
|
|
|
|
2009-06-25 03:26:07 +05:30
|
|
|
:param source: Object used to initialize the new object
|
|
|
|
:type source: PrimaryObject
|
2007-02-20 06:09:10 +05:30
|
|
|
"""
|
|
|
|
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 = MarkerType()
|
|
|
|
|
|
|
|
def get_change_time(self):
|
|
|
|
"""
|
2008-02-24 19:25:55 +05:30
|
|
|
Return the time that the data was last changed.
|
|
|
|
|
|
|
|
The value in the format returned by the time.time() command.
|
2007-02-20 06:09:10 +05:30
|
|
|
|
2009-06-25 03:26:07 +05:30
|
|
|
:returns: Time that the data was last changed. The value in the format
|
2008-02-24 19:25:55 +05:30
|
|
|
returned by the time.time() command.
|
2009-06-25 03:26:07 +05:30
|
|
|
:rtype: int
|
2007-02-20 06:09:10 +05:30
|
|
|
"""
|
|
|
|
return self.change
|
|
|
|
|
|
|
|
def get_change_display(self):
|
|
|
|
"""
|
2008-02-24 19:25:55 +05:30
|
|
|
Return the string representation of the last change time.
|
2007-02-20 06:09:10 +05:30
|
|
|
|
2009-06-25 03:26:07 +05:30
|
|
|
:returns: string representation of the last change time.
|
|
|
|
:rtype: str
|
2007-02-20 06:09:10 +05:30
|
|
|
|
|
|
|
"""
|
|
|
|
if self.change:
|
|
|
|
return unicode(time.strftime('%x %X', time.localtime(self.change)),
|
2007-05-02 09:35:41 +05:30
|
|
|
CODESET)
|
2007-02-20 06:09:10 +05:30
|
|
|
else:
|
|
|
|
return u''
|
|
|
|
|
|
|
|
def set_handle(self, handle):
|
|
|
|
"""
|
2008-02-24 19:25:55 +05:30
|
|
|
Set the database handle for the primary object.
|
2007-02-20 06:09:10 +05:30
|
|
|
|
2009-06-25 03:26:07 +05:30
|
|
|
:param handle: object database handle
|
|
|
|
:type handle: str
|
2007-02-20 06:09:10 +05:30
|
|
|
"""
|
|
|
|
self.handle = handle
|
|
|
|
|
|
|
|
def get_handle(self):
|
|
|
|
"""
|
2008-02-24 19:25:55 +05:30
|
|
|
Return the database handle for the primary object.
|
2007-02-20 06:09:10 +05:30
|
|
|
|
2009-06-25 03:26:07 +05:30
|
|
|
:returns: database handle associated with the object
|
|
|
|
:rtype: str
|
2007-02-20 06:09:10 +05:30
|
|
|
"""
|
|
|
|
return self.handle
|
|
|
|
|
|
|
|
def set_gramps_id(self, gramps_id):
|
|
|
|
"""
|
2008-02-24 19:25:55 +05:30
|
|
|
Set the GRAMPS ID for the primary object.
|
2007-02-20 06:09:10 +05:30
|
|
|
|
2009-06-25 03:26:07 +05:30
|
|
|
:param gramps_id: GRAMPS ID
|
|
|
|
:type gramps_id: str
|
2007-02-20 06:09:10 +05:30
|
|
|
"""
|
|
|
|
self.gramps_id = gramps_id
|
|
|
|
|
|
|
|
def get_gramps_id(self):
|
|
|
|
"""
|
2008-02-24 19:25:55 +05:30
|
|
|
Return the GRAMPS ID for the primary object.
|
2007-02-20 06:09:10 +05:30
|
|
|
|
2009-06-25 03:26:07 +05:30
|
|
|
:returns: GRAMPS ID associated with the object
|
|
|
|
:rtype: str
|
2007-02-20 06:09:10 +05:30
|
|
|
"""
|
|
|
|
return self.gramps_id
|
|
|
|
|
|
|
|
def has_handle_reference(self, classname, handle):
|
|
|
|
"""
|
2008-02-24 19:25:55 +05:30
|
|
|
Return True if the object has reference to a given handle of given
|
|
|
|
primary object type.
|
2007-02-20 06:09:10 +05:30
|
|
|
|
2009-06-25 03:26:07 +05:30
|
|
|
:param classname: The name of the primary object class.
|
|
|
|
:type classname: str
|
|
|
|
:param handle: The handle to be checked.
|
|
|
|
:type handle: str
|
|
|
|
|
|
|
|
:returns:
|
|
|
|
Returns whether the object has reference to this handle of
|
|
|
|
this object type.
|
|
|
|
|
|
|
|
:rtype: bool
|
2007-02-20 06:09:10 +05:30
|
|
|
"""
|
|
|
|
return False
|
|
|
|
|
|
|
|
def remove_handle_references(self, classname, handle_list):
|
|
|
|
"""
|
2008-02-24 19:25:55 +05:30
|
|
|
Remove all references in this object to object handles in the list.
|
2007-02-20 06:09:10 +05:30
|
|
|
|
2009-06-25 03:26:07 +05:30
|
|
|
: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-02-20 06:09:10 +05:30
|
|
|
"""
|
|
|
|
pass
|
|
|
|
|
|
|
|
def replace_handle_reference(self, classname, old_handle, new_handle):
|
|
|
|
"""
|
2008-02-24 19:25:55 +05:30
|
|
|
Replace all references to old handle with those to the new handle.
|
2007-02-20 06:09:10 +05:30
|
|
|
|
2009-06-25 03:26:07 +05:30
|
|
|
: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-02-20 06:09:10 +05:30
|
|
|
"""
|
|
|
|
pass
|
|
|
|
|
|
|
|
def set_marker(self, marker):
|
2007-05-02 09:35:41 +05:30
|
|
|
"""
|
2008-02-24 19:25:55 +05:30
|
|
|
Set the marker for the object.
|
2007-05-02 09:35:41 +05:30
|
|
|
|
2009-06-25 03:26:07 +05:30
|
|
|
:param marker: marker assigned to the object
|
|
|
|
:type marker: MarkerType
|
2007-05-02 09:35:41 +05:30
|
|
|
"""
|
2007-02-20 06:09:10 +05:30
|
|
|
self.marker.set(marker)
|
|
|
|
|
|
|
|
def get_marker(self):
|
2007-05-02 09:35:41 +05:30
|
|
|
"""
|
2008-02-24 19:25:55 +05:30
|
|
|
Return the marker for the object.
|
|
|
|
|
|
|
|
The exact type depends on the derived class type.
|
2007-05-02 09:35:41 +05:30
|
|
|
|
2009-06-25 03:26:07 +05:30
|
|
|
:returns: Returns the marker for the object.
|
|
|
|
:rtype: MarkerType
|
2007-05-02 09:35:41 +05:30
|
|
|
"""
|
2007-02-20 06:09:10 +05:30
|
|
|
return self.marker
|
|
|
|
|
|
|
|
def has_source_reference(self, handle):
|
2007-05-02 09:35:41 +05:30
|
|
|
"""
|
2008-02-24 19:25:55 +05:30
|
|
|
Indicate if the object has a source references.
|
|
|
|
|
|
|
|
In the base class, no such references exist. Derived classes should
|
|
|
|
override this if they provide source references.
|
2007-05-02 09:35:41 +05:30
|
|
|
"""
|
2007-02-20 06:09:10 +05:30
|
|
|
return False
|
|
|
|
|
|
|
|
def has_media_reference(self, handle):
|
2007-05-02 09:35:41 +05:30
|
|
|
"""
|
2008-02-24 19:25:55 +05:30
|
|
|
Indicate if the object has a media references.
|
|
|
|
|
|
|
|
In the base class, no such references exist. Derived classes should
|
|
|
|
override this if they provide media references.
|
2007-05-02 09:35:41 +05:30
|
|
|
"""
|
2007-02-20 06:09:10 +05:30
|
|
|
return False
|
|
|
|
|
|
|
|
def remove_source_references(self, handle_list):
|
2007-05-02 09:35:41 +05:30
|
|
|
"""
|
2008-02-24 19:25:55 +05:30
|
|
|
Remove the specified source references from the object.
|
|
|
|
|
|
|
|
In the base class no such references exist. Derived classes should
|
|
|
|
override this if they provide source references.
|
2007-05-02 09:35:41 +05:30
|
|
|
"""
|
2007-02-20 06:09:10 +05:30
|
|
|
pass
|
|
|
|
|
|
|
|
def remove_media_references(self, handle_list):
|
2007-05-02 09:35:41 +05:30
|
|
|
"""
|
2008-02-24 19:25:55 +05:30
|
|
|
Remove the specified media references from the object.
|
|
|
|
|
|
|
|
In the base class no such references exist. Derived classes should
|
|
|
|
override this if they provide media references.
|
2007-05-02 09:35:41 +05:30
|
|
|
"""
|
2007-02-20 06:09:10 +05:30
|
|
|
pass
|
|
|
|
|
|
|
|
def replace_source_references(self, old_handle, new_handle):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def replace_media_references(self, old_handle, new_handle):
|
|
|
|
pass
|
2007-10-08 22:11:39 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Primary Object class
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
class PrimaryObject(BasicPrimaryObject):
|
|
|
|
"""
|
|
|
|
The PrimaryObject is the base class for all primary objects in the
|
2008-02-24 19:25:55 +05:30
|
|
|
database.
|
|
|
|
|
|
|
|
Primary objects are the core objects in the database.
|
2007-10-08 22:11:39 +05:30
|
|
|
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.
|
|
|
|
"""
|
|
|
|
|
|
|
|
def __init__(self, source=None):
|
|
|
|
"""
|
2008-02-24 19:25:55 +05:30
|
|
|
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.
|
2007-10-08 22:11:39 +05:30
|
|
|
|
2009-06-25 03:26:07 +05:30
|
|
|
:param source: Object used to initialize the new object
|
|
|
|
:type source: PrimaryObject
|
2007-10-08 22:11:39 +05:30
|
|
|
"""
|
|
|
|
BasicPrimaryObject.__init__(self, source)
|
|
|
|
|
|
|
|
def has_handle_reference(self, classname, handle):
|
|
|
|
"""
|
2008-02-24 19:25:55 +05:30
|
|
|
Return True if the object has reference to a given handle of given
|
|
|
|
primary object type.
|
2007-10-08 22:11:39 +05:30
|
|
|
|
2009-06-25 03:26:07 +05:30
|
|
|
:param classname: The name of the primary object class.
|
|
|
|
:type classname: str
|
|
|
|
:param handle: The handle to be checked.
|
|
|
|
:type handle: str
|
|
|
|
:returns: Returns whether the object has reference to this handle
|
|
|
|
of this object type.
|
|
|
|
:rtype: bool
|
2007-10-08 22:11:39 +05:30
|
|
|
"""
|
|
|
|
if classname == 'Source' and isinstance(self, SourceBase):
|
|
|
|
return self.has_source_reference(handle)
|
|
|
|
elif classname == 'MediaObject' and isinstance(self, MediaBase):
|
|
|
|
return self.has_media_reference(handle)
|
|
|
|
else:
|
|
|
|
return self._has_handle_reference(classname, handle)
|
|
|
|
|
|
|
|
def remove_handle_references(self, classname, handle_list):
|
|
|
|
"""
|
2008-02-24 19:25:55 +05:30
|
|
|
Remove all references in this object to object handles in the list.
|
2007-10-08 22:11:39 +05:30
|
|
|
|
2009-06-25 03:26:07 +05:30
|
|
|
: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-10-08 22:11:39 +05:30
|
|
|
"""
|
|
|
|
if classname == 'Source' and isinstance(self, SourceBase):
|
|
|
|
self.remove_source_references(handle_list)
|
|
|
|
elif classname == 'MediaObject' and isinstance(self, MediaBase):
|
|
|
|
self.remove_media_references(handle_list)
|
|
|
|
else:
|
|
|
|
self._remove_handle_references(classname, handle_list)
|
|
|
|
|
|
|
|
def replace_handle_reference(self, classname, old_handle, new_handle):
|
|
|
|
"""
|
2008-02-24 19:25:55 +05:30
|
|
|
Replace all references to old handle with those to the new handle.
|
2007-10-08 22:11:39 +05:30
|
|
|
|
2009-06-25 03:26:07 +05:30
|
|
|
: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-10-08 22:11:39 +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)
|
|
|
|
else:
|
|
|
|
self._replace_handle_reference(classname, old_handle, new_handle)
|
|
|
|
|
|
|
|
def _has_handle_reference(self, classname, handle):
|
|
|
|
"""
|
2008-02-24 19:25:55 +05:30
|
|
|
Return True if the handle is referenced by the object.
|
2007-10-08 22:11:39 +05:30
|
|
|
"""
|
|
|
|
return False
|
|
|
|
|
|
|
|
def _remove_handle_references(self, classname, handle_list):
|
|
|
|
"""
|
2008-02-24 19:25:55 +05:30
|
|
|
Remove the handle references from the object.
|
2007-10-08 22:11:39 +05:30
|
|
|
"""
|
|
|
|
pass
|
|
|
|
|
|
|
|
def _replace_handle_reference(self, classname, old_handle, new_handle):
|
|
|
|
"""
|
2008-02-24 19:25:55 +05:30
|
|
|
Replace the handle reference with the new reference.
|
2007-10-08 22:11:39 +05:30
|
|
|
"""
|
|
|
|
pass
|
|
|
|
|
|
|
|
def set_marker(self, marker):
|
|
|
|
self.marker.set(marker)
|
|
|
|
|
|
|
|
def get_marker(self):
|
|
|
|
return self.marker
|