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

Source Code for Module gen.lib.name

  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: name.py 10103 2008-02-24 13:55:55Z acraphae $ 
 22   
 23  """ 
 24  Name class for GRAMPS. 
 25  """ 
 26   
 27  #------------------------------------------------------------------------- 
 28  # 
 29  # GRAMPS modules 
 30  # 
 31  #------------------------------------------------------------------------- 
 32  from gen.lib.secondaryobj import SecondaryObject 
 33  from gen.lib.privacybase import PrivacyBase 
 34  from gen.lib.srcbase import SourceBase 
 35  from gen.lib.notebase import NoteBase 
 36  from gen.lib.datebase import DateBase 
 37  from gen.lib.nametype import NameType 
 38   
 39  #------------------------------------------------------------------------- 
 40  # 
 41  # Personal Name 
 42  # 
 43  #------------------------------------------------------------------------- 
44 -class Name(SecondaryObject, PrivacyBase, SourceBase, NoteBase, DateBase):
45 """ 46 Provide name information about a person. 47 48 A person may have more that one name throughout his or her life. 49 """ 50 51 DEF = 0 # Default format (determined by gramps-wide prefs) 52 LNFN = 1 # last name first name [patronymic] 53 FNLN = 2 # first name last name 54 PTFN = 3 # patronymic first name 55 FN = 4 # first name 56
57 - def __init__(self, source=None, data=None):
58 """Create a new Name instance, copying from the source if provided.""" 59 PrivacyBase.__init__(self, source) 60 SourceBase.__init__(self, source) 61 NoteBase.__init__(self, source) 62 DateBase.__init__(self, source) 63 if data: 64 (privacy, source_list, note, date, 65 self.first_name, self.surname, self.suffix, self.title, 66 name_type, self.prefix, self.patronymic, 67 self.group_as, self.sort_as, self.display_as, self.call) = data 68 self.type = NameType(name_type) 69 PrivacyBase.unserialize(self, privacy) 70 SourceBase.unserialize(self, source_list) 71 NoteBase.unserialize(self, note) 72 DateBase.unserialize(self, date) 73 elif source: 74 self.first_name = source.first_name 75 self.surname = source.surname 76 self.suffix = source.suffix 77 self.title = source.title 78 self.type = source.type 79 self.prefix = source.prefix 80 self.patronymic = source.patronymic 81 self.group_as = source.group_as 82 self.sort_as = source.sort_as 83 self.display_as = source.display_as 84 self.call = source.call 85 else: 86 self.first_name = "" 87 self.surname = "" 88 self.suffix = "" 89 self.title = "" 90 self.type = NameType() 91 self.prefix = "" 92 self.patronymic = "" 93 self.group_as = "" 94 self.sort_as = self.DEF 95 self.display_as = self.DEF 96 self.call = u''
97
98 - def serialize(self):
99 """ 100 Convert the object to a serialized tuple of data. 101 """ 102 return (PrivacyBase.serialize(self), 103 SourceBase.serialize(self), 104 NoteBase.serialize(self), 105 DateBase.serialize(self), 106 self.first_name, self.surname, self.suffix, self.title, 107 self.type.serialize(), self.prefix, self.patronymic, 108 self.group_as, self.sort_as, self.display_as, self.call)
109
110 - def is_empty(self):
111 """ 112 Indicate if the name is empty. 113 """ 114 return (self.first_name == u"" and self.surname == u"" and 115 self.suffix == u"" and self.title == u"" and 116 self.prefix == u"" and self.patronymic == u"")
117
118 - def unserialize(self, data):
119 """ 120 Convert a serialized tuple of data to an object. 121 """ 122 (privacy, source_list, note_list, date, 123 self.first_name, self.surname, self.suffix, self.title, 124 name_type, self.prefix, self.patronymic, 125 self.group_as, self.sort_as, self.display_as, self.call) = data 126 self.type = NameType(name_type) 127 PrivacyBase.unserialize(self, privacy) 128 SourceBase.unserialize(self, source_list) 129 NoteBase.unserialize(self, note_list) 130 DateBase.unserialize(self, date) 131 return self
132
133 - def get_text_data_list(self):
134 """ 135 Return the list of all textual attributes of the object. 136 137 @return: Returns the list of all textual attributes of the object. 138 @rtype: list 139 """ 140 return [self.first_name, self.surname, self.suffix, self.title, 141 str(self.type), self.prefix, self.patronymic, self.call]
142
143 - def get_text_data_child_list(self):
144 """ 145 Return the list of child objects that may carry textual data. 146 147 @return: Returns the list of child objects that may carry textual data. 148 @rtype: list 149 """ 150 return self.source_list
151
152 - def get_note_child_list(self):
153 """ 154 Return the list of child secondary objects that may refer notes. 155 156 @return: Returns the list of child secondary child objects that may 157 refer notes. 158 @rtype: list 159 """ 160 return self.source_list
161
162 - def get_handle_referents(self):
163 """ 164 Return the list of child objects which may, directly or through 165 their children, reference primary objects. 166 167 @return: Returns the list of objects refereincing primary objects. 168 @rtype: list 169 """ 170 return self.source_list
171
172 - def get_referenced_handles(self):
173 """ 174 Return the list of (classname, handle) tuples for all directly 175 referenced primary objects. 176 177 @return: List of (classname, handle) tuples for referenced objects. 178 @rtype: list 179 """ 180 return self.get_referenced_note_handles()
181
182 - def set_group_as(self, name):
183 """ 184 Set the grouping name for a person. 185 186 Normally, this is the person's surname. However, some locales group 187 equivalent names (e.g. Ivanova and Ivanov in Russian are usually 188 considered equivalent. 189 190 Note that there is also a database wide grouping set_name_group_mapping 191 So one might map a name Smith to SmithNew, and have one person still 192 grouped with name Smith. Hence, group_as can be equal to surname! 193 """ 194 self.group_as = name
195
196 - def get_group_as(self):
197 """ 198 Return the grouping name, which is used to group equivalent surnames. 199 """ 200 return self.group_as
201
202 - def get_group_name(self):
203 """ 204 Return the grouping name, which is used to group equivalent surnames. 205 """ 206 if self.group_as: 207 return self.group_as 208 else: 209 return self.surname
210
211 - def set_sort_as(self, value):
212 """ 213 Specifies the sorting method for the specified name. 214 215 Typically the locale's default should be used. However, there may be 216 names where a specific sorting structure is desired for a name. 217 """ 218 self.sort_as = value
219
220 - def get_sort_as(self):
221 """ 222 Return the selected sorting method for the name. 223 224 The options are LNFN (last name, first name), FNLN (first name, last 225 name), etc. 226 """ 227 return self.sort_as
228
229 - def set_display_as(self, value):
230 """ 231 Specifies the display format for the specified name. 232 233 Typically the locale's default should be used. However, there may be 234 names where a specific display format is desired for a name. 235 """ 236 self.display_as = value
237
238 - def get_display_as(self):
239 """ 240 Return the selected display format for the name. 241 242 The options are LNFN (last name, first name), FNLN (first name, last 243 name), etc. 244 """ 245 return self.display_as
246
247 - def get_call_name(self):
248 """ 249 Return the call name. 250 251 The call name's exact definition is not predetermined, and may be 252 locale specific. 253 """ 254 return self.call
255
256 - def set_call_name(self, val):
257 """ 258 Set the call name. 259 260 The call name's exact definition is not predetermined, and may be 261 locale specific. 262 """ 263 self.call = val
264
265 - def get_surname_prefix(self):
266 """ 267 Return the prefix (or article) of a surname. 268 269 The prefix is not used for sorting or grouping. 270 """ 271 return self.prefix
272
273 - def set_surname_prefix(self, val):
274 """ 275 Set the prefix (or article) of a surname. 276 277 Examples of articles would be 'de' or 'van'. 278 """ 279 self.prefix = val
280
281 - def set_type(self, the_type):
282 """Set the type of the Name instance.""" 283 self.type.set(the_type)
284
285 - def get_type(self):
286 """Return the type of the Name instance.""" 287 return self.type
288
289 - def set_first_name(self, name):
290 """Set the given name for the Name instance.""" 291 self.first_name = name
292
293 - def set_patronymic(self, name):
294 """Set the patronymic name for the Name instance.""" 295 self.patronymic = name
296
297 - def set_surname(self, name):
298 """Set the surname (or last name) for the Name instance.""" 299 self.surname = name
300
301 - def set_suffix(self, name):
302 """Set the suffix (such as Jr., III, etc.) for the Name instance.""" 303 self.suffix = name
304
305 - def get_first_name(self):
306 """Return the given name for the Name instance.""" 307 return self.first_name
308
309 - def get_patronymic(self):
310 """Return the patronymic name for the Name instance.""" 311 return self.patronymic
312
313 - def get_surname(self):
314 """Return the surname (or last name) for the Name instance.""" 315 return self.surname
316
317 - def get_upper_surname(self):
318 """Return the surname (or last name) for the Name instance.""" 319 return self.surname.upper()
320
321 - def get_suffix(self):
322 """Return the suffix for the Name instance.""" 323 return self.suffix
324
325 - def set_title(self, title):
326 """Set the title (Dr., Reverand, Captain) for the Name instance.""" 327 self.title = title
328
329 - def get_title(self):
330 """Return the title for the Name instance.""" 331 return self.title
332
333 - def get_name(self):
334 """ 335 Return a name string built from the components of the Name instance, 336 in the form of surname, Firstname. 337 """ 338 339 if self.patronymic: 340 first = "%s %s" % (self.first_name, self.patronymic) 341 else: 342 first = self.first_name 343 if self.suffix: 344 if self.prefix: 345 return "%s %s, %s %s" % (self.prefix, self.surname, 346 first, self.suffix) 347 else: 348 return "%s, %s %s" % (self.surname, first, self.suffix) 349 else: 350 if self.prefix: 351 return "%s %s, %s" % (self.prefix, self.surname, first) 352 else: 353 return "%s, %s" % (self.surname, first)
354
355 - def get_upper_name(self):
356 """ 357 Return a name string built from the components of the Name instance, 358 in the form of surname, Firstname. 359 """ 360 361 if self.patronymic: 362 first = "%s %s" % (self.first_name, self.patronymic) 363 else: 364 first = self.first_name 365 if self.suffix: 366 if self.prefix: 367 return "%s %s, %s %s" % (self.prefix.upper(), 368 self.surname.upper(), first, 369 self.suffix) 370 else: 371 return "%s, %s %s" % (self.surname.upper(), first, self.suffix) 372 else: 373 if self.prefix: 374 return "%s %s, %s" % (self.prefix.upper(), 375 self.surname.upper(), 376 first) 377 else: 378 return "%s, %s" % (self.surname.upper(), first)
379
380 - def get_regular_name(self):
381 """ 382 Return a name string built from the components of the Name instance, 383 in the form of Firstname surname. 384 """ 385 if self.patronymic: 386 first = "%s %s" % (self.first_name, self.patronymic) 387 else: 388 first = self.first_name 389 if (self.suffix == ""): 390 if self.prefix: 391 return "%s %s %s" % (first, self.prefix, self.surname) 392 else: 393 return "%s %s" % (first, self.surname) 394 else: 395 if self.prefix: 396 return "%s %s %s, %s" % (first, self.prefix, self.surname, 397 self.suffix) 398 else: 399 return "%s %s, %s" % (first, self.surname, self.suffix)
400