Trees | Indices | Help |
|
---|
|
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: mediabase.py 10103 2008-02-24 13:55:55Z acraphae $ 22 23 """ 24 MediaBase class for GRAMPS. 25 """ 26 27 #------------------------------------------------------------------------- 28 # 29 # GRAMPS modules 30 # 31 #------------------------------------------------------------------------- 32 from gen.lib.mediaref import MediaRef 33 34 #------------------------------------------------------------------------- 35 # 36 # MediaBase class 37 # 38 #-------------------------------------------------------------------------40 """ 41 Base class for storing media references. 42 """ 4313845 """ 46 Create a new MediaBase, copying from source if not None. 47 48 @param source: Object used to initialize the new object 49 @type source: MediaBase 50 """ 51 52 if source: 53 self.media_list = [ MediaRef(mref) for mref in source.media_list ] 54 else: 55 self.media_list = []5658 """ 59 Convert the object to a serialized tuple of data. 60 """ 61 return [mref.serialize() for mref in self.media_list]6264 """ 65 Convert a serialized tuple of data to an object. 66 """ 67 self.media_list = [MediaRef().unserialize(item) for item in data]6870 """ 71 Add a L{MediaRef} instance to the object's media list. 72 73 @param media_ref: L{MediaRef} instance to be added to the object's 74 media list. 75 @type media_ref: L{MediaRef} 76 """ 77 self.media_list.append(media_ref)7880 """ 81 Return the list of L{MediaRef} instances associated with the object. 82 83 @returns: list of L{MediaRef} instances associated with the object 84 @rtype: list 85 """ 86 return self.media_list8789 """ 90 Set the list of L{MediaRef} instances associated with the object. 91 It replaces the previous list. 92 93 @param media_ref_list: list of L{MediaRef} instances to be assigned 94 to the object. 95 @type media_ref_list: list 96 """ 97 self.media_list = media_ref_list98100 """ 101 Return True if the object or any of it's child objects has reference 102 to this media object handle. 103 104 @param obj_handle: The media handle to be checked. 105 @type obj_handle: str 106 @return: Returns whether the object or any of it's child objects has 107 reference to this media handle. 108 @rtype: bool 109 """ 110 return obj_handle in [media_ref.ref for media_ref in self.media_list]111113 """ 114 Remove references to all media handles in the list. 115 116 @param obj_handle_list: The list of media handles to be removed. 117 @type obj_handle_list: list 118 """ 119 new_media_list = [ media_ref for media_ref in self.media_list \ 120 if media_ref.ref not in obj_handle_list ] 121 self.media_list = new_media_list122124 """ 125 Replace all references to old media handle with the new handle. 126 127 @param old_handle: The media handle to be replaced. 128 @type old_handle: str 129 @param new_handle: The media handle to replace the old one with. 130 @type new_handle: str 131 """ 132 refs_list = [ media_ref.ref for media_ref in self.media_list ] 133 n_replace = refs_list.count(old_handle) 134 for ix_replace in xrange(n_replace): 135 ix = refs_list.index(old_handle) 136 self.media_list[ix].ref = new_handle 137 refs_list[ix] = new_handle
Trees | Indices | Help |
|
---|
Generated by Epydoc 3.0.1 on Sun Mar 9 21:53:24 2008 | http://epydoc.sourceforge.net |