本文整理汇总了Python中gramps.gen.lib.Family类的典型用法代码示例。如果您正苦于以下问题:Python Family类的具体用法?Python Family怎么用?Python Family使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Family类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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_family
def __add_family(self, father, mother, trans):
family = Family()
family.set_father_handle(father.handle)
family.set_mother_handle(mother.handle)
fam_handle = self.db.add_family(family, trans)
father.add_family_handle(fam_handle)
mother.add_family_handle(fam_handle)
self.db.commit_person(father, trans)
self.db.commit_person(mother, trans)
return family
示例4: 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")
示例5: __init__
def __init__(self, dbstate, uistate, clicked):
self.clicked_func = clicked
self.filter_id = widgets.BasicEntry()
self.filter_father = widgets.BasicEntry()
self.filter_mother = widgets.BasicEntry()
self.filter_child = widgets.BasicEntry()
self.filter_event = Event()
self.filter_event.set_type((EventType.CUSTOM, ''))
self.etype = Gtk.ComboBox(has_entry=True)
self.family_stub = Family()
self.family_stub.set_relationship((FamilyRelType.CUSTOM, ''))
self.rtype = Gtk.ComboBox(has_entry=True)
self.event_menu = widgets.MonitoredDataType(
self.etype,
self.filter_event.set_type,
self.filter_event.get_type)
self.rel_menu = widgets.MonitoredDataType(
self.rtype,
self.family_stub.set_relationship,
self.family_stub.get_relationship)
self.filter_note = widgets.BasicEntry()
self.filter_regex = Gtk.CheckButton(label=_('Use regular expressions'))
self.tag = Gtk.ComboBox()
self.generic = Gtk.ComboBox()
SidebarFilter.__init__(self, dbstate, uistate, "Family")
示例6: read_family_line
def read_family_line(self,line,fields):
self.current_husband_handle = None
self.current_child_birthplace_handle = None
self.current_child_source_handle = None
self.current_family = Family()
self.db.add_family(self.current_family,self.trans)
#self.db.commit_family(self.current_family,self.trans)
self.fkeys.append(self.current_family.get_handle())
idx = 1;
LOG.debug("\nHusband:")
(idx, husband) = self.parse_person(fields,idx,Person.MALE,None)
if husband:
self.current_husband_handle = husband.get_handle()
self.current_family.set_father_handle(husband.get_handle())
self.db.commit_family(self.current_family,self.trans)
husband.add_family_handle(self.current_family.get_handle())
self.db.commit_person(husband,self.trans)
LOG.debug("Marriage:")
idx = self.parse_marriage(fields,idx)
LOG.debug("Wife:")
(idx,wife) = self.parse_person(fields,idx,Person.FEMALE,None)
if wife:
self.current_family.set_mother_handle(wife.get_handle())
self.db.commit_family(self.current_family,self.trans)
wife.add_family_handle(self.current_family.get_handle())
self.db.commit_person(wife,self.trans)
return None
示例7: 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()
示例8: FamilySidebarFilter
class FamilySidebarFilter(SidebarFilter):
def __init__(self, dbstate, uistate, clicked):
self.clicked_func = clicked
self.filter_id = widgets.BasicEntry()
self.filter_father = widgets.BasicEntry()
self.filter_mother = widgets.BasicEntry()
self.filter_child = widgets.BasicEntry()
self.filter_event = Event()
self.filter_event.set_type((EventType.CUSTOM, ''))
self.etype = Gtk.ComboBox(has_entry=True)
self.family_stub = Family()
self.family_stub.set_relationship((FamilyRelType.CUSTOM, ''))
self.rtype = Gtk.ComboBox(has_entry=True)
self.event_menu = widgets.MonitoredDataType(
self.etype,
self.filter_event.set_type,
self.filter_event.get_type)
self.rel_menu = widgets.MonitoredDataType(
self.rtype,
self.family_stub.set_relationship,
self.family_stub.get_relationship)
self.filter_note = widgets.BasicEntry()
self.filter_regex = Gtk.CheckButton(label=_('Use regular expressions'))
self.tag = Gtk.ComboBox()
self.generic = Gtk.ComboBox()
SidebarFilter.__init__(self, dbstate, uistate, "Family")
def create_widget(self):
cell = Gtk.CellRendererText()
cell.set_property('width', self._FILTER_WIDTH)
cell.set_property('ellipsize', self._FILTER_ELLIPSIZE)
self.generic.pack_start(cell, True)
self.generic.add_attribute(cell, 'text', 0)
self.on_filters_changed('Family')
cell = Gtk.CellRendererText()
cell.set_property('width', self._FILTER_WIDTH)
cell.set_property('ellipsize', self._FILTER_ELLIPSIZE)
self.tag.pack_start(cell, True)
self.tag.add_attribute(cell, 'text', 0)
self.etype.get_child().set_width_chars(5)
self.rtype.get_child().set_width_chars(5)
self.add_text_entry(_('ID'), self.filter_id)
self.add_text_entry(_('Father'), self.filter_father)
self.add_text_entry(_('Mother'), self.filter_mother)
self.add_text_entry(_('Child'), self.filter_child)
self.add_entry(_('Relationship'), self.rtype)
self.add_entry(_('Family Event'), self.etype)
self.add_text_entry(_('Family Note'), self.filter_note)
self.add_entry(_('Tag'), self.tag)
self.add_filter_entry(_('Custom filter'), self.generic)
self.add_regex_entry(self.filter_regex)
def clear(self, obj):
self.filter_id.set_text('')
self.filter_father.set_text('')
self.filter_mother.set_text('')
self.filter_child.set_text('')
self.filter_note.set_text('')
self.etype.get_child().set_text('')
self.rtype.get_child().set_text('')
self.tag.set_active(0)
self.generic.set_active(0)
def get_filter(self):
gid = str(self.filter_id.get_text()).strip()
father = str(self.filter_father.get_text()).strip()
mother = str(self.filter_mother.get_text()).strip()
child = str(self.filter_child.get_text()).strip()
note = str(self.filter_note.get_text()).strip()
etype = self.filter_event.get_type().xml_str()
rtype = self.family_stub.get_relationship().xml_str()
regex = self.filter_regex.get_active()
tag = self.tag.get_active() > 0
generic = self.generic.get_active() > 0
empty = not (gid or father or mother or child or note
or regex or etype or rtype or tag or generic)
if empty:
generic_filter = None
else:
generic_filter = GenericFamilyFilter()
if gid:
rule = RegExpIdOf([gid], use_regex=regex)
generic_filter.add_rule(rule)
if father:
rule = RegExpFatherName([father], use_regex=regex)
generic_filter.add_rule(rule)
#.........这里部分代码省略.........
示例9: __init__
#.........这里部分代码省略.........
elif fields[0] == "pevt":
#self.read_pevent_line(self.get_next_line(), fields)
pass
elif fields[0] == "notes-db":
self.read_database_notes_lines(line,fields)
elif fields[0] == "pages-ext" or "wizard-note":
pass
elif fields[0] == "end":
self.current_mode = None
else:
LOG.warning("parse_geneweb_file(): Token >%s< unknown. line %d skipped: %s" %
(fields[0],self.lineno,line))
except GedcomError as err:
self.errmsg(str(err))
t = time.time() - t
# translators: leave all/any {...} untranslated
msg = ngettext('Import Complete: {number_of} second',
'Import Complete: {number_of} seconds', t
).format(number_of=t)
self.db.enable_signals()
self.db.request_rebuild()
LOG.debug(msg)
LOG.debug("Families: %d" % len(self.fkeys))
LOG.debug("Individuals: %d" % len(self.ikeys))
return None
def read_family_line(self,line,fields):
self.current_husband_handle = None
self.current_child_birthplace_handle = None
self.current_child_source_handle = None
self.current_family = Family()
self.db.add_family(self.current_family,self.trans)
#self.db.commit_family(self.current_family,self.trans)
self.fkeys.append(self.current_family.get_handle())
idx = 1;
LOG.debug("\nHusband:")
(idx, husband) = self.parse_person(fields,idx,Person.MALE,None)
if husband:
self.current_husband_handle = husband.get_handle()
self.current_family.set_father_handle(husband.get_handle())
self.db.commit_family(self.current_family,self.trans)
husband.add_family_handle(self.current_family.get_handle())
self.db.commit_person(husband,self.trans)
LOG.debug("Marriage:")
idx = self.parse_marriage(fields,idx)
LOG.debug("Wife:")
(idx,wife) = self.parse_person(fields,idx,Person.FEMALE,None)
if wife:
self.current_family.set_mother_handle(wife.get_handle())
self.db.commit_family(self.current_family,self.trans)
wife.add_family_handle(self.current_family.get_handle())
self.db.commit_person(wife,self.trans)
return None
def read_relationship_person(self,line,fields):
LOG.debug("\Relationships:")
(idx,person) = self.parse_person(fields,1,Person.UNKNOWN,None)
if person:
self.current_relationship_person_handle = person.get_handle()
def read_relation_lines(self):
if not self.current_relationship_person_handle:
示例10: get_or_create_family
def get_or_create_family(self, family_ref, husband, wife):
"Return the family object for the give family ID."
# if a gramps_id and exists:
LOG.debug("get_or_create_family")
if family_ref.startswith("[") and family_ref.endswith("]"):
id_ = self.db.fid2user_format(family_ref[1:-1])
family = self.db.get_family_from_gramps_id(id_)
if family:
# don't delete, only add
fam_husband_handle = family.get_father_handle()
fam_wife_handle = family.get_mother_handle()
if husband:
if husband.get_handle() != fam_husband_handle:
# this husband is not the same old one! Add him!
family.set_father_handle(husband.get_handle())
if wife:
if wife.get_handle() != fam_wife_handle:
# this wife is not the same old one! Add her!
family.set_mother_handle(wife.get_handle())
LOG.debug(" returning existing family")
return family
# if not, create one:
family = Family()
# was marked with a gramps_id, but didn't exist, so we'll use it:
if family_ref.startswith("[") and family_ref.endswith("]"):
id_ = self.db.fid2user_format(family_ref[1:-1])
family.set_gramps_id(id_)
# add it:
family.set_handle(create_id())
if self.default_tag:
family.add_tag(self.default_tag.handle)
if husband:
family.set_father_handle(husband.get_handle())
husband.add_family_handle(family.get_handle())
if wife:
family.set_mother_handle(wife.get_handle())
wife.add_family_handle(family.get_handle())
if husband and wife:
family.set_relationship(FamilyRelType.MARRIED)
self.db.add_family(family, self.trans)
if husband:
self.db.commit_person(husband, self.trans)
if wife:
self.db.commit_person(wife, self.trans)
self.fam_count += 1
return family
示例11: exportData
def exportData(database, filename,
error_dialog=None, option_box=None, callback=None):
if not callable(callback):
callback = lambda percent: None # dummy
with OpenFileOrStdout(filename) as fp:
total = (len(database.note_map) +
len(database.person_map) +
len(database.event_map) +
len(database.family_map) +
len(database.repository_map) +
len(database.place_map) +
len(database.media_map) +
len(database.source_map))
count = 0.0
# GProlog ISO directives:
# /number must match the number of arguments to functions:
fp.write(":- discontiguous(data/2).\n")
fp.write(":- discontiguous(is_alive/2).\n")
fp.write(":- discontiguous(parent/2).\n")
# Rules:
fp.write("grandparent(X, Y) :- parent(X, Z), parent(Z, Y).\n")
fp.write("ancestor(X, Y) :- parent(X, Y).\n")
fp.write("ancestor(X, Y) :- parent(X, Z), ancestor(Z, Y).\n")
fp.write("sibling(X, Y) :- parent(Z, X), parent(Z, Y), X \= Y.\n")
# ---------------------------------
# Notes
# ---------------------------------
for note_handle in database.note_map.keys():
note = database.note_map[note_handle]
#write_line(fp, "note_details(%s, %s)" % (note_handle, note))
count += 1
callback(100 * count/total)
# ---------------------------------
# Event
# ---------------------------------
for event_handle in database.event_map.keys():
event = database.event_map[event_handle]
#write_line(fp, "event:", event_handle, event)
count += 1
callback(100 * count/total)
# ---------------------------------
# Person
# ---------------------------------
for person_handle in database.person_map.keys():
data = database.person_map[person_handle]
person = Person.create(data)
gid = person.gramps_id.lower()
fp.write("data(%s, '%s').\n" % (gid, escape(name_displayer.display(person))))
fp.write("is_alive(%s, '%s').\n" % (gid, probably_alive(person, database)))
count += 1
callback(100 * count/total)
# ---------------------------------
# Family
# ---------------------------------
for family_handle in database.family_map.keys():
data = database.family_map[family_handle]
family = Family.create(data)
father_handle = family.get_father_handle()
mother_handle = family.get_mother_handle()
parents = []
if mother_handle:
mother = database.get_person_from_handle(mother_handle)
if mother:
parents.append(mother.gramps_id.lower())
if father_handle:
father = database.get_person_from_handle(father_handle)
if father:
parents.append(father.gramps_id.lower())
children = []
for child_ref in family.get_child_ref_list():
child_handle = child_ref.ref
child = database.get_person_from_handle(child_handle)
if child:
children.append(child.gramps_id.lower())
for pid in parents:
for cid in children:
fp.write("parent(%s, %s).\n" % (pid, cid))
count += 1
callback(100 * count/total)
# ---------------------------------
# Repository
# ---------------------------------
for repository_handle in database.repository_map.keys():
repository = database.repository_map[repository_handle]
#write_line(fp, "repository:", repository_handle, repository)
count += 1
callback(100 * count/total)
# ---------------------------------
# Place
# ---------------------------------
#.........这里部分代码省略.........
示例12: exportData
def exportData(database, filename,
error_dialog=None, option_box=None, callback=None):
if not callable(callback):
callback = lambda percent: None # dummy
with OpenFileOrStdout(filename, encoding="utf-8") as fp:
total = (len(database.note_map) +
len(database.person_map) +
len(database.event_map) +
len(database.family_map) +
len(database.repository_map) +
len(database.place_map) +
len(database.media_map) +
len(database.citation_map) +
len(database.source_map) +
len(database.tag_map))
count = 0.0
# ---------------------------------
# Notes
# ---------------------------------
for handle in database.note_map.keys():
serial = database.note_map[handle]
write_line(fp, Note.create(serial))
count += 1
callback(100 * count/total)
# ---------------------------------
# Event
# ---------------------------------
for handle in database.event_map.keys():
serial = database.event_map[handle]
write_line(fp, Event.create(serial))
count += 1
callback(100 * count/total)
# ---------------------------------
# Person
# ---------------------------------
for handle in database.person_map.keys():
serial = database.person_map[handle]
write_line(fp, Person.create(serial))
count += 1
callback(100 * count/total)
# ---------------------------------
# Family
# ---------------------------------
for handle in database.family_map.keys():
serial = database.family_map[handle]
write_line(fp, Family.create(serial))
count += 1
callback(100 * count/total)
# ---------------------------------
# Repository
# ---------------------------------
for handle in database.repository_map.keys():
serial = database.repository_map[handle]
write_line(fp, Repository.create(serial))
count += 1
callback(100 * count/total)
# ---------------------------------
# Place
# ---------------------------------
for handle in database.place_map.keys():
serial = database.place_map[handle]
write_line(fp, Place.create(serial))
count += 1
callback(100 * count/total)
# ---------------------------------
# Source
# ---------------------------------
for handle in database.source_map.keys():
serial = database.source_map[handle]
write_line(fp, Source.create(serial))
count += 1
callback(100 * count/total)
# ---------------------------------
# Citation
# ---------------------------------
for handle in database.citation_map.keys():
serial = database.citation_map[handle]
write_line(fp, Citation.create(serial))
count += 1
callback(100 * count/total)
# ---------------------------------
# Media
# ---------------------------------
for handle in database.media_map.keys():
serial = database.media_map[handle]
write_line(fp, Media.create(serial))
count += 1
callback(100 * count/total)
#.........这里部分代码省略.........