def get(self, args: Dict, handle1: Handle, handle2: Handle) -> Response: """Get all possible relationships between two people.""" db_handle = get_db_handle() person1 = get_person_by_handle(db_handle, handle1) if person1 == {}: abort(404) person2 = get_person_by_handle(db_handle, handle2) if person2 == {}: abort(404) locale = get_locale_for_language(args["locale"], default=True) calc = get_relationship_calculator(reinit=True, clocale=locale) calc.set_depth(args["depth"]) data = calc.get_all_relationships(db_handle, person1, person2) result = [] index = 0 while index < len(data[0]): result.append({ "relationship_string": data[0][index], "common_ancestors": data[1][index], }) index = index + 1 if result == []: result = [{}] return self.response(200, result)
def get(self, args: Dict, handle1: Handle, handle2: Handle) -> Response: """Get the most direct relationship between two people.""" db_handle = get_db_handle() person1 = get_person_by_handle(db_handle, handle1) if person1 == {}: abort(404) person2 = get_person_by_handle(db_handle, handle2) if person2 == {}: abort(404) locale = get_locale_for_language(args["locale"], default=True) calc = get_relationship_calculator(reinit=True, clocale=locale) calc.set_depth(args["depth"]) data = calc.get_one_relationship(db_handle, person1, person2, extra_info=True) return self.response( 200, { "relationship_string": data[0], "distance_common_origin": data[1], "distance_common_other": data[2], }, )
def run(database, document, person): """ Loops through the families that the person is a child in, and display the information about the other children. """ # setup the simple access functions sdb = SimpleAccess(database) sdoc = SimpleDoc(document) stab = QuickTable(sdb) rel_class = get_relationship_calculator(glocale) # display the title # feature request 2356: avoid genitive form sdoc.title(_("Siblings of %s") % sdb.name(person)) sdoc.paragraph("") stab.columns(_("Sibling"), _("Gender"), _("Birth Date"), _("Type")) # grab our current id (self): gid = sdb.gid(person) # loop through each family in which the person is a child document.has_data = False for family in sdb.child_in(person): # loop through each child in the family for child in sdb.children(family): # only display if this child is not the active person if sdb.gid(child) != gid: rel_str = rel_class.get_sibling_relationship_string( rel_class.get_sibling_type(database, person, child), person.get_gender(), child.get_gender()) else: rel_str = _('self') # pass row the child object to make link: stab.row(child, sdb.gender(child), sdb.birth_or_fallback(child), rel_str) document.has_data = True stab.write(sdoc)
def personrelation1(self, rolepershandle, primpershandle): if rolepershandle: # Relation # For Single Person Events relation_text = "nicht verwandt" rel_calc = get_relationship_calculator(reinit=True, clocale=glocale) relation = rel_calc.get_one_relationship( self.__db, self.__db.get_person_from_handle(primpershandle), self.__db.get_person_from_handle(rolepershandle)) if relation: relation_text = _("%s" % relation) elif self.__db.get_person_from_handle( primpershandle ).gramps_id == self.__db.get_person_from_handle( rolepershandle).gramps_id: relation_text = _("IP ") elif (self.showinlaw == 1): inlaw_text = self.inlaw_rel(primpershandle, rolepershandle) relation_text = inlaw_text return (_("%s") % relation_text)
def __init__(self, database, document, person): self.database = database self.person = person self.sdb = SimpleAccess(database) self.sdoc = SimpleDoc(document) self.rel_class = get_relationship_calculator(glocale) self.msg_list = []
def __init__(self, database, document, person): self.database = database self.person = person self.sdb = SimpleAccess(database) self.sdoc = SimpleDoc(document) self.rel_class = get_relationship_calculator(glocale) self.msg_list = []
def main(self): for widget in self.vbox.get_children(): self.vbox.remove(widget) active_handle = self.get_active('Person') if active_handle: active = self.dbstate.db.get_person_from_handle(active_handle) self.relationship = get_relationship_calculator(glocale) random.seed( 0.66 ) # use a fixed arbitrary number so it is concistent on redraw segmap = SegmentMap() segmap.set_title( _('Chromosome Segment Map for ' + _nd.display(active) + ' [' + active.get_gramps_id() + ']')) segmap.set_axis(_('Chr')) segmap.dbstate = self.dbstate segmap.uistate = self.uistate segmap.segments = [] segmap.backref = self for assoc in active.get_person_ref_list(): if assoc.get_relation() == 'DNA': rgb_color = [ random.random(), random.random(), random.random() ] associate = self.dbstate.db.get_person_from_handle( assoc.ref) data, msg = self.relationship.get_relationship_distance_new( self.dbstate.db, active, associate) id_str = _( _nd.display(associate) + ' [' + associate.get_gramps_id() + ']') if data[0] == -1: side = 'U' else: side = data[2][0].upper() # Get Notes attached to Association for handle in assoc.get_note_list(): note = self.dbstate.db.get_note_from_handle(handle) for line in note.get().split('\n'): assoc_handle = assoc.ref write_chromo(line, side, rgb_color, assoc, segmap) # Get Notes attached to Citation which is attached to the Association for citation_handle in assoc.get_citation_list(): citation = self.dbstate.db.get_citation_from_handle( citation_handle) for handle in citation.get_note_list(): note = self.dbstate.db.get_note_from_handle(handle) for line in note.get().split('\n'): assoc_handle = assoc.ref write_chromo(line, side, rgb_color, assoc, segmap) if len(segmap.segments) > 0: segmap.show() self.vbox.pack_start(segmap, True, True, 0)
def add_relative(self, handle: Handle, ancestors: int = 1, offspring: int = 1): """Add events for a relative of the anchor person.""" person = self.db_handle.get_person_from_handle(handle) calculator = get_relationship_calculator(reinit=True, clocale=self.locale) calculator.set_depth(self.depth) relationship = calculator.get_one_relationship(self.db_handle, self.anchor_person, person) if self.relative_filters: found = False for relative in self.relative_filters: if relative in relationship: found = True break if not found: return if self.relative_event_filters: for event_ref in person.event_ref_list: event = self.db_handle.get_event_from_handle(event_ref.ref) self.add_event((event, person, relationship), relative=True) event = get_birth_or_fallback(self.db_handle, person) if event: self.add_event((event, person, relationship), relative=True) if person.handle not in self.birth_dates: self.birth_dates.update({person.handle: event.date}) event = get_death_or_fallback(self.db_handle, person) if event: self.add_event((event, person, relationship), relative=True) for family_handle in person.family_list: family = self.db_handle.get_family_from_handle(family_handle) event = get_marriage_or_fallback(self.db_handle, family) if event: self.add_event((event, person, relationship), relative=True) event = get_divorce_or_fallback(self.db_handle, family) if event: self.add_event((event, person, relationship), relative=True) if offspring > 1: for child_ref in family.child_ref_list: self.add_relative(child_ref.ref, offspring=offspring - 1) if ancestors > 1: if "father" in relationship or "mother" in relationship: for family_handle in person.parent_family_list: self.add_family(family_handle, include_children=False, ancestors=ancestors - 1)
def __init__(self, dbstate, user, options_class, name, callback=None): uistate = user.uistate self.label = _("Associations state tool") tool.Tool.__init__(self, dbstate, options_class, name) if uistate: ManagedWindow.__init__(self, uistate, [], self.__class__) stats_list = [] relationship = get_relationship_calculator() rel = "" plist = dbstate.db.get_person_handles(sort_handles=True) for handle in plist: person = dbstate.db.get_person_from_handle(handle) name1 = name_displayer.display(person) refs = person.get_person_ref_list() if refs: for ref in person.serialize()[-1]: (a, b, c, two, value) = ref person2 = dbstate.db.get_person_from_handle(two) name2 = name_displayer.display(person2) rel = relationship.get_one_relationship( dbstate.db, person2, person) stats_list.append((name1, value, name2, rel)) if uistate: titles = [ (_('Name'), 0, 200), (_('Type of link'), 1, 200), (_('Of'), 2, 200), (_('Relationship Calculator'), 2, 200), ] treeview = Gtk.TreeView() model = ListModel(treeview, titles) for entry in stats_list: model.add(entry, entry[0]) window = Gtk.Window() window.set_default_size(1000, 600) s = Gtk.ScrolledWindow() s.add(treeview) window.add(s) window.show_all() self.set_window(window, None, self.label) self.show() else: print('\t%s' * 4 % ('Name', 'Type of link', 'Of', 'RelCal')) print() for entry in stats_list: print('\t%s' * 4 % entry)
def __init__(self, database, options, user): """ Create the KinshipReport 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. maxdescend - Maximum generations of descendants to include. maxascend - Maximum generations of ancestors to include. incspouses - Whether to include spouses. inccousins - Whether to include cousins. incaunts - Whether to include aunts/uncles/nephews/nieces. pid - The Gramps ID of the center person for the report. 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) self.__db = self.database self.max_descend = menu.get_option_by_name('maxdescend').get_value() self.max_ascend = menu.get_option_by_name('maxascend').get_value() self.inc_spouses = menu.get_option_by_name('incspouses').get_value() self.inc_cousins = menu.get_option_by_name('inccousins').get_value() self.inc_aunts = menu.get_option_by_name('incaunts').get_value() pid = menu.get_option_by_name('pid').get_value() self.person = self.database.get_person_from_gramps_id(pid) if self.person is None: raise ReportError(_("Person %s is not in the Database") % pid) stdoptions.run_name_format_option(self, menu) self.rel_calc = get_relationship_calculator(reinit=True, clocale=self._locale) self.kinship_map = {} self.spouse_map = {}
def __init__(self, database, options, user): """ Create the KinshipReport 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. maxdescend - Maximum generations of descendants to include. maxascend - Maximum generations of ancestors to include. incspouses - Whether to include spouses. inccousins - Whether to include cousins. incaunts - Whether to include aunts/uncles/nephews/nieces. pid - The Gramps ID of the center person for the report. 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) self.__db = self.database self.max_descend = menu.get_option_by_name('maxdescend').get_value() self.max_ascend = menu.get_option_by_name('maxascend').get_value() self.inc_spouses = menu.get_option_by_name('incspouses').get_value() self.inc_cousins = menu.get_option_by_name('inccousins').get_value() self.inc_aunts = menu.get_option_by_name('incaunts').get_value() pid = menu.get_option_by_name('pid').get_value() self.person = self.database.get_person_from_gramps_id(pid) if self.person is None: raise ReportError(_("Person %s is not in the Database") % pid) stdoptions.run_name_format_option(self, menu) self.rel_calc = get_relationship_calculator(reinit=True, clocale=self._locale) self.kinship_map = {} self.spouse_map = {}
def __process_relationship(self, person1, person2): # --- Now let the party begin! --- self.doc.start_paragraph("FSR-Key") self.doc.write_text("starting") self.doc.end_paragraph() self.doc.start_table(None, "FSR-Table") # Main person self.doc.start_row() self.doc.start_cell("FSR-HeadCell", 3) self.doc.start_paragraph("FSR-Name") self.doc.write_text("First Person\n") self.doc.end_paragraph() self.__dump_person(person1, False, None) self.doc.start_paragraph("FSR-Name") self.doc.write_text("\nSecond Person\n") self.doc.end_paragraph() self.__dump_person(person2, False, None) self.doc.start_paragraph("FSR-Name") relationship = get_relationship_calculator() relate = "\nSecond person is the first person's " + relationship.get_one_relationship( self.database, person1, person2 ) self.doc.write_text(relate) self.doc.end_paragraph() self.doc.start_paragraph("FSR-Name") self.doc.write_text("\nCommon Ancestor\n") self.doc.write_text("The common ancestors for Person 1 and Person 2 are ") # firstAncestor = self.database.get_person_from_handle(); info, msg = relationship.get_relationship_distance_new( self.database, person1, person2, all_dist=True, only_birth=False ) self.doc.write_text(self.__process_ancestor_string(info)) self.doc.end_paragraph() # relationship = get_relationship_calculator() # self.doc.start_paragraph('FSR-Name') print("info:", info) print("message:", msg) self.doc.end_cell() self.doc.end_row() self.doc.end_table()
def __process_relationship(self, person1, person2): # --- Now let the party begin! --- self.doc.start_paragraph('FSR-Key') self.doc.write_text('starting') self.doc.end_paragraph() self.doc.start_table(None, 'FSR-Table') # Main person self.doc.start_row() self.doc.start_cell('FSR-HeadCell', 3) self.doc.start_paragraph('FSR-Name') self.doc.write_text("First Person\n") self.doc.end_paragraph() self.__dump_person(person1, False, None) self.doc.start_paragraph('FSR-Name') self.doc.write_text("\nSecond Person\n") self.doc.end_paragraph() self.__dump_person(person2, False, None) self.doc.start_paragraph('FSR-Name') relationship = get_relationship_calculator() relate = "\nSecond person is the first person's " + relationship.get_one_relationship( self.database, person1, person2) self.doc.write_text(relate) self.doc.end_paragraph() self.doc.start_paragraph('FSR-Name') self.doc.write_text("\nCommon Ancestor\n") self.doc.write_text( "The common ancestors for Person 1 and Person 2 are ") #firstAncestor = self.database.get_person_from_handle(); info, msg = relationship.get_relationship_distance_new( self.database, person1, person2, all_dist=True, only_birth=False) self.doc.write_text(self.__process_ancestor_string(info)) self.doc.end_paragraph() #relationship = get_relationship_calculator() #self.doc.start_paragraph('FSR-Name') print('info:', info) print('message:', msg) self.doc.end_cell() self.doc.end_row() self.doc.end_table()
def write_association(self, person1, person_ref): vbox = self.write_person('assoc', person_ref.ref) assoc = Gtk.Label(_('Association') + _(': ') + person_ref.rel) assoc.set_halign(Gtk.Align.START) vbox.pack_start(assoc, False, False, 0) calc = get_relationship_calculator() person2 = self.dbstate.db.get_person_from_handle(person_ref.ref) rel_txt = calc.get_one_relationship(self.dbstate.db, person1, person2) rel = Gtk.Label(_('Relationship') + _(': ') + rel_txt) rel.set_halign(Gtk.Align.START) vbox.pack_start(rel, False, False, 0) eventbox = self.make_dragbox(vbox, 'Person', person_ref.ref) eventbox.show_all() self.vbox2.pack_start(eventbox, False, False, 1)
def run(database, document, person): """ Loops through the families that the person is a child in, and display the information about the other children. """ # setup the simple access functions sdb = SimpleAccess(database) sdoc = SimpleDoc(document) stab = QuickTable(sdb) rel_class = get_relationship_calculator(glocale) # display the title # feature request 2356: avoid genitive form sdoc.title(_("Siblings of %s") % sdb.name(person)) sdoc.paragraph("") stab.columns(_("Sibling"), _("Gender"), _("Birth Date"), _("Type")) # grab our current id (self): gid = sdb.gid(person) # loop through each family in which the person is a child document.has_data = False for family in sdb.child_in(person): # loop through each child in the family for child in sdb.children(family): # only display if this child is not the active person if sdb.gid(child) != gid: rel_str = rel_class.get_sibling_relationship_string( rel_class.get_sibling_type(database, person, child), person.get_gender(), child.get_gender()) else: rel_str = _('self') # pass row the child object to make link: stab.row(child, sdb.gender(child), sdb.birth_or_fallback(child), rel_str) document.has_data = True if document.has_data: stab.write(sdoc) else: sdoc.header1(_("Not found") + "\n")
def init(self): self.selected_handles = set() self.relationship_calc = get_relationship_calculator() self.set_tooltip(_("Double-click name for details")) self.set_text(_("No Family Tree loaded.")) self.set_use_markup(True) self.gui.get_container_widget().remove(self.gui.textview) vbox = Gtk.VBox() hbox = Gtk.HBox() pause_button = Gtk.Button(_("Pause")) pause_button.connect("clicked", self.interrupt) continue_button = Gtk.Button(_("Continue")) continue_button.connect("clicked", self.resume) copy_button = Gtk.Button(_("Copy")) copy_button.connect("clicked", lambda widget: \ self.gui.pane.pageview.copy_to_clipboard('Person', self.selected_handles)) hbox.pack_start(pause_button, '', '', True) hbox.pack_start(copy_button, '', '', True) hbox.pack_start(continue_button, '', '', True) vbox.pack_start(self.gui.textview, '', '', True) vbox.pack_start(hbox, '', '', False) self.gui.get_container_widget().add_with_viewport(vbox) vbox.show_all()
def personrelation1(self, rolepershandle, primpershandle): if rolepershandle: # Relation # For Single Person Events relation_text = "nicht verwandt" rel_calc = get_relationship_calculator(reinit=True, clocale=glocale) relation = rel_calc.get_one_relationship( self.__db, self.__db.get_person_from_handle(primpershandle), self.__db.get_person_from_handle(rolepershandle)) if relation: relation_text = _("%s" % relation) elif self.__db.get_person_from_handle(primpershandle).gramps_id == self.__db.get_person_from_handle(rolepershandle).gramps_id: relation_text = _("IP ") elif (self.showinlaw == 1): inlaw_text = self.inlaw_rel(primpershandle, rolepershandle) relation_text = inlaw_text return (_("%s") % relation_text)
def init(self): self.selected_handles = set() self.relationship_calc = get_relationship_calculator() self.set_tooltip(_("Double-click name for details")) self.set_text(_("No Family Tree loaded.")) self.set_use_markup(True) self.gui.get_container_widget().remove(self.gui.textview) vbox = Gtk.VBox() hbox = Gtk.HBox() pause_button = Gtk.Button(_("Pause")) pause_button.connect("clicked", self.interrupt) continue_button = Gtk.Button(_("Continue")) continue_button.connect("clicked", self.resume) copy_button = Gtk.Button(_("Copy")) copy_button.connect("clicked", lambda widget: \ self.gui.pane.pageview.copy_to_clipboard('Person', self.selected_handles)) hbox.pack_start(pause_button, '', '', True) hbox.pack_start(copy_button, '', '', True) hbox.pack_start(continue_button, '', '', True) vbox.pack_start(self.gui.textview, '', '', True) vbox.pack_start(hbox, '', '', False) self.gui.get_container_widget().add_with_viewport(vbox) vbox.show_all()
def set_relationship_class(self): """method that rebinds the relationship to the current rel calc Should be called after load or reload of plugins """ self.relationship = get_relationship_calculator(reinit=True)
""" from gramps.gen.simple import SimpleAccess, SimpleDoc from gramps.gui.plug.quick import QuickTable from gramps.gen.const import GRAMPS_LOCALE as glocale from gramps.gen.lib.date import Today from gramps.gen.relationship import get_relationship_calculator from gramps.gen.utils.db import get_birth_or_fallback, get_death_or_fallback import gramps.gen.lib try: _trans = glocale.get_addon_translator(__file__) except ValueError: _trans = glocale.translation _ = _trans.gettext rel_calc = get_relationship_calculator() def levelname(inlaw, level): if level == 1: if not inlaw: return _("Parents") else: return _("Inlaw Parents") elif level == 2: if not inlaw: return _("Grandparents") else: return _("Inlaw Grandparents") elif level == 3: if not inlaw: return _("Great grandparents")
def __init__(self, dbstate, user, options_class, name, callback=None): uistate = user.uistate """ Relationship calculator class. """ tool.Tool.__init__(self, dbstate, options_class, name) ManagedWindow.__init__(self,uistate,[],self.__class__) #set the columns to see for data in BasePersonView.CONFIGSETTINGS: if data[0] == 'columns.rank': colord = data[1] elif data[0] == 'columns.visible': colvis = data[1] elif data[0] == 'columns.size': colsize = data[1] self.colord = [] for col, size in zip(colord, colsize): if col in colvis: self.colord.append((1, col, size)) else: self.colord.append((0, col, size)) self.dbstate = dbstate self.relationship = get_relationship_calculator(glocale) self.relationship.connect_db_signals(dbstate) self.glade = Glade() self.person = self.db.get_person_from_handle( uistate.get_active('Person')) name = '' if self.person: name = name_displayer.display(self.person) self.title = _('Relationship calculator: %(person_name)s' ) % {'person_name' : name} window = self.glade.toplevel self.titlelabel = self.glade.get_object('title') self.set_window(window, self.titlelabel, _('Relationship to %(person_name)s' ) % {'person_name' : name}, self.title) self.setup_configs('interface.relcalc', 600, 400) self.tree = self.glade.get_object("peopleList") self.text = self.glade.get_object("text1") self.textbuffer = Gtk.TextBuffer() self.text.set_buffer(self.textbuffer) self.model = PersonTreeModel(self.db, uistate) self.tree.set_model(self.model) self.tree.connect('key-press-event', self._key_press) self.selection = self.tree.get_selection() self.selection.set_mode(Gtk.SelectionMode.SINGLE) #keep reference of column so garbage collection works self.columns = [] for pair in self.colord: if not pair[0]: continue name = column_names[pair[1]] column = Gtk.TreeViewColumn(name, Gtk.CellRendererText(), markup=pair[1]) column.set_resizable(True) column.set_min_width(60) column.set_sizing(Gtk.TreeViewColumnSizing.GROW_ONLY) self.tree.append_column(column) #keep reference of column so garbage collection works self.columns.append(column) self.sel = self.tree.get_selection() self.changedkey = self.sel.connect('changed',self.on_apply_clicked) self.closebtn = self.glade.get_object("button5") self.closebtn.connect('clicked', self.close) if not self.person: self.window.hide() ErrorDialog(_('Active person has not been set'), _('You must select an active person for this ' 'tool to work properly.'), parent=uistate.window) self.close() return self.show()
def __init__(self, database, options, user): """ Create RelGraphReport 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. filter - Filter to be applied to the people of the database. The option class carries its number, and the function returning the list of filters. arrow - Arrow styles for heads and tails. showfamily - Whether to show family nodes. inc_id - Whether to include IDs. url - Whether to include URLs. inclimg - Include images or not imgpos - Image position, above/beside name color - Whether to use outline, colored outline or filled color in graph color_males - Colour to apply to males color_females - Colour to apply to females color_unknown - Colour to apply to unknown genders color_families - Colour to apply to families dashed - Whether to use dashed lines for non-birth relationships use_roundedcorners - Whether to use rounded corners for females name_format - Preferred format to display names incl_private - Whether to include private data event_choice - Whether to include dates and/or places occupation - Whether to include occupations 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 get_option_by_name = options.menu.get_option_by_name get_value = lambda name: get_option_by_name(name).get_value() 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) self._db = self.database self.includeid = get_value('inc_id') self.includeurl = get_value('url') self.includeimg = get_value('includeImages') self.imgpos = get_value('imageOnTheSide') self.use_roundedcorners = get_value('useroundedcorners') self.adoptionsdashed = get_value('dashed') self.show_families = get_value('showfamily') self.use_subgraphs = get_value('usesubgraphs') self.event_choice = get_value('event_choice') self.occupation = get_value('occupation') self.use_html_output = False self.colorize = get_value('color') color_males = get_value('colormales') color_females = get_value('colorfemales') color_unknown = get_value('colorunknown') color_families = get_value('colorfamilies') self.colors = { 'male': color_males, 'female': color_females, 'unknown': color_unknown, 'family': color_families } arrow_str = get_value('arrow') if 'd' in arrow_str: self.arrowheadstyle = 'normal' else: self.arrowheadstyle = 'none' if 'a' in arrow_str: self.arrowtailstyle = 'normal' else: self.arrowtailstyle = 'none' filter_option = get_option_by_name('filter') self._filter = filter_option.get_filter() stdoptions.run_name_format_option(self, menu) pid = get_value('pid') self.center_person = self._db.get_person_from_gramps_id(pid) if self.center_person is None: raise ReportError(_("Person %s is not in the Database") % pid) 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 __calc_person_key(self, person): """ The person key is a unique identifier that is built from the relationship to the default person. It consists of the "Ahnentafel" number of the common ancestor of the person with the default person, and then a letter representing the child number for each generation from the common ancestor to the person. If more than one common ancestor exists, the common ancestor with the lowest "Ahnentafel" number has precedence. For example, the second child of the third child of the father of the mother of the central person gets the person key "6cb". """ relationship = get_relationship_calculator() default_person = self.database.get_default_person() # No home person set. if default_person is None: return (-1, 0, "") # First try direct relationship. spousestring = "" info, msg = relationship.get_relationship_distance_new(self.database, default_person, person, all_dist=True) info = relationship.collapse_relations(info)[0] (rank, ancestor_handle, default_rel, default_fam, person_rel, person_fam) = info # Then try relationship to any spouse. if rank == -1: index = 0 for family_handle in default_person.get_family_handle_list(): index += 1 family = self.database.get_family_from_handle(family_handle) spouse_handle = utils.find_spouse(default_person, family) spouse = self.database.get_person_from_handle(spouse_handle) info, msg = relationship.get_relationship_distance_new( self.database, spouse, person, all_dist=True) info = relationship.collapse_relations(info)[0] (rank, ancestor_handle, default_rel, default_fam, person_rel, person_fam) = info if rank != -1: spousestring = utils.roman(index) break # If no relationship found at all, exit here. if rank == -1: return (rank, 0, "") # Calculate Ahnentafel number of common ancestor. ahnentafel = 1 for rel in default_rel: ahnentafel *= 2 if rel in (relationship.REL_MOTHER, relationship.REL_MOTHER_NOTBIRTH): ahnentafel += 1 # Find out child letters. child = person childletters = "" for rel in person_rel: family_handle = child.get_main_parents_family_handle() family = self.database.get_family_from_handle(family_handle) if rel in (relationship.REL_MOTHER, relationship.REL_MOTHER_NOTBIRTH): parent_handle = family.get_mother_handle() else: parent_handle = family.get_father_handle() parent = self.database.get_person_from_handle(parent_handle) # Count *all* children from this parent childletter = "?" index = 0 for family_handle in parent.get_family_handle_list(): family = self.database.get_family_from_handle(family_handle) for child_ref in family.get_child_ref_list(): if child_ref.ref == child.get_handle(): childletter = string.ascii_lowercase[index] break index += 1 else: continue break childletters = childletter + childletters child = parent return (rank, ahnentafel, "%s%s%s" % (spousestring, ahnentafel, childletters))
def persontable(self, liste, Fam, primarypersonhandle, primarypersonAhandle, primarypersonBhandle): if len(liste)>0: self.doc.start_table("EventTable", "SRC-EventTable") column_titles = [_("Person"), _("ID"), _("Role"),_("Relation")] self.doc.start_row() for title in column_titles: self.doc.start_cell("SRC-TableColumn") self.doc.start_paragraph("SRC-ColumnTitle") self.doc.write_text(title) self.doc.end_paragraph() self.doc.end_cell() self.doc.end_row() for (a,b) in liste: self.doc.start_row() self.doc.start_cell("SRC-Cell") self.doc.start_paragraph("SRC-SourceDetails") self.doc.write_text(_("%s") % self.__db.get_person_from_handle(b).primary_name.get_name()) self.doc.end_paragraph() self.doc.end_cell() self.doc.start_cell("SRC-Cell") self.doc.start_paragraph("SRC-SourceDetails") self.doc.write_text(_("%s") % self.__db.get_person_from_handle(b).gramps_id) self.doc.end_paragraph() self.doc.end_cell() self.doc.start_cell("SRC-Cell") self.doc.start_paragraph("SRC-SourceDetails") self.doc.write_text(_("%s") % a) self.doc.end_paragraph() self.doc.end_cell() # Relation # For Single Person Events if Fam == 0: relation_text = "nicht verwandt" self.doc.start_cell("SRC-Cell") self.doc.start_paragraph("SRC-SourceDetails") rel_calc = get_relationship_calculator() relation = rel_calc.get_one_relationship( self.__db, self.__db.get_person_from_handle(primarypersonhandle), self.__db.get_person_from_handle(b)) if relation: relation_text = _("%s" % relation) elif self.__db.get_person_from_handle(primarypersonhandle).gramps_id == self.__db.get_person_from_handle(b).gramps_id: relation_text = _("IP ") #################### # Relation # For Family Events if Fam == 1: relation_text = "nicht verwandt" relation_textA = "" relation_textB = "" self.doc.start_cell("SRC-Cell") self.doc.start_paragraph("SRC-SourceDetails") rel_calc = get_relationship_calculator() relationA = rel_calc.get_one_relationship( self.__db, self.__db.get_person_from_handle(primarypersonAhandle), self.__db.get_person_from_handle(b)) if relationA: relation_textA = _("To groom: %s" % relationA) elif self.__db.get_person_from_handle(primarypersonAhandle).gramps_id == self.__db.get_person_from_handle(b).gramps_id: relation_text = _("IP ") rel_calc = get_relationship_calculator() relationB = rel_calc.get_one_relationship( self.__db, self.__db.get_person_from_handle(primarypersonBhandle), self.__db.get_person_from_handle(b)) if relationB: relation_textB = _("To bride: %s" % relationB) elif self.__db.get_person_from_handle(primarypersonBhandle).gramps_id == self.__db.get_person_from_handle(b).gramps_id: relation_text = _("IP ") # relation_textF = relation_textA + relation_textB if (relation_textA + relation_textB) !="": relation_text = relation_textA + relation_textB ##################### self.doc.write_text(_("%s") % relation_text) self.doc.end_paragraph() self.doc.end_cell() self.doc.end_row() self.doc.end_table()
def personrelation(self, Fam, rolepershandle, primpershandle, primpersAhandle, primpersBhandle, inlaw): if rolepershandle: # Relation # For Single Person Events if Fam == 0: relation_text = "nicht verwandt" # self.doc.start_cell("SRC-Cell") # self.doc.start_paragraph("SRC-SourceDetails") #p rel_calc = Relationship.get_relationship_calculator() rel_calc = get_relationship_calculator() relation = rel_calc.get_one_relationship( self.__db, self.__db.get_person_from_handle(primpershandle), self.__db.get_person_from_handle(rolepershandle)) if relation: relation_text = _("%s" % relation) elif self.__db.get_person_from_handle( primpershandle ).gramps_id == self.__db.get_person_from_handle( rolepershandle).gramps_id: relation_text = _("IP ") elif (self.showinlaw == 1) and (Fam == 0): inlaw_text = self.inlaw_rel(primpershandle, rolepershandle) relation_text = inlaw_text return (_("%s") % relation_text) # Relation # For Family Events if Fam == 1: relation_text = "nicht verwandt" relation_textA = "" relation_textB = "" #p rel_calc = Relationship.get_relationship_calculator() rel_calc = get_relationship_calculator() relationA = rel_calc.get_one_relationship( self.__db, self.__db.get_person_from_handle(primpersAhandle), self.__db.get_person_from_handle(rolepershandle)) if relationA: relation_textA = _("To bride: %s" % relationA) elif self.__db.get_person_from_handle( primpersAhandle ).gramps_id == self.__db.get_person_from_handle( rolepershandle).gramps_id: relation_text = _("IP ") #p rel_calc = Relationship.get_relationship_calculator() rel_calc = get_relationship_calculator() relationB = rel_calc.get_one_relationship( self.__db, self.__db.get_person_from_handle(primpersBhandle), self.__db.get_person_from_handle(rolepershandle)) if relationB: relation_textB = _("To groom: %s" % relationB) elif self.__db.get_person_from_handle( primpersBhandle ).gramps_id == self.__db.get_person_from_handle( rolepershandle).gramps_id: relation_text = _("IP ") if (relation_textA + relation_textB) != "": relation_text = relation_textA + " " + relation_textB # relation_text = relation_text + str(primpersAhandle)+ " " + str(primpersBhandle) + " " + str(rolepershandle) if self.showinlaw == 0: return (_("%s") % relation_text)
def run(database, document, person): sdoc = SimpleDoc(document) name = gramps.gen.display.name.displayer.display(person) death_date = _get_date(database, person.get_death_ref()) sdoc.title(_("Number of %s's descendants") % name) sdoc.paragraph("") total = [] seen = [] outlived = [] alive = [] handles = [] _count_descendants(database, person, death_date, 0, total, seen, outlived, alive, handles) # Bring all lists to the same length. No list can be longer than "total". while len(seen) < len(total): seen.append(0) while len(outlived) < len(total): outlived.append(0) while len(alive) < len(total): alive.append(0) rel_calc = get_relationship_calculator() stab = QuickTable(document) if death_date: stab.columns( _("Generation"), _("Total"), _("Seen"), _("Outlived"), _("Now alive")) else: stab.columns( _("Generation"), _("Total"), _("Now alive")) n = 0 for (a, b, c, d, h) in zip(total, seen, outlived, alive, handles): n += 1 generation = rel_calc.get_plural_relationship_string(0, n) if death_date: # stab.row([generation, "PersonList"] + h, a, b, c, d) # Needs 3.2 stab.row(generation, a, b, c, d) else: # stab.row([generation, "PersonList"] + h, a, d) # Needs 3.2 stab.row(generation, a, d) stab.row_sort_val(0, n) if death_date: # stab.row([_("Total"), "PersonList"] + sum(handles, []), # Needs 3.2 stab.row(_("Total"), sum(total), sum(seen), sum(outlived), sum(alive)) else: # stab.row([_("Total"), "PersonList"] + sum(handles, []), # Needs 3.2 stab.row(_("Total"), sum(total), sum(alive)) stab.row_sort_val(0, n + 1) stab.write(sdoc) if death_date: sdoc.paragraph(_("Seen = number of descendants whose birth %s has " "lived to see") % name) sdoc.paragraph(_("Outlived = number of descendants who died while %s " "was still alive") % name)
def __init__(self, database, options, user): """ Create RelGraphReport 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. filter - Filter to be applied to the people of the database. The option class carries its number, and the function returning the list of filters. arrow - Arrow styles for heads and tails. showfamily - Whether to show family nodes. incid - Whether to include IDs. url - Whether to include URLs. inclimg - Include images or not imgpos - Image position, above/beside name color - Whether to use outline, colored outline or filled color in graph color_males - Colour to apply to males color_females - Colour to apply to females color_unknown - Colour to apply to unknown genders color_families - Colour to apply to families dashed - Whether to use dashed lines for non-birth relationships use_roundedcorners - Whether to use rounded corners for females name_format - Preferred format to display names incl_private - Whether to include private data event_choice - Whether to include dates and/or places occupation - Whether to include occupations 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 get_option_by_name = options.menu.get_option_by_name get_value = lambda name: get_option_by_name(name).get_value() lang = menu.get_option_by_name('trans').get_value() self._locale = self.set_locale(lang) stdoptions.run_private_data_option(self, menu) stdoptions.run_living_people_option(self, menu, self._locale) self._db = self.database self.includeid = get_value('incid') self.includeurl = get_value('url') self.includeimg = get_value('includeImages') self.imgpos = get_value('imageOnTheSide') self.use_roundedcorners = get_value('useroundedcorners') self.adoptionsdashed = get_value('dashed') self.show_families = get_value('showfamily') self.use_subgraphs = get_value('usesubgraphs') self.event_choice = get_value('event_choice') self.occupation = get_value('occupation') self.use_html_output = False self.colorize = get_value('color') color_males = get_value('colormales') color_females = get_value('colorfemales') color_unknown = get_value('colorunknown') color_families = get_value('colorfamilies') self.colors = { 'male': color_males, 'female': color_females, 'unknown': color_unknown, 'family': color_families } arrow_str = get_value('arrow') if 'd' in arrow_str: self.arrowheadstyle = 'normal' else: self.arrowheadstyle = 'none' if 'a' in arrow_str: self.arrowtailstyle = 'normal' else: self.arrowtailstyle = 'none' filter_option = get_option_by_name('filter') self._filter = filter_option.get_filter() stdoptions.run_name_format_option(self, menu) pid = get_value('pid') self.center_person = self._db.get_person_from_gramps_id(pid) 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 __init__(self, dbstate, user, options_class, name, callback=None): uistate = user.uistate self.label = _("Relation and distances with root") self.dbstate = dbstate FilterClass = GenericFilterFactory('Person') self.path = '.' filter = FilterClass() tool.Tool.__init__(self, dbstate, options_class, name) if uistate: window = Gtk.Window() window.set_default_size(880, 600) box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=0) window.add(box) # dirty work-around for Gtk.HeaderBar() and FolderChooser chooser = Gtk.FileChooserDialog( _("Folder Chooser"), parent=uistate.window, action=Gtk.FileChooserAction.SELECT_FOLDER, buttons=(_('_Cancel'), Gtk.ResponseType.CANCEL, _('_Select'), Gtk.ResponseType.OK)) chooser.set_tooltip_text(_("Please, select a folder")) status = chooser.run() if status == Gtk.ResponseType.OK: # work-around 'IsADirectoryError' with self() # TypeError: invalid file: gi.FunctionInfo() self.path = chooser.get_current_folder() chooser.destroy() ManagedWindow.__init__(self, uistate, [], self.__class__) self.titles = [ (_('Rel_id'), 0, 40, INTEGER), # would be INTEGER (_('Relation'), 1, 300, str), (_('Name'), 2, 200, str), (_('up'), 3, 35, INTEGER), (_('down'), 4, 35, INTEGER), (_('Common MRA'), 5, 40, INTEGER), (_('Rank'), 6, 40, INTEGER), (_('Period'), 7, 40, str), ] treeview = Gtk.TreeView() model = ListModel(treeview, self.titles) s = Gtk.ScrolledWindow() s.add(treeview) box.pack_start(s, True, True, 0) button = Gtk.Button(label=_("Save")) button.connect("clicked", self.button_clicked) box.pack_end(button, False, True, 0) self.stats_list = [] # behavior can be different according to CPU and generation depth max_level = config.get('behavior.generation-depth') # compact and interlinked tree # single core 2.80 Ghz needs +/- 0.1 second per person if max_level >= 15: var = max_level * 0.01 elif 10 <= max_level < 15: var = max_level * 0.02 else: var = max_level * 0.025 plist = self.dbstate.db.iter_person_handles() length = self.dbstate.db.get_number_of_people() default_person = self.dbstate.db.get_default_person() if uistate: self.progress = ProgressMeter(self.label, can_cancel=True, parent=window) else: self.progress = ProgressMeter(self.label) if default_person: # rather designed for run via GUI... root_id = default_person.get_gramps_id() ancestors = rules.person.IsAncestorOf([str(root_id), True]) descendants = rules.person.IsDescendantOf([str(root_id), True]) related = rules.person.IsRelatedWith([str(root_id)]) # filtering people can be useful on some large data set # counter on filtering pass was not efficient # Not the proper solution, but a lazy one providing expected message filter.add_rule(related) self.progress.set_pass(_('Please wait, filtering...')) filtered_list = filter.apply(self.dbstate.db, plist) relationship = get_relationship_calculator() else: # TODO: provide selection widget for CLI and GUI WarningDialog(_("No default_person")) return count = 0 filtered_people = len(filtered_list) self.progress.set_pass(_('Generating relation map...'), filtered_people) if self.progress.get_cancelled(): self.progress.close() return step_one = time.clock() # init for counters for handle in filtered_list: nb = len(self.stats_list) count += 1 self.progress.step() step_two = time.clock() start = 99 if count > start: # provide a basic interface for counters need = (step_two - step_one) / count wait = need * filtered_people remain = int(wait) - int(step_two - step_one) # sorry, lazy header = _("%d/%d \n %d/%d seconds \n %d/%d \n%f|\t%f" % (count, filtered_people, remain, int(wait), nb, length, float(need), float(var))) self.progress.set_header(header) if self.progress.get_cancelled(): self.progress.close() return person = dbstate.db.get_person_from_handle(handle) timeout_one = time.clock() # for delta and timeout estimations dist = relationship.get_relationship_distance_new(dbstate.db, default_person, person, only_birth=True) timeout_two = time.clock() rank = dist[0][0] if rank == -1 or rank > max_level: # not related and ignored people continue limit = timeout_two - timeout_one expect = (limit - var) / max_level if limit > var: n = name_displayer.display(person) _LOG.debug("Sorry! '{0}' needs {1} second, \ variation = '{2}'".format(n, limit, expect)) continue else: _LOG.debug("variation = '{}'".format( limit)) # delta, see above max_level 'wall' section rel = relationship.get_one_relationship( dbstate.db, default_person, person) rel_a = dist[0][2] Ga = len(rel_a) rel_b = dist[0][4] Gb = len(rel_b) mra = 1 # m: mother; f: father if Ga > 0: for letter in rel_a: if letter == 'm': mra = mra * 2 + 1 if letter == 'f': mra = mra * 2 # design: mra gender will be often female (m: mother) if rel_a[-1] == "f" and Gb != 0: # male gender, look at spouse mra = mra + 1 name = name_displayer.display(person) # pseudo privacy; sample for DNA stuff and mapping import hashlib no_name = hashlib.sha384(name.encode() + handle.encode()).hexdigest() _LOG.info(no_name) # own internal password via handle kekule = number.get_number(Ga, Gb, rel_a, rel_b) # workaround - possible unique ID and common numbers uuid = str(uuid4()) _LOG.info("Random UUID: {}".format(uuid)) if kekule == "u": # TODO: cousin(e)s need a key kekule = 0 if kekule == "nb": # non-birth kekule = -1 try: test = int(kekule) except: # 1: related to mother; 0.x : no more girls lineage kekule = 1 period = get_timeperiod(self.dbstate.db, handle) # sometimes 'iterator' (generator) is more faster #handle_list = map(handle, filtered_list) iterator = (handle for handle in filtered_list) # experimentations; not used yet new_list = [int(kekule), int(Ga), int(Gb), int(mra), int(rank)] line = (iterator, array('b', new_list)) self.stats_list.append( (int(kekule), rel, name, int(Ga), int(Gb), int(mra), int(rank), str(period))) self.progress.close() from itertools import groupby for key, items in groupby(self.stats_list, lambda x: x[0]): for subitem in items: _LOG.info(subitem) _LOG.debug("total: {}".format(nb)) for entry in self.stats_list: if uistate: model.add(entry, entry[0]) else: print(entry) if uistate: window.show() self.set_window(window, None, self.label) self.show()
def __init__(self, dbstate, user, options_class, name, callback=None): uistate = user.uistate self.label = _("Relation and distances with root") self.dbstate = dbstate FilterClass = GenericFilterFactory('Person') self.path = '.' filter = FilterClass() tool.Tool.__init__(self, dbstate, options_class, name) if uistate: window = Gtk.Window() window.set_default_size(880, 600) box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=0) window.add(box) # dirty work-around for Gtk.HeaderBar() and FolderChooser chooser = Gtk.FileChooserDialog(_("Folder Chooser"), parent=uistate.window, action=Gtk.FileChooserAction.SELECT_FOLDER, buttons=(_('_Cancel'), Gtk.ResponseType.CANCEL, _('_Select'), Gtk.ResponseType.OK)) chooser.set_tooltip_text(_("Please, select a folder")) status = chooser.run() if status == Gtk.ResponseType.OK: # work-around 'IsADirectoryError' with self() # TypeError: invalid file: gi.FunctionInfo() self.path = chooser.get_current_folder() chooser.destroy() ManagedWindow.__init__(self, uistate, [], self.__class__) self.titles = [ (_('Rel_id'), 0, 40, INTEGER), # would be INTEGER (_('Relation'), 1, 300, str), (_('Name'), 2, 200, str), (_('up'), 3, 35, INTEGER), (_('down'), 4, 35, INTEGER), (_('Common MRA'), 5, 40, INTEGER), (_('Rank'), 6, 40, INTEGER), (_('Period'), 7, 40, str), ] treeview = Gtk.TreeView() model = ListModel(treeview, self.titles) s = Gtk.ScrolledWindow() s.add(treeview) box.pack_start(s, True, True, 0) button = Gtk.Button(label=_("Save")) button.connect("clicked", self.button_clicked) box.pack_end(button, False, True, 0) self.stats_list = [] # behavior can be different according to CPU and generation depth max_level = config.get('behavior.generation-depth') # compact and interlinked tree # single core 2.80 Ghz needs +/- 0.1 second per person if max_level >= 15: var = max_level * 0.01 elif 10 <= max_level < 15: var = max_level * 0.02 else: var = max_level * 0.025 plist = self.dbstate.db.iter_person_handles() length = self.dbstate.db.get_number_of_people() default_person = self.dbstate.db.get_default_person() if uistate: self.progress = ProgressMeter(self.label, can_cancel=True, parent=window) else: self.progress = ProgressMeter(self.label) if default_person: # rather designed for run via GUI... root_id = default_person.get_gramps_id() ancestors = rules.person.IsAncestorOf([str(root_id), True]) descendants = rules.person.IsDescendantOf([str(root_id), True]) related = rules.person.IsRelatedWith([str(root_id)]) # filtering people can be useful on some large data set # counter on filtering pass was not efficient # Not the proper solution, but a lazy one providing expected message filter.add_rule(related) self.progress.set_pass(_('Please wait, filtering...')) filtered_list = filter.apply(self.dbstate.db, plist) relationship = get_relationship_calculator() else: # TODO: provide selection widget for CLI and GUI WarningDialog(_("No default_person")) return count = 0 filtered_people = len(filtered_list) self.progress.set_pass(_('Generating relation map...'), filtered_people) if self.progress.get_cancelled(): self.progress.close() return step_one = time.clock() # init for counters for handle in filtered_list: nb = len(self.stats_list) count += 1 self.progress.step() step_two = time.clock() start = 99 if count > start: # provide a basic interface for counters need = (step_two - step_one) / count wait = need * filtered_people remain = int(wait) - int(step_two - step_one) # sorry, lazy header = _("%d/%d \n %d/%d seconds \n %d/%d \n%f|\t%f" % (count, filtered_people, remain, int(wait), nb, length, float(need), float(var)) ) self.progress.set_header(header) if self.progress.get_cancelled(): self.progress.close() return person = dbstate.db.get_person_from_handle(handle) timeout_one = time.clock() # for delta and timeout estimations dist = relationship.get_relationship_distance_new( dbstate.db, default_person, person, only_birth=True) timeout_two = time.clock() rank = dist[0][0] if rank == -1 or rank > max_level: # not related and ignored people continue limit = timeout_two - timeout_one expect = (limit - var) / max_level if limit > var: n = name_displayer.display(person) _LOG.debug("Sorry! '{0}' needs {1} second, \ variation = '{2}'".format(n, limit, expect ) ) continue else: _LOG.debug("variation = '{}'".format(limit)) # delta, see above max_level 'wall' section rel = relationship.get_one_relationship( dbstate.db, default_person, person) rel_a = dist[0][2] Ga = len(rel_a) rel_b = dist[0][4] Gb = len(rel_b) mra = 1 # m: mother; f: father if Ga > 0: for letter in rel_a: if letter == 'm': mra = mra * 2 + 1 if letter == 'f': mra = mra * 2 # design: mra gender will be often female (m: mother) if rel_a[-1] == "f" and Gb != 0: # male gender, look at spouse mra = mra + 1 name = name_displayer.display(person) # pseudo privacy; sample for DNA stuff and mapping import hashlib no_name = hashlib.sha384(name.encode() + handle.encode()).hexdigest() _LOG.info(no_name) # own internal password via handle kekule = number.get_number(Ga, Gb, rel_a, rel_b) # workaround - possible unique ID and common numbers uuid = str(uuid4()) _LOG.info("Random UUID: {}".format(uuid)) if kekule == "u": # TODO: cousin(e)s need a key kekule = 0 if kekule == "nb": # non-birth kekule = -1 try: test = int(kekule) except: # 1: related to mother; 0.x : no more girls lineage kekule = 1 period = get_timeperiod(self.dbstate.db, handle) # sometimes 'iterator' (generator) is more faster #handle_list = map(handle, filtered_list) iterator = (handle for handle in filtered_list) # experimentations; not used yet new_list=[int(kekule), int(Ga), int(Gb), int(mra), int(rank)] if max_level > 7: line = (iterator, array('l', new_list)) else: line = (iterator, array('b', new_list)) self.stats_list.append((int(kekule), rel, name, int(Ga), int(Gb), int(mra), int(rank), str(period))) self.progress.close() from itertools import groupby for key, items in groupby(self.stats_list, lambda x: x[0]): for subitem in items: _LOG.info(subitem) _LOG.debug("total: {}".format(nb)) for entry in self.stats_list: if uistate: model.add(entry, entry[0]) else: print(entry) if uistate: window.show() self.set_window(window, None, self.label) self.show()
def main(self): # Write heading text to gramplet self.set_text(_("Relations of related people in your database:")) # Define basic variables database = self.dbstate.db rel_calc = get_relationship_calculator() family_handle_list = [] # Will keep list of families with no ancestors # Find all base families with no ancestors in the database. flist = database.iter_family_handles() for familyhandle in flist: family = database.get_family_from_handle(familyhandle) # Check if mother of this family is child of another family # If this is the case, skip this family ancestorHandle = family.get_mother_handle() if ancestorHandle: mother = database.get_person_from_handle(ancestorHandle) parent_handle_list = mother.get_parent_family_handle_list() if parent_handle_list: continue # Check if father of this family is child of another family # If this is the case, skip this family ancestorHandle = family.get_father_handle() if ancestorHandle: father = database.get_person_from_handle(ancestorHandle) parent_handle_list = father.get_parent_family_handle_list() if parent_handle_list: continue # Members of this family have no ancestors. Add family to base # family handle list family_handle_list.append(familyhandle) yield True # The base family handle list now contains all families that have # no ancestors. Now iterate through found families. For each family # first find all descendants and then check if one person in this # family tree is partner of another person in the same tree. # # Related relatives may be found more than once from different base # families. Therefore we hold a list of all found pairs to avoid # listing them more than once pair_p1_list = [] # List of all 1st related partners for all families pair_p2_list = [] # List of all 2nd related partners for all families for familyhandle in family_handle_list: # Build list of all related persons (descendants) of this family. self.person_handle_list = [] family = database.get_family_from_handle(familyhandle) # Add all descendants of the father to person list of this family father_handle = family.get_father_handle() if father_handle: father = database.get_person_from_handle(father_handle) # Add all descendants of the father self.addDescendants(father_handle) mother_handle = family.get_mother_handle() # Add all descendants of the mother to person list of this family if mother_handle: mother = database.get_person_from_handle(mother_handle) # Add all descendants of the mother self.addDescendants(mother_handle) # The person list of all descendants for this family is complete. # Now check for every person in the list if it has a partner that # is also in this list for checkHandle in self.person_handle_list: person = database.get_person_from_handle(checkHandle) if person: pfamily_handle_list = person.get_family_handle_list() if pfamily_handle_list: for family_handle in pfamily_handle_list: # Skip the family if it is listed in the base # families list (which should be quite short). if family_handle in family_handle_list: continue # If current person is father or mother in a family # find the handle of the partner family = database.get_family_from_handle( family_handle) father_handle = family.get_father_handle() mother_handle = family.get_mother_handle() if checkHandle == father_handle: handlepartner = mother_handle else: handlepartner = father_handle # If the partner is in our list of persons of this # family tree, both are related. if handlepartner in self.person_handle_list: newEntry = True # Check if this pair is already in the lists of # related partners. A and B will also appear as # B and A. So we have to cross check for ii in range(len(pair_p1_list)): if checkHandle == pair_p1_list[ii]: if handlepartner == pair_p2_list[ii]: newEntry = False if checkHandle == pair_p2_list[ii]: if handlepartner == pair_p1_list[ii]: newEntry = False # If this pair is not yet listed, add them to # the list and show their relationship in the # gramplet window. if newEntry: # Add pair to list of found related relatives pair_p1_list.append(checkHandle) pair_p2_list.append(handlepartner) partner = self.dbstate.db. \ get_person_from_handle(handlepartner) # Find relation between the partners by use # of the relationship calculator. Print all # relationships A to B and B to A. rel_strings, common_an = \ rel_calc.get_all_relationships(database, person, partner) rel_strings1, common_an1 = \ rel_calc.get_all_relationships(database, partner, person) if len(rel_strings) > 1: # Output names of both partners as links p1name = name_displayer.display(person) self.append_text("\n\n") self.link(p1name, 'Person', checkHandle) p2name = name_displayer.display( partner) self.append_text(" " + _("and") + " ") self.link(p2name, 'Person', handlepartner) self.append_text(" " + \ _("are partners and") + \ ":") # Omit the first relationship from list for x in range(1, len(rel_strings)): self.append_text("\n%s" % rel_strings[x]) try: self.append_text( " & %s" % rel_strings1[x]) except: continue # Print list of common ancestors for # the found relation. # Remove duplicate ancestors anc_list = list(set(common_an[x])) for anc in anc_list: person = database. \ get_person_from_handle(anc) if person: # Print ancestor as link pname = name_displayer. \ display(person) self.append_text("\n\t" \ + _("Common ancestor") \ + " ") self.link( pname, 'Person', anc) # After the check for each persons family allow other # threads to do some work. yield True # If the list of related pairs is empty we did not find any related # relatives in the database. if len(pair_p1_list) == 0: self.append_text("\n" + _("No relatives in a relation found") + ".\n") self.append_text("\n\n" + _("END") + "\n") return
def listeventref(self): sc = {'source': 'S_ID', 'citalist': 'C_ID' } stc = {} citation_without_notes = 0 EMPTY = " " def toYear(date): yeartext = date.get_year() return yeartext # build citation list cl cl = [] i=1 for ci in self.__db.iter_citations(): if ci.source_handle in self.source_handles: # sc[ci.source_handle].append(ci.handle) cl.append(ci.handle) # build citations - event dic xy #(a,b): set([('Citation', 'c4a8c46041e08799b17')]) # event: c4a8c4f95b01e38564a event: Taufe #!! # Nur Taufen ! ci = defaultdict(list) for ev in self.__db.iter_events(): if ev.type.is_baptism(): evcithandlelist = ev.get_referenced_citation_handles() for (a,b) in evcithandlelist: if b in cl: ci[b].append(ev.handle) cikeys = ci.keys() # for di in cikeys: # print ((di), di in cl) # print (len(cikeys)) # print ("CITA", len(ci.keys()), len(sc.values()) ) # print ("SOURCE", len(sc.keys()), len(sc.values()), len(sc[0]) ) # build citasource dictionary sc = defaultdict(list) for ci2 in self.__db.iter_citations(): if ci2.handle in cikeys: # print("HALLO ", ci2, ci2.source_handle) sc[ci2.source_handle].append(ci2.handle) sckeys = sc.keys() # for di in sckeys: # print ((di), sc[di]) # print (len(sckeys), len(sc[di])) # build eventpersonrole dictionary # event: c4a8c4f95b01e38564a event: Taufe refhandlelist =[] pedic ={} pedic = defaultdict(set) for pe in self.__db.get_person_handles(): for eventref in self.__db.get_person_from_handle(pe).event_ref_list: # print(eventref, eventref.ref, eventref.get_role(), pe ) # print(eventref.get_role(), pe ) pedic[eventref.ref].add((eventref,pe)) # pedic[eventref.ref].add(eventref.get_role(),pe) #source # skeys = sc.keys() # skeys.sort(key=lambda x:self._formatlocal_source_text(self.__db.get_source_from_handle(x))) # for s in skeys: for s in sorted(sc.keys()): self._user.step_progress() self.doc.start_paragraph("SRC-SourceTitle") self.doc.write_text(self._formatlocal_source_text(self.__db.get_source_from_handle(s))) self.doc.end_paragraph() self.doc.start_paragraph("SRC-SourceDetails") self.doc.write_text(_(" ID: %s") % self.__db.get_source_from_handle(s).gramps_id) self.doc.end_paragraph() # note in sources for sourcenotehandle in self.__db.get_source_from_handle(s).get_note_list(): self.doc.start_paragraph("SRC-NoteDetails") self.doc.write_text(_(" Type: %s") % self.__db.get_note_from_handle(sourcenotehandle).type) self.doc.write_text(_(" N-ID: %s") % self.__db.get_note_from_handle(sourcenotehandle).gramps_id) self.doc.end_paragraph() self.doc.start_paragraph("SRC-NoteText") self.doc.write_text(_(" %s") % self.__db.get_note_from_handle(sourcenotehandle).text) self.doc.end_paragraph() self.doc.start_table("EventTable", "SRC-EventTable") # column_titles = [_("LNr"), _("Source"), _("Date"),_("Person"),_("Parents"), # _("Godparents"),_("Relation")] column_titles = [_("LNr"), _("Source"), _("Date"),_("Person"),_("Parents"), _("Paten"),_("Beziehung")] self.doc.start_row() for title in column_titles: self.doc.start_cell("SRC-TableColumn") self.doc.start_paragraph("SRC-ColumnTitle") self.doc.write_text(title) self.doc.end_paragraph() self.doc.end_cell() self.doc.end_row() i = 1 ckeys = sc[s] ckeys.sort(key=lambda x:self.__db.get_citation_from_handle(x).page) for c in ckeys: # c contains citationhandles self._user.step_progress() self.doc.start_row() self.doc.start_cell("SRC-TableColumn") self.doc.start_paragraph("SRC-SourceDetails") self.doc.write_text(_("%d") % i) self.doc.end_paragraph() self.doc.end_cell() self.doc.start_cell("SRC-TableColumn") self.doc.start_paragraph("SRC-SourceDetails") self.doc.write_text(_(" %s") % self.__db.get_citation_from_handle(c).page) self.doc.end_paragraph() self.doc.end_cell() self.doc.start_cell("SRC-TableColumn") self.doc.start_paragraph("SRC-SourceDetails") self.doc.write_text (_(" %s ") % get_date(self.__db.get_citation_from_handle(c))) self.doc.end_paragraph() self.doc.end_cell() self.doc.start_cell("SRC-TableColumn") self.doc.start_paragraph("SRC-SourceDetails") for e in ci[c]: event = self.__db.get_event_from_handle(e) for (a,b) in pedic[e]: if a.get_role().is_primary(): self.doc.write_text(_("%s") % event.get_type()) self.doc.write_text(_(" ( %s )") % event.gramps_id) self.doc.write_text(_(" %s") % self.__db.get_person_from_handle(b).primary_name.get_name()) primarypersonhandle = b liste = pedic[e].copy() self.doc.end_paragraph() self.doc.end_cell() self.doc.start_cell("SRC-TableColumn") self.doc.start_paragraph("SRC-SourceDetails") #Eltern und Ort family_handle = self.__db.get_person_from_handle(primarypersonhandle).get_main_parents_family_handle() if family_handle: fh = self.__db.get_family_from_handle(family_handle).father_handle if fh: self.doc.write_text (_("%s ") % self.__db.get_person_from_handle(fh).primary_name.get_name()) self.doc.end_paragraph() self.doc.start_paragraph("SRC-SourceDetails") mh = self.__db.get_family_from_handle(family_handle).mother_handle if mh: self.doc.write_text (_("%s ") % self.__db.get_person_from_handle(mh).primary_name.get_name()) place = '' place_handle = event.get_place_handle() if place_handle: place = place_displayer.display_event(self.database, event) # self.doc.write_text(_(" from %s") % # place) self.doc.write_text(_(" von %s") % place) self.doc.end_paragraph() self.doc.end_cell() self.doc.start_cell("SRC-TableColumn") for e in ci[c]: for (a,b) in pedic[e]: if not a.get_role().is_primary(): self.doc.start_paragraph("SRC-SourceDetails") relation_text = "n.v." rel_calc = get_relationship_calculator() relation = rel_calc.get_one_relationship( self.__db, self.__db.get_person_from_handle(primarypersonhandle), self.__db.get_person_from_handle(b)) if relation: relation_text = _("%s" % relation) self.doc.write_text(_(" %s") % self.__db.get_person_from_handle(b).primary_name.get_name()) self.doc.write_text(_(" ( %s )") % relation_text) self.doc.end_paragraph() self.doc.end_cell() self.doc.start_cell("SRC-TableColumn") # note in citations for notehandle in self.__db.get_citation_from_handle(c).get_note_list(): self._user.step_progress() self.doc.start_paragraph("SRC-NoteText") self.doc.write_text(_(" %s") % self.__db.get_note_from_handle(notehandle).text) self.doc.end_paragraph() self.doc.end_cell() self.doc.end_row() i += 1 self.doc.end_table()
def set_relationship_class(self): """method that rebinds the relationship to the current rel calc Should be called after load or reload of plugins """ self.relationship = get_relationship_calculator(reinit=True)
def __init__(self, database, options, user): """ Create RelGraphReport 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. filter - Filter to be applied to the people of the database. The option class carries its number, and the function returning the list of filters. arrow - Arrow styles for heads and tails. showfamily - Whether to show family nodes. incid - Whether to include IDs. incdate - Whether to include dates. justyears - Use years only. use_place - Whether to replace missing dates with place url - Whether to include URLs. inclimg - Include images or not imgpos - Image position, above/beside name color - Whether to use outline, colored outline or filled color in graph color_males - Colour to apply to males color_females - Colour to apply to females color_unknown - Colour to apply to unknown genders color_families - Colour to apply to families dashed - Whether to use dashed lines for non-birth relationships use_roundedcorners - Whether to use rounded corners for females """ Report.__init__(self, database, options, user) self.database = database menu = options.menu get_option_by_name = options.menu.get_option_by_name get_value = lambda name: get_option_by_name(name).get_value() self.includeid = get_value('incid') self.includedates = get_value('incdate') self.includeurl = get_value('url') self.includeimg = get_value('includeImages') self.imgpos = get_value('imageOnTheSide') self.use_roundedcorners = get_value('useroundedcorners') self.adoptionsdashed = get_value('dashed') self.show_families = get_value('showfamily') self.just_years = get_value('justyears') self.use_place = get_value('use_place') self.use_subgraphs = get_value('usesubgraphs') self.colorize = get_value('color') color_males = get_value('colormales') color_females = get_value('colorfemales') color_unknown = get_value('colorunknown') color_families = get_value('colorfamilies') self.colors = { 'male': color_males, 'female': color_females, 'unknown': color_unknown, 'family': color_families } arrow_str = get_value('arrow') if 'd' in arrow_str: self.arrowheadstyle = 'normal' else: self.arrowheadstyle = 'none' if 'a' in arrow_str: self.arrowtailstyle = 'normal' else: self.arrowtailstyle = 'none' filter_option = get_option_by_name('filter') self._filter = filter_option.get_filter() lang = menu.get_option_by_name('trans').get_value() self._locale = self.set_locale(lang) name_format = menu.get_option_by_name("name_format").get_value() if name_format != 0: self._name_display.set_default_format(name_format) self.center_person = database.get_person_from_gramps_id( get_value('pid')) 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 main(self): # Write heading text to gramplet self.set_text(_("Relations of related people in your database:")) # Define basic variables database = self.dbstate.db rel_calc = get_relationship_calculator() family_handle_list = [] # Will keep list of families with no ancestors # Find all base families with no ancestors in the database. flist = database.iter_family_handles() for familyhandle in flist: family = database.get_family_from_handle(familyhandle) # Check if mother of this family is child of another family # If this is the case, skip this family ancestorHandle = family.get_mother_handle() if ancestorHandle: mother = database.get_person_from_handle(ancestorHandle) parent_handle_list = mother.get_parent_family_handle_list() if parent_handle_list: continue # Check if father of this family is child of another family # If this is the case, skip this family ancestorHandle = family.get_father_handle() if ancestorHandle: father = database.get_person_from_handle(ancestorHandle) parent_handle_list = father.get_parent_family_handle_list() if parent_handle_list: continue # Members of this family have no ancestors. Add family to base # family handle list family_handle_list.append(familyhandle) yield True # The base family handle list now contains all families that have # no ancestors. Now iterate through found families. For each family # first find all descendants and then check if one person in this # family tree is partner of another person in the same tree. # # Related relatives may be found more than once from different base # families. Therefore we hold a list of all found pairs to avoid # listing them more than once pair_p1_list = [] # List of all 1st related partners for all families pair_p2_list = [] # List of all 2nd related partners for all families for familyhandle in family_handle_list: # Build list of all related persons (descendants) of this family. self.person_handle_list = [] family = database.get_family_from_handle(familyhandle) # Add all descendants of the father to person list of this family father_handle = family.get_father_handle() if father_handle: father = database.get_person_from_handle(father_handle) # Add all descendants of the father self.addDescendants(father_handle) mother_handle = family.get_mother_handle() # Add all descendants of the mother to person list of this family if mother_handle: mother = database.get_person_from_handle(mother_handle) # Add all descendants of the mother self.addDescendants(mother_handle) # The person list of all descendants for this family is complete. # Now check for every person in the list if it has a partner that # is also in this list for checkHandle in self.person_handle_list: person = database.get_person_from_handle(checkHandle) if person: pfamily_handle_list = person.get_family_handle_list() if pfamily_handle_list: for family_handle in pfamily_handle_list: # Skip the family if it is listed in the base # families list (which should be quite short). if family_handle in family_handle_list: continue # If current person is father or mother in a family # find the handle of the partner family = database.get_family_from_handle(family_handle) father_handle = family.get_father_handle() mother_handle = family.get_mother_handle() if checkHandle == father_handle: handlepartner = mother_handle else: handlepartner = father_handle # If the partner is in our list of persons of this # family tree, both are related. if handlepartner in self.person_handle_list: newEntry = True; # Check if this pair is already in the lists of # related partners. A and B will also appear as # B and A. So we have to cross check for ii in range(len(pair_p1_list)): if checkHandle == pair_p1_list[ii]: if handlepartner == pair_p2_list[ii]: newEntry = False if checkHandle == pair_p2_list[ii]: if handlepartner == pair_p1_list[ii]: newEntry = False # If this pair is not yet listed, add them to # the list and show their relationship in the # gramplet window. if newEntry: # Add pair to list of found related relatives pair_p1_list.append(checkHandle) pair_p2_list.append(handlepartner) partner = self.dbstate.db. \ get_person_from_handle(handlepartner) # Find relation between the partners by use # of the relationship calculator. Print all # relationships A to B and B to A. rel_strings, common_an = \ rel_calc.get_all_relationships(database, person, partner) rel_strings1, common_an1 = \ rel_calc.get_all_relationships(database, partner, person) if len(rel_strings) > 1: # Output names of both partners as links p1name = name_displayer.display(person) self.append_text("\n\n") self.link(p1name, 'Person', checkHandle) p2name = name_displayer.display(partner) self.append_text(" " + _("and") + " ") self.link(p2name, 'Person', handlepartner) self.append_text(" " + \ _("are partners and") + \ ":") # Omit the first relationship from list for x in range(1, len(rel_strings)): self.append_text("\n%s" % rel_strings[x]) try: self.append_text(" & %s" % rel_strings1[x]) except: continue # Print list of common ancestors for # the found relation. # Remove duplicate ancestors anc_list = list(set(common_an[x])) for anc in anc_list: person = database. \ get_person_from_handle(anc) if person: # Print ancestor as link pname = name_displayer. \ display(person) self.append_text("\n\t" \ + _("Common ancestor") \ + " ") self.link(pname, 'Person', anc) # After the check for each persons family allow other # threads to do some work. yield True # If the list of related pairs is empty we did not find any related # relatives in the database. if len(pair_p1_list) == 0: self.append_text("\n" + _("No relatives in a relation found") + ".\n") self.append_text("\n\n" + _("END") + "\n") return
def __init__(self, dbstate, user, options_class, name, callback=None): uistate = user.uistate """ Relationship calculator class. """ tool.Tool.__init__(self, dbstate, options_class, name) ManagedWindow.__init__(self,uistate,[],self.__class__) #set the columns to see for data in BasePersonView.CONFIGSETTINGS: if data[0] == 'columns.rank': colord = data[1] elif data[0] == 'columns.visible': colvis = data[1] elif data[0] == 'columns.size': colsize = data[1] self.colord = [] for col, size in zip(colord, colsize): if col in colvis: self.colord.append((1, col, size)) else: self.colord.append((0, col, size)) self.dbstate = dbstate self.relationship = get_relationship_calculator(glocale) self.relationship.connect_db_signals(dbstate) self.glade = Glade() self.person = self.db.get_person_from_handle( uistate.get_active('Person')) name = '' if self.person: name = name_displayer.display(self.person) self.title = _('Relationship calculator: %(person_name)s' ) % {'person_name' : name} window = self.glade.toplevel self.titlelabel = self.glade.get_object('title') self.set_window(window, self.titlelabel, _('Relationship to %(person_name)s' ) % {'person_name' : name}, self.title) self.setup_configs('interface.relcalc', 600, 400) self.tree = self.glade.get_object("peopleList") self.text = self.glade.get_object("text1") self.textbuffer = Gtk.TextBuffer() self.text.set_buffer(self.textbuffer) self.model = PersonTreeModel(self.db) self.tree.set_model(self.model) self.tree.connect('key-press-event', self._key_press) self.selection = self.tree.get_selection() self.selection.set_mode(Gtk.SelectionMode.SINGLE) #keep reference of column so garbage collection works self.columns = [] for pair in self.colord: if not pair[0]: continue name = column_names[pair[1]] column = Gtk.TreeViewColumn(name, Gtk.CellRendererText(), markup=pair[1]) column.set_resizable(True) column.set_min_width(60) column.set_sizing(Gtk.TreeViewColumnSizing.GROW_ONLY) self.tree.append_column(column) #keep reference of column so garbage collection works self.columns.append(column) self.sel = self.tree.get_selection() self.changedkey = self.sel.connect('changed',self.on_apply_clicked) self.closebtn = self.glade.get_object("button5") self.closebtn.connect('clicked', self.close) if not self.person: self.window.hide() ErrorDialog(_('Active person has not been set'), _('You must select an active person for this ' 'tool to work properly.'), parent=uistate.window) self.close() return self.show()
def __calc_person_key(self, person): """ The person key is a unique identifier that is built from the relationship to the default person. It consists of the "Ahnentafel" number of the common ancestor of the person with the default person, and then a letter representing the child number for each generation from the common ancestor to the person. If more than one common ancestor exists, the common ancestor with the lowest "Ahnentafel" number has precedence. For example, the second child of the third child of the father of the mother of the central person gets the person key "6cb". """ relationship = get_relationship_calculator() default_person = self.database.get_default_person() # No home person set. if default_person is None: return (-1, 0, "") # First try direct relationship. spousestring = "" info, msg = relationship.get_relationship_distance_new(self.database, default_person, person, all_dist=True) info = relationship.collapse_relations(info)[0] (rank, ancestor_handle, default_rel, default_fam, person_rel, person_fam) = info # Then try relationship to any spouse. if rank == -1: index = 0 for family_handle in default_person.get_family_handle_list(): index += 1 family = self.database.get_family_from_handle(family_handle) spouse_handle = utils.find_spouse(default_person, family) spouse = self.database.get_person_from_handle(spouse_handle) info, msg = relationship.get_relationship_distance_new(self.database, spouse, person, all_dist=True) info = relationship.collapse_relations(info)[0] (rank, ancestor_handle, default_rel, default_fam, person_rel, person_fam) = info if rank != -1: spousestring = utils.roman(index) break # If no relationship found at all, exit here. if rank == -1: return (rank, 0, "") # Calculate Ahnentafel number of common ancestor. ahnentafel = 1 for rel in default_rel: ahnentafel *= 2 if rel in (relationship.REL_MOTHER, relationship.REL_MOTHER_NOTBIRTH): ahnentafel += 1 # Find out child letters. child = person childletters = "" for rel in person_rel: family_handle = child.get_main_parents_family_handle() family = self.database.get_family_from_handle(family_handle) if rel in (relationship.REL_MOTHER, relationship.REL_MOTHER_NOTBIRTH): parent_handle = family.get_mother_handle() else: parent_handle = family.get_father_handle() parent = self.database.get_person_from_handle(parent_handle) # Count *all* children from this parent childletter = "?" index = 0 for family_handle in parent.get_family_handle_list(): family = self.database.get_family_from_handle(family_handle) for child_ref in family.get_child_ref_list(): if child_ref.ref == child.get_handle(): childletter = string.ascii_lowercase[index] break index += 1 else: continue break childletters = childletter + childletters child = parent return (rank, ahnentafel, "%s%s%s" % (spousestring, ahnentafel, childletters))
def persontable(self, liste, Fam, primarypersonhandle, primarypersonAhandle, primarypersonBhandle): if len(liste) > 0: self.doc.start_table("EventTable", "SRC-EventTable") column_titles = [_("Person"), _("ID"), _("Role"), _("Relation")] self.doc.start_row() for title in column_titles: self.doc.start_cell("SRC-TableColumn") self.doc.start_paragraph("SRC-ColumnTitle") self.doc.write_text(title) self.doc.end_paragraph() self.doc.end_cell() self.doc.end_row() for (a, b) in liste: self.doc.start_row() self.doc.start_cell("SRC-Cell") self.doc.start_paragraph("SRC-SourceDetails") self.doc.write_text( _("%s") % self.__db.get_person_from_handle( b).primary_name.get_name()) self.doc.end_paragraph() self.doc.end_cell() self.doc.start_cell("SRC-Cell") self.doc.start_paragraph("SRC-SourceDetails") self.doc.write_text( _("%s") % self.__db.get_person_from_handle(b).gramps_id) self.doc.end_paragraph() self.doc.end_cell() self.doc.start_cell("SRC-Cell") self.doc.start_paragraph("SRC-SourceDetails") self.doc.write_text(_("%s") % a) self.doc.end_paragraph() self.doc.end_cell() # Relation # For Single Person Events if Fam == 0: relation_text = "nicht verwandt" self.doc.start_cell("SRC-Cell") self.doc.start_paragraph("SRC-SourceDetails") rel_calc = get_relationship_calculator() relation = rel_calc.get_one_relationship( self.__db, self.__db.get_person_from_handle(primarypersonhandle), self.__db.get_person_from_handle(b)) if relation: relation_text = _("%s" % relation) elif self.__db.get_person_from_handle( primarypersonhandle ).gramps_id == self.__db.get_person_from_handle( b).gramps_id: relation_text = _("IP ") #################### # Relation # For Family Events if Fam == 1: relation_text = "nicht verwandt" relation_textA = "" relation_textB = "" self.doc.start_cell("SRC-Cell") self.doc.start_paragraph("SRC-SourceDetails") rel_calc = get_relationship_calculator() relationA = rel_calc.get_one_relationship( self.__db, self.__db.get_person_from_handle(primarypersonAhandle), self.__db.get_person_from_handle(b)) if relationA: relation_textA = _("To groom: %s" % relationA) elif self.__db.get_person_from_handle( primarypersonAhandle ).gramps_id == self.__db.get_person_from_handle( b).gramps_id: relation_text = _("IP ") rel_calc = get_relationship_calculator() relationB = rel_calc.get_one_relationship( self.__db, self.__db.get_person_from_handle(primarypersonBhandle), self.__db.get_person_from_handle(b)) if relationB: relation_textB = _("To bride: %s" % relationB) elif self.__db.get_person_from_handle( primarypersonBhandle ).gramps_id == self.__db.get_person_from_handle( b).gramps_id: relation_text = _("IP ") # relation_textF = relation_textA + relation_textB if (relation_textA + relation_textB) != "": relation_text = relation_textA + relation_textB ##################### self.doc.write_text(_("%s") % relation_text) self.doc.end_paragraph() self.doc.end_cell() self.doc.end_row() self.doc.end_table()
def collect_data(self, filter, center_person): """ This method runs through the data, and collects all the people to be processed """ self.center_person = center_person # Get all people in Database people = self.database.iter_person_handles() # Apply the preferred people filter people_handles = filter.apply(self.database, people, user=self.user) entire_database = False self.rel_calc = get_relationship_calculator() if len(people_handles) == self.database.get_number_of_people(): entire_database = True # For everyone in entire database, get top most ascendants self.ascendants = list() self.user.begin_progress( self.title, _('Getting ascendants from %s people...') % (len(people_handles)), len(people_handles)) for person_handle in people_handles: self.user.step_progress() self.__process_ascendants(person_handle) self.user.end_progress() # If we have all ascendants from all families, getting descendants # For all these people should result in the entire database self.descendants = list() self.user.begin_progress( self.title, _('Verifying descendants from %s people...') % (len(self.ascendants)), len(self.ascendants)) for person_handle in self.ascendants: self.user.step_progress() if person_handle not in self.descendants: self.descendants.append(person_handle) self.__process_descendants(person_handle) self.user.end_progress() # For this run all descendants count should be the same # as total people handle count if len(people_handles) != len(self.descendants): # If this is the case then we must have some orphans # This should never be the case, but either way. # Lets get them and add them to ascendants. self.user.begin_progress( self.title, _('Getting missing descendants from %s people...') % (len(people_handles)), len(people_handles)) for person_handle in people_handles: self.user.step_progress() if person_handle not in self.descendants: self.ascendants.append(person_handle) self.descendants.append(person_handle) self.user.end_progress() # Prune the ascendants self.persons_pruned = list() self.__prune_ascendants(False) self.__prune_ascendants(True) # Ultimate test get all descendants of ascendants after pruning # We will get most of entire tree but we won't get the partners # that we just pruned out. self.descendants = list() self.user.begin_progress( self.title, _('Verifying descendants from %s people after pruning...') % (len(self.ascendants)), len(self.ascendants)) for person_handle in self.ascendants: self.user.step_progress() if person_handle not in self.descendants: self.descendants.append(person_handle) self.__process_descendants(person_handle) self.user.end_progress() if len(people_handles) != \ (len(self.descendants) + len(self.persons_pruned)): # If this is the case then we must have some orphans # This is likely to occur where a non related spouse # Has other spouses. Normal detailed desdendant tree # Does not show these. self.user.begin_progress( self.title, _('Getting missing descendants from %s people ...') % (len(people_handles)), len(people_handles)) for person_handle in people_handles: self.user.step_progress() if person_handle not in self.descendants: person = \ self.database.get_person_from_handle(person_handle) for mate_handle in self.__get_mate_handles(person): if mate_handle not in self.descendants: # Determine which person should be added # person_handle or mate_handle. # For this person check if other mates are # are in our descendants, if they are that's # the person we want. add_handle = self.__get_preferred_handle( person_handle, mate_handle) if add_handle not in self.ascendants: self.ascendants.append(add_handle) self.__remove_descendants_from_ascendants( person_handle) if add_handle not in self.descendants: self.descendants.append(add_handle) self.__process_descendants(add_handle) self.user.end_progress() else: # If not processing entire database, then list should be # the result of the filter itself. self.ascendants = list() self.user.begin_progress( self.title, _('Getting ascendants from %s people...') % (len(people_handles)), len(people_handles)) for person_handle in people_handles: self.user.step_progress() person = self.database.get_person_from_handle(person_handle) person_father, person_mother = \ self.__get_parent_handles(person_handle) if person_father and person_father in people_handles: continue if person_mother and person_mother in people_handles: continue # Person's parent does not exist in people_handles so # add to ascendants if not there. if person_handle not in self.ascendants: self.ascendants.append(person_handle) self.user.end_progress() # Prune ascendants of unecessary mates self.persons_pruned = list() self.__prune_ascendants(False) self.__prune_ascendants(True) return self.ascendants
def collect_data(self): """ This method runs through the data, and collects the relevant dates and text. """ people = self.database.iter_person_handles() people = self.filter.apply(self.database, people, user=self._user) ngettext = self._locale.translation.ngettext # to see "nearby" comments rel_calc = get_relationship_calculator(reinit=True, clocale=self._locale) with self._user.progress(_('Birthday and Anniversary Report'), _('Reading database...'), len(people)) as step: for person_handle in people: step() person = self.database.get_person_from_handle(person_handle) birth_ref = person.get_birth_ref() birth_date = None if birth_ref: birth_event = self.database.get_event_from_handle( birth_ref.ref) birth_date = birth_event.get_date_object() if (self.birthdays and birth_date is not None and birth_date.is_valid()): birth_date = gregorian(birth_date) year = birth_date.get_year() month = birth_date.get_month() day = birth_date.get_day() prob_alive_date = Date(self.year, month, day) nyears = self.year - year # add some things to handle maiden name: father_lastname = None # husband, actually if self.maiden_name in ['spouse_first', 'spouse_last' ]: # get husband's last name: if person.get_gender() == Person.FEMALE: family_list = person.get_family_handle_list() if len(family_list) > 0: if self.maiden_name == 'spouse_first': fhandle = family_list[0] else: fhandle = family_list[-1] fam = self.database.get_family_from_handle( fhandle) father_handle = fam.get_father_handle() mother_handle = fam.get_mother_handle() if mother_handle == person_handle: if father_handle: father = self.database.get_person_from_handle( father_handle) if father is not None: primary_name = father.get_primary_name( ) if primary_name: father_lastname = Surname.get_surname( primary_name. get_primary_surname()) short_name = self.get_name(person, father_lastname) alive = probably_alive(person, self.database, prob_alive_date) if ((self.alive and alive) or not self.alive): comment = "" if self.relationships: relation = rel_calc.get_one_relationship( self.database, self.center_person, person, olocale=self._locale) if relation: # FIXME this won't work for RTL languages comment = " --- %s" % relation if nyears == 0: text = self._('%(person)s, birth%(relation)s') % { 'person': short_name, 'relation': comment } else: # translators: leave all/any {...} untranslated text = ngettext('{person}, {age}{relation}', '{person}, {age}{relation}', nyears).format(person=short_name, age=nyears, relation=comment) self.add_day_item(text, month, day, person) if self.anniversaries: family_list = person.get_family_handle_list() for fhandle in family_list: fam = self.database.get_family_from_handle(fhandle) father_handle = fam.get_father_handle() mother_handle = fam.get_mother_handle() if father_handle == person.get_handle(): spouse_handle = mother_handle else: continue # with next person if the father is not "person" # this will keep from duplicating the anniversary if spouse_handle: spouse = self.database.get_person_from_handle( spouse_handle) if spouse: spouse_name = self.get_name(spouse) short_name = self.get_name(person) # TEMP: this will handle ordered events # Gramps 3.0 will have a new mechanism for start/stop events are_married = None for event_ref in fam.get_event_ref_list(): event = self.database.get_event_from_handle( event_ref.ref) if event.type in [ EventType.MARRIAGE, EventType.MARR_ALT ]: are_married = event elif event.type in [ EventType.DIVORCE, EventType.ANNULMENT, EventType.DIV_FILING ]: are_married = None if are_married is not None: for event_ref in fam.get_event_ref_list(): event = self.database.get_event_from_handle( event_ref.ref) event_obj = event.get_date_object() if event_obj is not Date.EMPTY and event_obj.is_valid( ): event_obj = gregorian(event_obj) year = event_obj.get_year() month = event_obj.get_month() day = event_obj.get_day() nyears = self.year - year if event_obj.is_valid(): if nyears == 0: text = self._( "%(spouse)s and\n %(person)s, wedding" ) % { 'spouse': spouse_name, 'person': short_name } else: # translators: leave all/any {...} untranslated text = ngettext( "{spouse} and\n {person}, {nyears}", "{spouse} and\n {person}, {nyears}", nyears).format( spouse=spouse_name, person=short_name, nyears=nyears) prob_alive_date = Date( self.year, month, day) alive1 = probably_alive( person, self.database, prob_alive_date) alive2 = probably_alive( spouse, self.database, prob_alive_date) if (self.alive and alive1 and alive2 ) or not self.alive: self.add_day_item( text, month, day, spouse)
""" from gramps.gen.simple import SimpleAccess, SimpleDoc from gramps.gui.plug.quick import QuickTable from gramps.gen.const import GRAMPS_LOCALE as glocale from gramps.gen.lib.date import Today from gramps.gen.relationship import get_relationship_calculator from gramps.gen.utils.db import get_birth_or_fallback, get_death_or_fallback import gramps.gen.lib try: _trans = glocale.get_addon_translator(__file__) except ValueError: _trans = glocale.translation _ = _trans.gettext rel_calc = get_relationship_calculator() def levelname(inlaw, level): if level == 1: if not inlaw: return _("Parents") else: return _("Inlaw Parents") elif level == 2: if not inlaw: return _("Grandparents") else: return _("Inlaw Grandparents") elif level == 3: if not inlaw:
def personrelation(self, Fam, rolepershandle, primpershandle, primpersAhandle, primpersBhandle, inlaw): if rolepershandle: # Relation # For Single Person Events if Fam == 0: relation_text = "nicht verwandt" # self.doc.start_cell("SRC-Cell") # self.doc.start_paragraph("SRC-SourceDetails") #p rel_calc = Relationship.get_relationship_calculator() rel_calc = get_relationship_calculator() relation = rel_calc.get_one_relationship( self.__db, self.__db.get_person_from_handle(primpershandle), self.__db.get_person_from_handle(rolepershandle)) if relation: relation_text = _("%s" % relation) elif self.__db.get_person_from_handle(primpershandle).gramps_id == self.__db.get_person_from_handle(rolepershandle).gramps_id: relation_text = _("IP ") elif (self.showinlaw == 1) and (Fam == 0): inlaw_text = self.inlaw_rel(primpershandle, rolepershandle) relation_text = inlaw_text return (_("%s") % relation_text) # Relation # For Family Events if Fam == 1: relation_text = "nicht verwandt" relation_textA = "" relation_textB = "" #p rel_calc = Relationship.get_relationship_calculator() rel_calc = get_relationship_calculator() relationA = rel_calc.get_one_relationship( self.__db, self.__db.get_person_from_handle(primpersAhandle), self.__db.get_person_from_handle(rolepershandle)) if relationA: relation_textA = _("To bride: %s" % relationA) elif self.__db.get_person_from_handle(primpersAhandle).gramps_id == self.__db.get_person_from_handle(rolepershandle).gramps_id: relation_text = _("IP ") #p rel_calc = Relationship.get_relationship_calculator() rel_calc = get_relationship_calculator() relationB = rel_calc.get_one_relationship( self.__db, self.__db.get_person_from_handle(primpersBhandle), self.__db.get_person_from_handle(rolepershandle)) if relationB: relation_textB = _("To groom: %s" % relationB) elif self.__db.get_person_from_handle(primpersBhandle).gramps_id == self.__db.get_person_from_handle(rolepershandle).gramps_id: relation_text = _("IP ") if (relation_textA + relation_textB) !="": relation_text = relation_textA + " " + relation_textB # relation_text = relation_text + str(primpersAhandle)+ " " + str(primpersBhandle) + " " + str(rolepershandle) if self.showinlaw == 0: return (_("%s") % relation_text)
def collect_data(self): """ This method runs through the data, and collects the relevant dates and text. """ people = self.database.iter_person_handles() with self._user.progress(_('Birthday and Anniversary Report'), _('Applying Filter...'), self.database.get_number_of_people()) as step: people = self.filter.apply(self.database, people, step) ngettext = self._locale.translation.ngettext # to see "nearby" comments rel_calc = get_relationship_calculator(reinit=True, clocale=self._locale) with self._user.progress(_('Birthday and Anniversary Report'), _('Reading database...'), len(people)) as step: for person_handle in people: step() person = self.database.get_person_from_handle(person_handle) birth_ref = person.get_birth_ref() birth_date = None if birth_ref: birth_event = self.database.get_event_from_handle(birth_ref.ref) birth_date = birth_event.get_date_object() if (self.birthdays and birth_date is not None and birth_date.is_valid()): birth_date = gregorian(birth_date) year = birth_date.get_year() month = birth_date.get_month() day = birth_date.get_day() prob_alive_date = Date(self.year, month, day) nyears = self.year - year # add some things to handle maiden name: father_lastname = None # husband, actually if self.maiden_name in ['spouse_first', 'spouse_last']: # get husband's last name: if person.get_gender() == Person.FEMALE: family_list = person.get_family_handle_list() if len(family_list) > 0: if self.maiden_name == 'spouse_first': fhandle = family_list[0] else: fhandle = family_list[-1] fam = self.database.get_family_from_handle(fhandle) father_handle = fam.get_father_handle() mother_handle = fam.get_mother_handle() if mother_handle == person_handle: if father_handle: father = self.database.get_person_from_handle(father_handle) if father is not None: primary_name = father.get_primary_name() if primary_name: father_lastname = Surname.get_surname(primary_name.get_primary_surname()) short_name = self.get_name(person, father_lastname) alive = probably_alive(person, self.database, prob_alive_date) if ((self.alive and alive) or not self.alive): comment = "" if self.relationships: relation = rel_calc.get_one_relationship( self.database, self.center_person, person, olocale=self._locale) if relation: # FIXME this won't work for RTL languages comment = " --- %s" % relation if nyears == 0: text = self._('%(person)s, birth%(relation)s') % { 'person' : short_name, 'relation' : comment} else: # translators: leave all/any {...} untranslated text = ngettext('{person}, {age}{relation}', '{person}, {age}{relation}', nyears).format(person=short_name, age=nyears, relation=comment) self.add_day_item(text, month, day, person) if self.anniversaries: family_list = person.get_family_handle_list() for fhandle in family_list: fam = self.database.get_family_from_handle(fhandle) father_handle = fam.get_father_handle() mother_handle = fam.get_mother_handle() if father_handle == person.get_handle(): spouse_handle = mother_handle else: continue # with next person if the father is not "person" # this will keep from duplicating the anniversary if spouse_handle: spouse = self.database.get_person_from_handle(spouse_handle) if spouse: spouse_name = self.get_name(spouse) short_name = self.get_name(person) # TEMP: this will handle ordered events # Gramps 3.0 will have a new mechanism for start/stop events are_married = None for event_ref in fam.get_event_ref_list(): event = self.database.get_event_from_handle(event_ref.ref) if event.type in [EventType.MARRIAGE, EventType.MARR_ALT]: are_married = event elif event.type in [EventType.DIVORCE, EventType.ANNULMENT, EventType.DIV_FILING]: are_married = None if are_married is not None: for event_ref in fam.get_event_ref_list(): event = self.database.get_event_from_handle(event_ref.ref) event_obj = event.get_date_object() if event_obj is not Date.EMPTY and event_obj.is_valid(): event_obj = gregorian(event_obj) year = event_obj.get_year() month = event_obj.get_month() day = event_obj.get_day() nyears = self.year - year if event_obj.is_valid(): if nyears == 0: text = self._("%(spouse)s and\n %(person)s, wedding") % { 'spouse' : spouse_name, 'person' : short_name} else: # translators: leave all/any {...} untranslated text = ngettext("{spouse} and\n {person}, {nyears}", "{spouse} and\n {person}, {nyears}", nyears).format(spouse=spouse_name, person=short_name, nyears=nyears) prob_alive_date = Date(self.year, month, day) alive1 = probably_alive(person, self.database, prob_alive_date) alive2 = probably_alive(spouse, self.database, prob_alive_date) if (self.alive and alive1 and alive2) or not self.alive: self.add_day_item(text, month, day, spouse)
def collect_data(self, filter, center_person): """ This method runs through the data, and collects all the people to be processed """ self.center_person = center_person # Get all people in Database people = self.database.iter_person_handles() # Apply the preferred people filter self.user.begin_progress(self.title, _('Applying Filter...'), self.database.get_number_of_people()) people_handles = filter.apply(self.database, people, self.user.step_progress) self.user.end_progress() entire_database = False self.rel_calc = get_relationship_calculator() if len(people_handles) == self.database.get_number_of_people(): entire_database = True # For everyone in entire database, get top most ascendants self.ascendants = list() self.user.begin_progress(self.title, _('Getting ascendants from %s people...') % (len(people_handles)), len(people_handles)) for person_handle in people_handles: self.user.step_progress() self.__process_ascendants(person_handle) self.user.end_progress() # If we have all ascendants from all families, getting descendants # For all these people should result in the entire database self.descendants = list() self.user.begin_progress(self.title, _('Verifying descendants from %s people...') % (len(self.ascendants)), len(self.ascendants)) for person_handle in self.ascendants: self.user.step_progress() if person_handle not in self.descendants: self.descendants.append(person_handle) self.__process_descendants(person_handle) self.user.end_progress() # For this run all descendants count should be the same # as total people handle count if len(people_handles) != len(self.descendants): # If this is the case then we must have some orphans # This should never be the case, but either way. # Lets get them and add them to ascendants. self.user.begin_progress(self.title, _('Getting missing descendants from %s people...') % (len(people_handles)), len(people_handles)) for person_handle in people_handles: self.user.step_progress() if person_handle not in self.descendants: self.ascendants.append(person_handle) self.descendants.append(person_handle) self.user.end_progress() # Prune the ascendants self.persons_pruned = list() self.__prune_ascendants(False) self.__prune_ascendants(True) # Ultimate test get all descendants of ascendants after pruning # We will get most of entire tree but we won't get the partners # that we just pruned out. self.descendants = list() self.user.begin_progress(self.title, _('Verifying descendants from %s people after pruning...') % (len(self.ascendants)), len(self.ascendants)) for person_handle in self.ascendants: self.user.step_progress() if person_handle not in self.descendants: self.descendants.append(person_handle) self.__process_descendants(person_handle) self.user.end_progress() if len(people_handles) != \ (len(self.descendants) + len(self.persons_pruned)): # If this is the case then we must have some orphans # This is likely to occur where a non related spouse # Has other spouses. Normal detailed desdendant tree # Does not show these. self.user.begin_progress(self.title, _('Getting missing descendants from %s people ...') % (len(people_handles)), len(people_handles)) for person_handle in people_handles: self.user.step_progress() if person_handle not in self.descendants: person = \ self.database.get_person_from_handle(person_handle) for mate_handle in self.__get_mate_handles(person): if mate_handle not in self.descendants: # Determine which person should be added # person_handle or mate_handle. # For this person check if other mates are # are in our descendants, if they are that's # the person we want. add_handle = self.__get_preferred_handle( person_handle, mate_handle) if add_handle not in self.ascendants: self.ascendants.append(add_handle) self.__remove_descendants_from_ascendants( person_handle) if add_handle not in self.descendants: self.descendants.append(add_handle) self.__process_descendants(add_handle) self.user.end_progress() else: # If not processing entire database, then list should be # the result of the filter itself. self.ascendants = list() self.user.begin_progress(self.title, _('Getting ascendants from %s people...') % (len(people_handles)), len(people_handles)) for person_handle in people_handles: self.user.step_progress() person = self.database.get_person_from_handle(person_handle) person_father, person_mother = \ self.__get_parent_handles(person_handle) if person_father and person_father in people_handles: continue if person_mother and person_mother in people_handles: continue # Person's parent does not exist in people_handles so # add to ascendants if not there. if person_handle not in self.ascendants: self.ascendants.append(person_handle) self.user.end_progress() # Prune ascendants of unecessary mates self.persons_pruned = list() self.__prune_ascendants(False) self.__prune_ascendants(True) return self.ascendants
def listeventref(self): sc = {'source': 'S_ID', 'citalist': 'C_ID' } stc = {} citation_without_notes = 0 EMPTY = " " def toYear(date): yeartext = date.get_year() return yeartext # build citation list cl cl = [] i=1 for ci in self.__db.iter_citations(): if ci.source_handle in self.source_handles: # sc[ci.source_handle].append(ci.handle) cl.append(ci.handle) # build citations - event dic xy #(a,b): set([('Citation', 'c4a8c46041e08799b17')]) # event: c4a8c4f95b01e38564a event: Taufe #!! # Nur Taufen ! ci = defaultdict(list) for ev in self.__db.iter_events(): if ev.type.is_baptism(): evcithandlelist = ev.get_referenced_citation_handles() for (a,b) in evcithandlelist: if b in cl: ci[b].append(ev.handle) cikeys = ci.keys() # for di in cikeys: # print ((di), di in cl) # print (len(cikeys)) # print ("CITA", len(ci.keys()), len(sc.values()) ) # print ("SOURCE", len(sc.keys()), len(sc.values()), len(sc[0]) ) # build citasource dictionary sc = defaultdict(list) for ci2 in self.__db.iter_citations(): if ci2.handle in cikeys: # print("HALLO ", ci2, ci2.source_handle) sc[ci2.source_handle].append(ci2.handle) sckeys = sc.keys() # for di in sckeys: # print ((di), sc[di]) # print (len(sckeys), len(sc[di])) # build eventpersonrole dictionary # event: c4a8c4f95b01e38564a event: Taufe refhandlelist =[] pedic ={} pedic = defaultdict(list) for pe in self.__db.get_person_handles(): for eventref in self.__db.get_person_from_handle(pe).event_ref_list: # print(eventref, eventref.ref, eventref.get_role(), pe ) # print(eventref.get_role(), pe ) ## pedic[eventref.ref].add((eventref,pe)) pedic[eventref.ref].append((eventref.get_role(),pe)) #source # skeys = sc.keys() # skeys.sort(key=lambda x:self._formatlocal_source_text(self.__db.get_source_from_handle(x))) # for s in skeys: for s in sorted(sc.keys()): self._user.step_progress() self.doc.start_paragraph("SRC-SourceTitle") self.doc.write_text(self._formatlocal_source_text(self.__db.get_source_from_handle(s))) self.doc.end_paragraph() self.doc.start_paragraph("SRC-SourceDetails") self.doc.write_text(_(" ID: %s") % self.__db.get_source_from_handle(s).gramps_id) self.doc.end_paragraph() # note in sources for sourcenotehandle in self.__db.get_source_from_handle(s).get_note_list(): self.doc.start_paragraph("SRC-NoteDetails") self.doc.write_text(_(" Type: %s") % self.__db.get_note_from_handle(sourcenotehandle).type) self.doc.write_text(_(" N-ID: %s") % self.__db.get_note_from_handle(sourcenotehandle).gramps_id) self.doc.end_paragraph() self.doc.start_paragraph("SRC-NoteText") self.doc.write_text(_(" %s") % self.__db.get_note_from_handle(sourcenotehandle).text) self.doc.end_paragraph() self.doc.start_table("EventTable", "SRC-EventTable") # column_titles = [_("LNr"), _("Source"), _("Date"),_("Person"),_("Parents"), # _("Godparents"),_("Relation")] column_titles = [_("LNr"), _("Source"), _("Date"),_("Person"),_("Parents"), _("Paten"),_("Beziehung")] self.doc.start_row() for title in column_titles: self.doc.start_cell("SRC-TableColumn") self.doc.start_paragraph("SRC-ColumnTitle") self.doc.write_text(title) self.doc.end_paragraph() self.doc.end_cell() self.doc.end_row() i = 1 ckeys = sc[s] ckeys.sort(key=lambda x:self.__db.get_citation_from_handle(x).page) for c in ckeys: # c contains citationhandles self._user.step_progress() self.doc.start_row() self.doc.start_cell("SRC-TableColumn") self.doc.start_paragraph("SRC-SourceDetails") self.doc.write_text(_("%d") % i) self.doc.end_paragraph() self.doc.end_cell() self.doc.start_cell("SRC-TableColumn") self.doc.start_paragraph("SRC-SourceDetails") self.doc.write_text(_(" %s") % self.__db.get_citation_from_handle(c).page) self.doc.end_paragraph() self.doc.end_cell() self.doc.start_cell("SRC-TableColumn") self.doc.start_paragraph("SRC-SourceDetails") self.doc.write_text (_(" %s ") % get_date(self.__db.get_citation_from_handle(c))) self.doc.end_paragraph() self.doc.end_cell() self.doc.start_cell("SRC-TableColumn") self.doc.start_paragraph("SRC-SourceDetails") for e in ci[c]: event = self.__db.get_event_from_handle(e) for (a,b) in pedic[e]: if a.is_primary(): self.doc.write_text(_("%s") % event.get_type()) self.doc.write_text(_(" ( %s )") % event.gramps_id) self.doc.write_text(_(" %s") % self.__db.get_person_from_handle(b).primary_name.get_name()) primarypersonhandle = b liste = pedic[e].copy() self.doc.end_paragraph() self.doc.end_cell() self.doc.start_cell("SRC-TableColumn") self.doc.start_paragraph("SRC-SourceDetails") #Eltern und Ort family_handle = self.__db.get_person_from_handle(primarypersonhandle).get_main_parents_family_handle() if family_handle: fh = self.__db.get_family_from_handle(family_handle).father_handle if fh: self.doc.write_text (_("%s ") % self.__db.get_person_from_handle(fh).primary_name.get_name()) self.doc.end_paragraph() self.doc.start_paragraph("SRC-SourceDetails") mh = self.__db.get_family_from_handle(family_handle).mother_handle if mh: self.doc.write_text (_("%s ") % self.__db.get_person_from_handle(mh).primary_name.get_name()) place = '' place_handle = event.get_place_handle() if place_handle: place = place_displayer.display_event(self.database, event) # self.doc.write_text(_(" from %s") % # place) self.doc.write_text(_(" von %s") % place) self.doc.end_paragraph() self.doc.end_cell() #Godparents self.doc.start_cell("SRC-TableColumn") for e in ci[c]: for (a,b) in pedic[e]: if not a.is_primary(): self.doc.start_paragraph("SRC-SourceDetails") relation_text = "n.v." rel_calc = get_relationship_calculator() relation = rel_calc.get_one_relationship( self.__db, self.__db.get_person_from_handle(primarypersonhandle), self.__db.get_person_from_handle(b)) if relation: relation_text = _("%s" % relation) self.doc.write_text(_(" %s") % self.__db.get_person_from_handle(b).primary_name.get_name()) self.doc.write_text(_(" ( %s )") % relation_text) self.doc.end_paragraph() self.doc.end_cell() self.doc.start_cell("SRC-TableColumn") # note in citations for notehandle in self.__db.get_citation_from_handle(c).get_note_list(): self._user.step_progress() self.doc.start_paragraph("SRC-NoteText") self.doc.write_text(_(" %s") % self.__db.get_note_from_handle(notehandle).text) self.doc.end_paragraph() self.doc.end_cell() self.doc.end_row() i += 1 self.doc.end_table()
def personline(self, liste, Fam, primarypersonhandle, primarypersonAhandle, primarypersonBhandle): if len(liste)>0: #USORT #for fn in sorted(fam_list, key=itemgetter(1,7)): for (a,b) in liste: # for (a,b) in sorted(liste, key=itemgetter(0)): self.doc.write_text(_("%s") % a) self.doc.write_text(_("%s") % _DELIMRole) self.doc.write_text(_("%s") % self.__db.get_person_from_handle(b).primary_name.get_name()) self.doc.write_text(_("%s") % _DELIM) self.doc.write_text(_("%s") % self.__db.get_person_from_handle(b).gramps_id) self.doc.write_text(_("%s") % _DELIM) # Relation # For Single Person Events if Fam == 0: relation_text = "nicht verwandt" rel_calc = get_relationship_calculator() relation = rel_calc.get_one_relationship( self.__db, self.__db.get_person_from_handle(primarypersonhandle), self.__db.get_person_from_handle(b)) if relation: relation_text = _("%s" % relation) elif self.__db.get_person_from_handle(primarypersonhandle).gramps_id == self.__db.get_person_from_handle(b).gramps_id: relation_text = _("IP ") #################### # Relation # For Family Events if Fam == 1: relation_text = "nicht verwandt" relation_textA = "" relation_textB = "" rel_calc = get_relationship_calculator() relationA = rel_calc.get_one_relationship( self.__db, self.__db.get_person_from_handle(primarypersonAhandle), self.__db.get_person_from_handle(b)) if relationA: relation_textA = _("To groom: %s" % relationA) elif self.__db.get_person_from_handle(primarypersonAhandle).gramps_id == self.__db.get_person_from_handle(b).gramps_id: relation_text = _("IP ") rel_calc = get_relationship_calculator() relationB = rel_calc.get_one_relationship( self.__db, self.__db.get_person_from_handle(primarypersonBhandle), self.__db.get_person_from_handle(b)) if relationB: relation_textB = _("To bride: %s" % relationB) elif self.__db.get_person_from_handle(primarypersonBhandle).gramps_id == self.__db.get_person_from_handle(b).gramps_id: relation_text = _("IP ") # relation_textF = relation_textA + relation_textB if (relation_textA + relation_textB) !="": relation_text = relation_textA + relation_textB ##################### self.doc.write_text(_("%s") % relation_text) self.doc.write_text(_("%s") % _DELIM)