def build_gui(self): """ Build the GUI interface. """ tip = _('Right-click on a row to edit the selected event' ' or the related place.') self.set_tooltip(tip) top = Gtk.TreeView() top.set_hover_selection(True) titles = [ ( '', NOSORT, 50, ), (_('Type'), 1, 100), (_('Description'), 2, 250), (_('Date'), 3, 160), ('', NOSORT, 50), (_('Place'), 4, 300), (_('Id'), 5, 80), (_('Latitude'), 6, 130), (_('Longitude'), 7, 130), ] self.model = ListModel(top, titles, right_click=self.menu_edit) return top
class Backlinks(Gramplet): """ Displays the back references for an object. """ def init(self): self.gui.WIDGET = self.build_gui() self.gui.get_container_widget().remove(self.gui.textview) self.gui.get_container_widget().add(self.gui.WIDGET) self.gui.WIDGET.show() def build_gui(self): """ Build the GUI interface. """ top = Gtk.TreeView() titles = [ (_('Type'), 1, 100), (_('Name'), 2, 100), ('', 3, 1), #hidden column for the handle ('', 4, 1) ] #hidden column for non-localized object type self.model = ListModel(top, titles, event_func=self.cb_double_click) return top def display_backlinks(self, active_handle): """ Display the back references for an object. """ for classname, handle in \ self.dbstate.db.find_backlink_handles(active_handle): name = navigation_label(self.dbstate.db, classname, handle)[0] self.model.add((_(classname), name, handle, classname)) self.set_has_data(self.model.count > 0) def get_has_data(self, active_handle): """ Return True if the gramplet has data, else return False. """ if active_handle is None: return False for handle in self.dbstate.db.find_backlink_handles(active_handle): return True return False def cb_double_click(self, treeview): """ Handle double click on treeview. """ (model, iter_) = treeview.get_selection().get_selected() if not iter_: return (objclass, handle) = (model.get_value(iter_, 3), model.get_value(iter_, 2)) edit_object(self.dbstate, self.uistate, objclass, handle)
def __init__(self, dbstate, user, options_class, name, callback=None): uistate = user.uistate self.label = _("Gender Statistics tool") tool.Tool.__init__(self, dbstate, options_class, name) stats_list = [] for name, value in dbstate.db.genderStats.stats.items(): stats_list.append( (name,) + value + (_GENDER[dbstate.db.genderStats.guess_gender(name)],) ) if uistate: ManagedWindow.__init__(self, uistate, [], self.__class__) titles = [(_('Name'), 0, 100), (_('Male'), 1, 70, INTEGER), (_('Female'), 2, 70, INTEGER), (_('Unknown'), 3, 90, INTEGER), (_('Guess'), 4, 70)] treeview = Gtk.TreeView() model = ListModel(treeview, titles) for entry in sorted(stats_list): model.add(entry, entry[0]) s = Gtk.ScrolledWindow() s.add(treeview) dialog = Gtk.Dialog() dialog.add_button(_('_Close'), Gtk.ResponseType.CLOSE) dialog.connect('response', self._response) dialog.vbox.pack_start(s, expand=True, fill=True, padding=0) self.set_window(dialog, None, self.label) self.setup_configs('interface.dumpgenderstats', 420, 300) self.show() else: if len(_('Name')) < 16: print('%s%s%s' % (_('Name'), " " * (16 - len(_('Name'))), _('Male')), '\t%s'*3 % (_('Female'), _('Unknown'), _('Guess'))) else: print(_('Name'), '\t%s'*4 % (_('Male'), _('Female'), _('Unknown'), _('Guess'))) print() for entry in sorted(stats_list): if len(entry[0]) < 16: print('%s%s%s' % (entry[0], " " * (16 - len(entry[0])), entry[1]), '\t%s'*3 % (entry[2:])) else: print(entry[0], '\t%s'*4 % (entry[1:]))
def build_gui(self): """ Build the GUI interface. """ tip = _('Double-click on a row to view a quick report showing ' 'all people with the selected attribute.') self.set_tooltip(tip) top = Gtk.TreeView() titles = [(_('Key'), 1, 100), (_('Value'), 2, 100)] self.model = ListModel(top, titles, event_func=self.display_report) return top
class Backlinks(Gramplet): """ Displays the back references for an object. """ def init(self): self.gui.WIDGET = self.build_gui() self.gui.get_container_widget().remove(self.gui.textview) self.gui.get_container_widget().add(self.gui.WIDGET) self.gui.WIDGET.show() def build_gui(self): """ Build the GUI interface. """ top = Gtk.TreeView() titles = [(_('Type'), 1, 100), (_('Name'), 2, 100), ('', 3, 1), #hidden column for the handle ('', 4, 1)] #hidden column for non-localized object type self.model = ListModel(top, titles, event_func=self.cb_double_click) return top def display_backlinks(self, active_handle): """ Display the back references for an object. """ for classname, handle in \ self.dbstate.db.find_backlink_handles(active_handle): name = navigation_label(self.dbstate.db, classname, handle)[0] self.model.add((_(classname), name, handle, classname)) self.set_has_data(self.model.count > 0) def get_has_data(self, active_handle): """ Return True if the gramplet has data, else return False. """ if active_handle is None: return False for handle in self.dbstate.db.find_backlink_handles(active_handle): return True return False def cb_double_click(self, treeview): """ Handle double click on treeview. """ (model, iter_) = treeview.get_selection().get_selected() if not iter_: return (objclass, handle) = (model.get_value(iter_, 3), model.get_value(iter_, 2)) edit_object(self.dbstate, self.uistate, objclass, handle)
def build_gui(self): """ Build the GUI interface. """ tip = _('Double-click on a row to edit the selected event.') self.set_tooltip(tip) top = Gtk.TreeView() titles = [('', NOSORT, 50,), (_('Date'), 1, 200), (_('Place'), 2, 200)] self.model = ListModel(top, titles, event_func=self.edit_event) return top
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)
class Attributes(Gramplet): """ Displays the attributes of an object. """ def init(self): self.gui.WIDGET = self.build_gui() self.gui.get_container_widget().remove(self.gui.textview) self.gui.get_container_widget().add(self.gui.WIDGET) self.gui.WIDGET.show() def build_gui(self): """ Build the GUI interface. """ tip = _('Double-click on a row to view a quick report showing ' 'all people with the selected attribute.') self.set_tooltip(tip) top = Gtk.TreeView() titles = [(_('Key'), 1, 100), (_('Value'), 2, 100)] self.model = ListModel(top, titles, event_func=self.display_report) return top def display_attributes(self, obj): """ Display the attributes of an object. """ for attr in obj.get_attribute_list(): self.model.add((str(attr.get_type()), attr.get_value())) self.set_has_data(self.model.count > 0) def display_report(self, treeview): """ Display the quick report for matching attribute key. """ model, iter_ = treeview.get_selection().get_selected() if iter_: key = model.get_value(iter_, 0) run_quick_report_by_name(self.dbstate, self.uistate, 'attribute_match', key) def get_has_data(self, obj): """ Return True if the gramplet has data, else return False. """ if obj is None: return False if obj.get_attribute_list(): return True return False
def build_gui(self): """ Build the GUI interface. """ top = Gtk.TreeView() titles = [ (_('Type'), 1, 100), (_('Name'), 2, 100), ('', 3, 1), #hidden column for the handle ('', 4, 1) ] #hidden column for non-localized object type self.model = ListModel(top, titles, event_func=self.cb_double_click) return top
def __init__(self, dbstate, user, options_class, name, callback=None): uistate = user.uistate self.label = _("Gender Statistics tool") tool.Tool.__init__(self, dbstate, options_class, name) stats_list = [] for name, value in dbstate.db.genderStats.stats.items(): stats_list.append((name, ) + value + ( _GENDER[dbstate.db.genderStats.guess_gender(name)], )) if uistate: ManagedWindow.__init__(self, uistate, [], self.__class__) titles = [(_('Name'), 0, 100), (_('Male'), 1, 70, INTEGER), (_('Female'), 2, 70, INTEGER), (_('Unknown'), 3, 90, INTEGER), (_('Guess'), 4, 70)] treeview = Gtk.TreeView() model = ListModel(treeview, titles) for entry in sorted(stats_list): model.add(entry, entry[0]) s = Gtk.ScrolledWindow() s.add(treeview) dialog = Gtk.Dialog() dialog.add_button(_('_Close'), Gtk.ResponseType.CLOSE) dialog.connect('response', self._response) dialog.vbox.pack_start(s, expand=True, fill=True, padding=0) self.set_window(dialog, None, self.label) self.setup_configs('interface.dumpgenderstats', 420, 300) self.show() else: if len(_('Name')) < 16: print( '%s%s%s' % (_('Name'), " " * (16 - len(_('Name'))), _('Male')), '\t%s' * 3 % (_('Female'), _('Unknown'), _('Guess'))) else: print( _('Name'), '\t%s' * 4 % (_('Male'), _('Female'), _('Unknown'), _('Guess'))) print() for entry in sorted(stats_list): if len(entry[0]) < 16: print( '%s%s%s' % (entry[0], " " * (16 - len(entry[0])), entry[1]), '\t%s' * 3 % (entry[2:])) else: print(entry[0], '\t%s' * 4 % (entry[1:]))
def build_gui(self): """ Build the GUI interface. """ tip = _('Double-click on a row to edit the selected source/citation.') self.set_tooltip(tip) top = Gtk.TreeView() titles = [('', NOSORT, 50,), (_('Source/Citation'), 1, 350), (_('Author'), 2, 200), (_('Publisher'), 3, 150)] self.model = ListModel(top, titles, list_mode="tree", event_func=self.invoke_editor) return top
def build_gui(self): """ Build the GUI interface. """ tip = _('Double-click on a row to edit the selected place.') self.set_tooltip(tip) top = Gtk.TreeView() titles = [('', 0, 50), (_('Name'), 1, 300), (_('Type'), 2, 150), (_('Date'), 5, 250), (_('ID'), 4, 100), ('', NOSORT, 50)] self.model = ListModel(top, titles, list_mode="tree", event_func=self.edit_place) return top
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 = [] 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) stats_list.append((name1, value, name2)) if uistate: titles = [ (_('Name'), 0, 200), (_('Type of link'), 1, 200), (_('Of'), 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(800, 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'*3 % ('Name','Type of link','Of')) print() for entry in stats_list: print('\t%s'*3 % entry)
def build_gui(self): """ Build the GUI interface. """ tip = _('Double-click on a row to edit the selected participant.') self.set_tooltip(tip) top = Gtk.TreeView() titles = [('', NOSORT, 50,), (_('Name'), 1, 250), (_('Role'), 2, 80), (_('Birth Date'), 3, 100), ('', 3, 100), (_('Spouses'), 4, 200)] self.model = ListModel(top, titles, event_func=self.edit_person) return top
def build_gui(self): """ Build the GUI interface. """ top = Gtk.HBox() self.photo = Photo() self.photo.show() view = Gtk.TreeView() titles = [(_('Object'), 1, 250)] self.model = ListModel(view, titles, list_mode="tree", select_func=self.row_selected) top.pack_start(view, True, True, 0) top.pack_start(self.photo, True, False, 5) top.show_all() return top
def build_gui(self): """ Build the GUI interface. """ self.view = Gtk.TreeView() self.view.set_tooltip_column(3) titles = [(_('Name'), 0, 230), (_('Birth'), 2, 100), ('', NOSORT, 1), ('', NOSORT, 1), # tooltip ('', NOSORT, 100)] # handle self.model = ListModel(self.view, titles, list_mode="tree", event_func=self.cb_double_click, right_click=self.cb_right_click) return self.view
def build_gui(self): """ Build the GUI interface. """ tip = _('Double-click on a row to edit the selected child.') self.set_tooltip(tip) top = Gtk.TreeView() titles = [( '', NOSORT, 50, ), (_('Child'), 1, 250), (_('Birth Date'), 3, 100), ('', 3, 100), (_('Death Date'), 5, 100), ('', 5, 100)] self.model = ListModel(top, titles, event_func=self.edit_person) return top
def build_gui(self): """ Build the GUI interface. """ tip = _('Double-click on a row to edit the object containing the ' 'selected attribute.') self.set_tooltip(tip) top = Gtk.TreeView() titles = [(_('Date'), 1, 100), ('', 1, 100), (_('Key'), 2, 100), (_('Value'), 3, 100), ( '', NOSORT, 50, )] self.model = ListModel(top, titles, event_func=self._display_editor) return top
def build_gui(self): """ Build the GUI interface. """ tip = _('Double-click on a row to edit the selected event.') self.set_tooltip(tip) top = Gtk.TreeView() titles = [( '', NOSORT, 50, ), (_('Type'), 1, 100), (_('Description'), 2, 150), (_('Date'), 3, 100), ('', NOSORT, 50), (_('Age'), 4, 100), ('', NOSORT, 50), (_('Place'), 5, 400), (_('Main Participants'), 6, 200), (_('Role'), 7, 100)] self.model = ListModel(top, titles, event_func=self.edit_event) return top
def build_gui(self): """ Build the GUI interface. """ tip = _('Double-click on a row to edit the selected event.') self.set_tooltip(tip) top = Gtk.TreeView() titles = [( '', NOSORT, 50, ), (_('Type'), 1, 100), (_('Date'), 3, 100), ('', 3, 100), (_('Age'), 4, 35), (_('Where Born'), 5, 160), (_('Condition'), 6, 75), (_('Occupation'), 7, 160), (_('Residence'), 8, 160)] self.model = ListModel(top, titles, event_func=self.edit_event) return top
def __init__(self, uistate, data, parent): super().__init__(uistate, [], self) self.window = Gtk.Dialog("Gramp") self.set_window(self.window, None, _("Database Information")) self.window.set_modal(True) self.ok = self.window.add_button(_("_OK"), Gtk.ResponseType.OK) self.ok.connect("clicked", self.on_ok_clicked) self.window.set_position(Gtk.WindowPosition.CENTER) self.window.set_default_size(600, 400) s = Gtk.ScrolledWindow() titles = [(_("Setting"), 0, 150), (_("Value"), 1, 400)] treeview = Gtk.TreeView() model = ListModel(treeview, titles) for key, value in sorted(data.items()): model.add((key, str(value)), key) s.add(treeview) self.window.vbox.pack_start(s, True, True, 0) self.show()
def __init__(self, dbstate, user, options_class, name, callback=None): uistate = user.uistate self.label = _("Gender Statistics tool") tool.Tool.__init__(self, dbstate, options_class, name) if uistate: ManagedWindow.__init__(self,uistate,[], self.__class__) stats_list = [] for name, value in dbstate.db.genderStats.stats.items(): stats_list.append( (name,) + value + (_GENDER[dbstate.db.genderStats.guess_gender(name)],) ) if uistate: titles = [ (_('Name'),0,100), (_('Male'),1,70,INTEGER), (_('Female'),2,70,INTEGER), (_('Unknown'),3,70,INTEGER), (_('Guess'),4,70) ] treeview = Gtk.TreeView() model = ListModel(treeview, titles) for entry in stats_list: model.add(entry, entry[0]) window = Gtk.Window() window.set_default_size(400, 300) 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'*5 % ('Name','Male','Female','Unknown','Guess')) print() for entry in stats_list: print('\t%s'*5 % entry)
def __init__(self, uistate, data, track): super().__init__(uistate, track, self, modal=True) self.window = Gtk.Dialog() self.set_window(self.window, None, _("Database Information")) self.setup_configs('interface.information', 600, 400) self.ok = self.window.add_button(_('_OK'), Gtk.ResponseType.OK) self.ok.connect('clicked', self.on_ok_clicked) s = Gtk.ScrolledWindow() titles = [(_('Setting'), 0, 150), (_('Value'), 1, 400)] treeview = Gtk.TreeView() model = ListModel(treeview, titles) for key, value in sorted(data.items()): model.add(( key, str(value), ), key) s.add(treeview) self.window.vbox.pack_start(s, True, True, 0) self.show()
def build_gui(self): """ Build the GUI interface. """ tip = _("Double-click on a row to edit the selected source/citation.") self.set_tooltip(tip) top = Gtk.TreeView() titles = [("", NOSORT, 50), (_("Source/Citation"), 1, 350), (_("Author"), 2, 200), (_("Publisher"), 3, 150)] self.model = ListModel(top, titles, list_mode="tree", event_func=self.invoke_editor) return top
def __init__(self, uistate, data, track): super().__init__(uistate, track, self, modal=True) self.window = Gtk.Dialog() self.set_window(self.window, None, _("Database Information")) self.setup_configs('interface.information', 600, 400) self.ok = self.window.add_button(_('_OK'), Gtk.ResponseType.OK) self.ok.connect('clicked', self.on_ok_clicked) s = Gtk.ScrolledWindow() titles = [ (_('Setting'), 0, 150), (_('Value'), 1, 400) ] treeview = Gtk.TreeView() model = ListModel(treeview, titles) for key, value in sorted(data.items()): model.add((key, str(value),), key) s.add(treeview) self.window.vbox.pack_start(s, True, True, 0) self.show()
def build_gui(self): """ Build the GUI interface. """ tip = _("Double-click on a row to edit the selected event.") self.set_tooltip(tip) top = Gtk.TreeView() titles = [("", NOSORT, 50), (_("Date"), 1, 200), (_("Place"), 2, 200)] self.model = ListModel(top, titles, event_func=self.edit_event) return top
def __init__(self, dbstate, uistate, track, the_list, the_map, callback): ManagedWindow.__init__(self,uistate,track,self.__class__) self.dellist = set() self.list = the_list self.map = the_map self.length = len(self.list) self.update = callback self.db = dbstate.db self.dbstate = dbstate self.uistate = uistate top = Glade(toplevel="mergelist") window = top.toplevel self.set_window(window, top.get_object('title'), _('Potential Merges')) self.setup_configs('interface.duplicatepeopletoolmatches', 500, 350) self.mlist = top.get_object("mlist") top.connect_signals({ "destroy_passed_object" : self.close, "on_do_merge_clicked" : self.on_do_merge_clicked, "on_help_show_clicked" : self.on_help_clicked, "on_delete_show_event" : self.close, "on_merge_ok_clicked" : self.__dummy, "on_help_clicked" : self.__dummy, "on_delete_merge_event" : self.__dummy, "on_delete_event" : self.__dummy, }) self.db.connect("person-delete", self.person_delete) mtitles = [ (_('Rating'),3,75), (_('First Person'),1,200), (_('Second Person'),2,200), ('',-1,0) ] self.list = ListModel(self.mlist,mtitles, event_func=self.on_do_merge_clicked) self.redraw() self.show()
def build_gui(self): """ Build the GUI interface. """ top = Gtk.TreeView() titles = [(_('Type'), 1, 100), (_('Name'), 2, 100), ('', 3, 1), #hidden column for the handle ('', 4, 1)] #hidden column for non-localized object type self.model = ListModel(top, titles, event_func=self.cb_double_click) return top
def build_gui(self): """ Build the GUI interface. """ self.top = Gtk.TreeView() titles = [ (_('Type'), 1, 100), (_('Name'), 2, 100), (_('Date'), 4, 200), ('sd', 4, 120), # sorted date column ('', 5, 1), #hidden column for the handle ('', 6, 1), #hidden column for non-localized object type ] self.model = ListModel(self.top, titles, event_func=self.cb_double_click) self.date_column = self.top.get_column(2) self.sdate = self.top.get_column(3) self.top.get_column(1).set_expand(True) # The name use the max # possible size return self.top
def __init__(self, uistate, data, parent): super().__init__(uistate, [], self) self.window = Gtk.Dialog('Gramp') self.set_window(self.window, None, _("Database Information")) self.window.set_modal(True) self.ok = self.window.add_button(_('_OK'), Gtk.ResponseType.OK) self.ok.connect('clicked', self.on_ok_clicked) self.window.set_position(Gtk.WindowPosition.CENTER) self.window.set_default_size(600, 400) s = Gtk.ScrolledWindow() titles = [(_('Setting'), 0, 150), (_('Value'), 1, 400)] treeview = Gtk.TreeView() model = ListModel(treeview, titles) for key, value in sorted(data.items()): model.add(( key, str(value), ), key) s.add(treeview) self.window.vbox.pack_start(s, True, True, 0) self.show()
def build_gui(self): """ Build the GUI interface. """ top = Gtk.HBox() self.photo = Photo() self.photo.show() view = Gtk.TreeView() titles = [(_("Object"), 1, 250)] self.model = ListModel(view, titles, list_mode="tree", select_func=self.row_selected) top.pack_start(view, True, True, 0) top.pack_start(self.photo, True, False, 5) top.show_all() return top
def build_gui(self): """ Build the GUI interface. """ self.view = Gtk.TreeView() self.view.set_tooltip_column(3) titles = [(_('Name'), 0, 230), (_('Birth'), 2, 100), ('', NOSORT, 1), ('', NOSORT, 1), # tooltip ('', NOSORT, 100)] # handle self.model = ListModel(self.view, titles, list_mode="tree", event_func=self.cb_double_click) return self.view
def build_gui(self): """ Build the GUI interface. """ tip = _('Double-click on a row to edit the object containing the ' 'selected attribute.') self.set_tooltip(tip) top = Gtk.TreeView() titles = [(_('Date'), 1, 100), ('', 1, 100), (_('Key'), 2, 100), (_('Value'), 3, 100), ('', NOSORT, 50,)] self.model = ListModel(top, titles, event_func=self._display_editor) return top
def build_gui(self): """ Build the GUI interface. """ tip = _('Double-click on a row to edit the selected place.') self.set_tooltip(tip) top = Gtk.TreeView() titles = [('', 0, 50), (_('Name'), 1, 300), (_('Type'), 2, 150), (_('Date'), 4, 150), ('', NOSORT, 50)] self.model = ListModel(top, titles, list_mode="tree", event_func=self.edit_place) return top
def __init__(self, dbstate, user, options_class, name, callback=None): uistate = user.uistate self.label = _("Gender Statistics tool") tool.Tool.__init__(self, dbstate, options_class, name) if uistate: ManagedWindow.__init__(self, uistate, [], self.__class__) stats_list = [] for name, value in dbstate.db.genderStats.stats.items(): stats_list.append((name, ) + value + ( _GENDER[dbstate.db.genderStats.guess_gender(name)], )) if uistate: titles = [(_('Name'), 0, 100), (_('Male'), 1, 70, INTEGER), (_('Female'), 2, 70, INTEGER), (_('Unknown'), 3, 70, INTEGER), (_('Guess'), 4, 70)] treeview = Gtk.TreeView() model = ListModel(treeview, titles) for entry in stats_list: model.add(entry, entry[0]) window = Gtk.Window() window.set_default_size(400, 300) 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' * 5 % ('Name', 'Male', 'Female', 'Unknown', 'Guess')) print() for entry in stats_list: print('\t%s' * 5 % entry)
def build_gui(self): """ Build the GUI interface. """ tip = _('Double-click on a row to edit the selected child.') self.set_tooltip(tip) top = Gtk.TreeView() titles = [('', NOSORT, 50,), (_('Child'), 1, 250), (_('Birth Date'), 3, 100), ('', 3, 100), (_('Death Date'), 5, 100), ('', 5, 100)] self.model = ListModel(top, titles, event_func=self.edit_person) return top
def build_gui(self): """ Build the GUI interface. """ tip = _("Double-click on a row to edit the selected place.") self.set_tooltip(tip) top = Gtk.TreeView() titles = [ ("", 0, 50), (_("Name"), 1, 300), (_("Type"), 2, 150), (_("Date"), 5, 250), (_("ID"), 4, 100), ("", NOSORT, 50), ] self.model = ListModel(top, titles, list_mode="tree", event_func=self.edit_place) return top
def build_gui(self): """ Build the GUI interface. """ tip = _('Double-click on a row to edit the selected event.') self.set_tooltip(tip) top = Gtk.TreeView() titles = [('', NOSORT, 50,), (_('Type'), 1, 100), (_('Description'), 2, 150), (_('Date'), 3, 100), ('', NOSORT, 50), (_('Age'), 4, 100), ('', NOSORT, 50), (_('Place'), 5, 400), (_('Main Participants'), 6, 200), (_('Role'), 7, 100)] self.model = ListModel(top, titles, event_func=self.edit_event) return top
def __init__(self, dbstate, uistate, track, the_list, the_map, callback): ManagedWindow.__init__(self,uistate,track,self.__class__) self.dellist = {} self.list = the_list self.map = the_map self.length = len(self.list) self.update = callback self.db = dbstate.db self.dbstate = dbstate self.uistate = uistate top = Glade(toplevel="mergelist") window = top.toplevel self.set_window(window, top.get_object('title'), _('Potential Merges')) self.setup_configs('interface.duplicatepeopletoolmatches', 500, 350) self.mlist = top.get_object("mlist") top.connect_signals({ "destroy_passed_object" : self.close, "on_do_merge_clicked" : self.on_do_merge_clicked, "on_help_show_clicked" : self.on_help_clicked, "on_delete_show_event" : self.close, "on_merge_ok_clicked" : self.__dummy, "on_help_clicked" : self.__dummy, "on_delete_merge_event" : self.__dummy, "on_delete_event" : self.__dummy, }) mtitles = [ (_('Rating'),3,75), (_('First Person'),1,200), (_('Second Person'),2,200), ('',-1,0) ] self.list = ListModel(self.mlist,mtitles, event_func=self.on_do_merge_clicked) self.redraw() self.show()
def build_gui(self): """ Build the GUI interface. """ tip = _('Right-click on a row to edit the selected event' ' or the related place.') self.set_tooltip(tip) top = Gtk.TreeView() top.set_hover_selection(True) titles = [('', NOSORT, 50,), (_('Type'), 1, 100), (_('Description'), 2, 250), (_('Date'), 3, 160), ('', NOSORT, 50), (_('Place'), 4, 300), (_('Id'), 5, 80), (_('Latitude'), 6, 130), (_('Longitude'), 7, 130), ] self.model = ListModel(top, titles, right_click=self.menu_edit) return top
class DuplicatePeopleToolMatches(ManagedWindow): def __init__(self, dbstate, uistate, track, the_list, the_map, callback): ManagedWindow.__init__(self, uistate, track, self.__class__) self.dellist = set() self.list = the_list self.map = the_map self.length = len(self.list) self.update = callback self.db = dbstate.db self.dbstate = dbstate self.uistate = uistate top = Glade(toplevel="mergelist") window = top.toplevel self.set_window(window, top.get_object('title'), _('Potential Merges')) self.setup_configs('interface.duplicatepeopletoolmatches', 500, 350) self.mlist = top.get_object("mlist") top.connect_signals({ "destroy_passed_object": self.close, "on_do_merge_clicked": self.on_do_merge_clicked, "on_help_show_clicked": self.on_help_clicked, "on_delete_show_event": self.close, "on_merge_ok_clicked": self.__dummy, "on_help_clicked": self.__dummy, "on_delete_merge_event": self.__dummy, "on_delete_event": self.__dummy, }) self.db.connect("person-delete", self.person_delete) mtitles = [(_('Rating'), 3, 75), (_('First Person'), 1, 200), (_('Second Person'), 2, 200), ('', -1, 0)] self.list = ListModel(self.mlist, mtitles, event_func=self.on_do_merge_clicked) self.redraw() self.show() def build_menu_names(self, obj): return (_("Merge candidates"), _("Merge persons")) def on_help_clicked(self, obj): """Display the relevant portion of Gramps manual""" display_help(WIKI_HELP_PAGE, WIKI_HELP_SEC) def redraw(self): list = [] for p1key, p1data in self.map.items(): if p1key in self.dellist: continue (p2key, c) = p1data if p2key in self.dellist: continue if p1key == p2key: continue list.append((c, p1key, p2key)) self.list.clear() for (c, p1key, p2key) in list: c1 = "%5.2f" % c c2 = "%5.2f" % (100 - c) p1 = self.db.get_person_from_handle(p1key) p2 = self.db.get_person_from_handle(p2key) if not p1 or not p2: continue pn1 = name_displayer.display(p1) pn2 = name_displayer.display(p2) self.list.add([c1, pn1, pn2, c2], (p1key, p2key)) def on_do_merge_clicked(self, obj): store, iter = self.list.selection.get_selected() if not iter: return (self.p1, self.p2) = self.list.get_object(iter) MergePerson(self.dbstate, self.uistate, self.track, self.p1, self.p2, self.on_update, True) def on_update(self): if self.db.has_person_handle(self.p1): titanic = self.p2 else: titanic = self.p1 self.dellist.add(titanic) self.update() self.redraw() def update_and_destroy(self, obj): self.update(1) self.close() def person_delete(self, handle_list): """ deal with person deletes outside of the tool """ self.dellist.update(handle_list) self.redraw() def __dummy(self, obj): """dummy callback, needed because a shared glade file is used for both toplevel windows and all signals must be handled. """ pass
class Citations(Gramplet, DbGUIElement): def __init__(self, gui, nav_group=0): Gramplet.__init__(self, gui, nav_group) DbGUIElement.__init__(self, self.dbstate.db) """ Displays the citations for an object. """ def init(self): self.gui.WIDGET = self.build_gui() self.gui.get_container_widget().remove(self.gui.textview) self.gui.get_container_widget().add(self.gui.WIDGET) self.gui.WIDGET.show() def _connect_db_signals(self): """ called on init of DbGUIElement, connect to db as required. """ self.callman.register_callbacks({'citation-update': self.changed}) self.callman.connect_all(keys=['citation']) def changed(self, handle): """ Called when a registered citation is updated. """ self.update() def build_gui(self): """ Build the GUI interface. """ tip = _('Double-click on a row to edit the selected source/citation.') self.set_tooltip(tip) top = Gtk.TreeView() titles = [('', NOSORT, 50,), (_('Source/Citation'), 1, 350), (_('Author'), 2, 200), (_('Publisher'), 3, 150)] self.model = ListModel(top, titles, list_mode="tree", event_func=self.invoke_editor) return top def add_citations(self, obj): for citation_handle in obj.get_citation_list(): self.add_citation_ref(citation_handle) def add_name_citations(self, obj): names = [obj.get_primary_name()] + obj.get_alternate_names() for name in names: self.add_citations(name) def add_attribute_citations(self, obj): for attr in obj.get_attribute_list(): self.add_citations(attr) def add_mediaref_citations(self, obj): for media_ref in obj.get_media_list(): self.add_citations(media_ref) self.add_attribute_citations(media_ref) media = self.dbstate.db.get_media_from_handle(media_ref.ref) self.add_media_citations(media) def add_media_citations(self, media): self.add_citations(media) self.add_attribute_citations(media) def add_eventref_citations(self, obj): for event_ref in obj.get_event_ref_list(): self.add_attribute_citations(event_ref) event = self.dbstate.db.get_event_from_handle(event_ref.ref) self.add_event_citations(event) def add_event_citations(self, event): self.add_citations(event) self.add_attribute_citations(event) self.add_mediaref_citations(event) place_handle = event.get_place_handle() if place_handle: place = self.dbstate.db.get_place_from_handle(place_handle) if place: self.add_place_citations(place) def add_place_citations(self, place): self.add_citations(place) self.add_mediaref_citations(place) def add_address_citations(self, obj): for address in obj.get_address_list(): self.add_citations(address) def add_lds_citations(self, obj): for lds in obj.get_lds_ord_list(): self.add_citations(lds) place_handle = lds.get_place_handle() place = self.dbstate.db.get_place_from_handle(place_handle) if place: self.add_place_citations(place) def add_association_citations(self, obj): for assoc in obj.get_person_ref_list(): self.add_citations(assoc) def add_citation_ref(self, citation_handle): """ Add a citation to the model. """ self.callman.register_handles({'citation': [citation_handle]}) citation = self.dbstate.db.get_citation_from_handle(citation_handle) page = citation.get_page() if not page: page = _('<No Citation>') source_handle = citation.get_reference_handle() source = self.dbstate.db.get_source_from_handle(source_handle) title = source.get_title() author = source.get_author() publisher = source.get_publication_info() if source_handle not in self.source_nodes: node = self.model.add([source_handle, title, author, publisher]) self.source_nodes[source_handle] = node self.model.add([citation_handle, page, '', ''], node=self.source_nodes[source_handle]) def check_citations(self, obj): return True if obj.get_citation_list() else False def check_name_citations(self, obj): names = [obj.get_primary_name()] + obj.get_alternate_names() for name in names: if self.check_citations(name): return True return False def check_attribute_citations(self, obj): for attr in obj.get_attribute_list(): if self.check_citations(attr): return True return False def check_mediaref_citations(self, obj): for media_ref in obj.get_media_list(): if self.check_citations(media_ref): return True if self.check_attribute_citations(media_ref): return True media = self.dbstate.db.get_media_from_handle(media_ref.ref) if self.check_media_citations(media): return True return False def check_media_citations(self, media): if self.check_citations(media): return True if self.check_attribute_citations(media): return True return False def check_eventref_citations(self, obj): if obj: for event_ref in obj.get_event_ref_list(): if self.check_attribute_citations(event_ref): return True event = self.dbstate.db.get_event_from_handle(event_ref.ref) if self.check_event_citations(event): return True return False def check_event_citations(self, event): if self.check_citations(event): return True if self.check_attribute_citations(event): return True if self.check_mediaref_citations(event): return True place_handle = event.get_place_handle() if place_handle: place = self.dbstate.db.get_place_from_handle(place_handle) if place and self.check_place_citations(place): return True return False def check_place_citations(self, place): if self.check_citations(place): return True if self.check_mediaref_citations(place): return True return False def check_address_citations(self, obj): for address in obj.get_address_list(): if self.check_citations(address): return True return False def check_lds_citations(self, obj): for lds in obj.get_lds_ord_list(): if self.check_citations(lds): return True place_handle = lds.get_place_handle() place = self.dbstate.db.get_place_from_handle(place_handle) if place and self.check_place_citations(place): return True return False def check_association_citations(self, obj): for assoc in obj.get_person_ref_list(): if self.check_citations(assoc): return True return False def invoke_editor(self, treeview): """ Edit the selected source or citation. """ model, iter_ = treeview.get_selection().get_selected() if iter_: handle = model.get_value(iter_, 0) # bug 9094. # str(model.get_path(iter_)) return something like NNN:MMM # So if we have only NNN, it's a node # removing the str() solves the problem. if len(model.get_path(iter_)) == 1: self.edit_source(handle) else: self.edit_citation(handle) def edit_source(self, handle): """ Edit the selected source. """ try: source = self.dbstate.db.get_source_from_handle(handle) EditSource(self.dbstate, self.uistate, [], source) except WindowActiveError: pass def edit_citation(self, handle): """ Edit the selected citation. """ try: citation = self.dbstate.db.get_citation_from_handle(handle) source_handle = citation.get_reference_handle() source = self.dbstate.db.get_source_from_handle(source_handle) EditCitation(self.dbstate, self.uistate, [], citation, source) except WindowActiveError: pass
class MediaBrowser(Gramplet): """ Displays an object tree and a media preview for a person. """ def init(self): self.gui.WIDGET = self.build_gui() self.gui.get_container_widget().remove(self.gui.textview) self.gui.get_container_widget().add_with_viewport(self.gui.WIDGET) self.gui.WIDGET.show() def build_gui(self): """ Build the GUI interface. """ top = Gtk.HBox() self.photo = Photo() self.photo.show() view = Gtk.TreeView() titles = [(_('Object'), 1, 250)] self.model = ListModel(view, titles, list_mode="tree", select_func=self.row_selected) top.pack_start(view, True, True, 0) top.pack_start(self.photo, True, False, 5) top.show_all() return top def db_changed(self): self.dbstate.db.connect('person-update', self.update) self.update() def active_changed(self, handle): self.update() def update_has_data(self): active_handle = self.get_active('Person') active = self.dbstate.db.get_person_from_handle(active_handle) self.set_has_data(self.get_has_data(active)) def main(self): active_handle = self.get_active('Person') active = self.dbstate.db.get_person_from_handle(active_handle) self.model.clear() self.photo.set_image(None) if active: self.display_data(active) else: self.set_has_data(False) def display_data(self, person): """ Display the object tree for the active person. """ self.add_media(person) self.add_events(person) self.add_sources(person) self.set_has_data(self.model.count > 0) def add_events(self, obj, parent_node=None): """ Add event nodes to the model. """ for event_ref in obj.get_event_ref_list(): handle = event_ref.ref name, event = navigation_label(self.dbstate.db, 'Event', handle) node = self.model.add([name], node=parent_node) self.add_sources(event, node) self.add_media(event, node) def add_sources(self, obj, parent_node=None): """ Add source nodes to the model. """ for citation_handle in obj.get_citation_list(): citation = self.dbstate.db.get_citation_from_handle(citation_handle) handle = citation.get_reference_handle() name, src = navigation_label(self.dbstate.db, 'Source', handle) node = self.model.add([name], node=parent_node) self.add_media(src, node) def add_media(self, obj, parent_node=None): """ Add media object nodes to the model. """ for media_ref in obj.get_media_list(): handle = media_ref.ref name, media = navigation_label(self.dbstate.db, 'Media', handle) full_path = media_path_full(self.dbstate.db, media.get_path()) rect = media_ref.get_rectangle() self.model.add([name], info=media_ref, node=parent_node) def row_selected(self, selection): """ Change the image when a row is selected. """ selected = self.model.get_selected_objects() if selected: if selected[0]: self.load_image(selected[0]) else: self.photo.set_image(None) else: self.photo.set_image(None) def load_image(self, media_ref): """ Display an image from the given media reference. """ media = self.dbstate.db.get_object_from_handle(media_ref.ref) full_path = media_path_full(self.dbstate.db, media.get_path()) mime_type = media.get_mime_type() rectangle = media_ref.get_rectangle() self.photo.set_image(full_path, mime_type, rectangle) def get_has_data(self, person): """ Return True if the gramplet has data, else return False. """ if person is None: return False elif person.get_event_ref_list(): return True elif person.get_citation_list(): return True elif person.get_media_list(): return True return False
class Events(Gramplet, DbGUIElement): def __init__(self, gui, nav_group=0): Gramplet.__init__(self, gui, nav_group) DbGUIElement.__init__(self, self.dbstate.db) """ Displays the events for a person or family. """ def init(self): self.gui.WIDGET = self.build_gui() self.gui.get_container_widget().remove(self.gui.textview) self.gui.get_container_widget().add(self.gui.WIDGET) self.gui.WIDGET.show() def _connect_db_signals(self): """ called on init of DbGUIElement, connect to db as required. """ self.callman.register_callbacks({'event-update': self.changed}) self.callman.connect_all(keys=['event']) def changed(self, handle): """ Called when a registered event is updated. """ self.update() def build_gui(self): """ Build the GUI interface. """ tip = _('Double-click on a row to edit the selected event.') self.set_tooltip(tip) top = Gtk.TreeView() titles = [('', NOSORT, 50,), (_('Type'), 1, 100), (_('Description'), 2, 150), (_('Date'), 3, 100), ('', NOSORT, 50), (_('Age'), 4, 100), ('', NOSORT, 50), (_('Place'), 5, 400), (_('Main Participants'), 6, 200), (_('Role'), 7, 100)] self.model = ListModel(top, titles, event_func=self.edit_event) return top def add_event_ref(self, event_ref, spouse=None): """ Add an event to the model. """ self.callman.register_handles({'event': [event_ref.ref]}) event = self.dbstate.db.get_event_from_handle(event_ref.ref) event_date = get_date(event) event_sort = '%012d' % event.get_date_object().get_sort_value() person_age = self.column_age(event) person_age_sort = self.column_sort_age(event) place = place_displayer.display_event(self.dbstate.db, event) participants = get_participant_from_event(self.dbstate.db, event_ref.ref) self.model.add((event.get_handle(), str(event.get_type()), event.get_description(), event_date, event_sort, person_age, person_age_sort, place, participants, str(event_ref.get_role()))) def column_age(self, event): """ Returns a string representation of age in years. Change precision=2 for "year, month", or precision=3 for "year, month, days" """ date = event.get_date_object() start_date = self.get_start_date() if date and start_date: return (date - start_date).format(precision=age_precision) else: return "" def column_sort_age(self, event): """ Returns a string version of number of days of age. """ date = event.get_date_object() start_date = self.get_start_date() if date and start_date: return "%09d" % int(date - start_date) else: return "" def edit_event(self, treeview): """ Edit the selected event. """ model, iter_ = treeview.get_selection().get_selected() if iter_: handle = model.get_value(iter_, 0) try: event = self.dbstate.db.get_event_from_handle(handle) EditEvent(self.dbstate, self.uistate, [], event) except WindowActiveError: pass
class PersonChildren(Children): """ Displays the children of a person. """ def build_gui(self): """ Build the GUI interface. """ tip = _('Double-click on a row to edit the selected child.') self.set_tooltip(tip) top = Gtk.TreeView() titles = [('', NOSORT, 50,), (_('Child'), 1, 250), (_('Birth Date'), 3, 100), ('', 3, 100), (_('Death Date'), 5, 100), ('', 5, 100), (_('Spouse'), 6, 250)] self.model = ListModel(top, titles, event_func=self.edit_person) return top def db_changed(self): self.dbstate.db.connect('person-update', self.update) def active_changed(self, handle): self.update() def main(self): active_handle = self.get_active('Person') self.model.clear() if active_handle: self.display_person(active_handle) else: self.set_has_data(False) def update_has_data(self): active_handle = self.get_active('Person') if active_handle: active = self.dbstate.db.get_person_from_handle(active_handle) self.set_has_data(self.get_has_data(active)) else: self.set_has_data(False) def get_has_data(self, active_person): """ Return True if the gramplet has data, else return False. """ if active_person is None: return False for family_handle in active_person.get_family_handle_list(): family = self.dbstate.db.get_family_from_handle(family_handle) if family and family.get_child_ref_list(): return True return False def display_person(self, active_handle): """ Display the children of the active person. """ active_person = self.dbstate.db.get_person_from_handle(active_handle) for family_handle in active_person.get_family_handle_list(): family = self.dbstate.db.get_family_from_handle(family_handle) self.display_family(family, active_person) self.set_has_data(self.model.count > 0) def display_family(self, family, active_person): """ Display the children of given family. """ spouse_handle = find_spouse(active_person, family) if spouse_handle: spouse = self.dbstate.db.get_person_from_handle(spouse_handle) else: spouse = None for child_ref in family.get_child_ref_list(): child = self.dbstate.db.get_person_from_handle(child_ref.ref) self.add_child(child, spouse) def add_child(self, child, spouse): """ Add a child to the model. """ name = name_displayer.display(child) if spouse: spouse = name_displayer.display(spouse) spouse = spouse or '' birth = get_birth_or_fallback(self.dbstate.db, child) birth_date, birth_sort, birth_place = self.get_date_place(birth) death = get_death_or_fallback(self.dbstate.db, child) death_date, death_sort, death_place = self.get_date_place(death) self.model.add((child.get_handle(), name, birth_date, birth_sort, death_date, death_sort, spouse))
class ShowMatches(ManagedWindow): def __init__(self, dbstate, uistate, track, the_list, the_map, callback): ManagedWindow.__init__(self,uistate,track,self.__class__) self.dellist = {} self.list = the_list self.map = the_map self.length = len(self.list) self.update = callback self.db = dbstate.db self.dbstate = dbstate self.uistate = uistate top = Glade(toplevel="mergelist") window = top.toplevel self.set_window(window, top.get_object('title'), _('Potential Merges')) self.mlist = top.get_object("mlist") top.connect_signals({ "destroy_passed_object" : self.close, "on_do_merge_clicked" : self.on_do_merge_clicked, "on_help_show_clicked" : self.on_help_clicked, "on_delete_show_event" : self.close, "on_merge_ok_clicked" : self.__dummy, "on_help_clicked" : self.__dummy, "on_delete_merge_event" : self.__dummy, "on_delete_event" : self.__dummy, }) mtitles = [ (_('Rating'),3,75), (_('First Person'),1,200), (_('Second Person'),2,200), ('',-1,0) ] self.list = ListModel(self.mlist,mtitles, event_func=self.on_do_merge_clicked) self.redraw() self.show() def build_menu_names(self, obj): return (_("Merge candidates"),None) def on_help_clicked(self, obj): """Display the relevant portion of GRAMPS manual""" display_help(WIKI_HELP_PAGE , WIKI_HELP_SEC) def redraw(self): list = [] for p1key, p1data in self.map.items(): if p1key in self.dellist: continue (p2key,c) = p1data if p1key == p2key: continue list.append((c,p1key,p2key)) self.list.clear() for (c,p1key,p2key) in list: c1 = "%5.2f" % c c2 = "%5.2f" % (100-c) p1 = self.db.get_person_from_handle(p1key) p2 = self.db.get_person_from_handle(p2key) if not p1 or not p2: continue pn1 = name_displayer.display(p1) pn2 = name_displayer.display(p2) self.list.add([c1, pn1, pn2,c2],(p1key,p2key)) def on_do_merge_clicked(self, obj): store,iter = self.list.selection.get_selected() if not iter: return (self.p1,self.p2) = self.list.get_object(iter) MergePerson(self.dbstate, self.uistate, self.p1, self.p2, self.on_update, True) def on_update(self): if self.db.has_person_handle(self.p1): phoenix = self.p1 titanic = self.p2 else: phoenix = self.p2 titanic = self.p1 self.dellist[titanic] = phoenix for key, data in self.dellist.items(): if data == titanic: self.dellist[key] = phoenix self.update() self.redraw() def update_and_destroy(self, obj): self.update(1) self.close() def __dummy(self, obj): """dummy callback, needed because a shared glade file is used for both toplevel windows and all signals must be handled. """ pass
class Citations(Gramplet, DbGUIElement): """ Displays the citations for an object. """ def __init__(self, gui, nav_group=0): Gramplet.__init__(self, gui, nav_group) DbGUIElement.__init__(self, self.dbstate.db) self.source_nodes = {} def init(self): self.gui.WIDGET = self.build_gui() self.gui.get_container_widget().remove(self.gui.textview) self.gui.get_container_widget().add(self.gui.WIDGET) self.gui.WIDGET.show() def _connect_db_signals(self): """ called on init of DbGUIElement, connect to db as required. """ self.callman.register_callbacks({ 'citation-update': self.changed, 'person-update': self.changed, 'family-update': self.changed, 'event-update': self.changed, 'media-update': self.changed, 'place-update': self.changed }) self.callman.connect_all( keys=['citation', 'family', 'person', 'event', 'media', 'place']) def changed(self, handle): """ Called when a registered citation is updated. """ self.update() def build_gui(self): """ Build the GUI interface. """ tip = _('Double-click on a row to edit the selected source/citation.') self.set_tooltip(tip) top = Gtk.TreeView() titles = [( '', NOSORT, 50, ), (_('Source/Date'), 1, 350), (_('Volume/Page'), 2, 150), (_('Confidence Level'), 3, 150), (_('Author'), 4, 200), (_('Publisher'), 5, 150)] self.model = ListModel(top, titles, list_mode="tree", event_func=self.invoke_editor) return top def add_citations(self, obj): for citation_handle in obj.get_citation_list(): self.add_citation_ref(citation_handle) def add_name_citations(self, obj): names = [obj.get_primary_name()] + obj.get_alternate_names() for name in names: self.add_citations(name) def add_attribute_citations(self, obj): for attr in obj.get_attribute_list(): self.add_citations(attr) def add_mediaref_citations(self, obj): for media_ref in obj.get_media_list(): self.add_citations(media_ref) self.add_attribute_citations(media_ref) media = self.dbstate.db.get_media_from_handle(media_ref.ref) self.add_media_citations(media) def add_media_citations(self, media): self.callman.register_handles({'media': [media.handle]}) self.add_citations(media) self.add_attribute_citations(media) def add_eventref_citations(self, obj): for event_ref in obj.get_event_ref_list(): self.add_attribute_citations(event_ref) event = self.dbstate.db.get_event_from_handle(event_ref.ref) self.add_event_citations(event) def add_event_citations(self, event): self.callman.register_handles({'event': [event.handle]}) self.add_citations(event) self.add_attribute_citations(event) self.add_mediaref_citations(event) place_handle = event.get_place_handle() if place_handle: place = self.dbstate.db.get_place_from_handle(place_handle) if place: self.add_place_citations(place) def add_place_citations(self, place): self.callman.register_handles({'place': [place.handle]}) self.add_citations(place) self.add_mediaref_citations(place) def add_address_citations(self, obj): for address in obj.get_address_list(): self.add_citations(address) def add_lds_citations(self, obj): for lds in obj.get_lds_ord_list(): self.add_citations(lds) place_handle = lds.get_place_handle() if place_handle: place = self.dbstate.db.get_place_from_handle(place_handle) if place: self.add_place_citations(place) def add_association_citations(self, obj): for assoc in obj.get_person_ref_list(): self.add_citations(assoc) def add_citation_ref(self, citation_handle): """ Add a citation to the model. """ self.callman.register_handles({'citation': [citation_handle]}) citation = self.dbstate.db.get_citation_from_handle(citation_handle) page = citation.get_page() if not page: page = _('<No Volume/Page>') source_handle = citation.get_reference_handle() source = self.dbstate.db.get_source_from_handle(source_handle) title = source.get_title() author = source.get_author() publisher = source.get_publication_info() confidence = citation.get_confidence_level() if source_handle not in self.source_nodes: node = self.model.add( [source_handle, title, '', '', author, publisher]) self.source_nodes[source_handle] = node self.model.add([ citation_handle, get_date(citation), page, _(conf_strings[confidence]), '', '' ], node=self.source_nodes[source_handle]) def check_citations(self, obj): return True if obj.get_citation_list() else False def check_name_citations(self, obj): names = [obj.get_primary_name()] + obj.get_alternate_names() for name in names: if self.check_citations(name): return True return False def check_attribute_citations(self, obj): for attr in obj.get_attribute_list(): if self.check_citations(attr): return True return False def check_mediaref_citations(self, obj): for media_ref in obj.get_media_list(): if self.check_citations(media_ref): return True if self.check_attribute_citations(media_ref): return True media = self.dbstate.db.get_media_from_handle(media_ref.ref) if self.check_media_citations(media): return True return False def check_media_citations(self, media): if self.check_citations(media): return True if self.check_attribute_citations(media): return True return False def check_eventref_citations(self, obj): if obj: for event_ref in obj.get_event_ref_list(): if self.check_attribute_citations(event_ref): return True event = self.dbstate.db.get_event_from_handle(event_ref.ref) if self.check_event_citations(event): return True return False def check_event_citations(self, event): if self.check_citations(event): return True if self.check_attribute_citations(event): return True if self.check_mediaref_citations(event): return True place_handle = event.get_place_handle() if place_handle: place = self.dbstate.db.get_place_from_handle(place_handle) if place and self.check_place_citations(place): return True return False def check_place_citations(self, place): if self.check_citations(place): return True if self.check_mediaref_citations(place): return True return False def check_address_citations(self, obj): for address in obj.get_address_list(): if self.check_citations(address): return True return False def check_lds_citations(self, obj): for lds in obj.get_lds_ord_list(): if self.check_citations(lds): return True place_handle = lds.get_place_handle() if place_handle: place = self.dbstate.db.get_place_from_handle(place_handle) if place and self.check_place_citations(place): return True return False def check_association_citations(self, obj): for assoc in obj.get_person_ref_list(): if self.check_citations(assoc): return True return False def invoke_editor(self, treeview): """ Edit the selected source or citation. """ model, iter_ = treeview.get_selection().get_selected() if iter_: handle = model.get_value(iter_, 0) # bug 9094. # str(model.get_path(iter_)) return something like NNN:MMM # So if we have only NNN, it's a node # removing the str() solves the problem. if len(model.get_path(iter_)) == 1: self.edit_source(handle) else: self.edit_citation(handle) def edit_source(self, handle): """ Edit the selected source. """ try: source = self.dbstate.db.get_source_from_handle(handle) EditSource(self.dbstate, self.uistate, [], source) except WindowActiveError: pass def edit_citation(self, handle): """ Edit the selected citation. """ try: citation = self.dbstate.db.get_citation_from_handle(handle) source_handle = citation.get_reference_handle() source = self.dbstate.db.get_source_from_handle(source_handle) EditCitation(self.dbstate, self.uistate, [], citation, source) except WindowActiveError: pass
class Descendant(Gramplet): def init(self): self.gui.WIDGET = self.build_gui() self.gui.get_container_widget().remove(self.gui.textview) self.gui.get_container_widget().add_with_viewport(self.gui.WIDGET) self.gui.WIDGET.show() def build_gui(self): """ Build the GUI interface. """ self.view = Gtk.TreeView() self.view.set_tooltip_column(3) titles = [(_('Name'), 0, 230), (_('Birth'), 2, 100), ('', NOSORT, 1), ('', NOSORT, 1), # tooltip ('', NOSORT, 100)] # handle self.model = ListModel(self.view, titles, list_mode="tree", event_func=self.cb_double_click, right_click=self.cb_right_click) return self.view def get_has_data(self, active_handle): """ Return True if the gramplet has data, else return False. """ if active_handle: person = self.dbstate.db.get_person_from_handle(active_handle) if person: for family_handle in person.get_family_handle_list(): family = self.dbstate.db.get_family_from_handle(family_handle) if family: for child_ref in family.get_child_ref_list(): return True return False def cb_double_click(self, treeview): """ Handle double click on treeview. """ (model, iter_) = treeview.get_selection().get_selected() if not iter_: return try: handle = model.get_value(iter_, 4) person = self.dbstate.db.get_person_from_handle(handle) EditPerson(self.dbstate, self.uistate, [], person) except WindowActiveError: pass def cb_right_click(self, treeview, event): """ Handle right click on treeview. """ (model, iter_) = treeview.get_selection().get_selected() sensitivity = 1 if iter_ else 0 menu = Gtk.Menu() menu.set_title(_('Descendent Menu')) entries = [ (_("Edit"), lambda obj: self.cb_double_click(treeview), sensitivity), (None, None, 0), (_("Copy all"), lambda obj: self.on_copy_all(treeview), 1), ] for stock_id, callback, sensitivity in entries: item = Gtk.ImageMenuItem(stock_id) if callback: item.connect("activate", callback) item.set_sensitive(sensitivity) item.show() menu.append(item) self.menu = menu self.menu.popup(None, None, None, None, event.button, event.time) def on_copy_all(self, treeview): model = treeview.get_model() text = model_to_text(model, [0, 1], level=1) text_to_clipboard(text) def db_changed(self): self.update() def active_changed(self, handle): self.update() def update_has_data(self): active_handle = self.get_active('Person') if active_handle: self.set_has_data(self.get_has_data(active_handle)) else: self.set_has_data(False) def main(self): active_handle = self.get_active('Person') self.model.clear() if active_handle: self.add_to_tree(None, active_handle) self.view.expand_all() self.set_has_data(self.get_has_data(active_handle)) else: self.set_has_data(False) def add_to_tree(self, parent_id, person_handle): person = self.dbstate.db.get_person_from_handle(person_handle) name = name_displayer.display(person) birth = get_birth_or_fallback(self.dbstate.db, person) death = get_death_or_fallback(self.dbstate.db, person) birth_text = birth_date = birth_sort = '' if birth: birth_date = get_date(birth) birth_sort = '%012d' % birth.get_date_object().get_sort_value() birth_text = _('%(abbr)s %(date)s') % \ {'abbr': birth.type.get_abbreviation(), 'date': birth_date} death_date = death_sort = death_text = '' if death: death_date = get_date(death) death_sort = '%012d' % death.get_date_object().get_sort_value() death_text = _('%(abbr)s %(date)s') % \ {'abbr': death.type.get_abbreviation(), 'date': death_date} tooltip = name + '\n' + birth_text + '\n' + death_text item_id = self.model.add([name, birth_date, birth_sort, tooltip, person_handle], node=parent_id) for family_handle in person.get_family_handle_list(): family = self.dbstate.db.get_family_from_handle(family_handle) for child_ref in family.get_child_ref_list(): self.add_to_tree(item_id, child_ref.ref) return item_id
class MediaBrowser(Gramplet): """ Displays an object tree and a media preview for a person. """ def init(self): self.gui.WIDGET = self.build_gui() self.gui.get_container_widget().remove(self.gui.textview) self.gui.get_container_widget().add_with_viewport(self.gui.WIDGET) self.gui.WIDGET.show() def build_gui(self): """ Build the GUI interface. """ top = Gtk.HBox() self.photo = Photo() self.photo.show() view = Gtk.TreeView() titles = [(_("Object"), 1, 250)] self.model = ListModel(view, titles, list_mode="tree", select_func=self.row_selected) top.pack_start(view, True, True, 0) top.pack_start(self.photo, True, False, 5) top.show_all() return top def db_changed(self): self.dbstate.db.connect("person-update", self.update) self.update() def active_changed(self, handle): self.update() def update_has_data(self): active_handle = self.get_active("Person") active = self.dbstate.db.get_person_from_handle(active_handle) self.set_has_data(self.get_has_data(active)) def main(self): active_handle = self.get_active("Person") active = self.dbstate.db.get_person_from_handle(active_handle) self.model.clear() self.photo.set_image(None) if active: self.display_data(active) else: self.set_has_data(False) def display_data(self, person): """ Display the object tree for the active person. """ self.add_media(person) self.add_events(person) self.add_sources(person) self.set_has_data(self.model.count > 0) def add_events(self, obj, parent_node=None): """ Add event nodes to the model. """ for event_ref in obj.get_event_ref_list(): handle = event_ref.ref name, event = navigation_label(self.dbstate.db, "Event", handle) node = self.model.add([name], node=parent_node) self.add_sources(event, node) self.add_media(event, node) def add_sources(self, obj, parent_node=None): """ Add source nodes to the model. """ for citation_handle in obj.get_citation_list(): citation = self.dbstate.db.get_citation_from_handle(citation_handle) handle = citation.get_reference_handle() name, src = navigation_label(self.dbstate.db, "Source", handle) node = self.model.add([name], node=parent_node) self.add_media(src, node) def add_media(self, obj, parent_node=None): """ Add media object nodes to the model. """ for media_ref in obj.get_media_list(): handle = media_ref.ref name, media = navigation_label(self.dbstate.db, "Media", handle) full_path = media_path_full(self.dbstate.db, media.get_path()) rect = media_ref.get_rectangle() self.model.add([name], info=media_ref, node=parent_node) def row_selected(self, selection): """ Change the image when a row is selected. """ selected = self.model.get_selected_objects() if selected: if selected[0]: self.load_image(selected[0]) else: self.photo.set_image(None) else: self.photo.set_image(None) def load_image(self, media_ref): """ Display an image from the given media reference. """ media = self.dbstate.db.get_object_from_handle(media_ref.ref) full_path = media_path_full(self.dbstate.db, media.get_path()) mime_type = media.get_mime_type() rectangle = media_ref.get_rectangle() self.photo.set_image(full_path, mime_type, rectangle) def get_has_data(self, person): """ Return True if the gramplet has data, else return False. """ if person is None: return False elif person.get_event_ref_list(): return True elif person.get_citation_list(): return True elif person.get_media_list(): return True return False
class Locations(Gramplet, DbGUIElement): """ Gramplet showing the locations of a place over time. """ def __init__(self, gui, nav_group=0): Gramplet.__init__(self, gui, nav_group) DbGUIElement.__init__(self, self.dbstate.db) def init(self): self.gui.WIDGET = self.build_gui() self.gui.get_container_widget().remove(self.gui.textview) self.gui.get_container_widget().add(self.gui.WIDGET) self.gui.WIDGET.show() def _connect_db_signals(self): """ called on init of DbGUIElement, connect to db as required. """ self.callman.register_callbacks({'place-update': self.changed}) self.callman.connect_all(keys=['place']) def db_changed(self): self.connect_signal('Place', self.update) def changed(self, handle): """ Called when a registered place is updated. """ self.update() def build_gui(self): """ Build the GUI interface. """ tip = _('Double-click on a row to edit the selected place.') self.set_tooltip(tip) top = Gtk.TreeView() titles = [('', 0, 50), (_('Name'), 1, 300), (_('Type'), 2, 150), (_('Date'), 4, 150), ('', NOSORT, 50)] self.model = ListModel(top, titles, list_mode="tree", event_func=self.edit_place) return top def active_changed(self, handle): self.update() def update_has_data(self): active_handle = self.get_active('Place') if active_handle: active = self.dbstate.db.get_place_from_handle(active_handle) self.set_has_data(self.get_has_data(active)) else: self.set_has_data(False) def get_has_data(self, place): """ Return True if the gramplet has data, else return False. """ pass def main(self): self.model.clear() self.callman.unregister_all() active_handle = self.get_active('Place') if active_handle: active = self.dbstate.db.get_place_from_handle(active_handle) if active: self.display_place(active, None, [active_handle]) else: self.set_has_data(False) else: self.set_has_data(False) def display_place(self, place, node, visited): """ Display the location hierarchy for the active place. """ pass def add_place(self, placeref, place, node, visited): """ Add a place to the model. """ place_date = get_date(placeref) place_sort = '%012d' % placeref.get_date_object().get_sort_value() place_name = place.get_name().get_value() place_type = str(place.get_type()) new_node = self.model.add([place.handle, place_name, place_type, place_date, place_sort], node=node) self.display_place(place, new_node, visited + [place.handle]) def edit_place(self, treeview): """ Edit the selected place. """ model, iter_ = treeview.get_selection().get_selected() if iter_: handle = model.get_value(iter_, 0) place = self.dbstate.db.get_place_from_handle(handle) try: EditPlace(self.dbstate, self.uistate, [], place) except WindowActiveError: pass
class Backlinks(Gramplet): """ Displays the back references for an object. """ def init(self): self.date_column = None self.evts = False self.gui.WIDGET = self.build_gui() self.gui.get_container_widget().remove(self.gui.textview) self.gui.get_container_widget().add(self.gui.WIDGET) self.gui.WIDGET.show() def build_gui(self): """ Build the GUI interface. """ self.top = Gtk.TreeView() titles = [ (_('Type'), 1, 100), (_('Name'), 2, 100), (_('Date'), 4, 200), ('sd', 4, 120), # sorted date column ('', 5, 1), #hidden column for the handle ('', 6, 1), #hidden column for non-localized object type ] self.model = ListModel(self.top, titles, event_func=self.cb_double_click) self.date_column = self.top.get_column(2) self.sdate = self.top.get_column(3) self.top.get_column(1).set_expand(True) # The name use the max # possible size return self.top def display_backlinks(self, active_handle): """ Display the back references for an object. """ self.evts = False sdcolumn = None for classname, handle in \ self.dbstate.db.find_backlink_handles(active_handle): name = navigation_label(self.dbstate.db, classname, handle)[0] sdcolumn = self.top.get_column(3) dcolumn = self.top.get_column(2) if classname == "Event": obj = self.dbstate.db.get_event_from_handle(handle) o_date = obj.get_date_object() date = displayer.display(o_date) sdate = "%09d" % o_date.get_sort_value() sdcolumn.set_sort_column_id(3) dcolumn.set_sort_column_id(3) self.evts = True else: sdcolumn.set_sort_column_id(1) date = sdate = "" self.model.add( (_(classname), name, date, sdate, handle, classname)) if self.evts: self.date_column.set_visible(True) sdcolumn.set_visible(False) else: self.date_column.set_visible(False) if sdcolumn: sdcolumn.set_visible(False) self.set_has_data(self.model.count > 0) def get_has_data(self, active_handle): """ Return True if the gramplet has data, else return False. """ if not active_handle: return False for handle in self.dbstate.db.find_backlink_handles(active_handle): return True return False def cb_double_click(self, treeview): """ Handle double click on treeview. """ (model, iter_) = treeview.get_selection().get_selected() if not iter_: return (objclass, handle) = (model.get_value(iter_, 5), model.get_value(iter_, 4)) edit_object(self.dbstate, self.uistate, objclass, handle)
def __init__(self): Gtk.TreeView.__init__(self) self.sections = {} titles = [(_('Key'), 1, 235), (_('Value'), 2, 325)] self.model = ListModel(self, titles, list_mode="tree")
class Overview(Gramplet): """ Displays an overview of events for a person or family. """ def init(self): self.gui.WIDGET = self.build_gui() self.gui.get_container_widget().remove(self.gui.textview) self.gui.get_container_widget().add_with_viewport(self.gui.WIDGET) self.gui.WIDGET.show() def build_gui(self): """ Build the GUI interface. """ tip = _('Double-click on a row to edit the selected event.') self.set_tooltip(tip) top = Gtk.TreeView() titles = [( '', NOSORT, 50, ), (_('Type'), 1, 100), (_('Date'), 3, 100), ('', 3, 100), (_('Age'), 4, 35), (_('Where Born'), 5, 160), (_('Condition'), 6, 75), (_('Occupation'), 7, 160), (_('Residence'), 8, 160)] self.model = ListModel(top, titles, event_func=self.edit_event) return top def add_event_ref(self, event_ref, spouse=None): """ Add an event to the model. """ values = self.get_attributes(event_ref) event = self.dbstate.db.get_event_from_handle(event_ref.ref) event_date = get_date(event) event_sort = '%012d' % event.get_date_object().get_sort_value() self.model.add( (event.get_handle(), str(event.get_type()), event_date, event_sort, values[0], values[1], values[2], values[3], values[4])) def get_attributes(self, event_ref): """ Get selected attributes from event reference. """ values = [''] * 5 for attr in event_ref.get_attribute_list(): if attr.get_type() == AttributeType.AGE: values[0] = attr.get_value() elif str(attr.get_type()) == _('Where Born'): values[1] = attr.get_value() elif str(attr.get_type()) == _('Condition'): values[2] = attr.get_value() elif str(attr.get_type()) == _('Occupation'): values[3] = attr.get_value() elif str(attr.get_type()) == _('Residence'): values[4] = attr.get_value() return values def edit_event(self, treeview): """ Edit the selected event. """ model, iter_ = treeview.get_selection().get_selected() if iter_: handle = model.get_value(iter_, 0) try: event = self.dbstate.db.get_event_from_handle(handle) EditEvent(self.dbstate, self.uistate, [], event) except WindowActiveError: pass
class Ancestor(Gramplet): def init(self): self.gui.WIDGET = self.build_gui() self.gui.get_container_widget().remove(self.gui.textview) self.gui.get_container_widget().add(self.gui.WIDGET) self.gui.WIDGET.show() def build_gui(self): """ Build the GUI interface. """ self.view = Gtk.TreeView() self.view.set_tooltip_column(3) titles = [(_('Name'), 0, 230), (_('Birth'), 2, 100), ('', NOSORT, 1), ('', NOSORT, 1), # tooltip ('', NOSORT, 100)] # handle self.model = ListModel(self.view, titles, list_mode="tree", event_func=self.cb_double_click) return self.view def get_has_data(self, active_handle): """ Return True if the gramplet has data, else return False. """ if active_handle: person = self.dbstate.db.get_person_from_handle(active_handle) if person: family_handle = person.get_main_parents_family_handle() family = self.dbstate.db.get_family_from_handle(family_handle) if family and (family.get_father_handle() or family.get_mother_handle()): return True return False def cb_double_click(self, treeview): """ Handle double click on treeview. """ (model, iter_) = treeview.get_selection().get_selected() if not iter_: return try: handle = model.get_value(iter_, 4) person = self.dbstate.db.get_person_from_handle(handle) EditPerson(self.dbstate, self.uistate, [], person) except WindowActiveError: pass def db_changed(self): self.update() def active_changed(self, handle): self.update() def update_has_data(self): active_handle = self.get_active('Person') if active_handle: self.set_has_data(self.get_has_data(active_handle)) else: self.set_has_data(False) def main(self): active_handle = self.get_active('Person') self.model.clear() if active_handle: self.add_to_tree(1, None, active_handle) self.view.expand_all() self.set_has_data(self.get_has_data(active_handle)) else: self.set_has_data(False) def add_to_tree(self, depth, parent_id, person_handle): if depth > config.get('behavior.generation-depth'): return person = self.dbstate.db.get_person_from_handle(person_handle) name = name_displayer.display(person) birth = get_birth_or_fallback(self.dbstate.db, person) death = get_death_or_fallback(self.dbstate.db, person) birth_text = birth_date = birth_sort = '' if birth: birth_date = get_date(birth) birth_sort = '%012d' % birth.get_date_object().get_sort_value() birth_text = _('%(abbr)s %(date)s') % \ {'abbr': birth.type.get_abbreviation(), 'date': birth_date} death_date = death_sort = death_text = '' if death: death_date = get_date(death) death_sort = '%012d' % death.get_date_object().get_sort_value() death_text = _('%(abbr)s %(date)s') % \ {'abbr': death.type.get_abbreviation(), 'date': death_date} tooltip = name + '\n' + birth_text + '\n' + death_text label = _('%(depth)s. %(name)s') % {'depth': depth, 'name': name} item_id = self.model.add([label, birth_date, birth_sort, tooltip, person_handle], node=parent_id) family_handle = person.get_main_parents_family_handle() family = self.dbstate.db.get_family_from_handle(family_handle) if family: if family.get_father_handle(): self.add_to_tree(depth + 1, item_id, family.get_father_handle()) if family.get_mother_handle(): self.add_to_tree(depth + 1, item_id, family.get_mother_handle()) return item_id
class Backlinks(Gramplet): """ Displays the back references for an object. """ def init(self): self.gui.WIDGET = self.build_gui() self.gui.get_container_widget().remove(self.gui.textview) self.gui.get_container_widget().add(self.gui.WIDGET) self.gui.WIDGET.show() def build_gui(self): """ Build the GUI interface. """ top = Gtk.TreeView() titles = [ (_('Type'), 1, 100), (_('Name'), 2, 100), ('', 3, 1), #hidden column for the handle ('', 4, 1), #hidden column for non-localized object type (_('Date'), 5, 100), ('', 6, 1) ] #hidden column for date sort value self.model = ListModel(top, titles, event_func=self.cb_double_click) return top def get_date1(self, event, handle): #for eventref in person.event_ref_list: # if handle == eventref.ref: # role = eventref.get_role().string # #print(f'{self.__format_date_place(eventref)}') return (f'{event.get_date_object()}') def display_backlinks(self, active_handle): """ Display the back references for an object. """ for classname, handle in \ self.dbstate.db.find_backlink_handles(active_handle): if classname == 'Event': name = navigation_label(self.dbstate.db, classname, handle)[0] print(classname, name) plevent = self.dbstate.db.get_event_from_handle(handle) #pldate = self.get_date(plevent, active_handle) pldate = get_date(plevent) pldate_sort = '%012d' % plevent.get_date_object( ).get_sort_value() self.model.add((_(classname), name, handle, classname, pldate, pldate_sort)) self.set_has_data(self.model.count > 0) def get_has_data(self, active_handle): """ Return True if the gramplet has data, else return False. """ if not active_handle: return False for handle in self.dbstate.db.find_backlink_handles(active_handle): return True return False def cb_double_click(self, treeview): """ Handle double click on treeview. """ (model, iter_) = treeview.get_selection().get_selected() if not iter_: return (objclass, handle) = (model.get_value(iter_, 3), model.get_value(iter_, 2)) edit_object(self.dbstate, self.uistate, objclass, handle)
class FamilyChildren(Children): """ Displays the children of a family. """ def build_gui(self): """ Build the GUI interface. """ tip = _('Double-click on a row to edit the selected child.') self.set_tooltip(tip) top = Gtk.TreeView() titles = [('', NOSORT, 50,), (_('Child'), 1, 250), (_('Birth Date'), 3, 100), ('', 3, 100), (_('Death Date'), 5, 100), ('', 5, 100)] self.model = ListModel(top, titles, event_func=self.edit_person) return top def db_changed(self): self.connect(self.dbstate.db, 'family-update', self.update) self.connect_signal('Family', self.update) # familiy active-changed self.connect(self.dbstate.db, 'person-update', self.update) def main(self): active_handle = self.get_active('Family') self.model.clear() if active_handle: family = self.dbstate.db.get_family_from_handle(active_handle) self.display_family(family) else: self.set_has_data(False) def update_has_data(self): active_handle = self.get_active('Family') if active_handle: active = self.dbstate.db.get_family_from_handle(active_handle) self.set_has_data(self.get_has_data(active)) else: self.set_has_data(False) def get_has_data(self, active_family): """ Return True if the gramplet has data, else return False. """ if active_family is None: return False if active_family.get_child_ref_list(): return True return False def display_family(self, family): """ Display the children of given family. """ for child_ref in family.get_child_ref_list(): child = self.dbstate.db.get_person_from_handle(child_ref.ref) self.add_child(child) self.set_has_data(self.model.count > 0) def add_child(self, child): """ Add a child to the model. """ name = name_displayer.display(child) birth = get_birth_or_fallback(self.dbstate.db, child) birth_date, birth_sort, birth_place = self.get_date_place(birth) death = get_death_or_fallback(self.dbstate.db, child) death_date, death_sort, death_place = self.get_date_place(death) self.model.add((child.get_handle(), name, birth_date, birth_sort, death_date, death_sort))
class Locations(Gramplet, DbGUIElement): """ Gramplet showing the locations of a place over time. """ def __init__(self, gui, nav_group=0): Gramplet.__init__(self, gui, nav_group) DbGUIElement.__init__(self, self.dbstate.db) def init(self): self.gui.WIDGET = self.build_gui() self.gui.get_container_widget().remove(self.gui.textview) self.gui.get_container_widget().add(self.gui.WIDGET) self.gui.WIDGET.show() def _connect_db_signals(self): """ called on init of DbGUIElement, connect to db as required. """ self.callman.register_callbacks({'place-update': self.changed}) self.callman.connect_all(keys=['place']) def db_changed(self): self.connect_signal('Place', self.update) def changed(self, handle): """ Called when a registered place is updated. """ self.update() def build_gui(self): """ Build the GUI interface. """ tip = _('Double-click on a row to edit the selected place.') self.set_tooltip(tip) top = Gtk.TreeView() titles = [('', 0, 50), (_('Name'), 1, 300), (_('Type'), 2, 150), (_('Date'), 5, 250), (_('ID'), 4, 100), ('', NOSORT, 50)] self.model = ListModel(top, titles, list_mode="tree", event_func=self.edit_place) return top def active_changed(self, handle): self.update() def update_has_data(self): active_handle = self.get_active('Place') if active_handle: active = self.dbstate.db.get_place_from_handle(active_handle) self.set_has_data(self.get_has_data(active)) else: self.set_has_data(False) def get_has_data(self, place): """ Return True if the gramplet has data, else return False. """ pass def main(self): self.model.clear() self.callman.unregister_all() active_handle = self.get_active('Place') if active_handle: active = self.dbstate.db.get_place_from_handle(active_handle) if active: self.display_place(active, None, [active_handle]) else: self.set_has_data(False) else: self.set_has_data(False) def display_place(self, place, node, visited): """ Display the location hierarchy for the active place. """ pass def add_place(self, placeref, place, node, visited): """ Add a place to the model. """ place_date = get_date(placeref) place_sort = '%012d' % placeref.get_date_object().get_sort_value() place_name = place.get_name().get_value() place_type = str(place.get_type()) place_id = place.get_gramps_id() new_node = self.model.add([ place.handle, place_name, place_type, place_date, place_id, place_sort ], node=node) self.display_place(place, new_node, visited + [place.handle]) def edit_place(self, treeview): """ Edit the selected place. """ model, iter_ = treeview.get_selection().get_selected() if iter_: handle = model.get_value(iter_, 0) place = self.dbstate.db.get_place_from_handle(handle) try: EditPlace(self.dbstate, self.uistate, [], place) except WindowActiveError: pass