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

Source Code for Module gen.lib.attribute

  1  # 
  2  # Gramps - a GTK+/GNOME based genealogy program 
  3  # 
  4  # Copyright (C) 2000-2007  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: attribute.py 10103 2008-02-24 13:55:55Z acraphae $ 
 22   
 23  """ 
 24  Attribute class for GRAMPS. 
 25  """ 
 26   
 27  #------------------------------------------------------------------------- 
 28  # 
 29  # GRAMPS modules 
 30  # 
 31  #------------------------------------------------------------------------- 
 32  from gen.lib.secondaryobj import SecondaryObject 
 33  from gen.lib.privacybase import PrivacyBase 
 34  from gen.lib.srcbase import SourceBase 
 35  from gen.lib.notebase import NoteBase 
 36  from gen.lib.attrtype import AttributeType 
 37   
 38  #------------------------------------------------------------------------- 
 39  # 
 40  # Attribute for Person/Family/MediaObject/MediaRef 
 41  # 
 42  #------------------------------------------------------------------------- 
43 -class Attribute(SecondaryObject, PrivacyBase, SourceBase, NoteBase):
44 """ 45 Provide a simple key/value pair for describing properties. 46 47 Used by the Person and Family objects to store descriptive information. 48 """ 49
50 - def __init__(self, source=None):
51 """ 52 Create a new Attribute object, copying from the source if provided. 53 """ 54 PrivacyBase.__init__(self, source) 55 SourceBase.__init__(self, source) 56 NoteBase.__init__(self, source) 57 58 if source: 59 self.type = source.type 60 self.value = source.value 61 else: 62 self.type = AttributeType() 63 self.value = ""
64
65 - def serialize(self):
66 """ 67 Convert the object to a serialized tuple of data. 68 """ 69 return (PrivacyBase.serialize(self), 70 SourceBase.serialize(self), 71 NoteBase.serialize(self), 72 self.type.serialize(), self.value)
73
74 - def unserialize(self, data):
75 """ 76 Convert a serialized tuple of data to an object. 77 """ 78 (privacy, source_list, note_list, the_type, self.value) = data 79 PrivacyBase.unserialize(self, privacy) 80 SourceBase.unserialize(self, source_list) 81 NoteBase.unserialize(self, note_list) 82 self.type.unserialize(the_type) 83 return self
84
85 - def get_text_data_list(self):
86 """ 87 Return the list of all textual attributes of the object. 88 89 @return: Returns the list of all textual attributes of the object. 90 @rtype: list 91 """ 92 return [self.value]
93
94 - def get_text_data_child_list(self):
95 """ 96 Return the list of child objects that may carry textual data. 97 98 @return: Returns the list of child objects that may carry textual data. 99 @rtype: list 100 """ 101 return self.source_list
102
103 - def get_handle_referents(self):
104 """ 105 Return the list of child objects which may, directly or through 106 their children, reference primary objects. 107 108 @return: Returns the list of objects refereincing primary objects. 109 @rtype: list 110 """ 111 return self.source_list
112
113 - def get_referenced_handles(self):
114 """ 115 Return the list of (classname, handle) tuples for all directly 116 referenced primary objects. 117 118 @return: List of (classname, handle) tuples for referenced objects. 119 @rtype: list 120 """ 121 return self.get_referenced_note_handles()
122
123 - def set_type(self, val):
124 """Set the type (or key) of the Attribute instance.""" 125 self.type.set(val)
126
127 - def get_type(self):
128 """Return the type (or key) or the Attribute instance.""" 129 return self.type
130
131 - def set_value(self, val):
132 """Set the value of the Attribute instance.""" 133 self.value = val
134
135 - def get_value(self):
136 """Return the value of the Attribute instance.""" 137 return self.value
138