def write_family(self, family_handle, person = None): family = self.dbstate.db.get_family_from_handle(family_handle) if family is None: from gramps.gui.dialog import WarningDialog WarningDialog( _('Broken family detected'), _('Please run the Check and Repair Database tool'), parent=self.uistate.window) return father_handle = family.get_father_handle() mother_handle = family.get_mother_handle() if self.get_handle() == father_handle: handle = mother_handle else: handle = father_handle vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL) heading = self.write_label(_('Family'), family, False) vbox.pack_start(heading, False, False, 1) if handle or family.get_relationship() != FamilyRelType.UNKNOWN: box = self.write_person(_('Spouse'), handle) if not self.write_relationship_events(box, family): self.write_relationship(box, family) ebox = self.make_dragbox(box, 'Person', handle) vbox.pack_start(ebox, False, False, 1) count = len(family.get_child_ref_list()) ex2 = Gtk.Expander(label='%s (%s):' % (_('Children'), count)) ex2.set_expanded(True) ex2.set_margin_start(24) vbox.pack_start(ex2, False, False, 6) vbox2 = Gtk.Box(orientation=Gtk.Orientation.VERTICAL) hbox = Gtk.Box() addchild = widgets.IconButton(self.add_child_to_fam, family.handle, 'list-add') addchild.set_tooltip_text(_('Add new child to family')) selchild = widgets.IconButton(self.sel_child_to_fam, family.handle, 'gtk-index') selchild.set_tooltip_text(_('Add existing child to family')) hbox.pack_start(addchild, False, True, 0) hbox.pack_start(selchild, False, True, 0) vbox2.pack_start(hbox, False, False, 0) i = 1 child_list = family.get_child_ref_list() for child_ref in child_list: widget = self.write_child(child_ref.ref, i, True) vbox2.pack_start(widget, True, True, 1) i += 1 ex2.add(vbox2) self.vbox2.pack_start(vbox, False, True, 0)
def write_parents(self, family_handle, person = None): family = self.dbstate.db.get_family_from_handle(family_handle) if not family: return vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL) heading = self.write_label(_('Parents'), family, True) vbox.pack_start(heading, False, False, 1) f_handle = family.get_father_handle() box = self.write_person(_('Father'), f_handle) ebox = self.make_dragbox(box, 'Person', f_handle) vbox.pack_start(ebox, False, False, 1) m_handle = family.get_mother_handle() box = self.write_person(_('Mother'), m_handle) ebox = self.make_dragbox(box, 'Person', m_handle) vbox.pack_start(ebox, False, False, 1) if self.show_siblings: active = self.get_handle() count = len(family.get_child_ref_list()) ex2 = Gtk.Expander(label='%s (%s):' % (_('Siblings'), count)) ex2.set_margin_start(24) ex2.set_expanded(True) vbox.pack_start(ex2, False, False, 6) vbox2 = Gtk.Box(orientation=Gtk.Orientation.VERTICAL) hbox = Gtk.Box() addchild = widgets.IconButton(self.add_child_to_fam, family.handle, 'list-add') addchild.set_tooltip_text(_('Add new child to family')) selchild = widgets.IconButton(self.sel_child_to_fam, family.handle, 'gtk-index') selchild.set_tooltip_text(_('Add existing child to family')) hbox.pack_start(addchild, False, True, 0) hbox.pack_start(selchild, False, True, 0) vbox2.pack_start(hbox, False, False, 0) i = 1 child_list = [ref.ref for ref in family.get_child_ref_list()] for child_handle in child_list: child_should_be_linked = (child_handle != active) widget = self.write_child(child_handle, i, child_should_be_linked) vbox2.pack_start(widget, True, True, 1) i += 1 ex2.add(vbox2) self.vbox2.pack_start(vbox, False, True, 0)
def write_child(self, handle, index, child_should_be_linked): """ Write a child cell (used for children and siblings of active person) """ vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL) parent = self.has_children( self.dbstate.db.get_person_from_handle(handle)) emph = False if child_should_be_linked and parent: emph = True elif child_should_be_linked and not parent: emph = False elif parent and not child_should_be_linked: emph = None if child_should_be_linked: link_func = self._person_link else: link_func = None name = self.get_name(handle, True) link_label = widgets.LinkLabel(name, link_func, handle, emph, theme=self.theme) link_label.set_padding(3, 0) if self._config.get('preferences.releditbtn'): button = widgets.IconButton(self.edit_person_button, handle) button.set_tooltip_text(_('Edit %s') % name[0]) else: button = None hbox = Gtk.Box() hbox.set_spacing(6) l = widgets.BasicLabel("%d." % index) l.set_width_chars(3) l.set_halign(Gtk.Align.END) hbox.pack_start(l, False, False, 0) person = self.dbstate.db.get_person_from_handle(handle) hbox.pack_start(link_label, False, False, 0) if self.show_details: box = self.info_box(handle) if box: hbox.pack_start(box, False, False, 0) if button is not None: hbox.pack_start(button, False, False, 0) if self.show_tags: tag_list = TagList(self.get_tag_list(person)) hbox.pack_start(tag_list, False, False, 0) hbox.show() vbox.pack_start(hbox, True, True, 0) ev = self.make_dragbox(vbox, 'Person', handle) if not child_should_be_linked: frame = Gtk.Frame() frame.set_shadow_type(Gtk.ShadowType.ETCHED_IN) frame.add(ev) return frame else: return ev
def write_event(self, event_ref, spouse, index): handle = event_ref.ref event = self.dbstate.db.get_event_from_handle(handle) etype = str(event.get_type()) desc = event.get_description() who = get_participant_from_event(self.dbstate.db, handle) title = etype if desc: title = '%s (%s)' % (title, desc) if spouse: spouse_name = name_displayer.display(spouse) title = '%s - %s' % (title, spouse_name) role = event_ref.get_role() if role in (EventRoleType.PRIMARY, EventRoleType.FAMILY): emph = True else: emph = False title = '%s of %s' % (title, who) vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL) link_func = self._event_link name = (title, None) handle = event_ref.ref link_label = widgets.LinkLabel(name, link_func, handle, emph, theme=self.theme) link_label.set_padding(3, 0) link_label.set_tooltip_text(_('Click to make this event active')) if self._config.get('preferences.releditbtn'): button = widgets.IconButton(self.edit_event_button, handle) button.set_tooltip_text(_('Edit %s') % name[0]) else: button = None hbox = widgets.LinkBox(link_label, button) if self.show_tags: tag_list = TagList(self.get_tag_list(event)) hbox.pack_start(tag_list, False, False, 0) vbox.pack_start(hbox, False, False, 0) line2 = self.format_event(event) vbox.pack_start(widgets.BasicLabel(line2), False, False, 0) for handle in event.get_citation_list(): self.write_citation(vbox, handle) eventbox = self.make_dragbox(vbox, 'Event', handle) eventbox.show_all() self.vbox2.pack_start(eventbox, False, False, 1)
def write_participant(self, person, attrs): vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL) handle = person.handle name = self.get_name(handle, True) if self.has_children(person): emph = True else: emph = False link_func = self._person_link link_label = widgets.LinkLabel(name, link_func, handle, emph, theme=self.theme) link_label.set_padding(3, 0) if self._config.get('preferences.releditbtn'): button = widgets.IconButton(self.edit_person_button, handle) button.set_tooltip_text(_('Edit %s') % name[0]) else: button = None hbox = Gtk.Box() hbox.set_spacing(6) hbox.pack_start(link_label, False, False, 0) if self.show_details: box = self.info_box(handle) if box: hbox.pack_start(box, False, False, 0) if button is not None: hbox.pack_start(button, False, False, 0) if self.show_tags: tag_list = TagList(self.get_tag_list(person)) hbox.pack_start(tag_list, False, False, 0) vbox.pack_start(hbox, False, False, 0) # Write attributes attr_grid = self.get_attribute_grid(attrs) attr_grid.set_margin_start(24) vbox.pack_start(attr_grid, False, False, 0) eventbox = self.make_dragbox(vbox, 'Person', handle) eventbox.show_all() self.vbox2.pack_start(eventbox, False, False, 1)
def write_person(self, title, handle): """ Create and show a person cell. """ vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL) if handle: name = self.get_name(handle, True) person = self.dbstate.db.get_person_from_handle(handle) parent = len(person.get_parent_family_handle_list()) > 0 if parent: emph = True else: emph = False link_label = widgets.LinkLabel(name, self._person_link, handle, emph, theme=self.theme) if self._config.get('preferences.releditbtn'): button = widgets.IconButton(self.edit_person_button, handle) button.set_tooltip_text(_('Edit %s') % name[0]) else: button = None hbox = Gtk.Box() hbox.set_spacing(6) hbox.pack_start(link_label, False, False, 0) if self.show_details: box = self.info_box(handle) if box: hbox.pack_start(box, False, False, 0) if button is not None: hbox.pack_start(button, False, False, 0) if self.show_tags: tag_list = TagList(self.get_tag_list(person)) hbox.pack_start(tag_list, False, False, 0) vbox.pack_start(hbox, True, True, 0) else: link_label = Gtk.Label(label=_('Unknown')) link_label.set_halign(Gtk.Align.START) link_label.show() vbox.pack_start(link_label, True, True, 0) return vbox
def write_title(self, event): self.handle = event.handle grid = Gtk.Grid() grid.set_column_spacing(12) grid.set_row_spacing(0) # event title and edit button etype = str(event.get_type()) desc = event.get_description() if desc: title = '%s (%s)' % (etype, desc) else: title = etype fmt = '<span size="larger" weight="bold">%s</span>' text = fmt % escape(title) label = widgets.MarkupLabel(text, halign=Gtk.Align.END) if self._config.get('preferences.releditbtn'): button = widgets.IconButton(self.edit_event_button, event.handle) button.set_tooltip_text(_('Edit %s') % title) else: button = None hbox = widgets.LinkBox(label, button) if self.show_tags: tag_list = TagList(self.get_tag_list(event)) hbox.pack_start(tag_list, False, False, 0) eventbox = self.make_dragbox(hbox, 'Event', event.get_handle()) grid.attach(eventbox, 0, 0, 2, 1) subgrid = Gtk.Grid() subgrid.set_column_spacing(12) subgrid.set_row_spacing(0) eventbox = self.make_dragbox(subgrid, 'Event', event.get_handle()) grid.attach(eventbox, 1, 1, 1, 1) # Gramps ID subgrid.attach(widgets.BasicLabel("%s:" % _('ID')), 1, 0, 1, 1) label = widgets.BasicLabel(event.gramps_id) label.set_hexpand(True) subgrid.attach(label, 2, 0, 1, 1) # Date subgrid.attach(widgets.BasicLabel("%s:" % 'Date'), 1, 1, 1, 1) subgrid.attach(widgets.BasicLabel(get_date(event)), 2, 1, 1, 1) # Place place = place_displayer.display_event(self.dbstate.db, event) subgrid.attach(widgets.BasicLabel("%s:" % 'Place'), 1, 2, 1, 1) subgrid.attach(widgets.BasicLabel(place), 2, 2, 1, 1) grid.show_all() vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL) vbox.pack_start(grid, False, True, 0) # Attributes attrs = event.get_attribute_list() if len(attrs): ex = Gtk.Expander(label='%s:' % _('Attributes')) attr_grid = self.get_attribute_grid(attrs) ex.set_margin_start(24) ex.add(attr_grid) ex.show() vbox.pack_start(ex, False, True, 0) vbox.show_all() return vbox
def write_node(self, grid, event_ref, spouse, index, start_date): handle = event_ref.ref event = self.dbstate.db.get_event_from_handle(handle) etype = str(event.get_type()) desc = event.get_description() who = get_participant_from_event(self.dbstate.db, handle) title = etype if desc: title = '%s (%s)' % (title, desc) if spouse: spouse_name = name_displayer.display(spouse) title = '%s - %s' % (title, spouse_name) role = event_ref.get_role() if role in (EventRoleType.PRIMARY, EventRoleType.FAMILY): emph = True else: emph = False title = '%s of %s' % (title, who) vbox1 = Gtk.Box(orientation=Gtk.Orientation.VERTICAL) link_func = self._event_link name = (title, None) handle = event_ref.ref link_label = widgets.LinkLabel(name, link_func, handle, emph, theme=self.theme) link_label.set_padding(3, 0) link_label.set_tooltip_text(_('Click to make this event active')) if self._config.get('preferences.releditbtn'): button = widgets.IconButton(self.edit_event_button, handle) button.set_tooltip_text(_('Edit %s') % name[0]) else: button = None hbox = widgets.LinkBox(link_label, button) if self.show_tags: tag_list = TagList(self.get_tag_list(event)) hbox.pack_start(tag_list, False, False, 0) vbox1.pack_start(hbox, False, False, 0) pname = place_displayer.display_event(self.dbstate.db, event) vbox1.pack_start(widgets.BasicLabel(pname), False, False, 0) vbox1.set_vexpand(False) vbox1.set_valign(Gtk.Align.CENTER) vbox1.show_all() eventbox = self.make_dragbox(vbox1, 'Event', handle) eventbox.set_hexpand(True) eventbox.set_vexpand(False) eventbox.set_valign(Gtk.Align.CENTER) eventbox.set_margin_top(1) eventbox.set_margin_bottom(1) eventbox.show_all() vbox2 = Gtk.Box(orientation=Gtk.Orientation.VERTICAL) dobj = event.get_date_object() date = widgets.BasicLabel(displayer.display(dobj)) vbox2.pack_start(date, False, False, 0) if start_date is not None: age_precision = config.get('preferences.age-display-precision') diff = (dobj - start_date).format(precision=age_precision) age = widgets.BasicLabel(diff) vbox2.pack_start(age, False, False, 0) vbox2.set_valign(Gtk.Align.CENTER) grid.add(vbox2) tl = Timeline() grid.attach_next_to(tl, vbox2, Gtk.PositionType.RIGHT, 1, 1) grid.attach_next_to(eventbox, tl, Gtk.PositionType.RIGHT, 1, 1)
def write_label(self, title, family, is_parent): """ Write a Family header row Shows following elements: (Parents/Family title label, Family gramps_id, and add-choose-edit-delete buttons) """ hbox = Gtk.Box() if family: msg = '<b>%s (%s):</b>' % (escape(title), escape(family.gramps_id)) else: msg = '<b>%s:</b>' % escape(title) label = widgets.MarkupLabel(msg, halign=Gtk.Align.START) hbox.pack_start(label, False, True, 0) bbox = Gtk.Box() if is_parent: call_fcn = self.add_parent_family del_fcn = self.delete_parent_family add_msg = _('Add a new set of parents') sel_msg = _('Add person as child to an existing family') edit_msg = _('Edit parents') ord_msg = _('Reorder parents') del_msg = _('Remove person as child of these parents') else: add_msg = _('Add a new family with person as parent') sel_msg = None edit_msg = _('Edit family') ord_msg = _('Reorder families') del_msg = _('Remove person as parent in this family') call_fcn = self.add_family del_fcn = self.delete_family if not self.toolbar_visible and not self.dbstate.db.readonly: # Show edit-Buttons if toolbar is not visible if self.reorder_sensitive: add = widgets.IconButton(self.reorder_button_press, None, 'view-sort-ascending') add.set_tooltip_text(ord_msg) bbox.pack_start(add, False, True, 0) add = widgets.IconButton(call_fcn, None, 'list-add') add.set_tooltip_text(add_msg) bbox.pack_start(add, False, True, 0) if is_parent: add = widgets.IconButton(self.select_family, None, 'gtk-index') add.set_tooltip_text(sel_msg) bbox.pack_start(add, False, True, 0) if family: edit = widgets.IconButton(self.edit_family_button, family.handle, 'gtk-edit') edit.set_tooltip_text(edit_msg) bbox.pack_start(edit, False, True, 0) if not self.dbstate.db.readonly: delete = widgets.IconButton(del_fcn, family.handle, 'list-remove') delete.set_tooltip_text(del_msg) bbox.pack_start(delete, False, True, 0) hbox.pack_start(bbox, False, True, 6) if family: if self.show_tags: tag_list = TagList(self.get_tag_list(family)) hbox.pack_start(tag_list, False, False, 3) eventbox = self.make_dragbox(hbox, 'Family', family.handle) return eventbox else: return hbox
def write_title(self, person): self.handle = person.handle grid = Gtk.Grid() grid.set_column_spacing(12) grid.set_row_spacing(0) # name and edit button name = name_displayer.display(person) fmt = '<span size="larger" weight="bold">%s</span>' text = fmt % escape(name) label = widgets.DualMarkupLabel(text, _GenderCode[person.gender], halign=Gtk.Align.END) if self._config.get('preferences.releditbtn'): button = widgets.IconButton(self.edit_person_button, person.handle) button.set_tooltip_text(_('Edit %s') % name) else: button = None hbox = widgets.LinkBox(label, button) if self.show_tags: tag_list = TagList(self.get_tag_list(person)) hbox.pack_start(tag_list, False, False, 0) eventbox = self.make_dragbox(hbox, 'Person', person.get_handle()) grid.attach(eventbox, 0, 0, 2, 1) subgrid = Gtk.Grid() subgrid.set_column_spacing(12) subgrid.set_row_spacing(0) eventbox = self.make_dragbox(subgrid, 'Person', person.get_handle()) grid.attach(eventbox, 1, 1, 1, 1) # GRAMPS ID subgrid.attach(widgets.BasicLabel("%s:" % _('ID')), 1, 0, 1, 1) label = widgets.BasicLabel(person.gramps_id) label.set_hexpand(True) subgrid.attach(label, 2, 0, 1, 1) # Birth event. birth = get_birth_or_fallback(self.dbstate.db, person) if birth: birth_title = birth.get_type() else: birth_title = _("Birth") subgrid.attach(widgets.BasicLabel("%s:" % birth_title), 1, 1, 1, 1) subgrid.attach(widgets.BasicLabel(self.format_event(birth)), 2, 1, 1, 1) death = get_death_or_fallback(self.dbstate.db, person) if death: death_title = death.get_type() else: death_title = _("Death") showed_death = False if birth: birth_date = birth.get_date_object() if (birth_date and birth_date.get_valid()): if death: death_date = death.get_date_object() if (death_date and death_date.get_valid()): age = death_date - birth_date subgrid.attach(widgets.BasicLabel("%s:" % death_title), 1, 2, 1, 1) subgrid.attach(widgets.BasicLabel("%s (%s)" % (self.format_event(death), age), Pango.EllipsizeMode.END), 2, 2, 1, 1) showed_death = True if not showed_death: age = Today() - birth_date if probably_alive(person, self.dbstate.db): subgrid.attach(widgets.BasicLabel("%s:" % _("Alive")), 1, 2, 1, 1) subgrid.attach(widgets.BasicLabel("(%s)" % age, Pango.EllipsizeMode.END), 2, 2, 1, 1) else: subgrid.attach(widgets.BasicLabel("%s:" % _("Death")), 1, 2, 1, 1) subgrid.attach(widgets.BasicLabel("%s (%s)" % (_("unknown"), age), Pango.EllipsizeMode.END), 2, 2, 1, 1) showed_death = True if not showed_death: subgrid.attach(widgets.BasicLabel("%s:" % death_title), 1, 2, 1, 1) subgrid.attach(widgets.BasicLabel(self.format_event(death)), 2, 2, 1, 1) mbox = Gtk.Box() mbox.add(grid) # image image_list = person.get_media_list() if image_list: button = self.get_thumbnail(image_list[0], size=SIZE_NORMAL) if button: mbox.pack_end(button, False, True, 0) mbox.show_all() return mbox