Beispiel #1
0
    def __init__(self, dbstate, uistate, clicked):
        self.clicked_func = clicked
        self.filter_name = widgets.BasicEntry()
        self.filter_id = widgets.BasicEntry()
        self.filter_birth = widgets.DateEntry(uistate, [])
        self.filter_death = widgets.DateEntry(uistate, [])
        self.filter_event = Event()
        self.filter_event.set_type((EventType.CUSTOM, ''))
        self.etype = Gtk.ComboBox(has_entry=True)
        if dbstate.is_open():
            self.custom_types = dbstate.db.get_event_types()
        else:
            self.custom_types = []
        self.event_menu = widgets.MonitoredDataType(
            self.etype,
            self.filter_event.set_type,
            self.filter_event.get_type,
            custom_values=self.custom_types)

        self.filter_note = widgets.BasicEntry()
        self.filter_gender = Gtk.ComboBoxText()
        list(
            map(self.filter_gender.append_text,
                [_('any'), _('male'),
                 _('female'), _('unknown')]))
        self.filter_gender.set_active(0)

        self.filter_regex = Gtk.CheckButton(label=_('Use regular expressions'))

        self.tag = Gtk.ComboBox()
        self.generic = Gtk.ComboBox()

        SidebarFilter.__init__(self, dbstate, uistate, "Person")
Beispiel #2
0
    def __init__(self, dbstate, uistate, clicked):
        self.clicked_func = clicked
        self.filter_id = widgets.BasicEntry()
        self.filter_desc = widgets.BasicEntry()
        self.filter_event = Event()
        self.filter_event.set_type((EventType.CUSTOM, ''))
        self.etype = Gtk.ComboBox(has_entry=True)
        if dbstate.is_open():
            self.custom_types = dbstate.db.get_event_types()
        else:
            self.custom_types = []

        self.event_menu = widgets.MonitoredDataType(
            self.etype,
            self.filter_event.set_type,
            self.filter_event.get_type,
            custom_values=self.custom_types)

        self.filter_mainparts = widgets.BasicEntry()
        self.filter_date = widgets.DateEntry(uistate, [])
        self.filter_place = widgets.BasicEntry()
        self.filter_note = widgets.BasicEntry()

        self.filter_regex = Gtk.CheckButton(label=_('Use regular expressions'))

        self.tag = Gtk.ComboBox()
        self.generic = Gtk.ComboBox()

        SidebarFilter.__init__(self, dbstate, uistate, "Event")
Beispiel #3
0
    def __init__(self, dbstate, uistate, clicked):
        self.clicked_func = clicked
        self.filter_id = widgets.BasicEntry()
        self.filter_father = widgets.BasicEntry()
        self.filter_mother = widgets.BasicEntry()
        self.filter_child = widgets.BasicEntry()

        self.filter_event = Event()
        self.filter_event.set_type((EventType.CUSTOM, ''))
        self.etype = Gtk.ComboBox(has_entry=True)

        self.family_stub = Family()
        self.family_stub.set_relationship((FamilyRelType.CUSTOM, ''))
        self.rtype = Gtk.ComboBox(has_entry=True)

        self.event_menu = widgets.MonitoredDataType(self.etype,
                                                    self.filter_event.set_type,
                                                    self.filter_event.get_type)

        self.rel_menu = widgets.MonitoredDataType(
            self.rtype, self.family_stub.set_relationship,
            self.family_stub.get_relationship)

        self.filter_note = widgets.BasicEntry()

        self.filter_regex = Gtk.CheckButton(label=_('Use regular expressions'))

        self.tag = Gtk.ComboBox()
        self.generic = Gtk.ComboBox()

        SidebarFilter.__init__(self, dbstate, uistate, "Family")
 def create_event(self, description=_("Estimated date"),
                  type=None, date=None, source=None,
                  note_text="", modifier=None):
     event = Event()
     event.set_description(description)
     note = Note()
     note.handle = create_id()
     note.type.set(NoteType.EVENT)
     note.set(note_text)
     self.db.add_note(note, self.trans)
     event.add_note(note.handle)
     if type:
         event.set_type(EventType(type))
     if date:
         if modifier:
             date.set_modifier(modifier)
         date.set_quality(Date.QUAL_ESTIMATED)
         date.set_yr_mon_day(date.get_year(), 0, 0)
         event.set_date_object(date)
     if source:
         citation = Citation()
         citation.set_reference_handle(source.get_handle())
         self.db.add_citation(citation, self.trans)
         event.add_citation(citation.get_handle())
         self.db.commit_source(source, self.trans)
     self.db.add_event(event, self.trans)
     return event
Beispiel #5
0
 def column_place(self, data):
     if data[COLUMN_PLACE]:
         event = Event()
         event.unserialize(data)
         return place_displayer.display_event(self.db, event)
     else:
         return ''
Beispiel #6
0
 def add_button_clicked(self, obj):
     try:
         ref = EventRef()
         event = Event()
         ref.set_role(self.default_role())
         event.set_type(self.default_type())
         self.get_ref_editor()(self.dbstate, self.uistate, self.track,
                               event, ref, self.object_added)
     except WindowActiveError:
         pass
Beispiel #7
0
    def sort_date(self, data):
        if data[COLUMN_DATE]:
            event = Event()
            event.unserialize(data)
            retval = "%09d" % event.get_date_object().get_sort_value()
            if not get_date_valid(event):
                return INVALID_DATE_FORMAT % retval
            else:
                return retval

        return ''
Beispiel #8
0
 def column_place(self, data):
     if data[COLUMN_PLACE]:
         cached, value = self.get_cached_value(data[0], "PLACE")
         if not cached:
             event = Event()
             event.unserialize(data)
             value = place_displayer.display_event(self.db, event)
             self.set_cached_value(data[0], "PLACE", value)
         return value
     else:
         return ''
Beispiel #9
0
 def column_date(self, data):
     if data[COLUMN_DATE]:
         event = Event()
         event.unserialize(data)
         date_str = get_date(event)
         if date_str != "":
             retval = escape(date_str)
         if not get_date_valid(event):
             return INVALID_DATE_FORMAT % retval
         else:
             return retval
     return ''
Beispiel #10
0
    def add_occupation(self, fields, data):
        """Read the ROLE property of a VCard."""
        occupation = data.strip()
        if occupation:
            event = Event()
            event.set_type(EventType(EventType.OCCUPATION))
            event.set_description(self.unesc(occupation))
            self.database.add_event(event, self.trans)

            event_ref = EventRef()
            event_ref.set_reference_handle(event.get_handle())
            self.person.add_event_ref(event_ref)
 def post(self, path):
     if "/" in path:
         handle, action = path.split("/")
     else:
         handle, action = path, "view"
     if handle == "add":
         event = Event()
         event.handle = handle = create_id()
     else:
         event = self.database.get_event_from_handle(handle)
     form = EventForm(self.database, _, instance=event)
     form.save(handler=self)
     self.redirect("/event/%(handle)s" % {"handle": handle})
Beispiel #12
0
def find_form_event(db, citation):
    """
    Given a citation for a form source, find the corresponding event.
    """
    handle = citation.get_reference_handle()
    source = db.get_source_from_handle(handle)
    form_type = get_form_type(get_form_id(source))

    for item in db.find_backlink_handles(citation.handle, ['Event']):
        event = db.get_event_from_handle(item[1])
        if event.get_type().xml_str() == form_type:
            return event

    return Event()
Beispiel #13
0
 def create_event(self,type,desc=None,date=None,place=None,source=None):
     event = Event()
     if type:
         event.set_type(EventType(type))
     if desc:
         event.set_description(desc)
     if date:
         event.set_date_object(date)
     if place:
         event.set_place_handle(place.get_handle())
     if source:
         event.add_citation(source.get_handle())
     self.db.add_event(event,self.trans)
     self.db.commit_event(event,self.trans)
     return event
Beispiel #14
0
    def __add_resi_event(self, person, placename, date_object):
        pn = PlaceName()
        pn.set_value(placename)
        place = Place()
        place.set_name(pn)
        placehandle = self.dbstate.db.add_place(place, self.trans)

        e = Event()
        e.set_type(EventType.RESIDENCE)
        e.set_date_object(date_object)
        e.set_place_handle(placehandle)
        e.set_description("marriage")
        eventhandle = self.dbstate.db.add_event(e, self.trans)

        eref = EventRef()
        eref.ref = eventhandle
        person.add_event_ref(eref)
        self.dbstate.db.commit_person(person, self.trans)
 def get(self, path=""):
     """
     HANDLE
     HANDLE/edit|delete
     /add
     b2cfa6ca1e174b1f63d/remove/eventref/1
     """
     page = int(self.get_argument("page", 1))
     search = self.get_argument("search", "")
     if "/" in path:
         handle, action = path.split("/", 1)
     else:
         handle, action = path, "view"
     if handle:
         if handle == "add":
             event = Event()
             action = "edit"
         else:
             event = self.database.get_event_from_handle(handle)
         if event:
             self.render(
                 "event.html",
                 **self.get_template_dict(tview=_("event detail"),
                                          action=action,
                                          page=page,
                                          search=search,
                                          form=EventForm(self.database,
                                                         _,
                                                         instance=event),
                                          logform=None))
             return
         else:
             self.clear()
             self.set_status(404)
             self.finish("<html><body>No such event</body></html>")
             return
     self.render(
         "page_view.html",
         **self.get_template_dict(
             tview=_("event view"),
             page=page,
             search=search,
             form=EventForm(self.database, _, table="Event"),
         ))
Beispiel #16
0
    def add_birthday(self, fields, data):
        """Read the BDAY property of a VCard."""
        date_str = data.strip()
        date_match = VCardParser.DATE_RE.match(date_str)
        date = Date()
        if date_match:
            if date_match.group(2):
                date_str = "%s-%s-%s" % (date_match.group(2),
                                         date_match.group(3),
                                         date_match.group(4))
            else:
                date_str = date_match.group(1)
            y, m, d = [int(x, 10) for x in date_str.split('-')]
            try:
                date.set(value=(d, m, y, False))
            except DateError:
                # TRANSLATORS: leave the {vcard_snippet} untranslated
                # in the format string, but you may re-order it if needed.
                self.__add_msg(
                    _("Invalid date in BDAY {vcard_snippet}, "
                      "preserving date as text.").format(vcard_snippet=data),
                    self.line_num - 1)
                date.set(modifier=Date.MOD_TEXTONLY, text=data)
        else:
            if date_str:
                # TRANSLATORS: leave the {vcard_snippet} untranslated.
                self.__add_msg(
                    _("Date {vcard_snippet} not in appropriate format "
                      "yyyy-mm-dd, preserving date as text.").format(
                          vcard_snippet=date_str), self.line_num - 1)
                date.set(modifier=Date.MOD_TEXTONLY, text=date_str)
            else:  # silently ignore an empty BDAY record
                return
        event = Event()
        event.set_type(EventType(EventType.BIRTH))
        event.set_date_object(date)
        self.database.add_event(event, self.trans)

        event_ref = EventRef()
        event_ref.set_reference_handle(event.get_handle())
        self.person.set_birth_ref(event_ref)
Beispiel #17
0
    def clone_button_clicked(self, obj):
        'Function called with the Clone button is clicked.'
        source_ref = self.get_selected()
        if source_ref and \
           source_ref[1] is not None \
           and source_ref[0] == self._WORKGROUP:
            source_event = self.dbstate.db.get_event_from_handle(
                source_ref[1].ref)

            try:
                ref = EventRef(source=source_ref[1])

                event = Event(source=source_event)
                event.set_gramps_id(
                    self.dbstate.db.find_next_event_gramps_id())
                event.set_handle(None)

                self.get_ref_editor()(self.dbstate, self.uistate, self.track,
                                      event, ref, self.object_added)
            except WindowActiveError:
                pass
Beispiel #18
0
    def clone(self, obj):
        """
        Clones the selected event.
        """
        event_list = self.selected_handles()

        if len(event_list) != 1:
            msg = _("Cannot clone event object.")
            msg2 = _("Exactly one event must be selected to perform a clone.")
            ErrorDialog(msg, msg2, parent=self.uistate.window)
        else:
            event = Event()
            event = copy.deepcopy(
                self.dbstate.db.get_event_from_handle(event_list[0]))
            event.gramps_id = None

            try:
                self.uistate.action = 'event-clone'
                EditEvent(self.dbstate, self.uistate, [], event)
            except WindowActiveError:
                pass
Beispiel #19
0
 def get_or_create_event(self,
                         object_,
                         type_,
                         date=None,
                         place=None,
                         source=None):
     """ Add or find a type event on object """
     # first, see if it exists
     LOG.debug("get_or_create_event")
     ref_list = object_.get_event_ref_list()
     LOG.debug("refs: %s", ref_list)
     # look for a match, and possible correction
     for ref in ref_list:
         event = self.db.get_event_from_handle(ref.ref)
         LOG.debug("   compare event type %s == %s", int(event.get_type()),
                   type_)
         if int(event.get_type()) == type_:
             # Match! Let's update
             if date:
                 event.set_date_object(date)
             if place:
                 event.set_place_handle(place.get_handle())
             if source:
                 self.find_and_set_citation(event, source)
             self.db.commit_event(event, self.trans)
             LOG.debug("   returning existing event")
             return (0, event)
     # else create it:
     LOG.debug("   creating event")
     event = Event()
     if type_:
         event.set_type(EventType(type_))
     if date:
         event.set_date_object(date)
     if place:
         event.set_place_handle(place.get_handle())
     if source:
         self.find_and_set_citation(event, source)
     self.db.add_event(event, self.trans)
     return (1, event)
Beispiel #20
0
    def _process(self, count, total, sql):
        # ---------------------------------
        # Process note
        # ---------------------------------
        notes = sql.query("""select * from note;""")
        for note in notes:
            (handle, gid, text, _format, note_type1, note_type2, change,
             private) = note
            styled_text = [text, []]
            markups = sql.query(
                """select * from link where from_handle = ? """
                """and to_type = 'markup';""", handle)
            for markup_link in markups:
                _from_type, _from_handle, _to_type, to_handle = markup_link
                markup_detail = sql.query(
                    """select * from markup where handle = ?;""", to_handle)
                for markup in markup_detail:
                    (_mhandle, markup0, markup1, value,
                     start_stop_list) = markup
                    ss_list = eval(start_stop_list)
                    styled_text[1] += [((markup0, markup1), value, ss_list)]

            tags = self.get_links(sql, "note", handle, "tag")

            g_note = Note()
            g_note.unserialize(
                (handle, gid, styled_text, _format, (note_type1, note_type2),
                 change, tags, bool(private)))
            self.db.add_note(g_note, self.trans)
            count += 1
            self.callback(100 * count / total)

        # ---------------------------------
        # Process event
        # ---------------------------------
        events = sql.query("""select * from event;""")
        for event in events:
            (handle, gid, the_type0, the_type1, description, change,
             private) = event

            note_list = self.get_note_list(sql, "event", handle)
            citation_list = self.get_citation_list(sql, "event", handle)
            media_list = self.get_media_list(sql, "event", handle)
            attribute_list = self.get_attribute_list(sql, "event", handle)

            date_handle = self.get_link(sql, "event", handle, "date")
            date = self.get_date(sql, date_handle)

            place_handle = self.get_link(sql, "event", handle, "place")
            place = self.get_place_from_handle(sql, place_handle)

            tags = self.get_links(sql, "event", handle, "tag")
            data = (handle, gid, (the_type0, the_type1), date, description,
                    place, citation_list, note_list, media_list,
                    attribute_list, change, tags, bool(private))

            g_event = Event()
            g_event.unserialize(data)
            self.db.add_event(g_event, self.trans)

            count += 1
            self.callback(100 * count / total)

        # ---------------------------------
        # Process person
        # ---------------------------------
        people = sql.query("""select * from person;""")
        for person in people:
            if person is None:
                continue
            (
                handle,  # 0
                gid,  # 1
                gender,  # 2
                death_ref_handle,  # 5
                birth_ref_handle,  # 6
                change,  # 17
                private,  # 19
            ) = person
            primary_name = self.get_names(sql, "person", handle, True)  # one
            alternate_names = self.get_names(sql, "person", handle, False)
            event_ref_list = self.get_event_ref_list(sql, "person", handle)
            family_list = self.get_family_list(sql, "person", handle)
            parent_family_list = self.get_parent_family_list(
                sql, "person", handle)
            media_list = self.get_media_list(sql, "person", handle)
            address_list = self.get_address_list(sql,
                                                 "person",
                                                 handle,
                                                 with_parish=False)
            attribute_list = self.get_attribute_list(sql, "person", handle)
            urls = self.get_url_list(sql, "person", handle)
            lds_ord_list = self.get_lds_list(sql, "person", handle)
            pcitation_list = self.get_citation_list(sql, "person", handle)
            pnote_list = self.get_note_list(sql, "person", handle)
            person_ref_list = self.get_person_ref_list(sql, "person", handle)
            death_ref_index = lookup(death_ref_handle, event_ref_list)
            birth_ref_index = lookup(birth_ref_handle, event_ref_list)
            tags = self.get_links(sql, "person", handle, "tag")

            data = (
                handle,  # 0
                gid,  # 1
                gender,  # 2
                primary_name,  # 3
                alternate_names,  # 4
                death_ref_index,  # 5
                birth_ref_index,  # 6
                event_ref_list,  # 7
                family_list,  # 8
                parent_family_list,  # 9
                media_list,  # 10
                address_list,  # 11
                attribute_list,  # 12
                urls,  # 13
                lds_ord_list,  # 14
                pcitation_list,  # 15
                pnote_list,  # 16
                change,  # 17
                tags,
                bool(private),  # 19
                person_ref_list,
            )  # 20

            g_pers = Person()
            g_pers.unserialize(data)
            self.db.add_person(g_pers, self.trans)
            count += 1
            self.callback(100 * count / total)
        # ---------------------------------
        # Process family
        # ---------------------------------
        families = sql.query("""select * from family;""")
        for family in families:
            (handle, gid, father_handle, mother_handle, the_type0, the_type1,
             change, private) = family

            child_ref_list = self.get_child_ref_list(sql, "family", handle)
            event_ref_list = self.get_event_ref_list(sql, "family", handle)
            media_list = self.get_media_list(sql, "family", handle)
            attribute_list = self.get_attribute_list(sql, "family", handle)
            lds_seal_list = self.get_lds_list(sql, "family", handle)
            citation_list = self.get_citation_list(sql, "family", handle)
            note_list = self.get_note_list(sql, "family", handle)
            tags = self.get_links(sql, "family", handle, "tag")

            data = (handle, gid, father_handle, mother_handle, child_ref_list,
                    (the_type0, the_type1), event_ref_list, media_list,
                    attribute_list, lds_seal_list, citation_list, note_list,
                    change, tags, private)
            g_fam = Family()
            g_fam.unserialize(data)
            self.db.add_family(g_fam, self.trans)

            count += 1
            self.callback(100 * count / total)
        # ---------------------------------
        # Process repository
        # ---------------------------------
        repositories = sql.query("""select * from repository;""")
        for repo in repositories:
            (handle, gid, the_type0, the_type1, name, change, private) = repo

            note_list = self.get_note_list(sql, "repository", handle)
            address_list = self.get_address_list(sql,
                                                 "repository",
                                                 handle,
                                                 with_parish=False)
            urls = self.get_url_list(sql, "repository", handle)
            tags = self.get_links(sql, "repository", handle, "tag")
            data = (handle, gid, (the_type0, the_type1), name, note_list,
                    address_list, urls, change, tags, private)
            g_rep = Repository()
            g_rep.unserialize(data)
            self.db.add_repository(g_rep, self.trans)
            count += 1
            self.callback(100 * count / total)
        # ---------------------------------
        # Process place
        # ---------------------------------
        places = sql.query("""select * from place;""")
        for place in places:
            count += 1
            (handle, gid, title, value, the_type0, the_type1, code, long, lat,
             lang, change, private) = place

            # We could look this up by "place_main", but we have the handle:
            #main_loc = self.get_main_location(sql, handle, with_parish=True)
            alt_loc_list = self.get_location_list(sql,
                                                  "place_alt",
                                                  handle,
                                                  with_parish=True)
            urls = self.get_url_list(sql, "place", handle)
            media_list = self.get_media_list(sql, "place", handle)
            citation_list = self.get_citation_list(sql, "place", handle)
            note_list = self.get_note_list(sql, "place", handle)
            tags = self.get_links(sql, "place", handle, "tag")
            place_type = (the_type0, the_type1)
            alt_place_name_list = self.get_alt_place_name_list(sql, handle)
            place_ref_list = self.get_place_ref_list(sql, handle)
            data = (handle, gid, title, long, lat, place_ref_list,
                    PlaceName(value=value,
                              lang=lang).serialize(), alt_place_name_list,
                    place_type, code, alt_loc_list, urls, media_list,
                    citation_list, note_list, change, tags, private)
            g_plac = Place()
            g_plac.unserialize(data)
            self.db.commit_place(g_plac, self.trans)
            self.callback(100 * count / total)

        # ---------------------------------
        # Process citation
        # ---------------------------------
        citations = sql.query("""select * from citation;""")
        for citation in citations:
            (handle, gid, confidence, page, source_handle, change,
             private) = citation
            date_handle = self.get_link(sql, "citation", handle, "date")
            date = self.get_date(sql, date_handle)
            note_list = self.get_note_list(sql, "citation", handle)
            media_list = self.get_media_list(sql, "citation", handle)
            datamap = self.get_datamap_list(sql, "citation", handle)
            tags = self.get_links(sql, "citation", handle, "tag")
            data = (handle, gid, date, page, confidence, source_handle,
                    note_list, media_list, datamap, change, tags, private)
            g_cit = Citation()
            g_cit.unserialize(data)
            self.db.commit_citation(g_cit, self.trans)
            count += 1
            self.callback(100 * count / total)

        # ---------------------------------
        # Process source
        # ---------------------------------
        sources = sql.query("""select * from source;""")
        for source in sources:
            (handle, gid, title, author, pubinfo, abbrev, change,
             private) = source
            note_list = self.get_note_list(sql, "source", handle)
            media_list = self.get_media_list(sql, "source", handle)
            datamap = self.get_datamap_list(sql, "source", handle)
            reporef_list = self.get_repository_ref_list(sql, "source", handle)
            tags = self.get_links(sql, "source", handle, "tag")

            data = (handle, gid, title, author, pubinfo, note_list, media_list,
                    abbrev, change, datamap, reporef_list, tags, private)
            g_src = Source()
            g_src.unserialize(data)
            self.db.commit_source(g_src, self.trans)
            count += 1
            self.callback(100 * count / total)
        # ---------------------------------
        # Process media
        # ---------------------------------
        media = sql.query("""select * from media;""")
        for med in media:
            (handle, gid, path, mime, desc, checksum, change, private) = med

            attribute_list = self.get_attribute_list(sql, "media", handle)
            citation_list = self.get_citation_list(sql, "media", handle)
            note_list = self.get_note_list(sql, "media", handle)

            date_handle = self.get_link(sql, "media", handle, "date")
            date = self.get_date(sql, date_handle)
            tags = self.get_links(sql, "media", handle, "tag")

            data = (handle, gid, path, mime, desc, checksum, attribute_list,
                    citation_list, note_list, change, date, tags, private)
            g_med = Media()
            g_med.unserialize(data)
            self.db.commit_media(g_med, self.trans)
            count += 1
            self.callback(100 * count / total)
        # ---------------------------------
        # Process tag
        # ---------------------------------
        tags = sql.query("""select * from tag;""")
        for tag in tags:
            (handle, name, color, priority, change) = tag

            data = (handle, name, color, priority, change)
            g_tag = Tag()
            g_tag.unserialize(data)
            self.db.commit_tag(g_tag, self.trans)
            count += 1
            self.callback(100 * count / total)
Beispiel #21
0
    def compare_people(self, p1, p2):

        name1 = p1.get_primary_name()
        name2 = p2.get_primary_name()

        chance = self.name_match(name1, name2)
        if chance == -1:
            return -1

        birth1_ref = p1.get_birth_ref()
        if birth1_ref:
            birth1 = self.db.get_event_from_handle(birth1_ref.ref)
        else:
            birth1 = Event()

        death1_ref = p1.get_death_ref()
        if death1_ref:
            death1 = self.db.get_event_from_handle(death1_ref.ref)
        else:
            death1 = Event()

        birth2_ref = p2.get_birth_ref()
        if birth2_ref:
            birth2 = self.db.get_event_from_handle(birth2_ref.ref)
        else:
            birth2 = Event()

        death2_ref = p2.get_death_ref()
        if death2_ref:
            death2 = self.db.get_event_from_handle(death2_ref.ref)
        else:
            death2 = Event()

        value = self.date_match(birth1.get_date_object(),
                                birth2.get_date_object())
        if value == -1:
            return -1
        chance += value

        value = self.date_match(death1.get_date_object(),
                                death2.get_date_object())
        if value == -1:
            return -1
        chance += value

        value = self.place_match(birth1.get_place_handle(),
                                 birth2.get_place_handle())
        if value == -1:
            return -1
        chance += value

        value = self.place_match(death1.get_place_handle(),
                                 death2.get_place_handle())
        if value == -1:
            return -1
        chance += value

        ancestors = []
        self.ancestors_of(p1.get_handle(), ancestors)
        if p2.get_handle() in ancestors:
            return -1

        ancestors = []
        self.ancestors_of(p2.get_handle(), ancestors)
        if p1.get_handle() in ancestors:
            return -1

        f1_id = p1.get_main_parents_family_handle()
        f2_id = p2.get_main_parents_family_handle()

        if f1_id and f2_id:
            f1 = self.db.get_family_from_handle(f1_id)
            f2 = self.db.get_family_from_handle(f2_id)
            dad1_id = f1.get_father_handle()
            if dad1_id:
                dad1 = get_name_obj(self.db.get_person_from_handle(dad1_id))
            else:
                dad1 = None
            dad2_id = f2.get_father_handle()
            if dad2_id:
                dad2 = get_name_obj(self.db.get_person_from_handle(dad2_id))
            else:
                dad2 = None

            value = self.name_match(dad1, dad2)

            if value == -1:
                return -1

            chance += value

            mom1_id = f1.get_mother_handle()
            if mom1_id:
                mom1 = get_name_obj(self.db.get_person_from_handle(mom1_id))
            else:
                mom1 = None
            mom2_id = f2.get_mother_handle()
            if mom2_id:
                mom2 = get_name_obj(self.db.get_person_from_handle(mom2_id))
            else:
                mom2 = None

            value = self.name_match(mom1, mom2)
            if value == -1:
                return -1

            chance += value

        for f1_id in p1.get_family_handle_list():
            f1 = self.db.get_family_from_handle(f1_id)
            for f2_id in p2.get_family_handle_list():
                f2 = self.db.get_family_from_handle(f2_id)
                if p1.get_gender() == Person.FEMALE:
                    father1_id = f1.get_father_handle()
                    father2_id = f2.get_father_handle()
                    if father1_id and father2_id:
                        if father1_id == father2_id:
                            chance += 1
                        else:
                            father1 = self.db.get_person_from_handle(
                                father1_id)
                            father2 = self.db.get_person_from_handle(
                                father2_id)
                            fname1 = get_name_obj(father1)
                            fname2 = get_name_obj(father2)
                            value = self.name_match(fname1, fname2)
                            if value != -1:
                                chance += value
                else:
                    mother1_id = f1.get_mother_handle()
                    mother2_id = f2.get_mother_handle()
                    if mother1_id and mother2_id:
                        if mother1_id == mother2_id:
                            chance += 1
                        else:
                            mother1 = self.db.get_person_from_handle(
                                mother1_id)
                            mother2 = self.db.get_person_from_handle(
                                mother2_id)
                            mname1 = get_name_obj(mother1)
                            mname2 = get_name_obj(mother2)
                            value = self.name_match(mname1, mname2)
                            if value != -1:
                                chance += value
        return chance
Beispiel #22
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()
Beispiel #23
0
 def add(self, obj):
     try:
         self.uistate.action = 'event-add'
         EditEvent(self.dbstate, self.uistate, [], Event())
     except WindowActiveError:
         pass
Beispiel #24
0
 def add(self, obj):
     try:
         EditEvent(self.dbstate, self.uistate, [], Event())
     except WindowActiveError:
         pass
Beispiel #25
0
from gramps.gen.plug.report import MenuReportOptions
import gramps.gen.datehandler
from gramps.gen.relationship import get_relationship_calculator
from gramps.gen.const import GRAMPS_LOCALE as glocale
try:
    _trans = glocale.get_addon_translator(__file__)
except ValueError:
    _trans = glocale.translation
_ = _trans.gettext

#------------------------------------------------------------------------
#
# Constants
#
#------------------------------------------------------------------------
empty_birth = Event()
empty_birth.set_type(EventType.BIRTH)

empty_marriage = Event()
empty_marriage.set_type(EventType.MARRIAGE)


#------------------------------------------------------------------------
#
# FamilySheet report
#
#------------------------------------------------------------------------
class FamilySheet(Report):
    """
    A Family Sheet is a page which contains all available info about a specific
    person, the families this person is a father or mother in, and the children
Beispiel #26
0
 def empty_object(self):
     return Event()