Package gen :: Package lib :: Module attrbase
[frames] | no frames]

Source Code for Module gen.lib.attrbase

  1  # 
  2  # Gramps - a GTK+/GNOME based genealogy program 
  3  # 
  4  # Copyright (C) 2000-2006  Donald N. Allingham 
  5  # 
  6  # This program is free software; you can redistribute it and/or modify 
  7  # it under the terms of the GNU General Public License as published by 
  8  # the Free Software Foundation; either version 2 of the License, or 
  9  # (at your option) any later version. 
 10  # 
 11  # This program is distributed in the hope that it will be useful, 
 12  # but WITHOUT ANY WARRANTY; without even the implied warranty of 
 13  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 14  # GNU General Public License for more details. 
 15  # 
 16  # You should have received a copy of the GNU General Public License 
 17  # along with this program; if not, write to the Free Software 
 18  # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
 19  # 
 20   
 21  # $Id: attrbase.py 10103 2008-02-24 13:55:55Z acraphae $ 
 22   
 23  """ 
 24  AttributeBase class for GRAMPS. 
 25  """ 
 26   
 27  #------------------------------------------------------------------------- 
 28  # 
 29  # GRAMPS modules 
 30  # 
 31  #------------------------------------------------------------------------- 
 32  from gen.lib.attribute import Attribute 
 33   
 34  #------------------------------------------------------------------------- 
 35  # 
 36  # AttributeBase class 
 37  # 
 38  #------------------------------------------------------------------------- 
39 -class AttributeBase:
40 """ 41 Base class for attribute-aware objects. 42 """ 43
44 - def __init__(self, source=None):
45 """ 46 Initialize a AttributeBase. 47 48 If the source is not None, then object is initialized from values of 49 the source object. 50 51 @param source: Object used to initialize the new object 52 @type source: AttributeBase 53 """ 54 if source: 55 self.attribute_list = [ Attribute(attribute) \ 56 for attribute in source.attribute_list ] 57 else: 58 self.attribute_list = []
59
60 - def serialize(self):
61 """ 62 Convert the object to a serialized tuple of data. 63 """ 64 return [attr.serialize() for attr in self.attribute_list]
65
66 - def unserialize(self, data):
67 """ 68 Convert a serialized tuple of data to an object. 69 """ 70 self.attribute_list = [Attribute().unserialize(item) for item in data]
71
72 - def add_attribute(self, attribute):
73 """ 74 Add the L{Attribute} instance to the object's list of attributes. 75 76 @param attribute: L{Attribute} instance to add. 77 @type attribute: L{Attribute} 78 """ 79 assert type(attribute) != unicode 80 self.attribute_list.append(attribute)
81
82 - def remove_attribute(self, attribute):
83 """ 84 Remove the specified L{Attribute} instance from the attribute list. 85 86 If the instance does not exist in the list, the operation has 87 no effect. 88 89 @param attribute: L{Attribute} instance to remove from the list 90 @type attribute: L{Attribute} 91 92 @return: True if the attribute was removed, False if it was not 93 in the list. 94 @rtype: bool 95 """ 96 if attribute in self.attribute_list: 97 self.attribute_list.remove(attribute) 98 return True 99 else: 100 return False
101
102 - def get_attribute_list(self):
103 """ 104 Return the list of L{Attribute} instances associated with the object. 105 106 @returns: Returns the list of L{Attribute} instances. 107 @rtype: list 108 """ 109 return self.attribute_list
110
111 - def set_attribute_list(self, attribute_list):
112 """ 113 Assign the passed list to the Person's list of L{Attribute} instances. 114 115 @param attribute_list: List of L{Attribute} instances to ba associated 116 with the Person 117 @type attribute_list: list 118 """ 119 self.attribute_list = attribute_list
120