本文整理汇总了Python中gramps.gen.proxy.CacheProxyDb.get_family_from_handle方法的典型用法代码示例。如果您正苦于以下问题:Python CacheProxyDb.get_family_from_handle方法的具体用法?Python CacheProxyDb.get_family_from_handle怎么用?Python CacheProxyDb.get_family_from_handle使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gramps.gen.proxy.CacheProxyDb
的用法示例。
在下文中一共展示了CacheProxyDb.get_family_from_handle方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: FanChart
# 需要导入模块: from gramps.gen.proxy import CacheProxyDb [as 别名]
# 或者: from gramps.gen.proxy.CacheProxyDb import get_family_from_handle [as 别名]
class FanChart(Report):
def __init__(self, database, options, user):
"""
Create the FanChart object that produces the report.
The arguments are:
database - the Gramps database instance
options - instance of the Options class for this report
user - a gen.user.User instance
This report needs the following parameters (class variables)
that come in the options class.
maxgen - Maximum number of generations to include.
circle - Draw a full circle, half circle, or quarter circle.
background - Background color is generation dependent or white.
radial - Print radial texts roundabout or as upright as possible.
draw_empty - draw background when there is no information
same_style - use the same style for all generation
incl_private - Whether to include private data
living_people - How to handle living people
years_past_death - Consider as living this many years after death
"""
Report.__init__(self, database, options, user)
menu = options.menu
self.set_locale(options.menu.get_option_by_name('trans').get_value())
stdoptions.run_private_data_option(self, menu)
stdoptions.run_living_people_option(self, menu, self._locale)
self.database = CacheProxyDb(self.database)
self.max_generations = menu.get_option_by_name('maxgen').get_value()
self.circle = menu.get_option_by_name('circle').get_value()
self.background = menu.get_option_by_name('background').get_value()
self.radial = menu.get_option_by_name('radial').get_value()
pid = menu.get_option_by_name('pid').get_value()
self.draw_empty = menu.get_option_by_name('draw_empty').get_value()
self.same_style = menu.get_option_by_name('same_style').get_value()
self.center_person = self.database.get_person_from_gramps_id(pid)
if self.center_person is None:
raise ReportError(_("Person %s is not in the Database") % pid)
self.graphic_style = []
self.text_style = []
for i in range(0, self.max_generations):
self.graphic_style.append('FC-Graphic' + '%02d' % i)
self.text_style.append('FC-Text' + '%02d' % i)
self.calendar = 0
self.height = 0
self.map = [None] * 2**self.max_generations
self.text = {}
def apply_filter(self, person_handle, index):
"""traverse the ancestors recursively until either the end
of a line is found, or until we reach the maximum number of
generations that we want to deal with"""
if (not person_handle) or (index >= 2**self.max_generations):
return
self.map[index-1] = person_handle
self.text[index-1] = self.get_info(person_handle, log2(index))
person = self.database.get_person_from_handle(person_handle)
family_handle = person.get_main_parents_family_handle()
if family_handle:
family = self.database.get_family_from_handle(family_handle)
self.apply_filter(family.get_father_handle(), index*2)
self.apply_filter(family.get_mother_handle(), (index*2)+1)
def write_report(self):
self.doc.start_page()
self.apply_filter(self.center_person.get_handle(), 1)
p_rn = self.center_person.get_primary_name().get_regular_name()
if self.circle == FULL_CIRCLE:
max_angle = 360.0
start_angle = 90
max_circular = 5
_x_ = self.doc.get_usable_width() / 2.0
_y_ = self.doc.get_usable_height() / 2.0
min_xy = min(_x_, _y_)
elif self.circle == HALF_CIRCLE:
max_angle = 180.0
start_angle = 180
max_circular = 3
_x_ = (self.doc.get_usable_width()/2.0)
_y_ = self.doc.get_usable_height()
min_xy = min(_x_, _y_)
else: # quarter circle
max_angle = 90.0
#.........这里部分代码省略.........
示例2: EndOfLineReport
# 需要导入模块: from gramps.gen.proxy import CacheProxyDb [as 别名]
# 或者: from gramps.gen.proxy.CacheProxyDb import get_family_from_handle [as 别名]
class EndOfLineReport(Report):
""" EndOfLine Report """
def __init__(self, database, options, user):
"""
Create the EndOfLineReport object that produces the report.
The arguments are:
database - the Gramps database instance
options - instance of the Options class for this report
user - a gen.user.User() instance
This report needs the following parameters (class variables)
that come in the options class.
name_format - Preferred format to display names
incl_private - Whether to include private data
living_people - How to handle living people
years_past_death - Consider as living this many years after death
"""
Report.__init__(self, database, options, user)
menu = options.menu
self.set_locale(menu.get_option_by_name('trans').get_value())
stdoptions.run_date_format_option(self, menu)
stdoptions.run_private_data_option(self, menu)
stdoptions.run_living_people_option(self, menu, self._locale)
self.database = CacheProxyDb(self.database)
pid = menu.get_option_by_name('pid').get_value()
self.center_person = self.database.get_person_from_gramps_id(pid)
if self.center_person is None:
raise ReportError(_("Person %s is not in the Database") % pid)
stdoptions.run_name_format_option(self, menu)
# eol_map is a map whose:
# keys are the generations of the people
# values are a map whose:
# keys are person handles
# values are an array whose:
# elements are an array of ancestor person handles that link
# the eol person handle to the person or interest
# eol_map[generation][person_handle][pedigree_idx][ancestor_handle_idx]
#
# There is an array of pedigrees because one person could show up twice
# in one generation (descendants marrying). Most people only have one
# pedigree.
#
# eol_map is populated by get_eol() which calls itself recursively.
self.eol_map = {}
self.get_eol(self.center_person, 1, [])
def get_eol(self, person, gen, pedigree):
"""
Recursively find the end of the line for each person
"""
person_handle = person.get_handle()
new_pedigree = list(pedigree) + [person_handle]
person_is_eol = False
families = person.get_parent_family_handle_list()
if person_handle in pedigree:
# This is a severe error!
# It indicates a loop in ancestry: A -> B -> A
person_is_eol = True
elif not families:
person_is_eol = True
else:
for family_handle in families:
family = self.database.get_family_from_handle(family_handle)
father_handle = family.get_father_handle()
mother_handle = family.get_mother_handle()
if father_handle:
father = self.database.get_person_from_handle(father_handle)
self.get_eol(father, gen+1, new_pedigree)
if mother_handle:
mother = self.database.get_person_from_handle(mother_handle)
self.get_eol(mother, gen+1, new_pedigree)
if not father_handle or not mother_handle:
person_is_eol = True
if person_is_eol:
# This person is the end of a line
if gen not in self.eol_map:
self.eol_map[gen] = {}
if person_handle not in self.eol_map[gen]:
self.eol_map[gen][person_handle] = []
self.eol_map[gen][person_handle].append(new_pedigree)
def write_report(self):
"""
The routine that actually creates the report.
At this point, the document is opened and ready for writing.
"""
pname = self._name_display.display(self.center_person)
#.........这里部分代码省略.........
示例3: RelGraphReport
# 需要导入模块: from gramps.gen.proxy import CacheProxyDb [as 别名]
# 或者: from gramps.gen.proxy.CacheProxyDb import get_family_from_handle [as 别名]
#.........这里部分代码省略.........
todolist = list()
todolist.append(person_handle)
while len(todolist) > 0:
# take the first person from todolist and do sanity check
cur = todolist.pop(0)
if cur in p_done:
continue
if cur not in person_handle_list:
p_done.add(cur)
continue
person = self.database.get_person_from_handle(cur)
# first check whether both parents are added
missing_parents = False
for parent_handle in find_parents(self.database, person):
if not parent_handle or parent_handle in p_done:
continue
if parent_handle not in person_handle_list:
continue
todolist.insert(0, parent_handle)
missing_parents = True
# if one of the parents is still missing, wait for them
if missing_parents:
continue
# add person to the sorted output
outlist.append(cur)
p_done.add(cur)
# add all spouses and children to the todo list
family_list = person.get_family_handle_list()
for fam_handle in family_list:
family = self.database.get_family_from_handle(fam_handle)
if family is None:
continue
if (family.get_father_handle() and
family.get_father_handle() != cur):
todolist.insert(0, family.get_father_handle())
if (family.get_mother_handle() and
family.get_mother_handle() != cur):
todolist.insert(0, family.get_mother_handle())
for child_ref in family.get_child_ref_list():
todolist.append(child_ref.ref)
# finally store the result
assert len(person_handle_list) == len(outlist)
return outlist
def add_child_links_to_families(self, person_handles):
"""
returns string of Graphviz edges linking parents to families or
children
"""
# Hash people in a dictionary for faster inclusion checking
person_dict = dict([handle, 1] for handle in person_handles)
for person_handle in person_handles:
if self._user:
self._user.step_progress()
person = self._db.get_person_from_handle(person_handle)
p_id = person.get_gramps_id()
for fam_handle in person.get_parent_family_handle_list():
family = self._db.get_family_from_handle(fam_handle)
father_handle = family.get_father_handle()
mother_handle = family.get_mother_handle()
示例4: DetAncestorReport
# 需要导入模块: from gramps.gen.proxy import CacheProxyDb [as 别名]
# 或者: from gramps.gen.proxy.CacheProxyDb import get_family_from_handle [as 别名]
#.........这里部分代码省略.........
stdoptions.run_name_format_option(self, menu)
self._nd = self._name_display
self.gen_handles = {}
self.prev_gen_handles = {}
if blankdate:
empty_date = EMPTY_ENTRY
else:
empty_date = ""
if blankplace:
empty_place = EMPTY_ENTRY
else:
empty_place = ""
self.__narrator = Narrator(self._db, self.verbose, use_call,
use_fulldate, empty_date, empty_place,
nlocale=self._locale,
get_endnote_numbers=self.endnotes)
self.bibli = Bibliography(Bibliography.MODE_DATE|Bibliography.MODE_PAGE)
def apply_filter(self, person_handle, index):
""" recurse up through the generations """
if (not person_handle) or (index >= 2**self.max_generations):
return
self.map[index] = person_handle
person = self._db.get_person_from_handle(person_handle)
family_handle = person.get_main_parents_family_handle()
if family_handle:
family = self._db.get_family_from_handle(family_handle)
self.apply_filter(family.get_father_handle(), index*2)
self.apply_filter(family.get_mother_handle(), (index*2)+1)
def write_report(self):
self.apply_filter(self.center_person.get_handle(), 1)
name = self._nd.display_name(self.center_person.get_primary_name())
if not name:
name = self._("Unknown")
self.doc.start_paragraph("DAR-Title")
# feature request 2356: avoid genitive form
title = self._("Ancestral Report for %s") % name
mark = IndexMark(title, INDEX_TYPE_TOC, 1)
self.doc.write_text(title, mark)
self.doc.end_paragraph()
generation = 0
for key in sorted(self.map):
if generation == 0 or key >= 2**generation:
if self.pgbrk and generation > 0:
self.doc.page_break()
self.doc.start_paragraph("DAR-Generation")
text = self._("Generation %d") % (generation+1)
mark = IndexMark(text, INDEX_TYPE_TOC, 2)
self.doc.write_text(text, mark)
self.doc.end_paragraph()
generation += 1
if self.childref:
self.prev_gen_handles = self.gen_handles.copy()
self.gen_handles.clear()
示例5: TagReport
# 需要导入模块: from gramps.gen.proxy import CacheProxyDb [as 别名]
# 或者: from gramps.gen.proxy.CacheProxyDb import get_family_from_handle [as 别名]
#.........这里部分代码省略.........
self.doc.end_paragraph()
self.doc.start_table('FamilyTable', 'TR-Table')
self.doc.start_row()
self.doc.start_cell('TR-TableCell')
self.doc.start_paragraph('TR-Normal-Bold')
self.doc.write_text(self._("Id"))
self.doc.end_paragraph()
self.doc.end_cell()
self.doc.start_cell('TR-TableCell')
self.doc.start_paragraph('TR-Normal-Bold')
self.doc.write_text(self._("Father"))
self.doc.end_paragraph()
self.doc.end_cell()
self.doc.start_cell('TR-TableCell')
self.doc.start_paragraph('TR-Normal-Bold')
self.doc.write_text(self._("Mother"))
self.doc.end_paragraph()
self.doc.end_cell()
self.doc.start_cell('TR-TableCell')
self.doc.start_paragraph('TR-Normal-Bold')
self.doc.write_text(self._("Relationship"))
self.doc.end_paragraph()
self.doc.end_cell()
self.doc.end_row()
for family_handle in fam_list:
family = self.database.get_family_from_handle(family_handle)
self.doc.start_row()
self.doc.start_cell('TR-TableCell')
self.doc.start_paragraph('TR-Normal')
self.doc.write_text(family.get_gramps_id())
self.doc.end_paragraph()
self.doc.end_cell()
self.doc.start_cell('TR-TableCell')
self.doc.start_paragraph('TR-Normal')
father_handle = family.get_father_handle()
if father_handle:
father = self.database.get_person_from_handle(father_handle)
mark = utils.get_person_mark(self.database, father)
self.doc.write_text(self._name_display.display(father), mark)
self.doc.end_paragraph()
self.doc.end_cell()
self.doc.start_cell('TR-TableCell')
self.doc.start_paragraph('TR-Normal')
mother_handle = family.get_mother_handle()
if mother_handle:
mother = self.database.get_person_from_handle(mother_handle)
mark = utils.get_person_mark(self.database, mother)
self.doc.write_text(self._name_display.display(mother), mark)
self.doc.end_paragraph()
self.doc.end_cell()
self.doc.start_cell('TR-TableCell')
self.doc.start_paragraph('TR-Normal')
relation = family.get_relationship()
示例6: DetDescendantReport
# 需要导入模块: from gramps.gen.proxy import CacheProxyDb [as 别名]
# 或者: from gramps.gen.proxy.CacheProxyDb import get_family_from_handle [as 别名]
#.........这里部分代码省略.........
empty_place = EMPTY_ENTRY
else:
empty_place = ""
stdoptions.run_name_format_option(self, menu)
self.__narrator = Narrator(self._db, self.verbose,
use_call, use_fulldate,
empty_date, empty_place,
nlocale=self._locale,
get_endnote_numbers=self.endnotes)
self.bibli = Bibliography(Bibliography.MODE_DATE|Bibliography.MODE_PAGE)
def apply_henry_filter(self, person_handle, index, pid, cur_gen=1):
""" Filter for Henry numbering """
if (not person_handle) or (cur_gen > self.max_generations):
return
if person_handle in self.dnumber:
if self.dnumber[person_handle] > pid:
self.dnumber[person_handle] = pid
else:
self.dnumber[person_handle] = pid
self.map[index] = person_handle
if len(self.gen_keys) < cur_gen:
self.gen_keys.append([index])
else:
self.gen_keys[cur_gen-1].append(index)
person = self._db.get_person_from_handle(person_handle)
index = 0
for family_handle in person.get_family_handle_list():
family = self._db.get_family_from_handle(family_handle)
for child_ref in family.get_child_ref_list():
_ix = max(self.map)
self.apply_henry_filter(child_ref.ref, _ix+1,
pid+HENRY[index], cur_gen+1)
index += 1
def apply_mhenry_filter(self, person_handle, index, pid, cur_gen=1):
""" Filter for Modified Henry numbering """
def mhenry():
""" convenience finction """
return str(index) if index < 10 else "(" + str(index) + ")"
if (not person_handle) or (cur_gen > self.max_generations):
return
self.dnumber[person_handle] = pid
self.map[index] = person_handle
if len(self.gen_keys) < cur_gen:
self.gen_keys.append([index])
else:
self.gen_keys[cur_gen-1].append(index)
person = self._db.get_person_from_handle(person_handle)
index = 1
for family_handle in person.get_family_handle_list():
family = self._db.get_family_from_handle(family_handle)
for child_ref in family.get_child_ref_list():
_ix = max(self.map)
self.apply_henry_filter(child_ref.ref, _ix+1,
pid+mhenry(), cur_gen+1)
index += 1
def apply_daboville_filter(self, person_handle, index, pid, cur_gen=1):
示例7: AncestorReport
# 需要导入模块: from gramps.gen.proxy import CacheProxyDb [as 别名]
# 或者: from gramps.gen.proxy.CacheProxyDb import get_family_from_handle [as 别名]
class AncestorReport(Report):
"""
Ancestor Report class
"""
def __init__(self, database, options, user):
"""
Create the AncestorReport object that produces the Ahnentafel report.
The arguments are:
database - the GRAMPS database instance
options - instance of the Options class for this report
user - a gen.user.User() instance
This report needs the following parameters (class variables)
that come in the options class.
gen - Maximum number of generations to include.
pagebbg - Whether to include page breaks between generations.
name_format - Preferred format to display names
incl_private - Whether to include private data
living_people - How to handle living people
years_past_death - Consider as living this many years after death
"""
Report.__init__(self, database, options, user)
self.map = {}
menu = options.menu
lang = menu.get_option_by_name('trans').get_value()
rlocale = self.set_locale(lang)
stdoptions.run_private_data_option(self, menu)
stdoptions.run_living_people_option(self, menu, rlocale)
self.database = CacheProxyDb(self.database)
self.max_generations = menu.get_option_by_name('maxgen').get_value()
self.pgbrk = menu.get_option_by_name('pagebbg').get_value()
self.opt_namebrk = menu.get_option_by_name('namebrk').get_value()
pid = menu.get_option_by_name('pid').get_value()
self.center_person = self.database.get_person_from_gramps_id(pid)
if (self.center_person == None) :
raise ReportError(_("Person %s is not in the Database") % pid )
stdoptions.run_name_format_option(self, menu)
self.__narrator = Narrator(self.database, use_fulldate=True,
nlocale=rlocale)
def apply_filter(self, person_handle, index, generation=1):
"""
Recursive function to walk back all parents of the current person.
When max_generations are hit, we stop the traversal.
"""
# check for end of the current recursion level. This happens
# if the person handle is None, or if the max_generations is hit
if not person_handle or generation > self.max_generations:
return
# store the person in the map based off their index number
# which is passed to the routine.
self.map[index] = person_handle
# retrieve the Person instance from the database from the
# passed person_handle and find the parents from the list.
# Since this report is for natural parents (birth parents),
# we have to handle that parents may not
person = self.database.get_person_from_handle(person_handle)
if person is None:
return
father_handle = None
mother_handle = None
for family_handle in person.get_parent_family_handle_list():
family = self.database.get_family_from_handle(family_handle)
# filter the child_ref_list to find the reference that matches
# the passed person. There should be exactly one, but there is
# nothing that prevents the same child in the list multiple times.
ref = [ c for c in family.get_child_ref_list()
if c.get_reference_handle() == person_handle]
if ref:
# If the father_handle is not defined and the relationship is
# BIRTH, then we have found the birth father. Same applies to
# the birth mother. If for some reason, the we have multiple
# people defined as the birth parents, we will select based on
# priority in the list
if not father_handle and \
ref[0].get_father_relation() == ChildRefType.BIRTH:
father_handle = family.get_father_handle()
if not mother_handle and \
ref[0].get_mother_relation() == ChildRefType.BIRTH:
mother_handle = family.get_mother_handle()
#.........这里部分代码省略.........
示例8: RecordsReport
# 需要导入模块: from gramps.gen.proxy import CacheProxyDb [as 别名]
# 或者: from gramps.gen.proxy.CacheProxyDb import get_family_from_handle [as 别名]
class RecordsReport(Report):
""" Records Report """
def __init__(self, database, options, user):
"""
This report needs the following parameters (class variables)
that come in the options class.
incl_private - Whether to include private data
living_people - How to handle living people
years_past_death - Consider as living this many years after death
"""
Report.__init__(self, database, options, user)
menu = options.menu
lang = options.menu.get_option_by_name('trans').get_value()
self._locale = self.set_locale(lang)
stdoptions.run_private_data_option(self, menu)
living_opt = stdoptions.run_living_people_option(self, menu,
self._locale)
self.database = CacheProxyDb(self.database)
self._lv = menu.get_option_by_name('living_people').get_value()
for (value, description) in living_opt.get_items(xml_items=True):
if value == self._lv:
living_desc = self._(description)
break
self.living_desc = self._(
"(Living people: %(option_name)s)") % {'option_name': living_desc}
filter_option = menu.get_option_by_name('filter')
self.filter = filter_option.get_filter()
self.top_size = menu.get_option_by_name('top_size').get_value()
self.callname = menu.get_option_by_name('callname').get_value()
self.footer = menu.get_option_by_name('footer').get_value()
self.include = {}
for (text, varname, default) in RECORDS:
self.include[varname] = menu.get_option_by_name(varname).get_value()
self._nf = stdoptions.run_name_format_option(self, menu)
def write_report(self):
"""
Build the actual report.
"""
records = find_records(self.database, self.filter,
self.top_size, self.callname,
trans_text=self._, name_format=self._nf,
living_mode=self._lv)
self.doc.start_paragraph('REC-Title')
title = self._("Records")
mark = IndexMark(title, INDEX_TYPE_TOC, 1)
self.doc.write_text(title, mark)
self.doc.end_paragraph()
self.doc.start_paragraph('REC-Subtitle')
filter_name = self.filter.get_name(self._locale)
self.doc.write_text("(%s)" % filter_name)
self.doc.end_paragraph()
if self._lv != LivingProxyDb.MODE_INCLUDE_ALL:
self.doc.start_paragraph('REC-Subtitle')
self.doc.write_text(self.living_desc)
self.doc.end_paragraph()
for (text, varname, top) in records:
if not self.include[varname]:
continue
self.doc.start_paragraph('REC-Heading')
self.doc.write_text(self._(text))
self.doc.end_paragraph()
last_value = None
rank = 0
for (number,
(sort, value, name, handletype, handle)) in enumerate(top):
mark = None
if handletype == 'Person':
person = self.database.get_person_from_handle(handle)
mark = utils.get_person_mark(self.database, person)
elif handletype == 'Family':
family = self.database.get_family_from_handle(handle)
# librecords.py checks that the family has both
# a father and a mother and also that each one is
# in the filter if any filter was used, so we don't
# have to do any similar checking here, it's been done
f_handle = family.get_father_handle()
dad = self.database.get_person_from_handle(f_handle)
f_mark = utils.get_person_mark(self.database, dad)
m_handle = family.get_mother_handle()
mom = self.database.get_person_from_handle(m_handle)
m_mark = utils.get_person_mark(self.database, mom)
else:
#.........这里部分代码省略.........