Exemplo n.º 1
0
 def cb_select(self, obj):
     SelectPlace = SelectorFactory('Place')
     sel = SelectPlace(self.dbstate, self.gui.uistate)
     place = sel.run()
     if not place:
         return
     self.selected_handle = place.handle
     selected_parent = self.dbstate.db.get_place_from_handle(
         self.selected_handle)
     self.selected_name = selected_parent.get_name().value
     self.enclosing_place.set_text(self.selected_name)
Exemplo n.º 2
0
 def sel_person_clicked(self, event):
     if self.selection_widget.get_current():
         SelectPerson = SelectorFactory('Person')
         sel = SelectPerson(self.dbstate, self.uistate, self.track,
                            _("Select Person"))
         person = sel.run()
         if person:
             self.set_current_person(person)
             self.selection_widget.clear_selection()
             self.refresh()
             self.enable_buttons()
Exemplo n.º 3
0
 def select_family(self, *obj):
     """
     Open a selection box to choose the ref family.
     """
     self.track = []
     self.skip_list = []
     self.ref_family = None
     self.reffamily_bookmark = None
     select_family = SelectorFactory('Family')
     sel = select_family(self.dbstate, self.uistate)
     self.reffamily = sel.run()
     self.goto_handle(None)
Exemplo n.º 4
0
 def selectPerson(self, obj):
     """
     Open a selection box to choose the ref person.
     """
     self.track = []
     self.skip_list = []
     self.refperson = None
     self.refperson_bookmark = None
     SelectPerson = SelectorFactory('Person')
     sel = SelectPerson(self.dbstate, self.uistate, self.track,
                        _("Select the person which will be our reference."),
                        skip=self.skip_list)
     self.refperson = sel.run()
     self.goto_handle(None)
Exemplo n.º 5
0
    def select_participant(self, *obj):
        SelectPerson = SelectorFactory('Person')
        dialog = SelectPerson(self.dbstate, self.uistate)
        person = dialog.run()
        if person is None:
            return

        ref = EventRef()
        ref.ref = self.handle
        person.add_event_ref(ref)

        try:
            EditPerson(self.dbstate, self.uistate, [], person)
        except WindowActiveError:
            pass
Exemplo n.º 6
0
    def sel_child_to_fam(self, obj, event, handle, surname=None):
        if button_activated(event, _LEFT_BUTTON):
            SelectPerson = SelectorFactory('Person')
            family = self.dbstate.db.get_family_from_handle(handle)
            # it only makes sense to skip those who are already in the family
            skip_list = [family.get_father_handle(),
                         family.get_mother_handle()]
            skip_list.extend(x.ref for x in family.get_child_ref_list())

            sel = SelectPerson(self.dbstate, self.uistate, [],
                               _("Select Child"), skip=skip_list)
            person = sel.run()

            if person:
                self.callback_add_child(person, handle)
Exemplo n.º 7
0
    def select_family(self, obj, event, handle):
        if button_activated(event, _LEFT_BUTTON):
            SelectFamily = SelectorFactory('Family')

            phandle = self.get_handle()
            person = self.dbstate.db.get_person_from_handle(phandle)
            skip = set(person.get_family_handle_list())

            dialog = SelectFamily(self.dbstate, self.uistate, skip=skip)
            family = dialog.run()

            if family:
                child = self.dbstate.db.get_person_from_handle(self.get_handle())

                self.dbstate.db.add_child_to_family(family, child)
Exemplo n.º 8
0
    def select_parents(self, *obj):
        SelectFamily = SelectorFactory('Family')

        phandle = self.handle
        person = self.dbstate.db.get_person_from_handle(phandle)
        skip = set(person.get_family_handle_list()+
                   person.get_parent_family_handle_list())

        dialog = SelectFamily(self.dbstate, self.uistate, skip=skip)
        family = dialog.run()

        if family:
            child = self.dbstate.db.get_person_from_handle(self.handle)

            self.dbstate.db.add_child_to_family(family, child)
Exemplo n.º 9
0
 def cb_select(self, obj):
     SelectPlace = SelectorFactory('Place')
     sel = SelectPlace(self.dbstate, self.gui.uistate)
     place = sel.run()
     if not place:
         return
     self.selected_handle = place.handle
     selected_parent = self.dbstate.db.get_place_from_handle(
         self.selected_handle)
     self.selected_name = selected_parent.get_name().value
     title = selected_parent.get_title()
     if title:
         self.selected_name += " (title={})".format(title)
     #self.enclosing_place.set_text(self.selected_name)
     self.but_set_enclosing.set_label(self.selected_name)
Exemplo n.º 10
0
class FamilySection(Gtk.Box):

    SelectFamily = SelectorFactory('Family')

    def __init__(self, dbstate, uistate, track, event, citation, form_id,
                 section):
        Gtk.Box.__init__(self, orientation=Gtk.Orientation.VERTICAL)

        self.dbstate = dbstate
        self.db = dbstate.db
        self.uistate = uistate
        self.track = track
        self.form_id = form_id
        self.section = section
        self.event = event
        self.citation = citation
        self.handle = None
        self.widgets = {}
        self.widgets2 = {}
        self.initial_handle = None

        self.role = EventRoleType()
        self.role.set_from_xml_str(section)

        hbox = Gtk.Box()

        title = get_section_title(form_id, section)
        title1, title2 = title.split('/')

        label = Gtk.Label('<b>%s</b>' % title1)
        label.set_use_markup(True)
        label.set_alignment(0, 0.5)
        hbox.pack_start(label, expand=False, fill=False, padding=3)

        image = Gtk.Image()
        image.set_from_icon_name('list-add', Gtk.IconSize.BUTTON)
        add_btn = Gtk.Button()
        add_btn.set_relief(Gtk.ReliefStyle.NONE)
        add_btn.add(image)
        add_btn.connect('clicked', self.__add_clicked)
        hbox.pack_start(add_btn, expand=False, fill=False, padding=3)

        image = Gtk.Image()
        image.set_from_icon_name('gtk-index', Gtk.IconSize.BUTTON)
        share_btn = Gtk.Button()
        share_btn.set_relief(Gtk.ReliefStyle.NONE)
        share_btn.add(image)
        share_btn.connect('clicked', self.__share_clicked)
        hbox.pack_start(share_btn, expand=False, fill=False, padding=3)

        self.pack_start(hbox, False, False, 0)
        self.grid = Gtk.Grid()
        self.pack_start(self.grid, False, False, 0)

        label = Gtk.Label('<b>%s</b>' % title2)
        label.set_use_markup(True)
        label.set_alignment(0, 0.5)
        self.pack_start(label, expand=False, fill=False, padding=3)

        self.grid2 = Gtk.Grid()
        self.pack_start(self.grid2, False, False, 0)
        self.show()

        columns = get_section_columns(self.form_id, self.section)
        self.headings = [column[0] for column in columns]
        self.tooltips = [column[1] for column in columns]

        self.set_columns(self.widgets, self.grid)
        self.set_columns(self.widgets2, self.grid2)

    def is_empty(self):
        return False if self.handle else True

    def set_columns(self, widgets, grid):
        for col, heading in enumerate(self.headings):
            label = Gtk.Label(heading)
            label.set_alignment(0.0, 0.5)
            label.show()
            entry = Gtk.Entry()
            entry.set_sensitive(False)
            widgets[heading] = entry
            entry.show()
            grid.attach(label, col, 0, 1, 1)
            grid.attach(entry, col, 1, 1, 1)

    def __add_clicked(self, obj):
        family = Family()
        EditFamily(self.dbstate, self.uistate, self.track, family,
                   self.__added)

    def __share_clicked(self, obj):
        handle = self.uistate.get_active('Family')
        sel = self.SelectFamily(self.dbstate,
                                self.uistate,
                                self.track,
                                default=handle)
        obj = sel.run()
        if obj:
            self.__added(obj)

    def __added(self, obj):
        self.handle = obj.handle
        for heading in self.headings:
            self.widgets[heading].set_sensitive(True)
            self.widgets2[heading].set_sensitive(True)
            if heading == _('Name'):
                family = self.db.get_family_from_handle(self.handle)
                father_handle = family.get_father_handle()
                if father_handle:
                    person = self.db.get_person_from_handle(father_handle)
                    name = name_displayer.display(person)
                    self.widgets[heading].set_text(name)
                mother_handle = family.get_mother_handle()
                if mother_handle:
                    person = self.db.get_person_from_handle(mother_handle)
                    name = name_displayer.display(person)
                    self.widgets2[heading].set_text(name)

    def populate_gui(self, event):
        for item in self.db.find_backlink_handles(event.get_handle(),
                                                  include_classes=['Family']):
            handle = item[1]
            obj = self.db.get_family_from_handle(item[1])

            for event_ref in obj.get_event_ref_list():
                if (event_ref.ref == self.event.get_handle()
                        and event_ref.get_role() == self.role):

                    attrs = {}
                    for attr in event_ref.get_attribute_list():
                        attr_type = str(attr.get_type())
                        attrs[attr_type] = attr.get_value()

                    self.__populate(obj, attrs)

    def __populate(self, obj, attrs):
        self.initial_handle = obj.handle
        self.__added(obj)
        for heading in self.headings:
            self.widgets[heading].set_text(attrs.get(GROOM + ' ' + heading,
                                                     ''))
            self.widgets2[heading].set_text(
                attrs.get(BRIDE + ' ' + heading, ''))

    def save(self, trans):
        if not self.handle:
            return

        obj = self.dbstate.db.get_family_from_handle(self.handle)
        event_ref = get_event_ref(self.event, obj, self.role)

        row = []
        for heading in self.headings:
            row.append(self.widgets[heading].get_text())
        write_attributes(self.citation,
                         row,
                         event_ref,
                         self.headings,
                         prefix=GROOM)
        row = []
        for heading in self.headings:
            row.append(self.widgets2[heading].get_text())
        write_attributes(self.citation,
                         row,
                         event_ref,
                         self.headings,
                         prefix=BRIDE)
        self.dbstate.db.commit_family(obj, trans)

        # Remove link to family no longer on form
        if self.initial_handle and self.handle != self.initial_handle:
            family = self.db.get_family_from_handle(self.initial_handle)
            ref_list = [
                event_ref for event_ref in obj.get_event_ref_list()
                if event_ref.ref != self.event.handle
            ]
            family.set_event_ref_list(ref_list)
            self.db.commit_family(family, trans)
Exemplo n.º 11
0
class MultiSection(Gtk.Box):

    SelectPerson = SelectorFactory('Person')

    def __init__(self, dbstate, uistate, track, event, citation, form_id,
                 section):
        Gtk.Box.__init__(self, orientation=Gtk.Orientation.VERTICAL)

        self.dbstate = dbstate
        self.db = dbstate.db
        self.uistate = uistate
        self.track = track
        self.form_id = form_id
        self.section = section
        self.event = event
        self.citation = citation

        self.model = None
        self.columns = []
        self.initial_people = []

        self.role = EventRoleType()
        self.role.set_from_xml_str(section)

        hbox = Gtk.Box()
        hbox.set_spacing(6)

        title = get_section_title(form_id, section)
        if title:
            label = Gtk.Label('<b>%s</b>' % title)
            label.set_use_markup(True)
            label.set_alignment(0, 0.5)
            label.set_margin_left(6)
            hbox.pack_start(label, expand=False, fill=False, padding=0)

        image = Gtk.Image()
        image.set_from_icon_name('list-add', Gtk.IconSize.BUTTON)
        add_btn = Gtk.Button()
        add_btn.set_relief(Gtk.ReliefStyle.NONE)
        add_btn.add(image)
        add_btn.connect('clicked', self.__add_person)
        hbox.pack_start(add_btn, expand=False, fill=True, padding=0)

        image = Gtk.Image()
        image.set_from_icon_name('gtk-index', Gtk.IconSize.BUTTON)
        share_btn = Gtk.Button()
        share_btn.set_relief(Gtk.ReliefStyle.NONE)
        share_btn.add(image)
        share_btn.connect('clicked', self.__share_person)
        hbox.pack_start(share_btn, expand=False, fill=True, padding=0)

        image = Gtk.Image()
        image.set_from_icon_name('list-remove', Gtk.IconSize.BUTTON)
        del_btn = Gtk.Button()
        del_btn.set_relief(Gtk.ReliefStyle.NONE)
        del_btn.add(image)
        del_btn.connect('clicked', self.__remove_person)
        hbox.pack_start(del_btn, expand=False, fill=True, padding=0)

        image = Gtk.Image()
        image.set_from_icon_name('go-up', Gtk.IconSize.BUTTON)
        up_btn = Gtk.Button()
        up_btn.set_relief(Gtk.ReliefStyle.NONE)
        up_btn.add(image)
        up_btn.connect('clicked', self.__move_person, 'up')
        hbox.pack_start(up_btn, expand=False, fill=True, padding=0)

        image = Gtk.Image()
        image.set_from_icon_name('go-down', Gtk.IconSize.BUTTON)
        down_btn = Gtk.Button()
        down_btn.set_relief(Gtk.ReliefStyle.NONE)
        down_btn.add(image)
        down_btn.connect('clicked', self.__move_person, 'down')
        hbox.pack_start(down_btn, expand=False, fill=True, padding=0)

        self.entry_grid = EntryGrid(callback=self.change_person)

        self.pack_start(hbox, expand=False, fill=True, padding=0)
        self.pack_start(self.entry_grid, expand=True, fill=True, padding=0)

        self.create_table()

    def is_empty(self):
        """
        Indicate if the tab contains any data. This is used to determine
        how the label should be displayed.
        """
        if self.model is None:
            return True
        return len(self.model) == 0

    def __add_person(self, button):
        """
        Create a new person and add them to the form.
        """
        person = Person()
        EditPerson(self.dbstate, self.uistate, self.track, person,
                   self.__person_added)

    def __person_added(self, person):
        """
        Called when a person is added to the form.
        """
        self.model.append(self.__new_person_row(person))

    def __edit_person(self, treeview, path, view_column):
        """
        Edit a person from selection.
        """
        model, iter_ = self.selection.get_selected()
        if iter_:
            handle = model.get_value(iter_, 0)
            if handle:
                person = self.dbstate.db.get_person_from_handle(handle)
                EditPerson(self.dbstate, self.uistate, self.track, person)

    def __share_person(self, button):
        """
        Select an existing person and add them to the form.
        """
        handle = None
        if len(self.model) > 0:
            iter_ = self.entry_grid.get_selected()
            if iter_:  # get from selection:
                handle = self.model.get_value(iter_, 0)
            else:  # get from first row
                handle = self.model[0][0]
        else:  # no rows, let's try to get active person:
            handle = self.uistate.get_active('Person')

        sel = self.SelectPerson(self.dbstate,
                                self.uistate,
                                self.track,
                                _("Select Person"),
                                default=handle)
        person = sel.run()
        if person:
            self.model.append(self.__new_person_row(person))

    def change_person(self, model, iter_):
        """
        Change an existing person in the form.
        """
        skip_list = []
        handle = self.model.get_value(iter_, 0)

        sel = self.SelectPerson(self.dbstate,
                                self.uistate,
                                self.track,
                                _("Select Person"),
                                skip=skip_list,
                                default=handle)
        person = sel.run()

        if person:
            self.model.set_value(iter_, 0, person.get_handle())

    def __new_person_row(self, person):
        """
        Create a new model entry for a person.
        """
        row = [None] * (len(self.columns) + 1)
        row[0] = person.handle

        # Insert name in column called "Name", if present
        if _('Name') in self.columns:
            name = name_displayer.display(person)
            row[self.columns.index(_('Name')) + 1] = name

        return row

    def __remove_person(self, button):
        """
        Remove a person from the form.
        """
        iter_ = self.entry_grid.get_selected()
        if iter_:
            self.model.remove(iter_)

    def __move_person(self, button, direction):
        """
        Change the position of a person in the list.
        """
        iter_ = self.entry_grid.get_selected()
        if iter_ is None:
            return

        row = self.model.get_path(iter_)[0]
        if direction == 'up' and row > 0:
            self.model.move_before(iter_, self.model.get_iter((row - 1, )))

        if direction == 'down' and row < len(self.model) - 1:
            self.model.move_after(iter_, self.model.get_iter((row + 1, )))

    def create_table(self):
        """
        Create a model and treeview for the form details.
        """
        columns = get_section_columns(self.form_id, self.section)

        self.columns = [column[0] for column in columns]
        self.model = Gtk.ListStore(*[str] * (len(columns) + 1))
        self.entry_grid.set_model(self.model)
        tooltips = [column[1] for column in columns]
        self.entry_grid.set_columns(self.columns, tooltips)
        self.entry_grid.build()

    def populate_gui(self, event):
        """
        Populate the model.
        """
        person_list = []
        for item in self.db.find_backlink_handles(event.get_handle(),
                                                  include_classes=['Person']):
            handle = item[1]
            person = self.db.get_person_from_handle(handle)
            for event_ref in person.get_event_ref_list():
                if (event_ref.ref == event.get_handle()
                        and event_ref.get_role() == self.role):
                    self.initial_people.append(handle)
                    attrs = {}
                    order = 0
                    for attr in event_ref.get_attribute_list():
                        attr_type = str(attr.get_type())
                        if attr_type == ORDER_ATTR:
                            order = int(attr.get_value())
                        else:
                            attrs[attr_type] = attr.get_value()
                    name = name_displayer.display(person)
                    person_list.append([order, handle, name, attrs])

        person_list.sort()

        for person_data in person_list:
            row = person_data[1:2]  # handle
            for attr in self.columns:
                if attr == _('Name'):
                    row.append(person_data[3].get(attr, person_data[2]))
                else:
                    row.append(person_data[3].get(attr))
            self.model.append(tuple(row))

    def save(self, trans):
        """
        Save the form details to the database.
        """
        # Update people on the form
        all_people = []
        for order, row in enumerate(self.model):
            all_people.append(row[0])
            person = self.db.get_person_from_handle(row[0])
            event_ref = get_event_ref(self.event, person, self.role)

            # Write attributes
            set_attribute(self.citation, event_ref, ORDER_ATTR, str(order + 1))
            for offset, name in enumerate(self.columns):
                value = row[offset + 1]
                set_attribute(self.citation, event_ref, name, value)
            self.db.commit_person(person, trans)

        # Remove links to people no longer on form
        for handle in (set(self.initial_people) - set(all_people)):
            person = self.db.get_person_from_handle(handle)
            ref_list = [
                event_ref for event_ref in person.get_event_ref_list()
                if event_ref.ref != self.event.handle
            ]
            person.set_event_ref_list(ref_list)
            self.db.commit_person(person, trans)
Exemplo n.º 12
0
class PersonSection(Gtk.Box):

    SelectPerson = SelectorFactory('Person')

    def __init__(self, dbstate, uistate, track, event, citation, form_id,
                 section):
        Gtk.Box.__init__(self, orientation=Gtk.Orientation.VERTICAL)

        self.dbstate = dbstate
        self.db = dbstate.db
        self.uistate = uistate
        self.track = track
        self.form_id = form_id
        self.section = section
        self.event = event
        self.citation = citation
        self.handle = None
        self.widgets = {}
        self.initial_handle = None

        self.role = EventRoleType()
        self.role.set_from_xml_str(section)

        hbox = Gtk.Box()

        title = get_section_title(form_id, section)
        label = Gtk.Label(label='<b>%s</b>' % title)
        label.set_use_markup(True)
        label.set_halign(Gtk.Align.START)
        label.set_valign(Gtk.Align.CENTER)
        hbox.pack_start(label, expand=False, fill=False, padding=3)

        image = Gtk.Image()
        image.set_from_icon_name('list-add', Gtk.IconSize.BUTTON)
        add_btn = Gtk.Button()
        add_btn.set_relief(Gtk.ReliefStyle.NONE)
        add_btn.add(image)
        add_btn.connect('clicked', self.__add_clicked)
        hbox.pack_start(add_btn, expand=False, fill=False, padding=3)

        image = Gtk.Image()
        image.set_from_icon_name('gtk-index', Gtk.IconSize.BUTTON)
        share_btn = Gtk.Button()
        share_btn.set_relief(Gtk.ReliefStyle.NONE)
        share_btn.add(image)
        share_btn.connect('clicked', self.__share_clicked)
        hbox.pack_start(share_btn, expand=False, fill=False, padding=3)

        self.pack_start(hbox, False, False, 0)
        self.grid = Gtk.Grid()
        self.pack_start(self.grid, False, False, 0)
        self.show()

        self.set_columns()

    def is_empty(self):
        return False if self.handle else True

    def set_columns(self):
        columns = get_section_columns(self.form_id, self.section)
        self.headings = [column[0] for column in columns]
        self.tooltips = [column[1] for column in columns]

        for col, heading in enumerate(self.headings):
            label = Gtk.Label(label=heading)
            label.set_halign(Gtk.Align.START)
            label.set_valign(Gtk.Align.CENTER)
            label.show()
            entry = MyEntry(heading)
            entry.set_tooltip_text(self.tooltips[col])
            entry.set_sensitive(False)
            self.widgets[heading] = entry
            entry.show()
            self.grid.attach(label, col, 0, 1, 1)
            self.grid.attach(entry, col, 1, 1, 1)

    def __add_clicked(self, obj):
        person = Person()
        EditPerson(self.dbstate, self.uistate, self.track, person,
                   self.__added)

    def __share_clicked(self, obj):
        handle = self.uistate.get_active('Person')
        sel = self.SelectPerson(self.dbstate,
                                self.uistate,
                                self.track,
                                _("Select Person"),
                                default=handle)
        obj = sel.run()
        if obj:
            self.__added(obj)

    def __added(self, obj):
        self.handle = obj.handle
        for heading in self.headings:
            self.widgets[heading].set_sensitive(True)
            if heading == _('Name'):
                person = self.db.get_person_from_handle(self.handle)
                name = name_displayer.display(person)
                self.widgets[heading].set_text(name)

    def populate_gui(self, event):
        for item in self.db.find_backlink_handles(event.get_handle(),
                                                  include_classes=['Person']):
            handle = item[1]
            obj = self.db.get_person_from_handle(item[1])

            for event_ref in obj.get_event_ref_list():
                if (event_ref.ref == self.event.get_handle()
                        and event_ref.get_role() == self.role):

                    attrs = {}
                    for attr in event_ref.get_attribute_list():
                        attr_type = str(attr.get_type())
                        attrs[attr_type] = attr.get_value()

                    self.__populate(obj, attrs)

    def __populate(self, obj, attrs):
        self.initial_handle = obj.handle
        self.__added(obj)
        for heading in self.headings:
            self.widgets[heading].set_text(attrs.get(heading, ''))

    def save(self, trans):
        if not self.handle:
            return

        obj = self.dbstate.db.get_person_from_handle(self.handle)
        event_ref = get_event_ref(self.event, obj, self.role)

        row = []
        for heading in self.headings:
            row.append(self.widgets[heading].get_text())
        write_attributes(self.citation, row, event_ref, self.headings)
        self.dbstate.db.commit_person(obj, trans)

        # Remove link to person no longer on form
        if self.initial_handle and self.handle != self.initial_handle:
            person = self.db.get_person_from_handle(self.initial_handle)
            ref_list = [
                event_ref for event_ref in obj.get_event_ref_list()
                if event_ref.ref != self.event.handle
            ]
            person.set_event_ref_list(ref_list)
            self.db.commit_person(person, trans)