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

Source Code for Module gen.lib.mediaobj

  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: mediaobj.py 10103 2008-02-24 13:55:55Z acraphae $ 
 22   
 23  """ 
 24  Media object for GRAMPS. 
 25  """ 
 26   
 27  #------------------------------------------------------------------------- 
 28  # 
 29  # standard python modules 
 30  # 
 31  #------------------------------------------------------------------------- 
 32  import os 
 33  from types import InstanceType 
 34   
 35  #------------------------------------------------------------------------- 
 36  # 
 37  # GRAMPS modules 
 38  # 
 39  #------------------------------------------------------------------------- 
 40  from gen.lib.primaryobj import PrimaryObject 
 41  from gen.lib.srcbase import SourceBase 
 42  from gen.lib.notebase import NoteBase 
 43  from gen.lib.datebase import DateBase 
 44  from gen.lib.attrbase import AttributeBase 
 45  from gen.lib.markertype import MarkerType 
 46   
 47  #------------------------------------------------------------------------- 
 48  # 
 49  # MediaObject class 
 50  # 
 51  #------------------------------------------------------------------------- 
52 -class MediaObject(SourceBase, NoteBase, DateBase, AttributeBase, 53 PrimaryObject):
54 """ 55 Containter for information about an image file, including location, 56 description and privacy. 57 """ 58
59 - def __init__(self, source=None):
60 """ 61 Initialize a MediaObject. 62 63 If source is not None, then object is initialized from values of the 64 source object. 65 66 @param source: Object used to initialize the new object 67 @type source: MediaObject 68 """ 69 PrimaryObject.__init__(self, source) 70 SourceBase.__init__(self, source) 71 NoteBase.__init__(self, source) 72 DateBase.__init__(self, source) 73 AttributeBase.__init__(self, source) 74 75 if source: 76 self.path = source.path 77 self.mime = source.mime 78 self.desc = source.desc 79 self.thumb = source.thumb 80 else: 81 self.path = "" 82 self.mime = "" 83 self.desc = "" 84 self.thumb = None
85
86 - def serialize(self):
87 """ 88 Convert the data held in the event to a Python tuple that 89 represents all the data elements. 90 91 This method is used to convert the object into a form that can easily 92 be saved to a database. 93 94 These elements may be primative Python types (string, integers), 95 complex Python types (lists or tuples, or Python objects. If the 96 target database cannot handle complex types (such as objectes or 97 lists), the database is responsible for converting the data into 98 a form that it can use. 99 100 @returns: Returns a python tuple containing the data that should 101 be considered persistent. 102 @rtype: tuple 103 """ 104 return (self.handle, self.gramps_id, self.path, self.mime, self.desc, 105 AttributeBase.serialize(self), 106 SourceBase.serialize(self), 107 NoteBase.serialize(self), 108 self.change, 109 DateBase.serialize(self), 110 self.marker.serialize(), 111 self.private)
112
113 - def unserialize(self, data):
114 """ 115 Convert the data held in a tuple created by the serialize method 116 back into the data in an Event structure. 117 118 @param data: tuple containing the persistent data associated the object 119 @type data: tuple 120 """ 121 (self.handle, self.gramps_id, self.path, self.mime, self.desc, 122 attribute_list, source_list, note_list, self.change, 123 date, marker, self.private) = data 124 125 self.marker = InstanceType(MarkerType) 126 self.marker.unserialize(marker) 127 AttributeBase.unserialize(self, attribute_list) 128 SourceBase.unserialize(self, source_list) 129 NoteBase.unserialize(self, note_list) 130 DateBase.unserialize(self, date)
131
132 - def get_text_data_list(self):
133 """ 134 Return the list of all textual attributes of the object. 135 136 @return: Returns the list of all textual attributes of the object. 137 @rtype: list 138 """ 139 return [self.path, self.mime, self.desc, self.gramps_id]
140
141 - def get_text_data_child_list(self):
142 """ 143 Return the list of child objects that may carry textual data. 144 145 @return: Returns the list of child objects that may carry textual data. 146 @rtype: list 147 """ 148 return self.attribute_list + self.source_list
149
150 - def get_sourcref_child_list(self):
151 """ 152 Return the list of child secondary objects that may refer sources. 153 154 @return: Returns the list of child secondary child objects that may 155 refer sources. 156 @rtype: list 157 """ 158 return self.attribute_list
159
160 - def get_note_child_list(self):
161 """ 162 Return the list of child secondary objects that may refer notes. 163 164 @return: Returns the list of child secondary child objects that may 165 refer notes. 166 @rtype: list 167 """ 168 return self.attribute_list + self.source_list
169
170 - def get_referenced_handles(self):
171 """ 172 Return the list of (classname, handle) tuples for all directly 173 referenced primary objects. 174 175 @return: List of (classname, handle) tuples for referenced objects. 176 @rtype: list 177 """ 178 return self.get_referenced_note_handles()
179
180 - def get_handle_referents(self):
181 """ 182 Return the list of child objects which may, directly or through 183 their children, reference primary objects. 184 185 @return: Returns the list of objects refereincing primary objects. 186 @rtype: list 187 """ 188 return self.attribute_list + self.source_list
189
190 - def set_mime_type(self, mime_type):
191 """ 192 Set the MIME type associated with the MediaObject. 193 194 @param mime_type: MIME type to be assigned to the object 195 @type mime_type: str 196 """ 197 self.mime = mime_type
198
199 - def get_mime_type(self):
200 """ 201 Return the MIME type associated with the MediaObject. 202 203 @returns: Returns the associated MIME type 204 @rtype: str 205 """ 206 return self.mime
207
208 - def set_path(self, path):
209 """Set the file path to the passed path.""" 210 self.path = os.path.normpath(path)
211
212 - def get_path(self):
213 """Return the file path.""" 214 return self.path
215
216 - def set_description(self, text):
217 """Set the description of the image.""" 218 self.desc = text
219
220 - def get_description(self):
221 """Return the description of the image.""" 222 return self.desc
223