本文整理汇总了Python中gramps.gen.lib.Person类的典型用法代码示例。如果您正苦于以下问题:Python Person类的具体用法?Python Person怎么用?Python Person使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Person类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: from_struct
def from_struct(struct):
"""
Given a struct with metadata, create a Gramps object.
"""
from gramps.gen.lib import (Person, Family, Event, Source, Place, Citation,
Repository, MediaObject, Note, Tag)
if isinstance(struct, dict):
if "_class" in struct.keys():
if struct["_class"] == "Person":
return Person.create(Person.from_struct(struct))
elif struct["_class"] == "Family":
return Family.create(Family.from_struct(struct))
elif struct["_class"] == "Event":
return Event.create(Event.from_struct(struct))
elif struct["_class"] == "Source":
return Source.create(Source.from_struct(struct))
elif struct["_class"] == "Place":
return Place.create(Place.from_struct(struct))
elif struct["_class"] == "Citation":
return Citation.create(Citation.from_struct(struct))
elif struct["_class"] == "Repository":
return Repository.create(Repository.from_struct(struct))
elif struct["_class"] == "MediaObject":
return MediaObject.create(MediaObject.from_struct(struct))
elif struct["_class"] == "Note":
return Note.create(Note.from_struct(struct))
elif struct["_class"] == "Tag":
return Tag.create(Tag.from_struct(struct))
raise AttributeError("invalid struct: %s" % struct)
示例2: instance_from_struct
def instance_from_struct(cls, struct):
"""
Given a struct with metadata, create a Gramps object.
self is class when called as a classmethod.
"""
from gramps.gen.lib import (Person, Family, Event, Source, Place, Citation,
Repository, Media, Note, Tag, Date)
if isinstance(struct, dict):
if "_class" in struct.keys():
if struct["_class"] == "Person":
return Person.create(Person.from_struct(struct))
elif struct["_class"] == "Family":
return Family.create(Family.from_struct(struct))
elif struct["_class"] == "Event":
return Event.create(Event.from_struct(struct))
elif struct["_class"] == "Source":
return Source.create(Source.from_struct(struct))
elif struct["_class"] == "Place":
return Place.create(Place.from_struct(struct))
elif struct["_class"] == "Citation":
return Citation.create(Citation.from_struct(struct))
elif struct["_class"] == "Repository":
return Repository.create(Repository.from_struct(struct))
elif struct["_class"] == "Media":
return Media.create(Media.from_struct(struct))
elif struct["_class"] == "Note":
return Note.create(Note.from_struct(struct))
elif struct["_class"] == "Tag":
return Tag.create(Tag.from_struct(struct))
elif struct["_class"] == "Date":
return Date().unserialize(Date.from_struct(struct, full=True))
raise AttributeError("invalid struct: %s" % struct)
示例3: 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
示例4: create_person
def create_person(self):
""" Used to create a new person we know doesn't exist """
person = Person()
if self.default_tag:
person.add_tag(self.default_tag.handle)
self.db.add_person(person, self.trans)
self.indi_count += 1
return person
示例5: __add_person
def __add_person(self, gender, first_name, surname, trans):
person = Person()
person.gender = gender
name = person.primary_name
name.first_name = first_name
surname1 = Surname()
surname1.surname = surname
name.set_surname_list([surname1])
self.all_surnames.append(surname)
self.db.add_person(person, trans)
示例6: get_or_create_person
def get_or_create_person(self,firstname,lastname):
person = None
mykey = firstname+lastname
if mykey in self.ikeys and firstname != "?" and lastname != "?":
person = self.db.get_person_from_handle(self.ikeys[mykey])
else:
person = Person()
self.db.add_person(person,self.trans)
self.db.commit_person(person,self.trans)
self.ikeys[mykey] = person.get_handle()
return person
示例7: add_mother_clicked
def add_mother_clicked(self, obj):
person = Person()
person.set_gender(Person.FEMALE)
autoname = config.get("behavior.surname-guessing")
# _("Father's surname"),
# _("None"),
# _("Combination of mother's and father's surname"),
# _("Icelandic style"),
if autoname == 2:
name = self.latin_american_child("mother")
else:
name = self.no_name()
person.set_primary_name(name)
EditPerson(self.dbstate, self.uistate, self.track, person, self.new_mother_added)
示例8: log
def log(self, ltype, action, handles):
for handle in set(handles):
if self.last_log == (ltype, action, handle):
continue
self.last_log = (ltype, action, handle)
self.timestamp()
# translators: needed for French, ignore otherwise
self.append_text(_("%s: ") % _(action))
if action == 'Deleted':
transaction = self.dbstate.db.transaction
if ltype == 'Person':
name = 'a person'
if transaction is not None:
for i in transaction.get_recnos(reverse=True):
(obj_type, trans_type, hndl, old_data, dummy) = \
transaction.get_record(i)
if isinstance(hndl, bytes):
hndl = str(hndl, "utf-8")
if (obj_type == PERSON_KEY and trans_type == TXNDEL
and hndl == handle):
person = Person()
person.unserialize(old_data)
name = name_displayer.display(person)
break
elif ltype == 'Family':
name = 'a family'
if transaction is not None:
for i in transaction.get_recnos(reverse=True):
(obj_type, trans_type, hndl, old_data, dummy) = \
transaction.get_record(i)
if isinstance(hndl, bytes):
hndl = str(hndl, "utf-8")
if (obj_type == FAMILY_KEY and trans_type == TXNDEL
and hndl == handle):
family = Family()
family.unserialize(old_data)
name = family_name(family, self.dbstate.db, name)
break
self.append_text(name)
else:
if ltype == 'Person':
person = self.dbstate.db.get_person_from_handle(handle)
name = name_displayer.display(person)
elif ltype == 'Family':
family = self.dbstate.db.get_family_from_handle(handle)
name = family_name(family, self.dbstate.db, 'a family')
self.link(name, ltype, handle)
self.append_text("\n")
示例9: add_button_clicked
def add_button_clicked(self, obj=None):
person = Person()
autoname = config.get("behavior.surname-guessing")
# _("Father's surname"),
# _("None"),
# _("Combination of mother's and father's surname"),
# _("Icelandic style"),
if autoname == 0:
name = self.north_american()
elif autoname == 2:
name = self.latin_american()
else:
name = self.no_name()
person.set_primary_name(name)
EditPerson(self.dbstate, self.uistate, self.track, person, self.new_child_added)
示例10: importData
def importData(db, filename, user):
"""Function called by Gramps to import data on persons in CSV format."""
db.disable_signals()
try:
with DbTxn(_("JSON import"), db, batch=True) as trans:
with OpenFileOrStdin(filename, encoding="utf-8") as fp:
line = fp.readline()
while line:
data = json.loads(line)
if data["_class"] == "Person":
obj = Person.create(Person.from_struct(data))
db.add_person(obj, trans)
elif data["_class"] == "Family":
obj = Family.create(Family.from_struct(data))
db.add_family(obj, trans)
elif data["_class"] == "Event":
obj = Event.create(Event.from_struct(data))
db.add_event(obj, trans)
elif data["_class"] == "Media":
obj = Media.create(Media.from_struct(data))
db.add_media(obj, trans)
elif data["_class"] == "Repository":
obj = Repository.create(Repository.from_struct(data))
db.add_repository(obj, trans)
elif data["_class"] == "Tag":
obj = Tag.create(Tag.from_struct(data))
db.add_tag(obj, trans)
elif data["_class"] == "Source":
obj = Source.create(Source.from_struct(data))
db.add_source(obj, trans)
elif data["_class"] == "Citation":
obj = Citation.create(Citation.from_struct(data))
db.add_citation(obj, trans)
elif data["_class"] == "Note":
obj = Note.create(Note.from_struct(data))
db.add_note(obj, trans)
elif data["_class"] == "Place":
obj = Place.create(Place.from_struct(data))
db.add_place(obj, trans)
else:
LOG.warn("ignored: " + data)
line = fp.readline()
except EnvironmentError as err:
user.notify_error(_("%s could not be opened\n") % filename, str(err))
db.enable_signals()
db.request_rebuild()
示例11: next_person
def next_person(self):
"""A VCard for another person is started."""
if self.person is not None:
self.finish_person()
LOG.warning("BEGIN property not properly closed by END property, "
"Gramps can't cope with nested VCards.")
self.person = Person()
self.formatted_name = ''
self.name_parts = ''
示例12: next_person
def next_person(self):
"""A VCard for another person is started."""
if self.person is not None:
self.finish_person()
self.__add_msg(_("BEGIN property not properly closed by END "
"property, Gramps can't cope with nested VCards."),
self.line_num - 1)
self.person = Person()
self.formatted_name = ''
self.name_parts = ''
示例13: get
def get(self, path=""):
"""
HANDLE
HANDLE/edit|delete
/add
b2cfa6ca1e174b1f63d/remove/eventref/1
"""
page = int(self.get_argument("page", 1))
search = self.get_argument("search", "")
if "/" in path:
handle, action= path.split("/", 1)
else:
handle, action = path, "view"
if handle:
if handle == "add":
person = Person()
person.primary_name.surname_list.append(Surname())
action = "edit"
else:
person = self.database.get_person_from_handle(handle)
if person:
person.probably_alive = True
self.render("person.html",
**self.get_template_dict(tview=_("person detail"),
action=action,
page=page,
search=search,
form=PersonForm(self.database, _, instance=person),
logform=None))
return
else:
self.clear()
self.set_status(404)
self.finish("<html><body>No such person</body></html>")
return
self.render("page_view.html",
**self.get_template_dict(tview=_("person view"),
page=page,
search=search,
form=PersonForm(self.database, _, table="Person"),
)
)
示例14: 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()
示例15: dump_parent
def dump_parent(self,title,person_handle):
if not person_handle and not self.missingInfo:
return
elif not person_handle:
person = Person()
else:
person = self.database.get_person_from_handle(person_handle)
name = self._name_display.display(person)
self.doc.start_table(title,'FGR-ParentTable')
self.doc.start_row()
self.doc.start_cell('FGR-ParentHead',3)
self.doc.start_paragraph('FGR-ParentName')
mark = ReportUtils.get_person_mark(self.database,person)
# translators: needed for French, ignore otherwise
self.doc.write_text(self._("%(str1)s: %(str2)s") % {
'str1' : title,
'str2' : name }, mark)
if self.gramps_ids:
gid = person.get_gramps_id()
if gid:
self.doc.write_text(" (%s)" % gid)
self.doc.end_paragraph()
self.doc.end_cell()
self.doc.end_row()
birth_ref = person.get_birth_ref()
birth = None
evtName = self._("Birth")
if birth_ref:
birth = self.database.get_event_from_handle(birth_ref.ref)
if birth or self.missingInfo:
self.dump_parent_event(evtName,birth)
death_ref = person.get_death_ref()
death = None
evtName = self._("Death")
if death_ref:
death = self.database.get_event_from_handle(death_ref.ref)
if death or self.missingInfo:
self.dump_parent_event(evtName,death)
self.dump_parent_parents(person)
if self.incParEvents:
for event_ref in person.get_primary_event_ref_list():
if event_ref != birth_ref and event_ref != death_ref:
event = self.database.get_event_from_handle(event_ref.ref)
event_type = self._get_type(event.get_type())
self.dump_parent_event(self._(event_type),event)
if self.incParAddr:
addrlist = person.get_address_list()[:]
for addr in addrlist:
location = ReportUtils.get_address_str(addr)
date = self._get_date(addr.get_date_object())
self.doc.start_row()
self.doc.start_cell("FGR-TextContents")
self.doc.start_paragraph('FGR-Normal')
self.doc.write_text(self._("Address"))
self.doc.end_paragraph()
self.doc.end_cell()
self.doc.start_cell("FGR-TextContents")
self.doc.start_paragraph('FGR-Normal')
self.doc.write_text(date)
self.doc.end_paragraph()
self.doc.end_cell()
self.doc.start_cell("FGR-TextContentsEnd")
self.doc.start_paragraph('FGR-Normal')
self.doc.write_text(location)
self.doc.end_paragraph()
self.doc.end_cell()
self.doc.end_row()
if self.incParNotes:
for notehandle in person.get_note_list():
note = self.database.get_note_from_handle(notehandle)
self.dump_parent_noteline(self._("Note"), note)
if self.includeAttrs:
for attr in person.get_attribute_list():
attr_type = self._get_type(attr.get_type())
self.dump_parent_line(self._(attr_type),attr.get_value())
if self.incParNames:
for alt_name in person.get_alternate_names():
name_type = self._get_type(alt_name.get_type())
name = self._name_display.display_name(alt_name)
self.dump_parent_line(self._(name_type), name)
self.doc.end_table()