1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 """
24 Note class for GRAMPS.
25 """
26
27
28
29
30
31
32 import re
33 from types import InstanceType
34
35
36
37
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
45
46
47
48
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
71
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
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
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
122
123
124 return text
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
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
162
173
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
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