本文整理汇总了Python中gramps.gen.proxy.CacheProxyDb.get_person_from_handle方法的典型用法代码示例。如果您正苦于以下问题:Python CacheProxyDb.get_person_from_handle方法的具体用法?Python CacheProxyDb.get_person_from_handle怎么用?Python CacheProxyDb.get_person_from_handle使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gramps.gen.proxy.CacheProxyDb
的用法示例。
在下文中一共展示了CacheProxyDb.get_person_from_handle方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: FanChart
# 需要导入模块: from gramps.gen.proxy import CacheProxyDb [as 别名]
# 或者: from gramps.gen.proxy.CacheProxyDb import get_person_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_person_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_person_from_handle [as 别名]
#.........这里部分代码省略.........
self.increlname = get_value('increlname')
if self.increlname:
self.rel_calc = get_relationship_calculator(reinit=True,
clocale=self._locale)
if __debug__:
self.advrelinfo = get_value('advrelinfo')
else:
self.advrelinfo = False
def write_report(self):
person_handles = self._filter.apply(self._db,
self._db.iter_person_handles(),
user=self._user)
person_handles = self.sort_persons(person_handles)
if len(person_handles) > 1:
if self._user:
self._user.begin_progress(_("Relationship Graph"),
_("Generating report"),
len(person_handles) * 2)
self.add_persons_and_families(person_handles)
self.add_child_links_to_families(person_handles)
if self._user:
self._user.end_progress()
def sort_persons(self, person_handle_list):
"sort persons by close relations"
# first make a list of all persons who don't have any parents
root_nodes = list()
for person_handle in person_handle_list:
person = self.database.get_person_from_handle(person_handle)
has_parent = False
for parent_handle in find_parents(self.database, person):
if parent_handle not in person_handle_list:
continue
has_parent = True
if not has_parent:
root_nodes.append(person_handle)
# now start from all root nodes we found and traverse their trees
outlist = list()
p_done = set()
for person_handle in root_nodes:
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)
示例4: KinshipReport
# 需要导入模块: from gramps.gen.proxy import CacheProxyDb [as 别名]
# 或者: from gramps.gen.proxy.CacheProxyDb import get_person_from_handle [as 别名]
#.........这里部分代码省略.........
self.add_kin(parent_handle, Ga, Gb)
self.traverse_down(parent_handle, Ga, Gb+1, person_handle)
if Ga < self.max_ascend:
self.traverse_up(parent_handle, Ga+1, 0)
def add_kin(self, person_handle, Ga, Gb):
"""
Add a person handle to the kin map.
"""
if Ga not in self.kinship_map:
self.kinship_map[Ga] = {}
if Gb not in self.kinship_map[Ga]:
self.kinship_map[Ga][Gb] = []
if person_handle not in self.kinship_map[Ga][Gb]:
self.kinship_map[Ga][Gb].append(person_handle)
def add_spouse(self, spouse_handle, Ga, Gb):
"""
Add a person handle to the spouse map.
"""
if Ga not in self.spouse_map:
self.spouse_map[Ga] = {}
if Gb not in self.spouse_map[Ga]:
self.spouse_map[Ga][Gb] = []
if spouse_handle not in self.spouse_map[Ga][Gb]:
self.spouse_map[Ga][Gb].append(spouse_handle)
def get_parent_handles(self, person_handle):
"""
Return an array of handles for all the parents of the
given person handle.
"""
parent_handles = []
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)
father_handle = family.get_father_handle()
if father_handle:
parent_handles.append(father_handle)
mother_handle = family.get_mother_handle()
if mother_handle:
parent_handles.append(mother_handle)
return parent_handles
def get_spouse_handles(self, person_handle):
"""
Return an array of handles for all the spouses of the
given person handle.
"""
spouses = []
person = self.__db.get_person_from_handle(person_handle)
for family_handle in person.get_family_handle_list():
family = self.__db.get_family_from_handle(family_handle)
father_handle = family.get_father_handle()
mother_handle = family.get_mother_handle()
spouse_handle = None
if mother_handle and father_handle == person_handle:
spouse_handle = mother_handle
elif father_handle and mother_handle == person_handle:
spouse_handle = father_handle
if spouse_handle and spouse_handle not in spouses:
spouses.append(spouse_handle)
return spouses
示例5: TagReport
# 需要导入模块: from gramps.gen.proxy import CacheProxyDb [as 别名]
# 或者: from gramps.gen.proxy.CacheProxyDb import get_person_from_handle [as 别名]
#.........这里部分代码省略.........
self.doc.end_paragraph()
self.doc.start_table('PeopleTable', '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._("Name"))
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._("Birth"))
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._("Death"))
self.doc.end_paragraph()
self.doc.end_cell()
self.doc.end_row()
for person_handle in ind_list:
person = self.database.get_person_from_handle(person_handle)
self.doc.start_row()
self.doc.start_cell('TR-TableCell')
self.doc.start_paragraph('TR-Normal')
self.doc.write_text(person.get_gramps_id())
self.doc.end_paragraph()
self.doc.end_cell()
name = self._name_display.display(person)
mark = utils.get_person_mark(self.database, person)
self.doc.start_cell('TR-TableCell')
self.doc.start_paragraph('TR-Normal')
self.doc.write_text(name, mark)
self.doc.end_paragraph()
self.doc.end_cell()
self.doc.start_cell('TR-TableCell')
self.doc.start_paragraph('TR-Normal')
birth_ref = person.get_birth_ref()
if birth_ref:
event = self.database.get_event_from_handle(birth_ref.ref)
self.doc.write_text(self._get_date(event.get_date_object()))
self.doc.end_paragraph()
self.doc.end_cell()
self.doc.start_cell('TR-TableCell')
self.doc.start_paragraph('TR-Normal')
death_ref = person.get_death_ref()
if death_ref:
event = self.database.get_event_from_handle(death_ref.ref)
self.doc.write_text(self._get_date(event.get_date_object()))
示例6: TimeLine
# 需要导入模块: from gramps.gen.proxy import CacheProxyDb [as 别名]
# 或者: from gramps.gen.proxy.CacheProxyDb import get_person_from_handle [as 别名]
#.........这里部分代码省略.........
# Generate the actual timeline
self.generate_timeline(low, high)
def generate_timeline(self, low, high):
""" generate the timeline """
st_size = self.name_size()
style_sheet = self.doc.get_style_sheet()
font = style_sheet.get_paragraph_style('TLG-Name').get_font()
incr = utils.pt2cm(font.get_size())
pad = incr * 0.75
_x1, _x2, _y1, _y2 = (0, 0, 0, 0)
start = st_size + 0.5
stop = self.doc.get_usable_width() - 0.5
size = stop - start
self.header = 2.6
# Sort the people as requested
with self._user.progress(_('Timeline'),
_('Sorting dates...'), 0) as step:
self.plist.sort(key=self.sort_func)
self.doc.start_page()
self.build_grid(low, high, start, stop, True)
index = 1
current = 1
length = len(self.plist)
with self._user.progress(_('Timeline'), _('Calculating timeline...'),
length) as step:
for p_id in self.plist:
person = self.database.get_person_from_handle(p_id)
birth = get_birth_or_fallback(self.database, person)
if birth:
bth = birth.get_date_object()
bth = bth.to_calendar(self.calendar).get_year()
else:
bth = None
death = get_death_or_fallback(self.database, person)
if death:
dth = death.get_date_object()
dth = dth.to_calendar(self.calendar).get_year()
else:
dth = None
dname = self._name_display.display(person)
mark = utils.get_person_mark(self.database, person)
self.doc.draw_text('TLG-text', dname, incr + pad,
self.header + (incr + pad) * index, mark)
_y1 = self.header + (pad + incr) * index
_y2 = self.header + ((pad + incr) * index) + incr
_y3 = (_y1 + _y2) / 2.0
w05 = 0.05
if bth:
start_offset = ((float(bth - low) / float(high - low)) *
size)
_x1 = start + start_offset
path = [(_x1, _y1), (_x1 + w05, _y3),
(_x1, _y2), (_x1 - w05, _y3)]
self.doc.draw_path('TLG-line', path)
示例7: AncestorReport
# 需要导入模块: from gramps.gen.proxy import CacheProxyDb [as 别名]
# 或者: from gramps.gen.proxy.CacheProxyDb import get_person_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_person_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:
#.........这里部分代码省略.........