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

Source Code for Module gen.lib.notebase

  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: notebase.py 10103 2008-02-24 13:55:55Z acraphae $ 
 22   
 23  """ 
 24  NoteBase class for GRAMPS. 
 25  """ 
 26   
 27  #------------------------------------------------------------------------- 
 28  # 
 29  # NoteBase class 
 30  # 
 31  #------------------------------------------------------------------------- 
32 -class NoteBase:
33 """ 34 Base class for storing notes. 35 36 Starting in 3.0 branch, the objects may have multiple notes. 37 Internally, this class maintains a list of Note handles, 38 as a note_list attribute of the NoteBase object. 39 """
40 - def __init__(self, source=None):
41 """ 42 Create a new NoteBase, copying from source if not None. 43 44 @param source: Object used to initialize the new object 45 @type source: NoteBase 46 """ 47 48 if source: 49 self.note_list = [handle for handle in source.note_list] 50 else: 51 self.note_list = []
52
53 - def serialize(self):
54 """ 55 Convert the object to a serialized tuple of data. 56 """ 57 return self.note_list
58
59 - def unserialize(self, data):
60 """ 61 Convert a serialized tuple of data to an object. 62 """ 63 self.note_list = [handle for handle in data]
64
65 - def add_note(self, handle):
66 """ 67 Add the L{Note} handle to the list of note handles. 68 69 @param handle: L{Note} handle to add the list of notes 70 @type handle: str 71 72 @return: True if handle was added, False if it already was in the list 73 @rtype: bool 74 """ 75 if handle in self.note_list: 76 return False 77 else: 78 self.note_list.append(handle) 79 return True
80
81 - def remove_note(self, handle):
82 """ 83 Remove the specified handle from the list of note handles, and all 84 secondary child objects. 85 86 @param handle: L{Note} handle to remove from the list of notes 87 @type handle: str 88 """ 89 if handle in self.note_list: 90 self.note_list.remove(handle) 91 for item in self.get_note_child_list(): 92 item.remove_note(handle)
93
94 - def get_note_child_list(self):
95 """ 96 Return the list of child secondary objects that may refer notes. 97 98 All methods which inherit from NoteBase and have other child objects 99 with notes, should return here a list of child objects which are 100 NoteBase 101 102 @return: Returns the list of child secondary child objects that may 103 refer notes. 104 @rtype: list 105 """ 106 return []
107
108 - def get_note_list(self):
109 """ 110 Return the list of L{Note} handles associated with the object. 111 112 @return: The list of L{Note} handles 113 @rtype: list 114 """ 115 return self.note_list
116
117 - def set_note_list(self, note_list):
118 """ 119 Assign the passed list to be object's list of L{Note} handles. 120 121 @param note_list: List of L{Note} handles to be set on the object 122 @type note_list: list 123 """ 124 self.note_list = note_list
125
127 """ 128 Return the list of (classname, handle) tuples for all referenced notes. 129 130 This method should be used to get the L{Note} portion of the list 131 by objects that store note lists. 132 133 @return: List of (classname, handle) tuples for referenced objects. 134 @rtype: list 135 """ 136 return [('Note', handle) for handle in self.note_list]
137