gramps/src/gen/lib/ldsordbase.py

118 lines
3.7 KiB
Python
Raw Normal View History

2006-04-04 23:37:23 +05:30
#
# Gramps - a GTK+/GNOME based genealogy program
#
# Copyright (C) 2000-2006 Donald N. Allingham
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# 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
#
2006-04-21 00:00:28 +05:30
# $Id$
2006-04-04 23:37:23 +05:30
"""
LdsOrdBase class for GRAMPS.
2006-04-04 23:37:23 +05:30
"""
#-------------------------------------------------------------------------
#
# GRAMPS modules
#
#-------------------------------------------------------------------------
from gen.lib.ldsord import LdsOrd
2006-04-04 23:37:23 +05:30
#-------------------------------------------------------------------------
#
# LdsOrdBase classes
#
#-------------------------------------------------------------------------
class LdsOrdBase(object):
2006-04-04 23:37:23 +05:30
"""
Base class for lds_ord-aware objects.
"""
def __init__(self, source=None):
2006-04-04 23:37:23 +05:30
"""
Initialize a LdsOrdBase.
If the source is not None, then object is initialized from values of
the source object.
2006-04-04 23:37:23 +05:30
:param source: Object used to initialize the new object
:type source: LdsOrdBase
2006-04-04 23:37:23 +05:30
"""
if source:
self.lds_ord_list = [ LdsOrd(lds_ord) \
for lds_ord in source.lds_ord_list ]
else:
self.lds_ord_list = []
def serialize(self):
"""
Convert the object to a serialized tuple of data.
"""
2006-04-05 22:45:44 +05:30
return [lds_ord.serialize() for lds_ord in self.lds_ord_list]
2006-04-04 23:37:23 +05:30
def unserialize(self, data):
"""
Convert a serialized tuple of data to an object
"""
2006-04-04 23:37:23 +05:30
self.lds_ord_list = [LdsOrd().unserialize(item) for item in data]
def add_lds_ord(self, lds_ord):
2006-04-04 23:37:23 +05:30
"""
2009-07-02 13:58:29 +05:30
Add the :class:`~gen.lib.ldsord.LdsOrd` instance to the object's list of lds_ordes.
2006-04-04 23:37:23 +05:30
2009-07-02 13:58:29 +05:30
:param lds_ord: :class:`~gen.lib.ldsord.LdsOrd` instance to add to the object's lds_ord list
:type lds_ord: list
2006-04-04 23:37:23 +05:30
"""
self.lds_ord_list.append(lds_ord)
def remove_lds_ord(self, lds_ord):
2006-04-04 23:37:23 +05:30
"""
2009-07-02 13:58:29 +05:30
Remove the specified :class:`~gen.lib.ldsord.LdsOrd` instance from the lds_ord list.
If the instance does not exist in the list, the operation has no effect.
2006-04-04 23:37:23 +05:30
2009-07-02 13:58:29 +05:30
:param lds_ord: :class:`~gen.lib.ldsord.LdsOrd` instance to remove from the list
:type lds_ord: :class:`~gen.lib.ldsord.LdsOrd`
2006-04-04 23:37:23 +05:30
:returns: True if the lds_ord was removed, False if it was not in the list.
:rtype: bool
2006-04-04 23:37:23 +05:30
"""
if lds_ord in self.lds_ord_list:
self.lds_ord_list.remove(lds_ord)
return True
else:
return False
def get_lds_ord_list(self):
"""
2009-07-02 13:58:29 +05:30
Return the list of :class:`~gen.lib.ldsord.LdsOrd` instances associated with the object.
2006-04-04 23:37:23 +05:30
2009-07-02 13:58:29 +05:30
:returns: Returns the list of :class:`~gen.lib.ldsord.LdsOrd` instances
:rtype: list
2006-04-04 23:37:23 +05:30
"""
return self.lds_ord_list
def set_lds_ord_list(self, lds_ord_list):
2006-04-04 23:37:23 +05:30
"""
2009-07-02 13:58:29 +05:30
Assign the passed list to the object's list of :class:`~gen.lib.ldsord.LdsOrd` instances.
2009-07-02 13:58:29 +05:30
:param lds_ord_list: List of :class:`~gen.lib.ldsord.LdsOrd` instances to be associated
2006-04-04 23:37:23 +05:30
with the object
:type lds_ord_list: list
2006-04-04 23:37:23 +05:30
"""
self.lds_ord_list = lds_ord_list