本文整理汇总了Python中gramps.gen.lib.Name类的典型用法代码示例。如果您正苦于以下问题:Python Name类的具体用法?Python Name怎么用?Python Name使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Name类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: latin_american_child
def latin_american_child(self, parent):
"""
If SURNAME_GUESSING is latin american, then find a child
and return their name for the father or mother.
parent = "mother" | "father"
"""
name = Name()
#the editor requires a surname
name.add_surname(Surname())
name.set_primary_surname(0)
# for each child, find one with a last name
for ref in self.obj.get_child_ref_list():
child = self.db.get_person_from_handle(ref.ref)
if child:
pname = child.get_primary_name()
preset_name(child, name) # add the known family surnames, etc.
surnames = name.get_surname_list()
if len(surnames) < 2:
return name
else:
#return first for the father, and last for the mother
if parent == 'father':
name.set_surname_list([surnames[0]])
return name
else:
name.set_surname_list([surnames[-1]])
return name
return name
示例2: add
def add(self, *obj):
person = Person()
# attempt to get the current surname
(model, pathlist) = self.selection.get_selected_rows()
name = Name()
#the editor requires a surname
name.add_surname(Surname())
name.set_primary_surname(0)
basepers = None
if len(pathlist) == 1:
path = pathlist[0]
pathids = path.get_indices()
if len(pathids) == 1:
path = Gtk.TreePath((pathids[0], 0))
iter_ = model.get_iter(path)
handle = model.get_handle_from_iter(iter_)
basepers = self.dbstate.db.get_person_from_handle(handle)
if basepers:
preset_name(basepers, name)
person.set_primary_name(name)
try:
EditPerson(self.dbstate, self.uistate, [], person)
except WindowActiveError:
pass
示例3: latin_american
def latin_american(self):
"""
Child inherits name from father and mother
"""
name = Name()
#the editor requires a surname
name.add_surname(Surname())
name.set_primary_surname(0)
if self.family:
father_handle = self.family.get_father_handle()
mother_handle = self.family.get_mother_handle()
father = self.dbstate.db.get_person_from_handle(father_handle)
mother = self.dbstate.db.get_person_from_handle(mother_handle)
if not father and not mother:
return name
if not father:
preset_name(mother, name)
return name
if not mother:
preset_name(father, name)
return name
#we take first surname, and keep that
mothername = Name()
preset_name(mother, mothername)
preset_name(father, name)
mothersurname = mothername.get_surname_list()[0]
mothersurname.set_primary(False)
name.set_surname_list([name.get_surname_list()[0], mothersurname])
return name
else:
return name
示例4: _get_styled
def _get_styled(name, callname, placeholder=False,
trans_text=glocale.translation.sgettext, name_format=None):
"""
Return a StyledText object with the name formatted according to the
parameters:
@param callname: whether the callname should be used instead of the first
name (CALLNAME_REPLACE), underlined within the first name
(CALLNAME_UNDERLINE_ADD) or not used at all (CALLNAME_DONTUSE).
@param placeholder: whether a series of underscores should be inserted as a
placeholder if first name or surname are missing.
@param trans_text: allow deferred translation of strings
@type trans_text: a GrampsLocale sgettext instance
trans_text is a defined keyword (see po/update_po.py, po/genpot.sh)
:param name_format: optional format to control display of person's name
:type name_format: None or int
"""
# Make a copy of the name object so we don't mess around with the real
# data.
n = Name(source=name)
# Insert placeholders.
if placeholder:
if not n.first_name:
n.first_name = "____________"
if not n.surname:
n.surname = "____________"
if n.call:
if callname == CALLNAME_REPLACE:
# Replace first name with call name.
n.first_name = n.call
elif callname == CALLNAME_UNDERLINE_ADD:
if n.call not in n.first_name:
# Add call name to first name.
# translators: used in French+Russian, ignore otherwise
n.first_name = trans_text('"%(callname)s" (%(firstname)s)') % {
'callname': n.call,
'firstname': n.first_name }
real_format = name_displayer.get_default_format()
if name_format is not None:
name_displayer.set_default_format(name_format)
text = name_displayer.display_name(n)
name_displayer.set_default_format(real_format)
tags = []
if n.call:
if callname == CALLNAME_UNDERLINE_ADD:
# "name" in next line is on purpose: only underline the call name
# if it was a part of the *original* first name
if n.call in name.first_name:
# Underline call name
callpos = text.find(n.call)
tags = [StyledTextTag(StyledTextTagType.UNDERLINE, True,
[(callpos, callpos + len(n.call))])]
return StyledText(text, tags)
示例5: add_nicknames
def add_nicknames(self, fields, data):
"""Read the NICKNAME property of a VCard."""
for nick in self.split_unescaped(data, ','):
nickname = nick.strip()
if nickname:
name = Name()
name.set_nick_name(self.unesc(nickname))
self.person.add_alternate_name(name)
示例6: no_name
def no_name(self):
"""
Default surname guess.
"""
name = Name()
#the editor requires a surname
name.add_surname(Surname())
name.set_primary_surname(0)
return name
示例7: add_button_clicked
def add_button_clicked(self, obj):
name = Name()
#the editor requires a surname
name.add_surname(Surname())
name.set_primary_surname(0)
try:
from .. import EditName
EditName(self.dbstate, self.uistate, self.track,
name, self.add_callback)
except WindowActiveError:
pass
示例8: _get_styled
def _get_styled(name, callname, placeholder=False, name_format=None):
"""
Return a StyledText object with the name formatted according to the
parameters:
@param callname: whether the callname should be used instead of the first
name (CALLNAME_REPLACE), underlined within the first name
(CALLNAME_UNDERLINE_ADD) or not used at all (CALLNAME_DONTUSE).
@param placeholder: whether a series of underscores should be inserted as a
placeholder if first name or surname are missing.
"""
# Make a copy of the name object so we don't mess around with the real
# data.
n = Name(source=name)
# Insert placeholders.
if placeholder:
if not n.first_name:
n.first_name = "____________"
if not n.surname:
n.surname = "____________"
if n.call:
if callname == CALLNAME_REPLACE:
# Replace first name with call name.
n.first_name = n.call
elif callname == CALLNAME_UNDERLINE_ADD:
if n.call not in n.first_name:
# Add call name to first name.
n.first_name = "\"%(call)s\" (%(first)s)" % {
'call': n.call,
'first': n.first_name}
real_format = name_displayer.get_default_format()
if name_format is not None:
name_displayer.set_default_format(name_format)
text = name_displayer.display_name(n)
name_displayer.set_default_format(real_format)
tags = []
if n.call:
if callname == CALLNAME_UNDERLINE_ADD:
# "name" in next line is on purpose: only underline the call name
# if it was a part of the *original* first name
if n.call in name.first_name:
# Underline call name
callpos = text.find(n.call)
tags = [StyledTextTag(StyledTextTagType.UNDERLINE, True,
[(callpos, callpos + len(n.call))])]
return StyledText(text, tags)
示例9: north_american
def north_american(self):
"""
Child inherits name from father
"""
name = Name()
#the editor requires a surname
name.add_surname(Surname())
name.set_primary_surname(0)
father_handle = self.family.get_father_handle()
if father_handle:
father = self.dbstate.db.get_person_from_handle(father_handle)
preset_name(father, name)
return name
示例10: north_american_child
def north_american_child(self):
"""
If SURNAME_GUESSING is north american, then find a child
and return their name for the father.
"""
# for each child, find one with a last name
name = Name()
#the editor requires a surname
name.add_surname(Surname())
name.set_primary_surname(0)
for ref in self.obj.get_child_ref_list():
child = self.db.get_person_from_handle(ref.ref)
if child:
preset_name(child, name)
return name
return name
示例11: get_name
def get_name(self, person, maiden_name = None):
""" Return person's name, unless maiden_name given,
unless married_name listed.
"""
# Get all of a person's names:
primary_name = person.get_primary_name()
married_name = None
names = [primary_name] + person.get_alternate_names()
for name in names:
if int(name.get_type()) == NameType.MARRIED:
married_name = name
break # use first
# Now, decide which to use:
if maiden_name is not None:
if married_name is not None:
name = Name(married_name)
else:
name = Name(primary_name)
surname = Surname()
surname.set_surname(maiden_name)
name.set_surname_list([surname])
else:
name = Name(primary_name)
name.set_display_as(self.name_format)
return _nd.display_name(name)
示例12: add_name
def add_name(self):
"""
Add the name to the person.
Returns True on success, False on failure.
"""
if not self.name_parts.strip():
LOG.warning("VCard is malformed missing the compulsory N property,"
" so there is no name; skip it.")
return False
if not self.formatted_name:
LOG.warning("VCard is malformed missing the compulsory FN property"
", get name from N alone.")
data_fields = self.split_unescaped(self.name_parts, ';')
if len(data_fields) != 5:
LOG.warning("VCard is malformed wrong number of name components.")
name = Name()
name.set_type(NameType(NameType.BIRTH))
if data_fields[0].strip():
# assume first surname is primary
for surname_str in self.split_unescaped(data_fields[0], ','):
surname = Surname()
prefix, sname = splitof_nameprefix(self.unesc(surname_str))
surname.set_surname(sname.strip())
surname.set_prefix(prefix.strip())
name.add_surname(surname)
if len(data_fields) > 1 and data_fields[1].strip():
given_name = ' '.join(self.unesc(
self.split_unescaped(data_fields[1], ',')))
else:
given_name = ''
if len(data_fields) > 2 and data_fields[2].strip():
additional_names = ' '.join(self.unesc(
self.split_unescaped(data_fields[2], ',')))
else:
additional_names = ''
self.add_firstname(given_name.strip(), additional_names.strip(), name)
if len(data_fields) > 3 and data_fields[3].strip():
name.set_title(' '.join(self.unesc(
self.split_unescaped(data_fields[3], ','))))
if len(data_fields) > 4 and data_fields[4].strip():
name.set_suffix(' '.join(self.unesc(
self.split_unescaped(data_fields[4], ','))))
self.person.set_primary_name(name)
return True
示例13: _parse_person
def _parse_person(self, line_number, row, col):
"Parse the content of a Person line."
surname = rd(line_number, row, col, "surname")
firstname = rd(line_number, row, col, "firstname", "")
callname = rd(line_number, row, col, "callname")
title = rd(line_number, row, col, "title")
prefix = rd(line_number, row, col, "prefix")
suffix = rd(line_number, row, col, "suffix")
gender = rd(line_number, row, col, "gender")
source = rd(line_number, row, col, "source")
note = rd(line_number, row, col, "note")
birthplace = rd(line_number, row, col, "birthplace")
birthplace_id = rd(line_number, row, col, "birthplace_id")
birthdate = rd(line_number, row, col, "birthdate")
birthsource = rd(line_number, row, col, "birthsource")
baptismplace = rd(line_number, row, col, "baptismplace")
baptismplace_id = rd(line_number, row, col, "baptismplace_id")
baptismdate = rd(line_number, row, col, "baptismdate")
baptismsource = rd(line_number, row, col, "baptismsource")
burialplace = rd(line_number, row, col, "burialplace")
burialplace_id = rd(line_number, row, col, "burialplace_id")
burialdate = rd(line_number, row, col, "burialdate")
burialsource = rd(line_number, row, col, "burialsource")
deathplace = rd(line_number, row, col, "deathplace")
deathplace_id = rd(line_number, row, col, "deathplace_id")
deathdate = rd(line_number, row, col, "deathdate")
deathsource = rd(line_number, row, col, "deathsource")
deathcause = rd(line_number, row, col, "deathcause")
grampsid = rd(line_number, row, col, "grampsid")
person_ref = rd(line_number, row, col, "person")
#########################################################
# if this person already exists, don't create them
person = self.lookup("person", person_ref)
if person is None:
if surname is None:
LOG.warn("empty surname for new person on line %d" %
line_number)
surname = ""
# new person
person = self.create_person()
name = Name()
name.set_type(NameType(NameType.BIRTH))
name.set_first_name(firstname)
surname_obj = Surname()
surname_obj.set_surname(surname)
name.add_surname(surname_obj)
person.set_primary_name(name)
else:
name = person.get_primary_name()
#########################################################
if person_ref is not None:
self.storeup("person", person_ref, person)
# replace
if surname is not None:
name.get_primary_surname().set_surname(surname)
if firstname is not None:
name.set_first_name(firstname)
if callname is not None:
name.set_call_name(callname)
if title is not None:
name.set_title(title)
if prefix is not None:
name.get_primary_surname().set_prefix(prefix)
name.group_as = '' # HELP? what should I do here?
if suffix is not None:
name.set_suffix(suffix)
if note is not None:
# append notes, if previous notes
previous_notes_list = person.get_note_list()
updated_note = False
for note_handle in previous_notes_list:
previous_note = self.db.get_note_from_handle(note_handle)
if previous_note.type == NoteType.PERSON:
previous_text = previous_note.get()
if note not in previous_text:
note = previous_text + "\n" + note
previous_note.set(note)
self.db.commit_note(previous_note, self.trans)
updated_note = True
break
if not updated_note:
# add new note here
new_note = Note()
new_note.handle = create_id()
new_note.type.set(NoteType.PERSON)
new_note.set(note)
if self.default_tag:
new_note.add_tag(self.default_tag.handle)
self.db.add_note(new_note, self.trans)
person.add_note(new_note.handle)
if grampsid is not None:
person.gramps_id = grampsid
elif person_ref is not None:
if person_ref.startswith("[") and person_ref.endswith("]"):
person.gramps_id = self.db.id2user_format(person_ref[1:-1])
if (person.get_gender() == Person.UNKNOWN and
gender is not None):
gender = gender.lower()
if gender == gender_map[Person.MALE].lower():
gender = Person.MALE
#.........这里部分代码省略.........
示例14: sort_name
def sort_name(self, data):
n = Name()
n.unserialize(data[COLUMN_NAME])
return (n.get_primary_surname().get_surname(), n.get_first_name())
示例15: run_tool
#.........这里部分代码省略.........
# dates.append( d)
# except:
# d = Date()
# d.set_as_text("Date.set Exception %s" % ("".join(traceback.format_exception(*sys.exc_info())),))
# dates.append( d)
#self.progress.step()
#d = Date()
#d.set(Date.QUAL_NONE,Date.MOD_NONE,
# Date.CAL_GREGORIAN,(44,7,1789,False),"Text comment")
#dates.append( d)
#d = Date()
#d.set(Date.QUAL_NONE,Date.MOD_NONE,
# Date.CAL_GREGORIAN,(4,77,1789,False),"Text comment")
#dates.append( d)
#d = Date()
#d.set(Date.QUAL_NONE,Date.MOD_SPAN,
# Date.CAL_GREGORIAN,
# (4,7,1789,False,55,8,1876,False),"Text comment")
#dates.append( d)
#d = Date()
#d.set(Date.QUAL_NONE,Date.MOD_SPAN,
# Date.CAL_GREGORIAN,
# (4,7,1789,False,5,88,1876,False),"Text comment")
#dates.append( d)
with DbTxn(_("Date Test Plugin"), self.db, batch=True) as self.trans:
self.db.disable_signals()
self.progress.set_pass(_('Generating dates'),
len(dates))
# create pass and fail tags
pass_handle = self.create_tag(_('Pass'), '#0000FFFF0000')
fail_handle = self.create_tag(_('Fail'), '#FFFF00000000')
# now add them as birth to new persons
i = 1
for dateval in dates:
person = Person()
surname = Surname()
surname.set_surname("DateTest")
name = Name()
name.add_surname(surname)
name.set_first_name("Test %d" % i)
person.set_primary_name(name)
self.db.add_person(person, self.trans)
bevent = Event()
bevent.set_type(EventType.BIRTH)
bevent.set_date_object(dateval)
bevent.set_description("Date Test %d (source)" % i)
bevent_h = self.db.add_event(bevent, self.trans)
bevent_ref = EventRef()
bevent_ref.set_reference_handle(bevent_h)
# for the death event display the date as text and parse it back to a new date
ndate = None
try:
datestr = _dd.display( dateval)
try:
ndate = _dp.parse( datestr)
if not ndate:
ndate = Date()
ndate.set_as_text("DateParser None")
person.add_tag(fail_handle)
else:
person.add_tag(pass_handle)
except:
ndate = Date()
ndate.set_as_text("DateParser Exception %s" % ("".join(traceback.format_exception(*sys.exc_info())),))
person.add_tag(fail_handle)
else:
person.add_tag(pass_handle)
except:
ndate = Date()
ndate.set_as_text("DateDisplay Exception: %s" % ("".join(traceback.format_exception(*sys.exc_info())),))
person.add_tag(fail_handle)
if dateval.get_modifier() != Date.MOD_TEXTONLY \
and ndate.get_modifier() == Date.MOD_TEXTONLY:
# parser was unable to correctly parse the string
ndate.set_as_text( "TEXTONLY: "+ndate.get_text())
person.add_tag(fail_handle)
if dateval.get_modifier() == Date.MOD_TEXTONLY \
and dateval.get_text().count("Traceback") \
and pass_handle in person.get_tag_list():
person.add_tag(fail_handle)
devent = Event()
devent.set_type(EventType.DEATH)
devent.set_date_object(ndate)
devent.set_description("Date Test %d (result)" % i)
devent_h = self.db.add_event(devent, self.trans)
devent_ref = EventRef()
devent_ref.set_reference_handle(devent_h)
person.set_birth_ref(bevent_ref)
person.set_death_ref(devent_ref)
self.db.commit_person(person, self.trans)
i = i + 1
self.progress.step()
self.db.enable_signals()
self.db.request_rebuild()
self.progress.close()