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

Source Code for Module gen.lib.note

  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: note.py 10230 2008-03-08 21:20:42Z pez4brian $ 
 22   
 23  """ 
 24  Note class for GRAMPS. 
 25  """ 
 26   
 27  #------------------------------------------------------------------------- 
 28  # 
 29  # standard python modules 
 30  # 
 31  #------------------------------------------------------------------------- 
 32  import re 
 33  from types import InstanceType 
 34   
 35  #------------------------------------------------------------------------- 
 36  # 
 37  # GRAMPS modules 
 38  # 
 39  #------------------------------------------------------------------------- 
 40  from gen.lib.primaryobj import BasicPrimaryObject 
 41  from gen.lib.notetype import NoteType 
 42  from gen.lib.markertype import MarkerType 
 43   
 44  #ROOT_START_TAG = '<gramps>' 
 45   
 46  #------------------------------------------------------------------------- 
 47  # 
 48  # Class for notes used throughout the majority of GRAMPS objects 
 49  # 
 50  #------------------------------------------------------------------------- 
51 -class Note(BasicPrimaryObject):
52 """ 53 Introduction 54 ============ 55 The Note class defines a text note. The note may be preformatted 56 or 'flowed', which indicates that it text string is considered 57 to be in paragraphs, separated by newlines. 58 """ 59 60 FLOWED = 0 61 FORMATTED = 1 62
63 - def __init__(self, text = ""):
64 """ 65 Create a new Note object, initializing from the passed string. 66 """ 67 BasicPrimaryObject.__init__(self) 68 self.text = text 69 self.format = Note.FLOWED 70 self.type = NoteType()
71
72 - def serialize(self):
73 """ 74 Convert the object to a serialized tuple of data. 75 """ 76 return (self.handle, self.gramps_id, self.text, self.format, 77 self.type.serialize(), self.change, self.marker.serialize(), 78 self.private)
79
80 - def unserialize(self, data):
81 """ 82 Convert a serialized tuple of data to an object. 83 """ 84 (self.handle, self.gramps_id, self.text, self.format, 85 the_type, self.change, the_marker, self.private) = data 86 87 self.marker = InstanceType(MarkerType) 88 self.marker.unserialize(the_marker) 89 self.type = InstanceType(NoteType) 90 self.type.unserialize(the_type)
91
92 - def get_text_data_list(self):
93 """ 94 Return the list of all textual attributes of the object. 95 96 @return: Returns the list of all textual attributes of the object. 97 @rtype: list 98 """ 99 return [self.text]
100
101 - def set(self, text):
102 """ 103 Set the text associated with the note to the passed string. 104 105 @param text: Text string defining the note contents. 106 @type text: str 107 """ 108 self.text = text
109
110 - def get(self, markup=False):
111 """ 112 Return the text string associated with the note. 113 114 @param markup: If note should be returned with markup or plain text 115 @type markup: boolean 116 @returns: Returns the text string defining the note contents. 117 @rtype: str 118 """ 119 text = self.text 120 # 121 # if not markup and text.startswith(ROOT_START_TAG): 122 # text = self.delete_tags(text) 123 124 return text
125 # 126 # def delete_tags(self, markup_text): 127 # """ 128 # Create a plain text version of the note text by removing all pango 129 # markup tags. 130 # 131 # @param markup_text: Pango style markup text 132 # @type markup_text: str 133 # @return: Plain text 134 # @rtype: str 135 # """ 136 # text = re.sub(r'(<.*?>)', '', markup_text) 137 # 138 # text = text.replace('&amp;', '&') 139 # text = text.replace('&lt;', '<') 140 # text = text.replace('&gt;', '>') 141 # 142 # return text 143
144 - def append(self, text):
145 """ 146 Append the specified text to the text associated with the note. 147 148 @param text: Text string to be appended to the note. 149 @type text: str 150 """ 151 self.text = self.text + text
152
153 - def set_format(self, format):
154 """ 155 Set the format of the note to the passed value. 156 157 The value can either indicate Flowed or Preformatted. 158 159 @type format: int 160 """ 161 self.format = format
162
163 - def get_format(self):
164 """ 165 Return the format of the note. 166 167 The value can either indicate Flowed or Preformatted. 168 169 @returns: 0 indicates Flowed, 1 indicates Preformated 170 @rtype: int 171 """ 172 return self.format
173
174 - def set_type(self, the_type):
175 """ 176 Set descriptive type of the Note. 177 178 @param the_type: descriptive type of the Note 179 @type the_type: str 180 """ 181 self.type.set(the_type)
182
183 - def get_type(self):
184 """ 185 Get descriptive type of the Note. 186 187 @returns: the descriptive type of the Note 188 @rtype: str 189 """ 190 return self.type
191 192 if __name__ == "__main__": 193 import hotshot 194 prof = hotshot.Profile("note.profile") 195 196 f = open("notetest3_10.txt") 197 note = Note(f.read()) 198 199 for i in range(100000): 200 prof.runcall(note.get) 201 prof.close() 202