Пример #1
0
 def column_marriage(self, data):
     family = self.db.get_family_from_handle(data[0])
     event = get_marriage_or_fallback(self.db, family, "<i>%s</i>")
     if event:
         if event.date.format:
             return event.date.format % displayer.display(event.date)
         elif not get_date_valid(event):
             return invalid_date_format % displayer.display(event.date)
         else:
             return "%s" % displayer.display(event.date)
     else:
         return ''
Пример #2
0
    def load_parent(self, handle, name_obj, birth_obj, birth_label, death_obj,
                    death_label, btn_index, btn_add, btn_del, btn_edit):
        # is a parent used here:
        is_used = handle is not None

        # now we display the area:
        if is_used:
            db = self.db
            person = db.get_person_from_handle(handle)
            name = "%s [%s]" % (name_displayer.display(person),
                                person.gramps_id)
            birth = get_birth_or_fallback(db, person)
            self.callman.register_handles({'person': [handle]})
            if birth:
                #if event changes it view needs to update
                self.callman.register_handles({'event': [birth.get_handle()]})
                # translators: needed for French, ignore otherwise
                birth_label.set_label(_("%s:") % birth.get_type())

            death = get_death_or_fallback(db, person)
            if death:
                #if event changes it view needs to update
                self.callman.register_handles({'event': [death.get_handle()]})
                # translators: needed for French, ignore otherwise
                death_label.set_label(_("%s:") % death.get_type())

            btn_edit.set_tooltip_text(_('Edit %s') % name)
            btn_index.hide()
            btn_add.hide()
            btn_del.show()
            btn_edit.show()
        else:
            name = ""
            birth = None
            death = None

            btn_index.show()
            btn_add.show()
            btn_del.hide()
            btn_edit.hide()

        if name_obj:
            name_obj.set_text(name)
        if birth:
            birth_str = displayer.display(birth.get_date_object())
        else:
            birth_str = ""
        birth_obj.set_text(birth_str)
        if death:
            death_str = displayer.display(death.get_date_object())
        else:
            death_str = ""
        death_obj.set_text(death_str)
Пример #3
0
 def column_marriage(self, data):
     family = self.db.get_family_from_handle(data[0])
     event = get_marriage_or_fallback(self.db, family, "<i>%s</i>")
     if event:
         if event.date.format:
             return event.date.format % displayer.display(event.date)
         elif not get_date_valid(event):
             return invalid_date_format % displayer.display(event.date)
         else:
             return "%s" % displayer.display(event.date)
     else:
         return ''
Пример #4
0
    def load_parent(self, handle, name_obj, birth_obj, birth_label, death_obj,
                    death_label, btn_index, btn_add, btn_del, btn_edit):
        # is a parent used here:
        is_used = handle is not None

        # now we display the area:
        if is_used:
            db = self.db
            person = db.get_person_from_handle(handle)
            name = "%s [%s]" % (name_displayer.display(person),
                                person.gramps_id)
            birth = get_birth_or_fallback(db, person)
            self.callman.register_handles({'person': [handle]})
            if birth:
                #if event changes it view needs to update
                self.callman.register_handles({'event': [birth.get_handle()]})
                # translators: needed for French, ignore otherwise
                birth_label.set_label(_("%s:") % birth.get_type())

            death = get_death_or_fallback(db, person)
            if death:
                #if event changes it view needs to update
                self.callman.register_handles({'event': [death.get_handle()]})
                # translators: needed for French, ignore otherwise
                death_label.set_label(_("%s:") % death.get_type())

            btn_edit.set_tooltip_text(_('Edit %s') % name)
            btn_index.hide()
            btn_add.hide()
            btn_del.show()
            btn_edit.show()
        else:
            name = ""
            birth = None
            death = None

            btn_index.show()
            btn_add.show()
            btn_del.hide()
            btn_edit.hide()

        if name_obj:
            name_obj.set_text(name)
        if birth:
            birth_str = displayer.display(birth.get_date_object())
        else:
            birth_str = ""
        birth_obj.set_text(birth_str)
        if death:
            death_str = displayer.display(death.get_date_object())
        else:
            death_str = ""
        death_obj.set_text(death_str)
Пример #5
0
def run(database, document, date):
    """
    Display people probably alive and their ages on a particular date.
    """
    # setup the simple access functions
    sdb = SimpleAccess(database)
    sdoc = SimpleDoc(document)
    stab = QuickTable(sdb)
    if not date.get_valid():
        sdoc.paragraph("Date is not a valid date.")
        return
    # display the title
    if date.get_day_valid():
        sdoc.title(_("People and their ages the %s") % displayer.display(date))
    else:
        sdoc.title(_("People and their ages on %s") % displayer.display(date))
    stab.columns(_("Person"), _("Age"),
                 _("Status"))  # Actual Date makes column unicode
    alive_matches = 0
    dead_matches = 0
    for person in sdb.all_people():
        alive, birth, death, explain, relative = \
            probably_alive(person, database, date, return_range=True)
        # Doesn't show people probably alive but no way of figuring an age:
        if alive:
            if birth:
                diff_span = (date - birth)
                stab.row(person, str(diff_span), _("Alive: %s") % explain)
                stab.row_sort_val(1, int(diff_span))
            else:
                stab.row(person, "", _("Alive: %s") % explain)
                stab.row_sort_val(1, 0)
            alive_matches += 1
        else:  # not alive
            if birth:
                diff_span = (date - birth)
                stab.row(person, str(diff_span), _("Deceased: %s") % explain)
                stab.row_sort_val(1, int(diff_span))
            else:
                stab.row(person, "", _("Deceased: %s") % explain)
                stab.row_sort_val(1, 1)
            dead_matches += 1

    document.has_data = (alive_matches + dead_matches) > 0
    sdoc.paragraph(
        _("\nLiving matches: %(alive)d, "
          "Deceased matches: %(dead)d\n") % {
              'alive': alive_matches,
              'dead': dead_matches
          })
    if document.has_data:
        stab.write(sdoc)
    sdoc.paragraph("")
Пример #6
0
def run(database, document, date):
    """
    Display people probably alive and their ages on a particular date.
    """
    # setup the simple access functions
    sdb = SimpleAccess(database)
    sdoc = SimpleDoc(document)
    stab = QuickTable(sdb)
    if not date.get_valid():
        sdoc.paragraph("Date is not a valid date.")
        return
    # display the title
    if date.get_day_valid():
        sdoc.title(_("People and their ages the %s") %
               displayer.display(date))
    else:
        sdoc.title(_("People and their ages on %s") %
               displayer.display(date))
    stab.columns(_("Person"), _("Age"), _("Status")) # Actual Date makes column unicode
    alive_matches = 0
    dead_matches = 0
    for person in sdb.all_people():
        alive, birth, death, explain, relative = \
            probably_alive(person, database, date, return_range=True)
        # Doesn't show people probably alive but no way of figuring an age:
        if alive:
            if birth:
                diff_span = (date - birth)
                stab.row(person, str(diff_span), _("Alive: %s") % explain)
                stab.row_sort_val(1, int(diff_span))
            else:
                stab.row(person, "", _("Alive: %s") % explain)
                stab.row_sort_val(1, 0)
            alive_matches += 1
        else: # not alive
            if birth:
                diff_span = (date - birth)
                stab.row(person, str(diff_span), _("Deceased: %s") % explain)
                stab.row_sort_val(1, int(diff_span))
            else:
                stab.row(person, "", _("Deceased: %s") % explain)
                stab.row_sort_val(1, 1)
            dead_matches += 1

    document.has_data = (alive_matches + dead_matches) > 0
    sdoc.paragraph(_("\nLiving matches: %(alive)d, "
                     "Deceased matches: %(dead)d\n") %
                         {'alive' : alive_matches, 'dead' : dead_matches})
    if document.has_data:
        stab.write(sdoc)
    sdoc.paragraph("")
Пример #7
0
    def __init__(self, field, button, value, uistate, track, readonly=False):
        """
        Create a connection between the date_obj, text_obj and the pixmap_obj.
        Assigns callbacks to parse and change date when the text
        in text_obj is changed, and to invoke Date Editor when the LED
        button_obj is pressed. 
        """
        self.uistate = uistate
        self.track = track
        self.date_obj = value
        self.text_obj = field
        self.button_obj = button

        image = Gtk.Image()
        image.set_from_icon_name('gramps-date-edit', Gtk.IconSize.BUTTON)
        self.button_obj.set_image(image)
        self.button_obj.set_relief(Gtk.ReliefStyle.NORMAL)
        self.pixmap_obj = self.button_obj.get_child()
        
        self.text_obj.connect('validate', self.validate)
        self.text_obj.connect('content-changed', self.set_date)
        self.button_obj.connect('clicked', self.invoke_date_editor)
        
        self.text_obj.set_text(displayer.display(self.date_obj))
        self.text_obj.validate()

        self.text_obj.set_editable(not readonly)
        self.button_obj.set_sensitive(not readonly)
Пример #8
0
    def get_event_text(self, the_type, handle, data):
        """
        Come up with a short line of text that we can use as
        a summary to represent this event.
        """

        # get the event:
        event = self.tables[the_type]['get_func'](handle)

        # first check to see if the event has a descriptive name
        text = event.get_description()  # (this is rarely set for events)

        # if we don't have a description...
        if text == '':
            # ... then we merge together several fields

            # get the event type (marriage, birth, death, etc.)
            text = str(event.get_type())

            # see if there is a date
            date = _dd.display(event.get_date_object())
            if date != '':
                text += '; %s' % date

            # see if there is a place
            if event.get_place_handle():
                text += '; %s' % _pd.display_event(self.db, event)

        return text
Пример #9
0
    def get_event_text(self, the_type, handle, data):
        """
        Come up with a short line of text that we can use as
        a summary to represent this event.
        """

        # get the event:
        event = self.tables[the_type]['get_func'](handle)

        # first check to see if the event has a descriptive name
        text = event.get_description()  # (this is rarely set for events)

        # if we don't have a description...
        if text == '':
            # ... then we merge together several fields

            # get the event type (marriage, birth, death, etc.)
            text = str(event.get_type())

            # see if there is a date
            date = _dd.display(event.get_date_object())
            if date != '':
                text += '; %s' % date

            # see if there is a place
            if event.get_place_handle():
                text += '; %s' % _pd.display_event(self.db, event)

        return text
Пример #10
0
 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)
Пример #11
0
    def format_event(self, event):
        if event:
            dobj = event.get_date_object()
            phandle = event.get_place_handle()
            if phandle:
                pname = place_displayer.display_event(self.dbstate.db, event)
            else:
                pname = None

            value = {
                'date' : displayer.display(dobj),
                'place' : pname,
                }
        else:
            pname = None
            dobj = None

        if dobj:
            if pname:
                return _('%(date)s in %(place)s') % value
            else:
                return '%(date)s' % value
        elif pname:
            return pname
        else:
            return ''
Пример #12
0
    def __init__(self, field, button, value, uistate, track, readonly=False):
        """
        Create a connection between the date_obj, text_obj and the pixmap_obj.
        Assigns callbacks to parse and change date when the text
        in text_obj is changed, and to invoke Date Editor when the LED
        button_obj is pressed. 
        """
        self.uistate = uistate
        self.track = track
        self.date_obj = value
        self.text_obj = field
        self.button_obj = button

        image = Gtk.Image()
        image.set_from_stock('gramps-date-edit', Gtk.IconSize.BUTTON)
        self.button_obj.set_image(image)
        self.button_obj.set_relief(Gtk.ReliefStyle.NORMAL)
        self.pixmap_obj = self.button_obj.get_child()
        
        self.text_obj.connect('validate', self.validate)
        self.text_obj.connect('content-changed', self.set_date)
        self.button_obj.connect('clicked', self.invoke_date_editor)
        
        self.text_obj.set_text(displayer.display(self.date_obj))
        self.text_obj.validate()

        self.text_obj.set_editable(not readonly)
        self.button_obj.set_sensitive(not readonly)
Пример #13
0
    def write_event_ref(self, vbox, ename, event):
        if event:
            dobj = event.get_date_object()
            phandle = event.get_place_handle()
            if phandle:
                pname = place_displayer.display_event(self.dbstate.db, event)
            else:
                pname = None

            value = {
                'date' : displayer.display(dobj),
                'place' : pname,
                'event_type' : ename,
                }
        else:
            pname = None
            dobj = None
            value = { 'event_type' : ename, }

        if dobj:
            if pname:
                self.write_data(
                    vbox, _('%(event_type)s: %(date)s in %(place)s') %
                    value)
            else:
                self.write_data(
                    vbox, _('%(event_type)s: %(date)s') % value)
        elif pname:
            self.write_data(
                vbox, _('%(event_type)s: %(place)s') % value)
        else:
            self.write_data(
                vbox, '%(event_type)s:' % value)
Пример #14
0
    def __census_changed(self, combo):
        """
        Called when the user selects a new census from the combo box.
        """
        model = combo.get_model()
        index = combo.get_active()
        census_id = model[index][2]

        # Set date
        census_date = get_census_date(census_id)

        date_text = self.widgets['date_text']
        date_text.set_text(displayer.display(census_date))
        self.event.set_date_object(census_date)
        self.citation.set_date_object(census_date)

        # Set source
        self.citation.set_reference_handle(model[index][0])

        # Set new columns
        columns = get_census_columns(census_id)
        report_columns = get_report_columns(census_id)
        self.details.create_table(columns, report_columns)
        heading_list = get_census_headings(census_id)
        self.headings.create_table(heading_list)
Пример #15
0
 def column_marriage(self, data):
     handle = data[0]
     cached, value = self.get_cached_value(handle, "MARRIAGE")
     if not cached:
         family = self.db.get_family_from_handle(data[0])
         event = get_marriage_or_fallback(self.db, family, "<i>%s</i>")
         if event:
             if event.date.format:
                 value = event.date.format % displayer.display(event.date)
             elif not get_date_valid(event):
                 value = invalid_date_format % displayer.display(event.date)
             else:
                 value = "%s" % displayer.display(event.date)
         else:
             value = ''
         self.set_cached_value(handle, "MARRIAGE", value)
     return value
Пример #16
0
    def create_widget(self):
        cell = Gtk.CellRendererText()
        cell.set_property('width', self._FILTER_WIDTH)
        cell.set_property('ellipsize', self._FILTER_ELLIPSIZE)
        self.generic.pack_start(cell, True)
        self.generic.add_attribute(cell, 'text', 0)
        self.on_filters_changed('Person')

        cell = Gtk.CellRendererText()
        cell.set_property('width', self._FILTER_WIDTH)
        cell.set_property('ellipsize', self._FILTER_ELLIPSIZE)
        self.tag.pack_start(cell, True)
        self.tag.add_attribute(cell, 'text', 0)

        self.etype.get_child().set_width_chars(5)

        exdate1 = Date()
        exdate2 = Date()
        exdate1.set(Date.QUAL_NONE, Date.MOD_RANGE, Date.CAL_GREGORIAN,
                    (0, 0, 1800, False, 0, 0, 1900, False))
        exdate2.set(Date.QUAL_NONE, Date.MOD_BEFORE, Date.CAL_GREGORIAN,
                    (0, 0, 1850, False))

        msg1 = displayer.display(exdate1)
        msg2 = displayer.display(exdate2)

        self.add_text_entry(_('Name'), self.filter_name)
        self.add_text_entry(_('ID'), self.filter_id)
        self.add_entry(_('Gender'), self.filter_gender)
        self.add_text_entry(
            _('Birth date'), self.filter_birth,
            _('example: "%(msg1)s" or "%(msg2)s"') % {
                'msg1': msg1,
                'msg2': msg2
            })
        self.add_text_entry(
            _('Death date'), self.filter_death,
            _('example: "%(msg1)s" or "%(msg2)s"') % {
                'msg1': msg1,
                'msg2': msg2
            })
        self.add_entry(_('Event'), self.etype)
        self.add_text_entry(_('Note'), self.filter_note)
        self.add_entry(_('Tag'), self.tag)
        self.add_filter_entry(_('Custom filter'), self.generic)
        self.add_regex_entry(self.filter_regex)
Пример #17
0
 def column_marriage(self, data):
     handle = data[0]
     cached, value = self.get_cached_value(handle, "MARRIAGE")
     if not cached:
         family = self.db.get_family_from_handle(data[0])
         event = get_marriage_or_fallback(self.db, family, "<i>%s</i>")
         if event:
             if event.date.format:
                 value = event.date.format % displayer.display(event.date)
             elif not get_date_valid(event):
                 value = invalid_date_format % displayer.display(event.date)
             else:
                 value = "%s" % displayer.display(event.date)
         else:
             value = ''
         self.set_cached_value(handle, "MARRIAGE", value)
     return value
Пример #18
0
    def __populate_gui(self, event):
        """
        Populate the GUI for a given form event.
        """
        # Set source
        handle = self.citation.get_reference_handle()
        source = self.db.get_source_from_handle(handle)
        source_text = self.widgets['source_text']
        source_text.set_text(source.get_title())
        form_id = get_form_id(source)

        # Set event type
        event_type = EventType()
        event_type.set_from_xml_str(get_form_type(form_id))
        self.event.set_type(event_type)

        # Set date
        form_date = get_form_date(form_id)
        date_text = self.widgets['date_text']
        date_button = self.widgets['date_button']
        if form_date is not None:
            date_text.set_text(displayer.display(form_date))
            self.event.set_date_object(form_date)
            self.citation.set_date_object(form_date)
            date_text.set_editable(False)
            date_button.set_sensitive(False)
        else:
            date_text.set_text(get_date(event))
            date_text.set_editable(True)
            date_button.set_sensitive(True)

        # Create tabs
        self.details = DetailsTab(self.dbstate,
                             self.uistate,
                             self.track,
                             self.event,
                             self.citation,
                             form_id)

        self.headings = HeadingsTab(self.dbstate,
                                       self.uistate,
                                       self.track,
                                       self.event,
                                       self.citation,
                                       form_id)

        self.gallery_list = GalleryTab(self.dbstate,
                                       self.uistate,
                                       self.track,
                                       self.citation.get_media_list())

        self._add_tab(self.notebook, self.details)
        self._add_tab(self.notebook, self.headings)
        self._add_tab(self.notebook, self.gallery_list)

        self.notebook.show_all()
        self.notebook.set_current_page(0)
Пример #19
0
 def update_after_editor(self, date_obj):
     """
     Update text entry and validate it
     """
     if date_obj:
         # first we set the text entry, that emits 'content-changed'
         # signal thus the date object gets updated too
         self.text_obj.set_text(displayer.display(date_obj))
         self.text_obj.validate()
Пример #20
0
 def update_after_editor(self, date_obj):
     """
     Update text entry and validate it
     """
     if date_obj:
         # first we set the text entry, that emits 'content-changed'
         # signal thus the date object gets updated too
         self.text_obj.set_text(displayer.display(date_obj))
         self.text_obj.validate()
Пример #21
0
 def __init__(self, obj_list, db):
     Gtk.ListStore.__init__(self, str, str, str, str, object)
     self.db = db
     for obj in obj_list:
         place = self.db.get_place_from_handle(obj.ref)
         self.append(row=[place.get_gramps_id(),
                          place.get_name().get_value(),
                          str(place.get_type()), 
                          displayer.display(obj.date), 
                          obj, ])
Пример #22
0
    def create_widget(self):
        cell = Gtk.CellRendererText()
        cell.set_property('width', self._FILTER_WIDTH)
        cell.set_property('ellipsize', self._FILTER_ELLIPSIZE)
        self.generic.pack_start(cell, True)
        self.generic.add_attribute(cell, 'text', 0)
        self.on_filters_changed('Person')

        cell = Gtk.CellRendererText()
        cell.set_property('width', self._FILTER_WIDTH)
        cell.set_property('ellipsize', self._FILTER_ELLIPSIZE)
        self.tag.pack_start(cell, True)
        self.tag.add_attribute(cell, 'text', 0)

        self.etype.get_child().set_width_chars(5)

        exdate1 = Date()
        exdate2 = Date()
        exdate1.set(Date.QUAL_NONE, Date.MOD_RANGE,
                    Date.CAL_GREGORIAN, (0, 0, 1800, False,
                                                0, 0, 1900, False))
        exdate2.set(Date.QUAL_NONE, Date.MOD_BEFORE,
                    Date.CAL_GREGORIAN, (0, 0, 1850, False))

        msg1 = displayer.display(exdate1)
        msg2 = displayer.display(exdate2)

        self.add_text_entry(_('Name'), self.filter_name)
        self.add_text_entry(_('ID'), self.filter_id)
        self.add_entry(_('Gender'), self.filter_gender)
        self.add_text_entry(_('Birth date'), self.filter_birth,
                            _('example: "%(msg1)s" or "%(msg2)s"') % {'msg1':msg1, 'msg2':msg2})
        self.add_text_entry(_('Death date'), self.filter_death,
                            _('example: "%(msg1)s" or "%(msg2)s"') % {'msg1':msg1, 'msg2':msg2})
        self.add_entry(_('Event'), self.etype)
        self.add_text_entry(_('Note'), self.filter_note)
        self.add_entry(_('Tag'), self.tag)
        self.add_filter_entry(_('Custom filter'), self.generic)
        self.add_regex_entry(self.filter_regex)
Пример #23
0
 def bubble_message(self, event, lat, lon, marks):
     """
     Add the popup menu.
     """
     self.menu = Gtk.Menu()
     menu = self.menu
     menu.set_title("family")
     message = ""
     oldplace = ""
     prevmark = None
     for mark in marks:
         if message != "":
             add_item = Gtk.MenuItem(label=message)
             add_item.show()
             menu.append(add_item)
             self.add_event_bubble_message(event, lat, lon,
                                           prevmark, add_item)
         if mark[0] != oldplace:
             message = "%s :" % mark[0]
             self.add_place_bubble_message(event, lat, lon,
                                           marks, menu, message, mark)
             oldplace = mark[0]
         evt = self.dbstate.db.get_event_from_gramps_id(mark[10])
         # format the date as described in preferences.
         date = displayer.display(evt.get_date_object())
         if date == "":
             date = _("Unknown")
         if mark[5] == EventRoleType.PRIMARY:
             message = "(%s) %s : %s" % (date, mark[7], mark[1])
         elif mark[5] == EventRoleType.FAMILY:
             evt = self.dbstate.db.get_event_from_gramps_id(mark[10])
             (father_name,
              mother_name) = self._get_father_and_mother_name(evt)
             message = "(%s) %s : %s - %s" % (date, mark[7],
                                              father_name, mother_name)
         else:
             evt = self.dbstate.db.get_event_from_gramps_id(mark[10])
             descr = evt.get_description()
             if descr == "":
                 descr = _('No description')
             message = "(%s) %s => %s" % (date, mark[5], descr)
         prevmark = mark
     add_item = Gtk.MenuItem(label=message)
     add_item.show()
     menu.append(add_item)
     self.add_event_bubble_message(event, lat, lon, prevmark, add_item)
     menu.popup(None, None, None,
                None, event.button, event.time)
     return 1
Пример #24
0
def format_datetime(datestring):
    """
    Convert an exif timestamp into a string for display, using the
    standard Gramps date format.
    """
    try:
        timestamp = datetime.strptime(datestring, '%Y:%m:%d %H:%M:%S')
    except ValueError:
        return _('Invalid format')
    date_part = Date()
    date_part.set_yr_mon_day(timestamp.year, timestamp.month, timestamp.day)
    date_str = displayer.display(date_part)
    time_str = _('%(hr)02d:%(min)02d:%(sec)02d') % {'hr': timestamp.hour,
                                                    'min': timestamp.minute,
                                                    'sec': timestamp.second}
    return _('%(date)s %(time)s') % {'date': date_str, 'time': time_str}
Пример #25
0
    def __populate_gui(self, event):
        """
        Populate the GUI for a given form event.
        """
        # Set source
        handle = self.citation.get_reference_handle()
        source = self.db.get_source_from_handle(handle)
        source_text = self.widgets['source_text']
        source_text.set_text(source.get_title())
        form_id = get_form_id(source)

        # Set event type
        event_type = EventType()
        event_type.set_from_xml_str(get_form_type(form_id))
        self.event.set_type(event_type)

        # Set date
        form_date = get_form_date(form_id)
        date_text = self.widgets['date_text']
        date_button = self.widgets['date_button']
        if form_date is not None:
            date_text.set_text(displayer.display(form_date))
            self.event.set_date_object(form_date)
            self.citation.set_date_object(form_date)
            date_text.set_editable(False)
            date_button.set_sensitive(False)
        else:
            date_text.set_text(get_date(event))
            date_text.set_editable(True)
            date_button.set_sensitive(True)

        # Create tabs
        self.details = DetailsTab(self.dbstate, self.uistate, self.track,
                                  self.event, self.citation, form_id)

        self.headings = HeadingsTab(self.dbstate, self.uistate, self.track,
                                    self.event, self.citation, form_id)

        self.gallery_list = GalleryTab(self.dbstate, self.uistate, self.track,
                                       self.citation.get_media_list())

        self._add_tab(self.notebook, self.details)
        self._add_tab(self.notebook, self.headings)
        self._add_tab(self.notebook, self.gallery_list)

        self.notebook.show_all()
        self.notebook.set_current_page(0)
Пример #26
0
 def sort_family_pr(self, fam_h):
     """ This prepares the family; list of children and the proposed list
         of sorted children.  It also returns an indicator of 'easy', i.e.
         if all children have valid dates.
     """
     fam = self.db.get_family_from_handle(fam_h)
     child_ref_list = fam.get_child_ref_list()
     children = []
     for index, child_ref in enumerate(child_ref_list):
         child = self.db.get_person_from_handle(child_ref.ref)
         birth = get_birth_or_fallback(self.db, child)
         if birth:
             b_date_s = birth.get_date_object().get_sort_value()
             birth_str = displayer.display(birth.get_date_object())
         else:
             b_date_s = 0
             birth_str = ""
         children.append(
             (name_displayer.display(child), birth_str, b_date_s, index))
     sorted_children = sorted(children, key=lambda child: child[2])
     return (children, sorted_children)
Пример #27
0
    def format_box(self, event, main_type):
        if event:
            dobj = event.get_date_object()
            pname = place_displayer.display_event(self.dbstate.db, event)
            value = {
                'abbrev': event.type.get_abbreviation(),
                'date' : displayer.display(dobj),
                'place' : pname
                }
        else:
            return ''

        if pname and not dobj.is_empty():
            info = _('%(abbrev)s %(date)s in %(place)s') % value
        else:
            info = _('%(abbrev)s %(date)s%(place)s') % value

        if event.type != main_type:
            return '<i>%s</i>' % escape(info)
        else:
            return escape(info)
Пример #28
0
    def run_tool(self):
        self.progress = ProgressMeter(_('Running Date Test'),'',
                                        parent=self.parent_window)
        self.progress.set_pass(_('Generating dates'),
                               4)
        dates = []
        # first some valid dates
        calendar = Date.CAL_GREGORIAN
        for quality in (Date.QUAL_NONE, Date.QUAL_ESTIMATED,
                        Date.QUAL_CALCULATED):
            for modifier in (Date.MOD_NONE, Date.MOD_BEFORE,
                             Date.MOD_AFTER, Date.MOD_ABOUT):
                for slash1 in (False,True):
                    for month in range(0,13):
                        for day in (0,5,27):
                            if not month and day:
                                continue
                            d = Date()
                            d.set(quality,modifier,calendar,(day,month,1789,slash1),"Text comment")
                            dates.append( d)
            for modifier in (Date.MOD_RANGE, Date.MOD_SPAN):
                for slash1 in (False,True):
                    for slash2 in (False,True):
                        for month in range(0,13):
                            for day in (0,5,27):
                                if not month and day:
                                    continue

                                d = Date()
                                d.set(quality,modifier,calendar,(day,month,1789,slash1,day,month,1876,slash2),"Text comment")
                                dates.append( d)

                                if not month:
                                    continue

                                d = Date()
                                d.set(quality,modifier,calendar,(day,month,1789,slash1,day,13-month,1876,slash2),"Text comment")
                                dates.append( d)

                                if not day:
                                    continue

                                d = Date()
                                d.set(quality,modifier,calendar,(day,month,1789,slash1,32-day,month,1876,slash2),"Text comment")
                                dates.append( d)
                                d = Date()
                                d.set(quality,modifier,calendar,(day,month,1789,slash1,32-day,13-month,1876,slash2),"Text comment")
                                dates.append( d)
            modifier = Date.MOD_TEXTONLY
            d = Date()
            d.set(quality,modifier,calendar,Date.EMPTY,
                  "This is a textual date")
            dates.append( d)
            self.progress.step()
        
        # test invalid dates
        #dateval = (4,7,1789,False,5,8,1876,False)
        #for l in range(1,len(dateval)):
        #    d = Date()
        #    try:
        #        d.set(Date.QUAL_NONE,Date.MOD_NONE,
        #              Date.CAL_GREGORIAN,dateval[:l],"Text comment")
        #        dates.append( d)
        #    except DateError, e:
        #        d.set_as_text("Date identified value correctly as invalid.\n%s" % e)
        #        dates.append( d)
        #    except:
        #        d = Date()
        #        d.set_as_text("Date.set Exception %s" % ("".join(traceback.format_exception(*sys.exc_info())),))
        #        dates.append( d)
        #for l in range(1,len(dateval)):
        #    d = Date()
        #    try:
        #        d.set(Date.QUAL_NONE,Date.MOD_SPAN,Date.CAL_GREGORIAN,dateval[:l],"Text comment")
        #        dates.append( d)
        #    except DateError, e:
        #        d.set_as_text("Date identified value correctly as invalid.\n%s" % e)
        #        dates.append( d)
        #    except:
        #        d = Date()
        #        d.set_as_text("Date.set Exception %s" % ("".join(traceback.format_exception(*sys.exc_info())),))
        #        dates.append( d)
        #self.progress.step()
        #d = Date()
        #d.set(Date.QUAL_NONE,Date.MOD_NONE,
        #      Date.CAL_GREGORIAN,(44,7,1789,False),"Text comment")
        #dates.append( d)
        #d = Date()
        #d.set(Date.QUAL_NONE,Date.MOD_NONE,
        #      Date.CAL_GREGORIAN,(4,77,1789,False),"Text comment")
        #dates.append( d)
        #d = Date()
        #d.set(Date.QUAL_NONE,Date.MOD_SPAN,
        #      Date.CAL_GREGORIAN,
        #      (4,7,1789,False,55,8,1876,False),"Text comment")
        #dates.append( d)
        #d = Date()
        #d.set(Date.QUAL_NONE,Date.MOD_SPAN,
        #      Date.CAL_GREGORIAN,
        #      (4,7,1789,False,5,88,1876,False),"Text comment")
        #dates.append( d)
        
        with DbTxn(_("Date Test Plugin"), self.db, batch=True) as self.trans:
            self.db.disable_signals()
            self.progress.set_pass(_('Generating dates'),
                                   len(dates))

            # create pass and fail tags
            pass_handle = self.create_tag(_('Pass'), '#0000FFFF0000')
            fail_handle = self.create_tag(_('Fail'), '#FFFF00000000')

            # now add them as birth to new persons
            i = 1
            for dateval in dates:
                person = Person()
                surname = Surname()
                surname.set_surname("DateTest")
                name = Name()
                name.add_surname(surname)
                name.set_first_name("Test %d" % i)
                person.set_primary_name(name)
                self.db.add_person(person, self.trans)
                bevent = Event()
                bevent.set_type(EventType.BIRTH)
                bevent.set_date_object(dateval)
                bevent.set_description("Date Test %d (source)" % i)
                bevent_h = self.db.add_event(bevent, self.trans)
                bevent_ref = EventRef()
                bevent_ref.set_reference_handle(bevent_h)
                # for the death event display the date as text and parse it back to a new date
                ndate = None
                try:
                    datestr = _dd.display( dateval)
                    try:
                        ndate = _dp.parse( datestr)
                        if not ndate:
                            ndate = Date()
                            ndate.set_as_text("DateParser None")
                            person.add_tag(fail_handle)
                        else:
                            person.add_tag(pass_handle)
                    except:
                        ndate = Date()
                        ndate.set_as_text("DateParser Exception %s" % ("".join(traceback.format_exception(*sys.exc_info())),))
                        person.add_tag(fail_handle)
                    else:
                        person.add_tag(pass_handle)
                except:
                    ndate = Date()
                    ndate.set_as_text("DateDisplay Exception: %s" % ("".join(traceback.format_exception(*sys.exc_info())),))
                    person.add_tag(fail_handle)
                
                if dateval.get_modifier() != Date.MOD_TEXTONLY \
                       and ndate.get_modifier() == Date.MOD_TEXTONLY:
                    # parser was unable to correctly parse the string
                    ndate.set_as_text( "TEXTONLY: "+ndate.get_text())
                    person.add_tag(fail_handle)
                if dateval.get_modifier() == Date.MOD_TEXTONLY \
                        and dateval.get_text().count("Traceback") \
                        and pass_handle in person.get_tag_list():
                    person.add_tag(fail_handle)
                
                devent = Event()
                devent.set_type(EventType.DEATH)
                devent.set_date_object(ndate)
                devent.set_description("Date Test %d (result)" % i)
                devent_h = self.db.add_event(devent, self.trans)
                devent_ref = EventRef()
                devent_ref.set_reference_handle(devent_h)
                person.set_birth_ref(bevent_ref)
                person.set_death_ref(devent_ref)
                self.db.commit_person(person, self.trans)
                i = i + 1
                self.progress.step()
        self.db.enable_signals()
        self.db.request_rebuild()
        self.progress.close()
Пример #29
0
    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)
Пример #30
0
 def bubble_message(self, event, lat, lon, marks):
     self.menu = Gtk.Menu()
     menu = self.menu
     message = ""
     oldplace = ""
     prevmark = None
     for mark in marks:
         if oldplace != "":
             add_item = Gtk.MenuItem(label=message)
             add_item.show()
             menu.append(add_item)
             self.itemoption = Gtk.Menu()
             itemoption = self.itemoption
             itemoption.show()
             message = ""
             add_item.set_submenu(itemoption)
             modify = Gtk.MenuItem(label=_("Edit Event"))
             modify.show()
             modify.connect("activate", self.edit_event, event, lat, lon,
                            prevmark)
             itemoption.append(modify)
             center = Gtk.MenuItem(label=_("Center on this place"))
             center.show()
             center.connect("activate", self.center_here, event, lat, lon,
                            prevmark)
             itemoption.append(center)
         if mark[0] != oldplace:
             if message != "":
                 add_item = Gtk.MenuItem()
                 add_item.show()
                 menu.append(add_item)
                 self.itemoption = Gtk.Menu()
                 itemoption = self.itemoption
                 itemoption.show()
                 message = ""
                 add_item.set_submenu(itemoption)
                 modify = Gtk.MenuItem(label=_("Edit Event"))
                 modify.show()
                 modify.connect("activate", self.edit_event, event, lat,
                                lon, mark)
                 itemoption.append(modify)
                 center = Gtk.MenuItem(label=_("Center on this place"))
                 center.show()
                 center.connect("activate", self.center_here, event, lat,
                                lon, mark)
                 itemoption.append(center)
             message = "%s :" % mark[0]
             self.add_place_bubble_message(event, lat, lon, marks, menu,
                                           message, mark)
             oldplace = mark[0]
             message = ""
         evt = self.dbstate.db.get_event_from_gramps_id(mark[10])
         # format the date as described in preferences.
         date = displayer.display(evt.get_date_object())
         if date == "":
             date = _("Unknown")
         if mark[11] == EventRoleType.PRIMARY:
             message = "(%s) %s : %s" % (date, mark[2], mark[1])
         elif mark[11] == EventRoleType.FAMILY:
             (father_name,
              mother_name) = self._get_father_and_mother_name(evt)
             message = "(%s) %s : %s - %s" % (date, mark[7], father_name,
                                              mother_name)
         else:
             descr = evt.get_description()
             if descr == "":
                 descr = _('No description')
             message = "(%s) %s => %s" % (date, mark[11], descr)
         prevmark = mark
     add_item = Gtk.MenuItem(label=message)
     add_item.show()
     menu.append(add_item)
     self.itemoption = Gtk.Menu()
     itemoption = self.itemoption
     itemoption.show()
     add_item.set_submenu(itemoption)
     modify = Gtk.MenuItem(label=_("Edit Event"))
     modify.show()
     modify.connect("activate", self.edit_event, event, lat, lon, prevmark)
     itemoption.append(modify)
     center = Gtk.MenuItem(label=_("Center on this place"))
     center.show()
     center.connect("activate", self.center_here, event, lat, lon, prevmark)
     itemoption.append(center)
     menu.show()
     menu.popup(None, None, None, None, event.button, event.time)
     return 1
Пример #31
0
 def column_date(self,data):
     if data[10]:
         date = Date()
         date.unserialize(data[10])
         return displayer.display(date)
     return ''
Пример #32
0
    def bubble_message(self, event, lat, lon, marks):
        """
        Create the menu for the selected marker
        """
        self.menu = Gtk.Menu()
        menu = self.menu
        menu.set_title("family")
        events = []
        message = ""
        oldplace = ""
        prevmark = None
        for mark in marks:
            for plce in self.all_place_list:
                if (plce[3] == mark[3] and plce[4] == mark[4]):
                    if plce[10] in events:
                        continue
                    else:
                        events.append(plce[10])

                    if plce[0] != oldplace:
                        message = "%s :" % plce[0]
                        self.add_place_bubble_message(event, lat, lon,
                                                      marks, menu,
                                                      message, plce)
                        oldplace = plce[0]
                        message = ""
                    evt = self.dbstate.db.get_event_from_gramps_id(plce[10])
                    # format the date as described in preferences.
                    date = displayer.display(evt.get_date_object())
                    if date == "":
                        date = _("Unknown")
                    if ( plce[11] == EventRoleType.PRIMARY ):
                        message = "(%s) %s : %s" % ( date, plce[2], plce[1] )
                    elif ( plce[11] == EventRoleType.FAMILY ):
                        (father_name, mother_name) = self._get_father_and_mother_name(evt)
                        message = "(%s) %s : %s - %s" % (date, plce[7],
                                                         father_name,
                                                         mother_name )
                    else:
                        descr = evt.get_description()
                        if descr == "":
                            descr = _('No description')
                        message = "(%s) %s => %s" % ( date, plce[11], descr)
                    prevmark = plce
                    add_item = Gtk.MenuItem(label=message)
                    add_item.show()
                    menu.append(add_item)
                    self.itemoption = Gtk.Menu()
                    itemoption = self.itemoption
                    itemoption.set_title(message)
                    itemoption.show()
                    add_item.set_submenu(itemoption)
                    modify = Gtk.MenuItem(label=_("Edit Event"))
                    modify.show()
                    modify.connect("activate", self.edit_event,
                                   event, lat, lon, prevmark)
                    itemoption.append(modify)
                    center = Gtk.MenuItem(label=_("Center on this place"))
                    center.show()
                    center.connect("activate", self.center_here,
                                   event, lat, lon, prevmark)
                    itemoption.append(center)
                    menu.show()
                    menu.popup(None, None, None,
                               None, event.button, event.time)
        return 0
    def run(self):
        BUTTONS = ((_("Select All"), self.select_all),
                   (_("Select None"), self.select_none),
                   (_("Toggle Selection"), self.toggle_select),
                   (_("Add Selected Events"), self.apply_selection),
                   )

        if hasattr(self, "table") and self.table:
            self.reselect = False
            if self.options.handler.options_dict['remove']:
                QuestionDialog(_("Remove Events, Notes, and Source and Reselect Data"),
                               _("Are you sure you want to remove previous events, notes, and source and reselect data?"),
                               _("Remove and Run Select Again"),
                               self.set_reselect,
                               self.window)
            else:
                QuestionDialog(_("Reselect Data"),
                               _("Are you sure you want to reselect data?"),
                               _("Run Select Again"),
                               self.set_reselect,
                               self.window)
            if not self.reselect:
                return

        current_date = Date()
        current_date.set_yr_mon_day(*time.localtime(time.time())[0:3])
        self.action = {}
        widget = self.add_results_frame(_("Select"))
        document = TextBufDoc(make_basic_stylesheet(), None)
        document.dbstate = self.dbstate
        document.uistate = self.uistate
        document.open("", container=widget)
        self.sdb = SimpleAccess(self.db)
        sdoc = SimpleDoc(document)
        stab = QuickTable(self.sdb)
        self.table = stab
        stab.columns(_("Select"), _("Person"), _("Action"),
                     _("Birth Date"), _("Death Date"),
                     _("Evidence"), _("Relative"))
        self.results_write(_("Processing...\n"))
        self.filter_option =  self.options.menu.get_option_by_name('filter')
        self.filter = self.filter_option.get_filter() # the actual filter
        people = self.filter.apply(self.db,
                                   self.db.iter_person_handles())
        num_people = self.db.get_number_of_people()
        source_text = self.options.handler.options_dict['source_text']
        source = None
        add_birth = self.options.handler.options_dict['add_birth']
        add_death = self.options.handler.options_dict['add_death']
        remove_old = self.options.handler.options_dict['remove']

        self.MAX_SIB_AGE_DIFF = self.options.handler.options_dict['MAX_SIB_AGE_DIFF']
        self.MAX_AGE_PROB_ALIVE = self.options.handler.options_dict['MAX_AGE_PROB_ALIVE']
        self.AVG_GENERATION_GAP = self.options.handler.options_dict['AVG_GENERATION_GAP']
        if remove_old:
            with DbTxn("", self.db, batch=True) as self.trans:
                self.db.disable_signals()
                self.results_write(_("Removing old estimations... "))
                self.progress.set_pass((_("Removing '%s'...") % source_text),
                                       num_people)
                for person_handle in people:
                    self.progress.step()
                    pupdate = 0
                    person = self.db.get_person_from_handle(person_handle)
                    birth_ref = person.get_birth_ref()
                    if birth_ref:
                        birth = self.db.get_event_from_handle(birth_ref.ref)
                        for citation_handle in birth.get_citation_list():
                            citation = self.db.get_citation_from_handle(citation_handle)
                            source_handle = citation.get_reference_handle()
                            #print "birth handle:", source_handle
                            source = self.db.get_source_from_handle(source_handle)
                            if source:
                                #print "birth source:", source, source.get_title()
                                if source.get_title() == source_text:
                                    person.set_birth_ref(None)
                                    person.remove_handle_references('Event',[birth_ref.ref])
                                    # remove note
                                    note_list = birth.get_referenced_note_handles()
                                    birth.remove_handle_references('Note',
                                      [note_handle for (obj_type, note_handle) in note_list])
                                    for (obj_type, note_handle) in note_list:
                                        self.db.remove_note(note_handle, self.trans)
                                    self.db.remove_event(birth_ref.ref, self.trans)
                                    self.db.commit_source(source, self.trans)
                                    pupdate = 1
                                    break
                    death_ref = person.get_death_ref()
                    if death_ref:
                        death = self.db.get_event_from_handle(death_ref.ref)
                        for citation_handle in death.get_citation_list():
                            citation = self.db.get_citation_from_handle(citation_handle)
                            source_handle = citation.get_reference_handle()
                            #print "death handle:", source_handle
                            source = self.db.get_source_from_handle(source_handle)
                            if source:
                                #print "death source:", source, source.get_title()
                                if source.get_title() == source_text:
                                    person.set_death_ref(None)
                                    person.remove_handle_references('Event',[death_ref.ref])
                                    # remove note
                                    note_list = death.get_referenced_note_handles()
                                    birth.remove_handle_references('Note',
                                      [note_handle for (obj_type, note_handle) in note_list])
                                    for (obj_type, note_handle) in note_list:
                                        self.db.remove_note(note_handle, self.trans)
                                    self.db.remove_event(death_ref.ref, self.trans)
                                    self.db.commit_source(source, self.trans)
                                    pupdate = 1
                                    break
                    if pupdate == 1:
                        self.db.commit_person(person, self.trans)
                if source:
                    self.db.remove_source(source.handle, self.trans)
                self.results_write(_("done!\n"))
                self.db.enable_signals()
                self.db.request_rebuild()
        if add_birth or add_death:
            self.results_write(_("Selecting... \n\n"))
            self.progress.set_pass(_('Selecting...'),
                                   num_people)
            row = 0
            for person_handle in people:
                self.progress.step()
                person = self.db.get_person_from_handle(person_handle)
                birth_ref = person.get_birth_ref()
                death_ref = person.get_death_ref()
                add_birth_event, add_death_event = False, False
                if not birth_ref or not death_ref:
                    date1, date2, explain, other = self.calc_estimates(person)
                    if birth_ref:
                        ev = self.db.get_event_from_handle(birth_ref.ref)
                        date1 = ev.get_date_object()
                    elif not birth_ref and add_birth and date1:
                        if date1.match( current_date, "<"):
                            add_birth_event = True
                            date1.make_vague()
                        else:
                            date1 = Date()
                    else:
                        date1 = Date()
                    if death_ref:
                        ev = self.db.get_event_from_handle(death_ref.ref)
                        date2 = ev.get_date_object()
                    elif not death_ref and add_death and date2:
                        if date2.match( current_date, "<"):
                            add_death_event = True
                            date2.make_vague()
                        else:
                            date2 = Date()
                    else:
                        date2 = Date()
                    # Describe
                    if add_birth_event and add_death_event:
                        action = _("Add birth and death events")
                    elif add_birth_event:
                        action = _("Add birth event")
                    elif add_death_event:
                        action = _("Add death event")
                    else:
                        continue
                    #stab.columns(_("Select"), _("Person"), _("Action"),
                    # _("Birth Date"), _("Death Date"), _("Evidence"), _("Relative"))
                    if add_birth == 1 and not birth_ref: # no date
                        date1 = Date()
                    if add_death == 1 and not death_ref: # no date
                        date2 = Date()
                    if person == other:
                        other = None
                    stab.row("checkbox",
                             person,
                             action,
                             date1,
                             date2,
                             explain or "",
                             other or "")
                    if add_birth_event:
                        stab.set_cell_markup(3, row, "<b>%s</b>" % date_displayer.display(date1))
                    if add_death_event:
                        stab.set_cell_markup(4, row, "<b>%s</b>" % date_displayer.display(date2))
                    self.action[person.handle] = (add_birth_event, add_death_event)
                    row += 1
            if row > 0:
                self.results_write("  ")
                for text, function in BUTTONS:
                    self.make_button(text, function, widget)
                self.results_write("\n")
                stab.write(sdoc)
                self.results_write("  ")
                for text, function in BUTTONS:
                    self.make_button(text, function, widget)
                self.results_write("\n")
            else:
                self.results_write(_("No events to be added."))
                self.results_write("\n")
        self.results_write("\n")
        self.progress.close()
        self.set_current_frame(_("Select"))
Пример #34
0
    def run_tool(self):
        self.progress = ProgressMeter(_('Running Date Test'),
                                      '',
                                      parent=self.parent_window)
        self.progress.set_pass(_('Generating dates'), 4)
        dates = []
        # first some valid dates
        calendar = Date.CAL_GREGORIAN
        for quality in (Date.QUAL_NONE, Date.QUAL_ESTIMATED,
                        Date.QUAL_CALCULATED):
            for modifier in (Date.MOD_NONE, Date.MOD_BEFORE, Date.MOD_AFTER,
                             Date.MOD_ABOUT):
                for slash1 in (False, True):
                    for month in range(0, 13):
                        for day in (0, 5, 27):
                            if not month and day:
                                continue
                            d = Date()
                            d.set(quality, modifier, calendar,
                                  (day, month, 1789, slash1), "Text comment")
                            dates.append(d)
            for modifier in (Date.MOD_RANGE, Date.MOD_SPAN):
                for slash1 in (False, True):
                    for slash2 in (False, True):
                        for month in range(0, 13):
                            for day in (0, 5, 27):
                                if not month and day:
                                    continue

                                d = Date()
                                d.set(quality, modifier, calendar,
                                      (day, month, 1789, slash1, day, month,
                                       1876, slash2), "Text comment")
                                dates.append(d)

                                if not month:
                                    continue

                                d = Date()
                                d.set(quality, modifier, calendar,
                                      (day, month, 1789, slash1, day,
                                       13 - month, 1876, slash2),
                                      "Text comment")
                                dates.append(d)

                                if not day:
                                    continue

                                d = Date()
                                d.set(quality, modifier, calendar,
                                      (day, month, 1789, slash1, 32 - day,
                                       month, 1876, slash2), "Text comment")
                                dates.append(d)
                                d = Date()
                                d.set(quality, modifier, calendar,
                                      (day, month, 1789, slash1, 32 - day,
                                       13 - month, 1876, slash2),
                                      "Text comment")
                                dates.append(d)
            modifier = Date.MOD_TEXTONLY
            d = Date()
            d.set(quality, modifier, calendar, Date.EMPTY,
                  "This is a textual date")
            dates.append(d)
            self.progress.step()

        # test invalid dates
        #dateval = (4,7,1789,False,5,8,1876,False)
        #for l in range(1,len(dateval)):
        #    d = Date()
        #    try:
        #        d.set(Date.QUAL_NONE,Date.MOD_NONE,
        #              Date.CAL_GREGORIAN,dateval[:l],"Text comment")
        #        dates.append( d)
        #    except DateError, e:
        #        d.set_as_text("Date identified value correctly as invalid.\n%s" % e)
        #        dates.append( d)
        #    except:
        #        d = Date()
        #        d.set_as_text("Date.set Exception %s" % ("".join(traceback.format_exception(*sys.exc_info())),))
        #        dates.append( d)
        #for l in range(1,len(dateval)):
        #    d = Date()
        #    try:
        #        d.set(Date.QUAL_NONE,Date.MOD_SPAN,Date.CAL_GREGORIAN,dateval[:l],"Text comment")
        #        dates.append( d)
        #    except DateError, e:
        #        d.set_as_text("Date identified value correctly as invalid.\n%s" % e)
        #        dates.append( d)
        #    except:
        #        d = Date()
        #        d.set_as_text("Date.set Exception %s" % ("".join(traceback.format_exception(*sys.exc_info())),))
        #        dates.append( d)
        #self.progress.step()
        #d = Date()
        #d.set(Date.QUAL_NONE,Date.MOD_NONE,
        #      Date.CAL_GREGORIAN,(44,7,1789,False),"Text comment")
        #dates.append( d)
        #d = Date()
        #d.set(Date.QUAL_NONE,Date.MOD_NONE,
        #      Date.CAL_GREGORIAN,(4,77,1789,False),"Text comment")
        #dates.append( d)
        #d = Date()
        #d.set(Date.QUAL_NONE,Date.MOD_SPAN,
        #      Date.CAL_GREGORIAN,
        #      (4,7,1789,False,55,8,1876,False),"Text comment")
        #dates.append( d)
        #d = Date()
        #d.set(Date.QUAL_NONE,Date.MOD_SPAN,
        #      Date.CAL_GREGORIAN,
        #      (4,7,1789,False,5,88,1876,False),"Text comment")
        #dates.append( d)

        with DbTxn(_("Date Test Plugin"), self.db, batch=True) as self.trans:
            self.db.disable_signals()
            self.progress.set_pass(_('Generating dates'), len(dates))

            # create pass and fail tags
            pass_handle = self.create_tag(_('Pass'), '#0000FFFF0000')
            fail_handle = self.create_tag(_('Fail'), '#FFFF00000000')

            # now add them as birth to new persons
            i = 1
            for dateval in dates:
                person = Person()
                surname = Surname()
                surname.set_surname("DateTest")
                name = Name()
                name.add_surname(surname)
                name.set_first_name("Test %d" % i)
                person.set_primary_name(name)
                self.db.add_person(person, self.trans)
                bevent = Event()
                bevent.set_type(EventType.BIRTH)
                bevent.set_date_object(dateval)
                bevent.set_description("Date Test %d (source)" % i)
                bevent_h = self.db.add_event(bevent, self.trans)
                bevent_ref = EventRef()
                bevent_ref.set_reference_handle(bevent_h)
                # for the death event display the date as text and parse it back to a new date
                ndate = None
                try:
                    datestr = _dd.display(dateval)
                    try:
                        ndate = _dp.parse(datestr)
                        if not ndate:
                            ndate = Date()
                            ndate.set_as_text("DateParser None")
                            person.add_tag(fail_handle)
                        else:
                            person.add_tag(pass_handle)
                    except:
                        ndate = Date()
                        ndate.set_as_text("DateParser Exception %s" % ("".join(
                            traceback.format_exception(*sys.exc_info())), ))
                        person.add_tag(fail_handle)
                    else:
                        person.add_tag(pass_handle)
                except:
                    ndate = Date()
                    ndate.set_as_text("DateDisplay Exception: %s" % ("".join(
                        traceback.format_exception(*sys.exc_info())), ))
                    person.add_tag(fail_handle)

                if dateval.get_modifier() != Date.MOD_TEXTONLY \
                       and ndate.get_modifier() == Date.MOD_TEXTONLY:
                    # parser was unable to correctly parse the string
                    ndate.set_as_text("TEXTONLY: " + ndate.get_text())
                    person.add_tag(fail_handle)
                if dateval.get_modifier() == Date.MOD_TEXTONLY \
                        and dateval.get_text().count("Traceback") \
                        and pass_handle in person.get_tag_list():
                    person.add_tag(fail_handle)

                devent = Event()
                devent.set_type(EventType.DEATH)
                devent.set_date_object(ndate)
                devent.set_description("Date Test %d (result)" % i)
                devent_h = self.db.add_event(devent, self.trans)
                devent_ref = EventRef()
                devent_ref.set_reference_handle(devent_h)
                person.set_birth_ref(bevent_ref)
                person.set_death_ref(devent_ref)
                self.db.commit_person(person, self.trans)
                i = i + 1
                self.progress.step()
        self.db.enable_signals()
        self.db.request_rebuild()
        self.progress.close()
Пример #35
0
 def bubble_message(self, event, lat, lon, marks):
     self.menu = Gtk.Menu()
     menu = self.menu
     menu.set_title("person")
     message = ""
     oldplace = ""
     prevmark = None
     for mark in marks:
         if oldplace != "":
             add_item = Gtk.MenuItem(label=message)
             add_item.show()
             menu.append(add_item)
             self.itemoption = Gtk.Menu()
             itemoption = self.itemoption
             itemoption.set_title(message)
             itemoption.show()
             message = ""
             add_item.set_submenu(itemoption)
             modify = Gtk.MenuItem(label=_("Edit Event"))
             modify.show()
             modify.connect("activate", self.edit_event,
                            event, lat, lon, prevmark)
             itemoption.append(modify)
             center = Gtk.MenuItem(label=_("Center on this place"))
             center.show()
             center.connect("activate", self.center_here,
                            event, lat, lon, prevmark)
             itemoption.append(center)
         if mark[0] != oldplace:
             if message != "":
                 add_item = Gtk.MenuItem()
                 add_item.show()
                 menu.append(add_item)
                 self.itemoption = Gtk.Menu()
                 itemoption = self.itemoption
                 itemoption.set_title(message)
                 itemoption.show()
                 message = ""
                 add_item.set_submenu(itemoption)
                 modify = Gtk.MenuItem(label=_("Edit Event"))
                 modify.show()
                 modify.connect("activate", self.edit_event,
                                event, lat, lon, mark)
                 itemoption.append(modify)
                 center = Gtk.MenuItem(label=_("Center on this place"))
                 center.show()
                 center.connect("activate", self.center_here,
                                event, lat, lon, mark)
                 itemoption.append(center)
             message = "%s :" % mark[0]
             self.add_place_bubble_message(event, lat, lon,
                                           marks, menu, message, mark)
             oldplace = mark[0]
             message = ""
         evt = self.dbstate.db.get_event_from_gramps_id(mark[10])
         # format the date as described in preferences.
         date = displayer.display(evt.get_date_object())
         if date == "":
             date = _("Unknown")
         if mark[11] == EventRoleType.PRIMARY:
             message = "(%s) %s : %s" % (date, mark[2], mark[1])
         elif mark[11] == EventRoleType.FAMILY:
             (father_name,
              mother_name) = self._get_father_and_mother_name(evt)
             message = "(%s) %s : %s - %s" % (date, mark[7],
                                              father_name, mother_name)
         else:
             descr = evt.get_description()
             if descr == "":
                 descr = _('No description')
             message = "(%s) %s => %s" % (date, mark[11], descr)
         prevmark = mark
     add_item = Gtk.MenuItem(label=message)
     add_item.show()
     menu.append(add_item)
     self.itemoption = Gtk.Menu()
     itemoption = self.itemoption
     itemoption.set_title(message)
     itemoption.show()
     add_item.set_submenu(itemoption)
     modify = Gtk.MenuItem(label=_("Edit Event"))
     modify.show()
     modify.connect("activate", self.edit_event, event, lat, lon, prevmark)
     itemoption.append(modify)
     center = Gtk.MenuItem(label=_("Center on this place"))
     center.show()
     center.connect("activate", self.center_here, event, lat, lon, prevmark)
     itemoption.append(center)
     menu.show()
     menu.popup(None, None, None,
                None, event.button, event.time)
     return 1
Пример #36
0
    def print_object(self, level, o):

        if issubclass(o.__class__, gramps.gen.lib.address.Address):
            # Details of address are printed by the subclass conditions,
            # primarily by LocationBase, because address is a subclass of
            # LocationBase
            pass

        if issubclass(o.__class__, gramps.gen.lib.addressbase.AddressBase):
            for address in o.get_address_list():
                self.print_header(level, _("Address"), ref=address)
                self.print_object(level+1, address)

        if isinstance(o, gramps.gen.lib.Attribute):
            # The unique information about attributes (the type) is printed by
            # AttributeBase
            pass

        if issubclass(o.__class__, gramps.gen.lib.attrbase.AttributeBase):
            for attribute in o.get_attribute_list():
                self.print_header(level, _("Attribute")+". ",
                                  type_desc=str(attribute.get_type()),
                                  obj_type=attribute.get_value(),
                                  privacy=attribute.get_privacy(),
                                  ref=attribute)
                self.print_object(level+1, attribute)

        if isinstance(o, gramps.gen.lib.ChildRef):
            # The unique information about ChildRef (the father relation and
            # mother relation) is printed by the main write_report function
            pass

        if issubclass(o.__class__, gramps.gen.lib.citationbase.CitationBase):
            if self.print_citations:
                self.print_header(level, "CitationBase tbd")

                for citation_handle in o.get_citation_list():
                    citation = self.database.get_citation_from_handle(
                                                            citation_handle)
                    self.print_object(level+1, citation)

        if isinstance(o, gramps.gen.lib.Citation):
            # the unique information about Citation (the page) is printed by the
            # bibliography code. The other unique information, the confidence is
            # printed here
            if o.get_confidence_level() != gramps.gen.lib.Citation.CONF_NORMAL:
                self.doc.start_paragraph("PE-Level%d" % min(level, 32))
                self.doc.start_bold()
                self.doc.write_text(_("Confidence") + " : ")
                self.doc.end_bold()
                self.doc.write_text(conf_strings.get(o.get_confidence_level(),
                                                     _('Unknown')))
                self.doc.end_paragraph()

            if self.print_citations:
                source_handle = o.get_reference_handle()
                source = self.database.get_source_from_handle(source_handle)
                self.print_object(level+1, source)

        if issubclass(o.__class__, gramps.gen.lib.datebase.DateBase):
            if o.get_date_object() and not o.get_date_object().is_empty():
                self.doc.start_paragraph("PE-Level%d" % min(level, 32))
                self.doc.start_bold()
                self.doc.write_text(_("Date") + " : ")
                self.doc.end_bold()
                self.doc.write_text(displayer.display(o.get_date_object()))
                self.doc.end_paragraph()

        if isinstance(o, gramps.gen.lib.Event):
            # The event type is printed by the main write_report function
            self.doc.start_paragraph("PE-Level%d" % min(level, 32))
            self.doc.start_bold()
            self.doc.write_text(_("Description") + " : ")
            self.doc.end_bold()
            self.doc.write_text(str(o.get_description()))
            self.doc.end_paragraph()

        if issubclass(o.__class__, gramps.gen.lib.eventref.EventRef):
            # The unique information about EventRef (the EventRoleType) is
            # printed by the main write_report function
            event = self.database.get_event_from_handle(o.get_reference_handle())
            self.print_header(level, _("Event"), event.get_gramps_id(),
                              _("Event type"), str(event.get_type()),
                              event.get_privacy(),
                              ref=event)
            self.print_object(level+1, event)

        if isinstance(o, gramps.gen.lib.Family):
            # The unique information about Family (father, mother and children,
            # FamilyRelType and event references) are printed by the main
            # write_report function
            pass

        if isinstance(o, gramps.gen.lib.LdsOrd):
            # The Ordinance type is printed by LdsOrdBase
            self.doc.start_paragraph("PE-Level%d" % min(level, 32))
            self.doc.start_bold()
            self.doc.write_text(_("Temple and status") + " : ")
            self.doc.end_bold()
            self.doc.write_text(", ".join((TEMPLES.name(o.get_temple()),
                                           o.status2str()
                                   )))
            self.doc.end_paragraph()

            f_h = o.get_family_handle()
            if f_h:
                family = self.database.get_family_from_handle(f_h)
                self.print_family_summary(level+1, family,
                                          _("LDS Ordinance family"))

        if issubclass(o.__class__, gramps.gen.lib.ldsordbase.LdsOrdBase):
            for ldsord in o.get_lds_ord_list():
                self.print_header(level, _("LDS "),
                                  type_desc=_("Ordinance"),
                                  obj_type=ldsord.type2str(),
                                  privacy=ldsord.get_privacy(),
                                  ref=ldsord)
                self.print_object(level+1, ldsord)

        if isinstance(o, gramps.gen.lib.Location):
            # The unique information about location (Parish) is printed by
            # Place. Location otherwise serves as a pointer to a LocationBase
            # object
            pass

        if issubclass(o.__class__, gramps.gen.lib.locationbase.LocationBase):
            self.doc.start_paragraph("PE-Level%d" % min(level, 32))
            self.doc.start_bold()
            self.doc.write_text(_("Street, City, County, State, Postal Code, "
                                  "Country, Phone number") + " : ")
            self.doc.end_bold()
            self.doc.write_text(", ".join((o.get_street(),
                                            o.get_city(),
                                            o.get_county(),
                                            o.get_state(),
                                            o.get_postal_code(),
                                            o.get_country(),
                                            o.get_phone())))
            self.doc.end_paragraph()

        if issubclass(o.__class__, gramps.gen.lib.mediabase.MediaBase):
            for mediaref in o.get_media_list():
                self.print_header(level, _("Media Reference"), ref=mediaref)
                self.print_object(level+1, mediaref)

        if isinstance(o, gramps.gen.lib.MediaObject):
            # thumb is not printed. The mime type is printed by MediaRef
            self.doc.start_paragraph("PE-Level%d" % min(level, 32))
            self.doc.start_bold()
            self.doc.write_text(_("Description and Path") + " : ")
            self.doc.end_bold()
            self.doc.write_text(o.get_description() + ", ")
            path = o.get_path()
            if path:
                mark = IndexMark("file://:" +
                                 media_path_full(self.database, path),
                                 LOCAL_HYPERLINK)
                self.doc.write_text(path, mark=mark)
            self.doc.end_paragraph()

            mime_type = o.get_mime_type()
            if mime_type and mime_type.startswith("image"):
                filename = media_path_full(self.database, o.get_path())
                if os.path.exists(filename):
                    self.doc.start_paragraph("PE-Level%d" % min(level, 32))
                    self.doc.add_media_object(filename, "single", 4.0, 4.0)
                    self.doc.end_paragraph()
                else:
                    self._user.warn(_("Could not add photo to page"),
                          "%s: %s" % (filename, _('File does not exist')))

        if isinstance(o, gramps.gen.lib.MediaRef):
            mediaobject_handle = o.get_reference_handle()
            mediaobject = self.database.get_object_from_handle(mediaobject_handle)

            if o.get_rectangle():
                self.doc.start_paragraph("PE-Level%d" % min(level, 32))
                self.doc.start_bold()
                self.doc.write_text(_("Referenced Region") + " : ")
                self.doc.end_bold()
                self.doc.write_text(", ".join((("%d" % i) for i in o.get_rectangle())))
                self.doc.end_paragraph()

                mime_type = mediaobject.get_mime_type()
                if mime_type and mime_type.startswith("image"):
                    filename = media_path_full(self.database,
                                               mediaobject.get_path())
                    if os.path.exists(filename):
                        self.doc.start_paragraph("PE-Level%d" % min(level, 32))
                        self.doc.add_media_object(filename, "single", 4.0, 4.0,
                                                  crop=o.get_rectangle()
                                                  )
                        self.doc.end_paragraph()

            desc = get_description(mediaobject.get_mime_type())
            if not desc:
                desc = _("unknown")
            self.print_header(level, _("Media Object"),
                              mediaobject.get_gramps_id(),
                              _("Mime type"),
                              desc,
                              mediaobject.get_privacy(),
                              ref=mediaobject)
            self.print_object(level+1, mediaobject)

        if isinstance(o, gramps.gen.lib.Name):
            # group_as, sort_as and display_as are not printed. NameType is
            # printed by the main write_report function
            self.doc.start_paragraph("PE-Level%d" % min(level, 32))
            self.doc.start_bold()
            self.doc.write_text(_("Given name(s): Title, Given, Suffix, "
                                  "Call Name, Nick Name, Family Nick Name") +
                                  " : ")
            self.doc.end_bold()
            self.doc.write_text(", ".join((o.get_title(),
                                           o.get_first_name(),
                                           o.get_suffix(),
                                           o.get_call_name(),
                                           o.get_nick_name(),
                                           o.get_family_nick_name())))
            self.doc.end_paragraph()

        if isinstance(o, gramps.gen.lib.Note):
            # The NoteType is printed by NoteBase. Whether the note is flowed or
            # not is not printed, but affects the way the note appears
            self.doc.write_styled_note(o.get_styledtext(),
                                       o.get_format(),
                                       "PE-Level%d" % min(level, 32),
                                       contains_html = o.get_type()
                                        == gramps.gen.lib.notetype.NoteType.HTML_CODE
                                      )

        if issubclass(o.__class__, gramps.gen.lib.notebase.NoteBase):
            for n_h in o.get_note_list():
                note = self.database.get_note_from_handle(n_h)
                self.print_header(level, _("Note"), note.get_gramps_id(),
                                  _("Note type"), str(note.get_type()),
                                  note.get_privacy())
                self.print_object(level+1, note)

        if issubclass(o.__class__, gramps.gen.lib.Person):
            # This is printed by the main write-report function
            pass

        if isinstance(o, gramps.gen.lib.Place):
            # The title, name, type, code and lat/long are printed by PlaceBase
            for placeref in o.get_placeref_list():
                self.print_header(level, _("Parent Place"))
                self.print_object(level+1, placeref)

#            location = o.get_main_location()
#            if location.get_parish():
#                self.print_header(level, _("Main Location"),
#                                  type_desc=_("Parish"),
#                                  obj_type=location.get_parish())
#            else:
#                self.print_header(level, _("Main Location"))
#
#            self.print_object(level+1, location)
#
            for location in o.get_alternate_locations():
                if location.get_parish():
                    self.print_header(level, _("Alternate Location"),
                                      type_desc=_("Parish"),
                                      obj_type=location.get_parish())
                else:
                    self.print_header(level, _("Alternate Location"))
                self.print_object(level+1, location)

        if issubclass(o.__class__, gramps.gen.lib.placebase.PlaceBase) or \
            issubclass(o.__class__, gramps.gen.lib.placeref.PlaceRef):
            if issubclass(o.__class__, gramps.gen.lib.placebase.PlaceBase):
                place_handle = o.get_place_handle()
            else:
                place_handle = o.get_reference_handle()
            place = self.database.get_place_from_handle(place_handle)
            if place:
                place_title = place_displayer.display(self.database, place)
                self.print_header(level, _("Place"), place.get_gramps_id(),
                                  _("Place Title"), place_title,
                                  privacy=place.get_privacy(),
                                  ref=place)
                self.doc.start_paragraph("PE-Level%d" % min(level+1, 32))
                self.doc.start_bold()
                self.doc.write_text(_("Name") + " : ")
                self.doc.end_bold()
                self.doc.write_text(place.get_name().value)
                self.doc.start_bold()
                self.doc.write_text(" " + _("Type") + " : ")
                self.doc.end_bold()
                self.doc.write_text(str(place.get_type()))
                self.doc.start_bold()
                self.doc.write_text(" " + _("Code") + " : ")
                self.doc.end_bold()
                self.doc.write_text(place.get_code())
                self.doc.end_paragraph()

                for name in place.get_alternative_names():
                    self.doc.start_paragraph("PE-Level%d" % min(level+1, 32))
                    self.doc.start_bold()
                    self.doc.write_text(_("Alternative Name") + " : ")
                    self.doc.end_bold()
                    self.doc.write_text(name)
                    self.doc.end_paragraph()

                if place.get_longitude() or place.get_latitude():
                    self.doc.start_paragraph("PE-Level%d" % min(level+1, 32))
                    self.doc.start_bold()
                    self.doc.write_text(_("Latitude, Longitude") + " : ")
                    self.doc.end_bold()
                    self.doc.write_text(", ".join((place.get_longitude(),
                                                   place.get_latitude())))
                    self.doc.end_paragraph()

                self.print_object(level+1, place)

        if issubclass(o.__class__, gramps.gen.lib.primaryobj.BasicPrimaryObject):
            # The Gramps ID is printed by the enclosing object
            pass


        if issubclass(o.__class__, gramps.gen.lib.privacybase.PrivacyBase):
            # The privacy is printed by the enclosing object
            pass

        if isinstance(o, gramps.gen.lib.RepoRef):
            # The media type is printed by source
            self.doc.start_paragraph("PE-Level%d" % min(level, 32))
            self.doc.start_bold()
            self.doc.write_text(_("Call number") + " : ")
            self.doc.end_bold()
            self.doc.write_text(o.get_call_number())
            self.doc.end_paragraph()

            repository_handle = o.get_reference_handle()
            repository = self.database.get_repository_from_handle(repository_handle)
            self.print_header(level, _("Repository"), repository.get_gramps_id(),
                              _("Repository type"), str(repository.get_type()),
                              privacy=repository.get_privacy())
            self.print_object(level+1, repository)

        if isinstance(o, gramps.gen.lib.Repository):
            # the repository type is printed by RepoRef
            pass

        if isinstance(o, gramps.gen.lib.Source):
            # The title, author, abbreviation and publication information are
            # printed by the bibliography code
#            data_map = o.get_data_map()
#            for key in data_map.keys():
#                self.doc.start_paragraph("PE-Level%d" % min(level, 32))
#                self.doc.start_bold()
#                self.doc.write_text(_("Data") + ". " + key + " : ")
#                self.doc.end_bold()
#                self.doc.write_text(data_map[key])
#                self.doc.end_paragraph()

            reporef_list = o.get_reporef_list()
            for reporef in reporef_list:
                self.print_header(level, _("Repository reference"),
                                  type_desc=_("Media type"),
                                  obj_type=str(reporef.get_media_type()),
                                  privacy=reporef.get_privacy())
                self.print_object(level+1, reporef)

        if isinstance(o, gramps.gen.lib.Surname):
            if o.get_origintype():
                self.print_header(level, _("Surname"),
                                  type_desc=_("Origin type"),
                                  obj_type=str(o.get_origintype()))
            else:
                self.print_header(level, _("Surname"),
                                  privacy=o.get_privacy())
            self.doc.start_paragraph("PE-Level%d" % min(level+1, 32))
            self.doc.start_bold()
            self.doc.write_text(_("Prefix, surname, connector") + " : ")
            self.doc.end_bold()
            self.doc.write_text(", ".join((o.get_prefix(), o.get_surname(),
                                           o.get_connector())))
            if o.get_primary():
                self.doc.write_text(" " + _("{This is the primary surname}"))
            self.doc.end_paragraph()

        if isinstance(o, gramps.gen.lib.surnamebase.SurnameBase):
            surname_list = o.get_surname_list()
            for surname in surname_list:
                self.print_object(level, surname)

        if issubclass(o.__class__, gramps.gen.lib.tagbase.TagBase):
            for tag_handle in o.get_tag_list():
                tag = self.database.get_tag_from_handle(tag_handle)
                self.doc.start_paragraph("PE-Level%d" % min(level, 32))
                self.doc.start_bold()
                self.doc.write_text(_("Tag name") + " : ")
                self.doc.end_bold()
                self.doc.write_text(tag.get_name())
                self.doc.end_paragraph()
                self.print_object(level+1, tag)

        if issubclass(o.__class__, gramps.gen.lib.Tag):
            # The tag name is printed by TagBase
            if o.get_color() != "#000000000000" or o.get_priority() != 0:
                self.doc.start_paragraph("PE-Level%d" % min(level, 32))
                self.doc.start_bold()
                self.doc.write_text(_("Tag colour and priority") + " : ")
                self.doc.end_bold()
                self.doc.write_text(o.get_color() + ", " +
                                    "%d" % o.get_priority())
                self.doc.end_paragraph()

        if issubclass(o.__class__, gramps.gen.lib.urlbase.UrlBase):
            for url in o.get_url_list():
                self.print_header(level, _("URL"),
                                  type_desc=_("Type"),
                                  obj_type=str(url.get_type()),
                                  privacy=url.get_privacy())
                self.print_object(level+1, url)

        if isinstance(o, gramps.gen.lib.Url):
            self.doc.start_paragraph("PE-Level%d" % min(level, 32))
            self.doc.start_bold()
            self.doc.write_text(_("Description and Path") + " : ")
            self.doc.end_bold()
            self.doc.write_text(o.get_description() + ", ")
            path = o.get_path()
            if path:
                mark = IndexMark(path, LOCAL_HYPERLINK)
                self.doc.write_text(path, mark=mark)
            self.doc.end_paragraph()

        return o
Пример #37
0
 def bubble_message(self, event, lat, lon, marks):
     self.menu = Gtk.Menu()
     menu = self.menu
     message = ""
     oldplace = ""
     prevmark = None
     for mark in marks:
         if message != "":
             add_item = Gtk.MenuItem(label=message)
             add_item.show()
             menu.append(add_item)
             self.itemoption = Gtk.Menu()
             itemoption = self.itemoption
             itemoption.show()
             add_item.set_submenu(itemoption)
             modify = Gtk.MenuItem(label=_("Edit Event"))
             modify.show()
             modify.connect("activate", self.edit_event,
                            event, lat, lon, prevmark)
             itemoption.append(modify)
             center = Gtk.MenuItem(label=_("Center on this place"))
             center.show()
             center.connect("activate", self.center_here,
                            event, lat, lon, prevmark)
             itemoption.append(center)
             evt = self.dbstate.db.get_event_from_gramps_id(mark[10])
             hdle = evt.get_handle()
             bookm = Gtk.MenuItem(label=_("Bookmark this event"))
             bookm.show()
             bookm.connect("activate", self.add_bookmark_from_popup, hdle)
             itemoption.append(bookm)
         if mark[0] != oldplace:
             message = "%s :" % mark[0]
             self.add_place_bubble_message(event, lat, lon,
                                           marks, menu, message, mark)
             oldplace = mark[0]
         evt = self.dbstate.db.get_event_from_gramps_id(mark[10])
         # format the date as described in preferences.
         date = displayer.display(evt.get_date_object())
         message = "(%s) %s : %s" % (date, EventType(mark[7]), mark[5])
         prevmark = mark
     add_item = Gtk.MenuItem(label=message)
     add_item.show()
     menu.append(add_item)
     self.itemoption = Gtk.Menu()
     itemoption = self.itemoption
     itemoption.show()
     add_item.set_submenu(itemoption)
     modify = Gtk.MenuItem(label=_("Edit Event"))
     modify.show()
     modify.connect("activate", self.edit_event, event, lat, lon, prevmark)
     itemoption.append(modify)
     center = Gtk.MenuItem(label=_("Center on this place"))
     center.show()
     center.connect("activate", self.center_here, event, lat, lon, prevmark)
     itemoption.append(center)
     evt = self.dbstate.db.get_event_from_gramps_id(mark[10])
     hdle = evt.get_handle()
     bookm = Gtk.MenuItem(label=_("Bookmark this event"))
     bookm.show()
     bookm.connect("activate", self.add_bookmark_from_popup, hdle)
     itemoption.append(bookm)
     menu.popup(None, None, None,
                None, event.button, event.time)
     return 1
Пример #38
0
    def print_object(self, level, o):

        if issubclass(o.__class__, gramps.gen.lib.address.Address):
            # Details of address are printed by the subclass conditions,
            # primarily by LocationBase, because address is a subclass of
            # LocationBase
            pass

        if issubclass(o.__class__, gramps.gen.lib.addressbase.AddressBase):
            for address in o.get_address_list():
                self.print_header(level, _("Address"), ref=address)
                self.print_object(level + 1, address)

        if isinstance(o, gramps.gen.lib.Attribute):
            # The unique information about attributes (the type) is printed by
            # AttributeBase
            pass

        if issubclass(o.__class__, gramps.gen.lib.attrbase.AttributeBase):
            for attribute in o.get_attribute_list():
                self.print_header(level,
                                  _("Attribute") + ". ",
                                  type_desc=str(attribute.get_type()),
                                  obj_type=attribute.get_value(),
                                  privacy=attribute.get_privacy(),
                                  ref=attribute)
                self.print_object(level + 1, attribute)

        if isinstance(o, gramps.gen.lib.ChildRef):
            # The unique information about ChildRef (the father relation and
            # mother relation) is printed by the main write_report function
            pass

        if issubclass(o.__class__, gramps.gen.lib.citationbase.CitationBase):
            if self.print_citations:
                self.print_header(level, "CitationBase tbd")

                for citation_handle in o.get_citation_list():
                    citation = self.database.get_citation_from_handle(
                        citation_handle)
                    self.print_object(level + 1, citation)

        if isinstance(o, gramps.gen.lib.Citation):
            # the unique information about Citation (the page) is printed by the
            # bibliography code. The other unique information, the confidence is
            # printed here
            if o.get_confidence_level() != gramps.gen.lib.Citation.CONF_NORMAL:
                self.doc.start_paragraph("PE-Level%d" % min(level, 32))
                self.doc.start_bold()
                self.doc.write_text(_("Confidence") + " : ")
                self.doc.end_bold()
                self.doc.write_text(
                    conf_strings.get(o.get_confidence_level(), _('Unknown')))
                self.doc.end_paragraph()

            if self.print_citations:
                source_handle = o.get_reference_handle()
                source = self.database.get_source_from_handle(source_handle)
                self.print_object(level + 1, source)

        if issubclass(o.__class__, gramps.gen.lib.datebase.DateBase):
            if o.get_date_object() and not o.get_date_object().is_empty():
                self.doc.start_paragraph("PE-Level%d" % min(level, 32))
                self.doc.start_bold()
                self.doc.write_text(_("Date") + " : ")
                self.doc.end_bold()
                self.doc.write_text(displayer.display(o.get_date_object()))
                self.doc.end_paragraph()

        if isinstance(o, gramps.gen.lib.Event):
            # The event type is printed by the main write_report function
            self.doc.start_paragraph("PE-Level%d" % min(level, 32))
            self.doc.start_bold()
            self.doc.write_text(_("Description") + " : ")
            self.doc.end_bold()
            self.doc.write_text(str(o.get_description()))
            self.doc.end_paragraph()

        if issubclass(o.__class__, gramps.gen.lib.eventref.EventRef):
            # The unique information about EventRef (the EventRoleType) is
            # printed by the main write_report function
            event = self.database.get_event_from_handle(
                o.get_reference_handle())
            self.print_header(level,
                              _("Event"),
                              event.get_gramps_id(),
                              _("Event type"),
                              str(event.get_type()),
                              event.get_privacy(),
                              ref=event)
            self.print_object(level + 1, event)

        if isinstance(o, gramps.gen.lib.Family):
            # The unique information about Family (father, mother and children,
            # FamilyRelType and event references) are printed by the main
            # write_report function
            pass

        if isinstance(o, gramps.gen.lib.LdsOrd):
            # The Ordinance type is printed by LdsOrdBase
            self.doc.start_paragraph("PE-Level%d" % min(level, 32))
            self.doc.start_bold()
            self.doc.write_text(_("Temple and status") + " : ")
            self.doc.end_bold()
            self.doc.write_text(", ".join(
                (TEMPLES.name(o.get_temple()), o.status2str())))
            self.doc.end_paragraph()

            f_h = o.get_family_handle()
            if f_h:
                family = self.database.get_family_from_handle(f_h)
                self.print_family_summary(level + 1, family,
                                          _("LDS Ordinance family"))

        if issubclass(o.__class__, gramps.gen.lib.ldsordbase.LdsOrdBase):
            for ldsord in o.get_lds_ord_list():
                self.print_header(level,
                                  _("LDS "),
                                  type_desc=_("Ordinance"),
                                  obj_type=ldsord.type2str(),
                                  privacy=ldsord.get_privacy(),
                                  ref=ldsord)
                self.print_object(level + 1, ldsord)

        if isinstance(o, gramps.gen.lib.Location):
            # The unique information about location (Parish) is printed by
            # Place. Location otherwise serves as a pointer to a LocationBase
            # object
            pass

        if issubclass(o.__class__, gramps.gen.lib.locationbase.LocationBase):
            self.doc.start_paragraph("PE-Level%d" % min(level, 32))
            self.doc.start_bold()
            self.doc.write_text(
                _("Street, City, County, State, Postal Code, "
                  "Country, Phone number") + " : ")
            self.doc.end_bold()
            self.doc.write_text(", ".join(
                (o.get_street(), o.get_city(), o.get_county(), o.get_state(),
                 o.get_postal_code(), o.get_country(), o.get_phone())))
            self.doc.end_paragraph()

        if issubclass(o.__class__, gramps.gen.lib.mediabase.MediaBase):
            for mediaref in o.get_media_list():
                self.print_header(level, _("Media Reference"), ref=mediaref)
                self.print_object(level + 1, mediaref)

        if isinstance(o, gramps.gen.lib.Media):
            # thumb is not printed. The mime type is printed by MediaRef
            self.doc.start_paragraph("PE-Level%d" % min(level, 32))
            self.doc.start_bold()
            self.doc.write_text(_("Description and Path") + " : ")
            self.doc.end_bold()
            self.doc.write_text(o.get_description() + ", ")
            path = o.get_path()
            if path:
                mark = IndexMark(
                    "file://:" + media_path_full(self.database, path),
                    LOCAL_HYPERLINK)
                self.doc.write_text(path, mark=mark)
            self.doc.end_paragraph()

            mime_type = o.get_mime_type()
            if mime_type and mime_type.startswith("image"):
                filename = media_path_full(self.database, o.get_path())
                if os.path.exists(filename):
                    self.doc.start_paragraph("PE-Level%d" % min(level, 32))
                    self.doc.add_media(filename, "single", 4.0, 4.0)
                    self.doc.end_paragraph()
                else:
                    self._user.warn(
                        _("Could not add photo to page"),
                        "%s: %s" % (filename, _('File does not exist')))

        if isinstance(o, gramps.gen.lib.MediaRef):
            media_handle = o.get_reference_handle()
            media = self.database.get_media_from_handle(media_handle)

            if o.get_rectangle():
                self.doc.start_paragraph("PE-Level%d" % min(level, 32))
                self.doc.start_bold()
                self.doc.write_text(_("Referenced Region") + " : ")
                self.doc.end_bold()
                self.doc.write_text(", ".join(
                    (("%d" % i) for i in o.get_rectangle())))
                self.doc.end_paragraph()

                mime_type = media.get_mime_type()
                if mime_type and mime_type.startswith("image"):
                    filename = media_path_full(self.database, media.get_path())
                    if os.path.exists(filename):
                        self.doc.start_paragraph("PE-Level%d" % min(level, 32))
                        self.doc.add_media(filename,
                                           "single",
                                           4.0,
                                           4.0,
                                           crop=o.get_rectangle())
                        self.doc.end_paragraph()

            desc = get_description(media.get_mime_type())
            if not desc:
                desc = _("unknown")
            self.print_header(level,
                              _("Media Object"),
                              media.get_gramps_id(),
                              _("Mime type"),
                              desc,
                              media.get_privacy(),
                              ref=media)
            self.print_object(level + 1, media)

        if isinstance(o, gramps.gen.lib.Name):
            # group_as, sort_as and display_as are not printed. NameType is
            # printed by the main write_report function
            self.doc.start_paragraph("PE-Level%d" % min(level, 32))
            self.doc.start_bold()
            self.doc.write_text(
                _("Given name(s): Title, Given, Suffix, "
                  "Call Name, Nick Name, Family Nick Name") + " : ")
            self.doc.end_bold()
            self.doc.write_text(", ".join(
                (o.get_title(), o.get_first_name(), o.get_suffix(),
                 o.get_call_name(), o.get_nick_name(),
                 o.get_family_nick_name())))
            self.doc.end_paragraph()

        if isinstance(o, gramps.gen.lib.Note):
            # The NoteType is printed by NoteBase. Whether the note is flowed or
            # not is not printed, but affects the way the note appears
            self.doc.write_styled_note(
                o.get_styledtext(),
                o.get_format(),
                "PE-Level%d" % min(level, 32),
                contains_html=o.get_type() ==
                gramps.gen.lib.notetype.NoteType.HTML_CODE)

        if issubclass(o.__class__, gramps.gen.lib.notebase.NoteBase):
            for n_h in o.get_note_list():
                note = self.database.get_note_from_handle(n_h)
                self.print_header(level, _("Note"), note.get_gramps_id(),
                                  _("Note type"), str(note.get_type()),
                                  note.get_privacy())
                self.print_object(level + 1, note)

        if issubclass(o.__class__, gramps.gen.lib.Person):
            # This is printed by the main write-report function
            pass

        if isinstance(o, gramps.gen.lib.Place):
            # The title, name, type, code and lat/long are printed by PlaceBase
            for placeref in o.get_placeref_list():
                self.print_header(level, _("Parent Place"))
                self.print_object(level + 1, placeref)


#            location = o.get_main_location()
#            if location.get_parish():
#                self.print_header(level, _("Main Location"),
#                                  type_desc=_("Parish"),
#                                  obj_type=location.get_parish())
#            else:
#                self.print_header(level, _("Main Location"))
#
#            self.print_object(level+1, location)
#
            for location in o.get_alternate_locations():
                if location.get_parish():
                    self.print_header(level,
                                      _("Alternate Location"),
                                      type_desc=_("Parish"),
                                      obj_type=location.get_parish())
                else:
                    self.print_header(level, _("Alternate Location"))
                self.print_object(level + 1, location)

        if issubclass(o.__class__, gramps.gen.lib.placebase.PlaceBase) or \
            issubclass(o.__class__, gramps.gen.lib.placeref.PlaceRef):
            if issubclass(o.__class__, gramps.gen.lib.placebase.PlaceBase):
                place_handle = o.get_place_handle()
            else:
                place_handle = o.get_reference_handle()
            if place_handle:
                place = self.database.get_place_from_handle(place_handle)
                if place:
                    place_title = place_displayer.display(self.database, place)
                    self.print_header(level,
                                      _("Place"),
                                      place.get_gramps_id(),
                                      _("Place Title"),
                                      place_title,
                                      privacy=place.get_privacy(),
                                      ref=place)
                    self.doc.start_paragraph("PE-Level%d" % min(level + 1, 32))
                    self.doc.start_bold()
                    self.doc.write_text(_("Name") + " : ")
                    self.doc.end_bold()
                    self.doc.write_text(place.get_name().value)
                    self.doc.start_bold()
                    self.doc.write_text(" " + _("Type") + " : ")
                    self.doc.end_bold()
                    self.doc.write_text(str(place.get_type()))
                    self.doc.start_bold()
                    self.doc.write_text(" " + _("Code") + " : ")
                    self.doc.end_bold()
                    self.doc.write_text(place.get_code())
                    self.doc.end_paragraph()

                    for name in place.get_alternative_names():
                        self.doc.start_paragraph("PE-Level%d" %
                                                 min(level + 1, 32))
                        self.doc.start_bold()
                        self.doc.write_text(_("Alternative Name") + " : ")
                        self.doc.end_bold()
                        self.doc.write_text(name.value)
                        self.doc.end_paragraph()

                    if place.get_longitude() or place.get_latitude():
                        self.doc.start_paragraph("PE-Level%d" %
                                                 min(level + 1, 32))
                        self.doc.start_bold()
                        self.doc.write_text(_("Latitude, Longitude") + " : ")
                        self.doc.end_bold()
                        self.doc.write_text(", ".join(
                            (place.get_longitude(), place.get_latitude())))
                        self.doc.end_paragraph()

                    self.print_object(level + 1, place)

        if issubclass(o.__class__,
                      gramps.gen.lib.primaryobj.BasicPrimaryObject):
            # The Gramps ID is printed by the enclosing object
            pass

        if issubclass(o.__class__, gramps.gen.lib.privacybase.PrivacyBase):
            # The privacy is printed by the enclosing object
            pass

        if isinstance(o, gramps.gen.lib.RepoRef):
            # The media type is printed by source
            self.doc.start_paragraph("PE-Level%d" % min(level, 32))
            self.doc.start_bold()
            self.doc.write_text(_("Call number") + " : ")
            self.doc.end_bold()
            self.doc.write_text(o.get_call_number())
            self.doc.end_paragraph()

            repository_handle = o.get_reference_handle()
            repository = self.database.get_repository_from_handle(
                repository_handle)
            self.print_header(level,
                              _("Repository"),
                              repository.get_gramps_id(),
                              _("Repository type"),
                              str(repository.get_type()),
                              privacy=repository.get_privacy())
            self.print_object(level + 1, repository)

        if isinstance(o, gramps.gen.lib.Repository):
            # the repository type is printed by RepoRef
            pass

        if isinstance(o, gramps.gen.lib.Source):
            # The title, author, abbreviation and publication information are
            # printed by the bibliography code
            #            data_map = o.get_data_map()
            #            for key in data_map.keys():
            #                self.doc.start_paragraph("PE-Level%d" % min(level, 32))
            #                self.doc.start_bold()
            #                self.doc.write_text(_("Data") + ". " + key + " : ")
            #                self.doc.end_bold()
            #                self.doc.write_text(data_map[key])
            #                self.doc.end_paragraph()

            reporef_list = o.get_reporef_list()
            for reporef in reporef_list:
                self.print_header(level,
                                  _("Repository reference"),
                                  type_desc=_("Media type"),
                                  obj_type=str(reporef.get_media_type()),
                                  privacy=reporef.get_privacy())
                self.print_object(level + 1, reporef)

        if isinstance(o, gramps.gen.lib.Surname):
            if o.get_origintype():
                self.print_header(level,
                                  _("Surname"),
                                  type_desc=_("Origin type"),
                                  obj_type=str(o.get_origintype()))
            else:
                self.print_header(level, _("Surname"), privacy=o.get_privacy())
            self.doc.start_paragraph("PE-Level%d" % min(level + 1, 32))
            self.doc.start_bold()
            self.doc.write_text(_("Prefix, surname, connector") + " : ")
            self.doc.end_bold()
            self.doc.write_text(", ".join(
                (o.get_prefix(), o.get_surname(), o.get_connector())))
            if o.get_primary():
                self.doc.write_text(" " + _("{This is the primary surname}"))
            self.doc.end_paragraph()

        if isinstance(o, gramps.gen.lib.surnamebase.SurnameBase):
            surname_list = o.get_surname_list()
            for surname in surname_list:
                self.print_object(level, surname)

        if issubclass(o.__class__, gramps.gen.lib.tagbase.TagBase):
            for tag_handle in o.get_tag_list():
                tag = self.database.get_tag_from_handle(tag_handle)
                self.doc.start_paragraph("PE-Level%d" % min(level, 32))
                self.doc.start_bold()
                self.doc.write_text(_("Tag name") + " : ")
                self.doc.end_bold()
                self.doc.write_text(tag.get_name())
                self.doc.end_paragraph()
                self.print_object(level + 1, tag)

        if issubclass(o.__class__, gramps.gen.lib.Tag):
            # The tag name is printed by TagBase
            if o.get_color() != "#000000000000" or o.get_priority() != 0:
                self.doc.start_paragraph("PE-Level%d" % min(level, 32))
                self.doc.start_bold()
                self.doc.write_text(_("Tag colour and priority") + " : ")
                self.doc.end_bold()
                self.doc.write_text(o.get_color() + ", " +
                                    "%d" % o.get_priority())
                self.doc.end_paragraph()

        if issubclass(o.__class__, gramps.gen.lib.urlbase.UrlBase):
            for url in o.get_url_list():
                self.print_header(level,
                                  _("URL"),
                                  type_desc=_("Type"),
                                  obj_type=str(url.get_type()),
                                  privacy=url.get_privacy())
                self.print_object(level + 1, url)

        if isinstance(o, gramps.gen.lib.Url):
            self.doc.start_paragraph("PE-Level%d" % min(level, 32))
            self.doc.start_bold()
            self.doc.write_text(_("Description and Path") + " : ")
            self.doc.end_bold()
            self.doc.write_text(o.get_description() + ", ")
            path = o.get_path()
            if path:
                mark = IndexMark(path, LOCAL_HYPERLINK)
                self.doc.write_text(path, mark=mark)
            self.doc.end_paragraph()

        return o
Пример #39
0
 def bubble_message(self, event, lat, lon, marks):
     """
     Create the menu for the selected marker
     """
     self.menu = Gtk.Menu()
     menu = self.menu
     menu.set_title("descendance")
     events = []
     message = ""
     oldplace = ""
     prevmark = None
     # Be sure all markers are sorted by place then dates.
     for mark in sorted(marks, key=operator.itemgetter(0,6)):
         if mark[10] in events:
             continue # avoid duplicate events
         else:
             events.append(mark[10])
         if mark[0] != oldplace:
             message = "%s :" % mark[0]
             self.add_place_bubble_message(event, lat, lon,
                                           marks, menu,
                                           message, mark)
             oldplace = mark[0]
             message = ""
         evt = self.dbstate.db.get_event_from_gramps_id(mark[10])
         # format the date as described in preferences.
         date = displayer.display(evt.get_date_object())
         if date == "":
             date = _("Unknown")
         if ( mark[11] == EventRoleType.PRIMARY ):
             person = self.dbstate.db.get_person_from_gramps_id(mark[1])
             message = "(%s) %s : %s" % ( date, mark[2], _nd.display(person) )
         elif ( mark[11] == EventRoleType.FAMILY ):
             (father_name, mother_name) = self._get_father_and_mother_name(evt)
             message = "(%s) %s : %s - %s" % (date, mark[2],
                                              father_name,
                                              mother_name )
         else:
             descr = evt.get_description()
             if descr == "":
                 descr = _('No description')
             message = "(%s) %s => %s" % ( date, mark[11], descr)
         prevmark = mark
         add_item = Gtk.MenuItem(label=message)
         add_item.show()
         menu.append(add_item)
         self.itemoption = Gtk.Menu()
         itemoption = self.itemoption
         itemoption.set_title(message)
         itemoption.show()
         add_item.set_submenu(itemoption)
         modify = Gtk.MenuItem(label=_("Edit Event"))
         modify.show()
         modify.connect("activate", self.edit_event,
                        event, lat, lon, prevmark)
         itemoption.append(modify)
         center = Gtk.MenuItem(label=_("Center on this place"))
         center.show()
         center.connect("activate", self.center_here,
                        event, lat, lon, prevmark)
         itemoption.append(center)
         person = self.dbstate.db.get_person_from_gramps_id(mark[8])
         hdle = person.get_handle()
         bookm = Gtk.MenuItem(label=_("Bookmark this person"))
         bookm.show()
         bookm.connect("activate", self.add_bookmark_from_popup, hdle)
         itemoption.append(bookm)
         menu.show()
         menu.popup(None, None, None,
                    None, event.button, event.time)
     return 1
    def run(self):
        BUTTONS = ((_("Select All"), self.select_all),
                   (_("Select None"), self.select_none),
                   (_("Toggle Selection"), self.toggle_select),
                   (_("Add Selected Events"), self.apply_selection),
                   )

        if hasattr(self, "table") and self.table:
            self.reselect = False
            if self.options.handler.options_dict['remove']:
                QuestionDialog(_("Remove Events, Notes, and Source and Reselect Data"),
                               _("Are you sure you want to remove previous events, notes, and source and reselect data?"),
                               _("Remove and Run Select Again"),
                               self.set_reselect,
                               self.window)
            else:
                QuestionDialog(_("Reselect Data"),
                               _("Are you sure you want to reselect data?"),
                               _("Run Select Again"),
                               self.set_reselect,
                               self.window)
            if not self.reselect:
                return

        current_date = Date()
        current_date.set_yr_mon_day(*time.localtime(time.time())[0:3])
        self.action = {}
        widget = self.add_results_frame(_("Select"))
        document = TextBufDoc(make_basic_stylesheet(), None)
        document.dbstate = self.dbstate
        document.uistate = self.uistate
        document.open("", container=widget)
        self.sdb = SimpleAccess(self.db)
        sdoc = SimpleDoc(document)
        stab = QuickTable(self.sdb)
        self.table = stab
        stab.columns(_("Select"), _("Person"), _("Action"),
                     _("Birth Date"), _("Death Date"),
                     _("Evidence"), _("Relative"))
        self.results_write(_("Processing...\n"))
        self.filter_option =  self.options.menu.get_option_by_name('filter')
        self.filter = self.filter_option.get_filter() # the actual filter
        people = self.filter.apply(self.db,
                                   self.db.iter_person_handles())
        num_people = self.db.get_number_of_people()
        source_text = self.options.handler.options_dict['source_text']
        source = None
        add_birth = self.options.handler.options_dict['add_birth']
        add_death = self.options.handler.options_dict['add_death']
        remove_old = self.options.handler.options_dict['remove']

        self.MAX_SIB_AGE_DIFF = self.options.handler.options_dict['MAX_SIB_AGE_DIFF']
        self.MAX_AGE_PROB_ALIVE = self.options.handler.options_dict['MAX_AGE_PROB_ALIVE']
        self.AVG_GENERATION_GAP = self.options.handler.options_dict['AVG_GENERATION_GAP']
        if remove_old:
            with DbTxn("", self.db, batch=True) as self.trans:
                self.db.disable_signals()
                self.results_write(_("Removing old estimations... "))
                self.progress.set_pass((_("Removing '%s'...") % source_text),
                                       num_people)
                supdate = None
                for person_handle in people:
                    self.progress.step()
                    pupdate = 0
                    person = self.db.get_person_from_handle(person_handle)
                    birth_ref = person.get_birth_ref()
                    if birth_ref:
                        birth = self.db.get_event_from_handle(birth_ref.ref)
                        for citation_handle in birth.get_citation_list():
                            citation = self.db.get_citation_from_handle(citation_handle)
                            source_handle = citation.get_reference_handle()
                            #print "birth handle:", source_handle
                            source = self.db.get_source_from_handle(source_handle)
                            if source:
                                if source.get_title() == source_text:
                                    #print("birth event removed from:",
                                    #      person.gramps_id)
                                    person.set_birth_ref(None)
                                    person.remove_handle_references('Event',[birth_ref.ref])
                                    # remove note
                                    note_list = birth.get_referenced_note_handles()
                                    birth.remove_handle_references('Note',
                                      [note_handle for (obj_type, note_handle) in note_list])
                                    for (obj_type, note_handle) in note_list:
                                        self.db.remove_note(note_handle, self.trans)
                                    self.db.remove_event(birth_ref.ref, self.trans)
                                    self.db.remove_citation(citation_handle,
                                                            self.trans)
                                    pupdate = 1
                                    supdate = source  # found the source.
                                    break
                    death_ref = person.get_death_ref()
                    if death_ref:
                        death = self.db.get_event_from_handle(death_ref.ref)
                        for citation_handle in death.get_citation_list():
                            citation = self.db.get_citation_from_handle(citation_handle)
                            source_handle = citation.get_reference_handle()
                            #print "death handle:", source_handle
                            source = self.db.get_source_from_handle(source_handle)
                            if source:
                                if source.get_title() == source_text:
                                    #print("death event removed from:",
                                    #      person.gramps_id)
                                    person.set_death_ref(None)
                                    person.remove_handle_references('Event',[death_ref.ref])
                                    # remove note
                                    note_list = death.get_referenced_note_handles()
                                    death.remove_handle_references('Note',
                                      [note_handle for (obj_type, note_handle) in note_list])
                                    for (obj_type, note_handle) in note_list:
                                        self.db.remove_note(note_handle, self.trans)
                                    self.db.remove_event(death_ref.ref, self.trans)
                                    self.db.remove_citation(citation_handle,
                                                            self.trans)
                                    pupdate = 1
                                    supdate = source  # found the source.
                                    break
                    if pupdate == 1:
                        self.db.commit_person(person, self.trans)
                if supdate:
                    self.db.remove_source(supdate.handle, self.trans)
            self.results_write(_("done!\n"))
            self.db.enable_signals()
            self.db.request_rebuild()
        if add_birth or add_death:
            self.results_write(_("Selecting... \n\n"))
            self.progress.set_pass(_('Selecting...'),
                                   num_people)
            row = 0
            for person_handle in people:
                self.progress.step()
                person = self.db.get_person_from_handle(person_handle)
                birth_ref = person.get_birth_ref()
                death_ref = person.get_death_ref()
                add_birth_event, add_death_event = False, False
                if not birth_ref or not death_ref:
                    date1, date2, explain, other = self.calc_estimates(person)
                    if birth_ref:
                        ev = self.db.get_event_from_handle(birth_ref.ref)
                        date1 = ev.get_date_object()
                    elif not birth_ref and add_birth and date1:
                        if date1.match( current_date, "<"):
                            add_birth_event = True
                            date1.make_vague()
                        else:
                            date1 = Date()
                    else:
                        date1 = Date()
                    if death_ref:
                        ev = self.db.get_event_from_handle(death_ref.ref)
                        date2 = ev.get_date_object()
                    elif not death_ref and add_death and date2:
                        if date2.match( current_date, "<"):
                            add_death_event = True
                            date2.make_vague()
                        else:
                            date2 = Date()
                    else:
                        date2 = Date()
                    # Describe
                    if add_birth_event and add_death_event:
                        action = _("Add birth and death events")
                    elif add_birth_event:
                        action = _("Add birth event")
                    elif add_death_event:
                        action = _("Add death event")
                    else:
                        continue
                    #stab.columns(_("Select"), _("Person"), _("Action"),
                    # _("Birth Date"), _("Death Date"), _("Evidence"), _("Relative"))
                    if add_birth == 1 and not birth_ref: # no date
                        date1 = Date()
                    if add_death == 1 and not death_ref: # no date
                        date2 = Date()
                    if person == other:
                        other = None
                    stab.row("checkbox",
                             person,
                             action,
                             date1,
                             date2,
                             explain or "",
                             other or "")
                    if add_birth_event:
                        stab.set_cell_markup(3, row, "<b>%s</b>" % date_displayer.display(date1))
                    if add_death_event:
                        stab.set_cell_markup(4, row, "<b>%s</b>" % date_displayer.display(date2))
                    self.action[person.handle] = (add_birth_event, add_death_event)
                    row += 1
            if row > 0:
                self.results_write("  ")
                for text, function in BUTTONS:
                    self.make_button(text, function, widget)
                self.results_write("\n")
                stab.write(sdoc)
                self.results_write("  ")
                for text, function in BUTTONS:
                    self.make_button(text, function, widget)
                self.results_write("\n")
            else:
                self.results_write(_("No events to be added."))
                self.results_write("\n")
        self.results_write("\n")
        self.set_current_frame(_("Select"))
Пример #41
0
 def column_date(self,data):
     if data[10]:
         date = Date()
         date.unserialize(data[10])
         return displayer.display(date)
     return ''
Пример #42
0
 def bubble_message(self, event, lat, lon, marks):
     """
     Create the menu for the selected marker
     """
     self.menu = Gtk.Menu()
     menu = self.menu
     menu.set_title("descendance")
     events = []
     message = ""
     oldplace = ""
     prevmark = None
     # Be sure all markers are sorted by place then dates.
     for mark in sorted(marks, key=operator.itemgetter(0,6)):
         if mark[10] in events:
             continue # avoid duplicate events
         else:
             events.append(mark[10])
         if mark[0] != oldplace:
             message = "%s :" % mark[0]
             self.add_place_bubble_message(event, lat, lon,
                                           marks, menu,
                                           message, mark)
             oldplace = mark[0]
             message = ""
         evt = self.dbstate.db.get_event_from_gramps_id(mark[10])
         # format the date as described in preferences.
         date = displayer.display(evt.get_date_object())
         if date == "":
             date = _("Unknown")
         if ( mark[11] == EventRoleType.PRIMARY ):
             person = self.dbstate.db.get_person_from_gramps_id(mark[1])
             message = "(%s) %s : %s" % ( date, mark[2], _nd.display(person) )
         elif ( mark[11] == EventRoleType.FAMILY ):
             (father_name, mother_name) = self._get_father_and_mother_name(evt)
             message = "(%s) %s : %s - %s" % (date, mark[2],
                                              father_name,
                                              mother_name )
         else:
             descr = evt.get_description()
             if descr == "":
                 descr = _('No description')
             message = "(%s) %s => %s" % ( date, mark[11], descr)
         prevmark = mark
         add_item = Gtk.MenuItem(label=message)
         add_item.show()
         menu.append(add_item)
         self.itemoption = Gtk.Menu()
         itemoption = self.itemoption
         itemoption.set_title(message)
         itemoption.show()
         add_item.set_submenu(itemoption)
         modify = Gtk.MenuItem(label=_("Edit Event"))
         modify.show()
         modify.connect("activate", self.edit_event,
                        event, lat, lon, prevmark)
         itemoption.append(modify)
         center = Gtk.MenuItem(label=_("Center on this place"))
         center.show()
         center.connect("activate", self.center_here,
                        event, lat, lon, prevmark)
         itemoption.append(center)
         person = self.dbstate.db.get_person_from_gramps_id(mark[8])
         hdle = person.get_handle()
         bookm = Gtk.MenuItem(label=_("Bookmark this person"))
         bookm.show()
         bookm.connect("activate", self.add_bookmark_from_popup, hdle)
         itemoption.append(bookm)
         menu.show()
         menu.popup(None, None,
                    lambda menu, data: (event.get_root_coords()[0],
                                        event.get_root_coords()[1], True),
                    None, event.button, event.time)
     return 1
Пример #43
0
 def bubble_message(self, event, lat, lon, marks):
     """
     Create the menu for the selected marker
     """
     self.newmenu = Gtk.Menu()
     menu = self.newmenu
     menu.set_title("person")
     events = []
     message = ""
     oldplace = ""
     prevmark = None
     for mark in marks:
         for plce in self.all_place_list:
             if (plce[3] == mark[3] and plce[4] == mark[4]):
                 if plce[10] in events:
                     continue
                 else:
                     events.append(plce[10])
                   
                 if plce[0] != oldplace:
                     message = "%s :" % plce[0]
                     self.add_place_bubble_message(event, lat, lon,
                                                   marks, menu,
                                                   message, plce)
                     oldplace = plce[0]
                     message = ""
                 evt = self.dbstate.db.get_event_from_gramps_id(plce[10])
                 # format the date as described in preferences.
                 date = displayer.display(evt.get_date_object())
                 if date == "":
                     date = _("Unknown")
                 if ( plce[11] == EventRoleType.PRIMARY ):
                     message = "(%s) %s : %s" % ( date, plce[2], plce[1] )
                 elif ( plce[11] == EventRoleType.FAMILY ):
                     (father_name, mother_name) = self._get_father_and_mother_name(evt)
                     message = "(%s) %s : %s - %s" % (date, plce[7],
                                                      father_name,
                                                      mother_name )
                 else:
                     descr = evt.get_description()
                     if descr == "":
                         descr = _('No description')
                     message = "(%s) %s => %s" % ( date, plce[11], descr)
                 prevmark = plce
                 self.add_item = Gtk.MenuItem(label=message)
                 add_item = self.add_item
                 add_item.show()
                 menu.append(add_item)
                 self.itemoption = Gtk.Menu()
                 itemoption = self.itemoption
                 itemoption.set_title(message)
                 itemoption.show()
                 add_item.set_submenu(itemoption)
                 modify = Gtk.MenuItem(label=_("Edit Event"))
                 modify.show()
                 modify.connect("activate", self.edit_event,
                                event, lat, lon, prevmark)
                 itemoption.append(modify)
                 center = Gtk.MenuItem(label=_("Center on this place"))
                 center.show()
                 center.connect("activate", self.center_here,
                                event, lat, lon, prevmark)
                 itemoption.append(center)
                 menu.show()
                 menu.popup(None, None,
                            lambda menu, data: (event.get_root_coords()[0],
                                                event.get_root_coords()[1], True),
                            None, event.button, event.time)
     return 0
Пример #44
0
 def bubble_message(self, event, lat, lon, marks):
     self.menu = Gtk.Menu()
     menu = self.menu
     menu.set_title("events")
     message = ""
     oldplace = ""
     prevmark = None
     for mark in marks:
         if message != "":
             add_item = Gtk.MenuItem(label=message)
             add_item.show()
             menu.append(add_item)
             self.itemoption = Gtk.Menu()
             itemoption = self.itemoption
             itemoption.set_title(message)
             itemoption.show()
             add_item.set_submenu(itemoption)
             modify = Gtk.MenuItem(label=_("Edit Event"))
             modify.show()
             modify.connect("activate", self.edit_event,
                            event, lat, lon, prevmark)
             itemoption.append(modify)
             center = Gtk.MenuItem(label=_("Center on this place"))
             center.show()
             center.connect("activate", self.center_here,
                            event, lat, lon, prevmark)
             itemoption.append(center)
             evt = self.dbstate.db.get_event_from_gramps_id(mark[10])
             hdle = evt.get_handle()
             bookm = Gtk.MenuItem(label=_("Bookmark this event"))
             bookm.show()
             bookm.connect("activate", self.add_bookmark_from_popup, hdle)
             itemoption.append(bookm)
         if mark[0] != oldplace:
             message = "%s :" % mark[0]
             self.add_place_bubble_message(event, lat, lon,
                                           marks, menu, message, mark)
             oldplace = mark[0]
         evt = self.dbstate.db.get_event_from_gramps_id(mark[10])
         # format the date as described in preferences.
         date = displayer.display(evt.get_date_object())
         message = "(%s) %s : %s" % (date, EventType(mark[7]), mark[5])
         prevmark = mark
     add_item = Gtk.MenuItem(label=message)
     add_item.show()
     menu.append(add_item)
     self.itemoption = Gtk.Menu()
     itemoption = self.itemoption
     itemoption.set_title(message)
     itemoption.show()
     add_item.set_submenu(itemoption)
     modify = Gtk.MenuItem(label=_("Edit Event"))
     modify.show()
     modify.connect("activate", self.edit_event, event, lat, lon, prevmark)
     itemoption.append(modify)
     center = Gtk.MenuItem(label=_("Center on this place"))
     center.show()
     center.connect("activate", self.center_here, event, lat, lon, prevmark)
     itemoption.append(center)
     evt = self.dbstate.db.get_event_from_gramps_id(mark[10])
     hdle = evt.get_handle()
     bookm = Gtk.MenuItem(label=_("Bookmark this event"))
     bookm.show()
     bookm.connect("activate", self.add_bookmark_from_popup, hdle)
     itemoption.append(bookm)
     menu.popup(None, None, None,
                None, event.button, event.time)
     return 1