Beispiel #1
0
 def display_family(self, active_handle):
     """
     Display the events for the active family.
     """
     active_family = self.dbstate.db.get_family_from_handle(active_handle)
     for event_ref in active_family.get_event_ref_list():
         self.add_event_ref(event_ref)
     self.set_has_data(self.model.count > 0)
     # for father, add all events
     father_handle = active_family.get_father_handle()
     if father_handle:
         father = self.dbstate.db.get_person_from_handle(father_handle)
         if father:
             for event_ref in father.get_event_ref_list():
                 surname = name_displayer.display(father)
                 self.add_event_ref(event_ref, name=surname)
     # for mother, add all events
     mother_handle = active_family.get_mother_handle()
     if mother_handle:
         mother = self.dbstate.db.get_person_from_handle(mother_handle)
         if mother:
             for event_ref in mother.get_event_ref_list():
                 surname = name_displayer.display(mother)
                 self.add_event_ref(event_ref, name=surname)
     # for each child, add all events
     child_ref_list = active_family.get_child_ref_list()
     if child_ref_list:
         for chld_ref in child_ref_list:
             if chld_ref:
                 child = self.dbstate.db.get_person_from_handle(chld_ref.ref)
                 if child:
                     for event_ref in child.get_event_ref_list():
                         surname = name_displayer.display(child)
                         self.add_event_ref(event_ref, name=surname)
Beispiel #2
0
 def family_label(self,family):
     if family is None:
         return "Unknown"
     f = self.dbstate.db.get_person_from_handle(
         family.get_father_handle())
     m = self.dbstate.db.get_person_from_handle(
         family.get_mother_handle())
     if f and m:
         label = _("%(gramps_id)s : %(father)s and %(mother)s") % {
             'father' : _nd.display(f),
             'mother' : _nd.display(m),
             'gramps_id' : family.gramps_id,
             }
     elif f:
         label = "%(gramps_id)s : %(father)s" % {
             'father' : _nd.display(f),
             'gramps_id' : family.gramps_id,
             }
     elif m:
         label = "%(gramps_id)s : %(mother)s" % {
             'mother' : _nd.display(m),
             'gramps_id' : family.gramps_id,
             }
     else:
         # No translation for bare gramps_id
         label = "%(gramps_id)s :" % {
             'gramps_id' : family.gramps_id,
             }
     return label
Beispiel #3
0
 def family_label(self, family):
     """
     Create the family label depending on existence of the father and mother
     """
     if family is None:
         return "Unknown"
     father = mother = None
     hdl = family.get_father_handle()
     if hdl:
         father = self.dbstate.db.get_person_from_handle(hdl)
     hdl = family.get_mother_handle()
     if hdl:
         mother = self.dbstate.db.get_person_from_handle(hdl)
     if father and mother:
         label = _("%(gramps_id)s : %(father)s and %(mother)s") % {
             'father' : _nd.display(father),
             'mother' : _nd.display(mother),
             'gramps_id' : family.gramps_id,
             }
     elif father:
         label = "%(gramps_id)s : %(father)s" % {
             'father' : _nd.display(father),
             'gramps_id' : family.gramps_id,
             }
     elif mother:
         label = "%(gramps_id)s : %(mother)s" % {
             'mother' : _nd.display(mother),
             'gramps_id' : family.gramps_id,
             }
     else:
         # No translation for bare gramps_id
         label = "%(gramps_id)s :" % {
             'gramps_id' : family.gramps_id,
             }
     return label
Beispiel #4
0
    def __process_family_2(self, family, person1, person2):

        missingbits = []

        if person1 is UnknownPerson or person1 is None:
            name1 = _("(unknown person)")
        else:
            name1 = name_displayer.display(person1)
            if not name1:
                name1 = _("(person with unknown name)")

        if person2 is UnknownPerson or person2 is None:
            name2 = _("(unknown person)")
        else:
            name2 = name_displayer.display(person2)
            if not name2:
                name2 = _("(person with unknown name)")

        name = _("%(name1)s and %(name2)s") % {
                'name1': name1,
                'name2': name2}

        if self.__family_complete_handle is not None and \
           self.__family_complete_handle not in family.get_tag_list():
            missingbits.append(_("family not complete"))

        if missingbits:
            self.link(name, 'Family', family.get_handle())
            self.append_text(_(": %(list)s\n") % {
                'list': _(", ").join(missingbits)})
            self.__counter += 1
Beispiel #5
0
    def update_parent_label(self):
        handle = self.obj.get_family_handle()
        if handle:
            family = self.dbstate.db.get_family_from_handle(handle)
            f = self.dbstate.db.get_person_from_handle(
                family.get_father_handle())
            m = self.dbstate.db.get_person_from_handle(
                family.get_mother_handle())
            if f and m:
                label = _("%(father)s and %(mother)s [%(gramps_id)s]") % {
                    'father' : name_displayer.display(f),
                    'mother' : name_displayer.display(m),
                    'gramps_id' : family.gramps_id,
                    }
            elif f:
                label = _("%(father)s [%(gramps_id)s]") % {
                    'father' : name_displayer.display(f),
                    'gramps_id' : family.gramps_id,
                    }
            elif m:
                label = _("%(mother)s [%(gramps_id)s]") % {
                    'mother' : name_displayer.display(m),
                    'gramps_id' : family.gramps_id,
                    }
            else:
                # No translation for bare gramps_id
                label = "[%(gramps_id)s]" % {
                    'gramps_id' : family.gramps_id,
                    }
        else:
            label = ""

        self.parents.set_text(label)
Beispiel #6
0
    def display_parents(self, active_person):
        """
        Display the parents of the active person.
        """
        family_handle = active_person.get_main_parents_family_handle()
        if family_handle:
            family = self.dbstate.db.get_family_from_handle(family_handle)
            handle = family.get_father_handle()
            if handle:
                father = self.dbstate.db.get_person_from_handle(handle)
                father_name = name_displayer.display(father)
            else:
                father_name = _('Unknown')
            handle = family.get_mother_handle()
            if handle:
                mother = self.dbstate.db.get_person_from_handle(handle)
                mother_name = name_displayer.display(mother)
            else:
                mother_name = _('Unknown')
        else:
            father_name = _('Unknown')
            mother_name = _('Unknown')

        self.add_row(_('Father'), father_name)
        self.add_row(_('Mother'), mother_name)
Beispiel #7
0
 def _createmap_for_one_family(self, family, color, place_list, reference):
     """
     Create all markers for one family : all event's places with a lat/lon.
     """
     dbstate = self.dbstate
     person = None
     try:
         person = dbstate.db.get_person_from_handle(family.get_father_handle())
     except:
         return
     family_id = family.gramps_id
     if person is None: # family without father ?
         handle = family.get_mother_handle()
         if handle:
             person = dbstate.db.get_person_from_handle(handle)
     if person is None:
         handle = self.uistate.get_active('Person')
         if handle:
             person = dbstate.db.get_person_from_handle(handle)
     if person is not None:
         family_list = person.get_family_handle_list()
         if len(family_list) > 0:
             fhandle = family_list[0] # first is primary
             fam = dbstate.db.get_family_from_handle(fhandle)
             father = mother = None
             handle = fam.get_father_handle()
             if handle:
                 father = dbstate.db.get_person_from_handle(handle)
             if father:
                 comment = _("Father : %(id)s : %(name)s") % {'id': father.gramps_id,
                                                     'name': _nd.display(father)}
                 self._createmap_for_one_person(father, color, place_list, reference)
             handle = fam.get_mother_handle()
             if handle:
                 mother = dbstate.db.get_person_from_handle(handle)
             if mother:
                 comment = _("Mother : %(id)s : %(name)s") % {'id': mother.gramps_id,
                                                     'name': _nd.display(mother)}
                 self._createmap_for_one_person(mother, color, place_list, reference)
             index = 0
             child_ref_list = fam.get_child_ref_list()
             if child_ref_list:
                 for child_ref in child_ref_list:
                     child = dbstate.db.get_person_from_handle(child_ref.ref)
                     if child:
                         index += 1
                         comment = _("Child : %(id)s - %(index)d "
                                     ": %(name)s") % {
                                         'id'    : child.gramps_id,
                                         'index' : index,
                                         'name'  : _nd.display(child)
                                      }
                         self._createmap_for_one_person(child, color, place_list, reference)
         else:
             comment = _("Person : %(id)s %(name)s has no family.") % {
                             'id' : person.gramps_id ,
                             'name' : _nd.display(person)
                             }
             self._createmap_for_one_person(person, color, place_list, reference)
Beispiel #8
0
    def _write_family(self, family_handle):
        """
        Generate a table row for this family record
        """
        family = self.database.get_family_from_handle(family_handle)

        self.doc.start_row()

        self.doc.start_cell("TR-TableCell")
        self.doc.start_paragraph("TR-Normal")
        self.doc.write_text(family.get_gramps_id())
        self.doc.end_paragraph()
        self.doc.end_cell()

        self.doc.start_cell("TR-TableCell")
        self.doc.start_paragraph("TR-Normal")
        father_handle = family.get_father_handle()
        if father_handle:
            father = self.database.get_person_from_handle(father_handle)
            mark = ReportUtils.get_person_mark(self.database, father)
            self.doc.write_text(name_displayer.display(father), mark)
        self.doc.end_paragraph()
        self.doc.end_cell()

        self.doc.start_cell("TR-TableCell")
        self.doc.start_paragraph("TR-Normal")
        mother_handle = family.get_mother_handle()
        if mother_handle:
            mother = self.database.get_person_from_handle(mother_handle)
            mark = ReportUtils.get_person_mark(self.database, mother)
            self.doc.write_text(name_displayer.display(mother), mark)
        self.doc.end_paragraph()
        self.doc.end_cell()

        # see if we can find a relationship event to include
        relationship_date = _PLACEHOLDER
        for evt_ref in family.get_event_ref_list():
            evt_handle = evt_ref.get_reference_handle()
            evt = self.database.get_event_from_handle(evt_handle)
            # FIXME: where are the event types defined in Gramps,
            # and are these the only important ones?
            # print repr(evt.get_type().string)
            if evt.get_type().string in ["Marriage", "Civil Union"]:
                relationship_date = gramps.gen.datehandler.get_date(evt)
        rel_msg = _("%(relationship_type)s on %(relationship_date)s") % {
            "relationship_type": family.get_relationship(),
            "relationship_date": relationship_date,
        }

        self.doc.start_cell("TR-TableCell")
        self.doc.start_paragraph("TR-Normal")
        self.doc.write_text(rel_msg)
        self.doc.end_paragraph()
        self.doc.end_cell()

        self.doc.end_row()
    def write_report(self):
        self.doc.start_paragraph("LOD-Title")
        self.doc.write_text(_("Lines of Descendency from %(ancestor)s to"
        " %(descendent)s" % { 'ancestor' : _nd.display(self.ancestor),
                              'descendent' : _nd.display(self.descendent) }))
        self.doc.end_paragraph()

        self.line = 1

        self.traverse(self.ancestor.get_handle())
Beispiel #10
0
def _get_subject(options, dbase):
    """
    Attempts to determine the subject of a set of options. The subject would
    likely be a person (using a PersonOption) or a filter (using a
    FilterOption)

    options: The ReportOptions class
    dbase: the database for which it corresponds
    """
    if not hasattr(options, "menu"):
        return ""
    menu = options.menu

    option_names = menu.get_all_option_names()
    if not option_names:
        return _("Entire Database")

    for name in option_names:
        option = menu.get_option_by_name(name)

        if isinstance(option, FilterOption):
            return option.get_filter().get_name()

        elif isinstance(option, PersonOption):
            gid = option.get_value()
            person = dbase.get_person_from_gramps_id(gid)
            return _nd.display(person)

        elif isinstance(option, FamilyOption):
            family = dbase.get_family_from_gramps_id(option.get_value())
            if not family:
                return ""
            family_id = family.get_gramps_id()
            fhandle = family.get_father_handle()
            mhandle = family.get_mother_handle()

            if fhandle:
                father = dbase.get_person_from_handle(fhandle)
                father_name = _nd.display(father)
            else:
                father_name = _("unknown father")

            if mhandle:
                mother = dbase.get_person_from_handle(mhandle)
                mother_name = _nd.display(mother)
            else:
                mother_name = _("unknown mother")

            name = _("%(father)s and %(mother)s (%(id)s)") % {
                                                'father' : father_name,
                                                'mother' : mother_name,
                                                'id' : family_id }
            return name

    return ""
Beispiel #11
0
 def get_menu_title(self):
     if self.obj and self.obj.get_handle():
         name = name_displayer.display(self.obj)
         title = _('Person: %(name)s') % {'name': name}
     else:
         name = name_displayer.display(self.obj)
         if name:
             title = _('New Person: %(name)s')  % {'name': name}
         else:
             title = _('New Person')
     return title
Beispiel #12
0
 def get_menu_title(self):
     if self.obj and self.obj.get_handle():
         name = name_displayer.display(self.obj)
         title = _("Person: %(name)s") % {"name": name}
     else:
         name = name_displayer.display(self.obj)
         if name:
             title = _("New Person: %(name)s") % {"name": name}
         else:
             title = _("New Person")
     return title
Beispiel #13
0
    def __rec_fill_data(self, gen, person, pos):
        """
        Recursively fill in the data
        """
        totdesc = 0
        nrfam = len(person.get_family_handle_list())
        self.gen2people[gen][pos][6] = nrfam
        for family_handle in person.get_family_handle_list():
            totdescfam = 0
            family = self.dbstate.db.get_family_from_handle(family_handle)

            spouse_handle = find_spouse(person, family)
            if spouse_handle:
                spouse = self.dbstate.db.get_person_from_handle(spouse_handle)
                spname = name_displayer.display(spouse)
            else:
                spname = ''
                spouse = None
            if family_handle in self.famhandle2desc:
                #family occurs via father and via mother in the chart, only
                #first to show and count.
                famdup = True
            else:
                famdup = False
            # family, duplicate or not, start angle, slice size, 
            #   text, spouse pos in gen, nrchildren, userdata, parnter, status
            self.gen2fam[gen].append([family, famdup, 0, 0, spname, pos, 0, [],
                                      spouse, NORMAL])
            posfam = len(self.gen2fam[gen]) - 1

            if not famdup:
                nrchild = len(family.get_child_ref_list())
                self.gen2fam[gen][-1][6] = nrchild
                for child_ref in family.get_child_ref_list():
                    child = self.dbstate.db.get_person_from_handle(child_ref.ref)
                    chname = name_displayer.display(child)
                    if child_ref.ref in self.handle2desc:
                        dup = True
                    else:
                        dup = False
                        self.handle2desc[child_ref.ref] = 0
                    # person, duplicate or not, start angle, slice size,
                    #         text, parent pos in fam, nrfam, userdata, status
                    self.gen2people[gen+1].append([child, dup, 0, 0, chname, 
                            posfam, 0, [], NORMAL])
                    totdescfam += 1 #add this person as descendant
                    pospers = len(self.gen2people[gen+1]) - 1
                    if not dup and not(self.generations == gen+2):
                        nrdesc = self.__rec_fill_data(gen+1, child, pospers)
                        self.handle2desc[child_ref.ref] += nrdesc
                        totdescfam += nrdesc # add children of him as descendants
                self.famhandle2desc[family_handle] = totdescfam
            totdesc += totdescfam
        return totdesc
    def write_path(self, path):
        gen = 1
        handle = path[0]
        next_person = self.database.get_person_from_handle(path[0])

        self.doc.start_paragraph('LOD-Line')
        self.doc.write_text('%(line)s. line:' % { 'line': self.line })
        self.doc.end_paragraph()
        self.line +=1

        for next_handle in path[1:]:
            person = next_person
            next_person = self.database.get_person_from_handle(next_handle)
            name = _nd.display(person)
            family_handle = next_person.get_main_parents_family_handle()
            family = self.database.get_family_from_handle(family_handle)
            mother = family.get_mother_handle()
            spouse_handle = \
                mother if mother != handle \
                    else family.get_father_handle()
            handle = next_handle
            spouse = self.database.get_person_from_handle(spouse_handle)
            if spouse:
                spouse_name = _nd.display(spouse)
            else:
                spouse_name = 'N.N.'
            if family.get_relationship() == FamilyRelType.MARRIED:
                abbrev = 'm.'
            else:
                abbrev = 'rw.'

            self.doc.start_paragraph("LOD-Entry")

            self.doc.write_text("%(gen)s. %(person)s %(abbrev)s %(spouse)s" % {
                'gen' : gen,
                'person' : name,
                'abbrev' : abbrev,
                'spouse' : spouse_name
                })

            self.doc.end_paragraph()

            gen += 1

        self.doc.start_paragraph("LOD-Entry")
        self.doc.write_text("%(gen)s. %(person)s" % {
            'gen' : gen,
            'person' : _nd.display(next_person)
            })
        self.doc.end_paragraph()
Beispiel #15
0
    def __process_family(self, family, person1, person2, append_list):

        if family.get_handle() in self.__processed_families:
            return

        self.__processed_families[family.get_handle()] = True

        missingbits = []

        if person1 is UnknownPerson or person1 is None:
            name1 = _("(unknown person)")
        else:
            name1 = name_displayer.display(person1)
            if not name1:
                name1 = _("(person with unknown name)")

        if person2 is UnknownPerson or person2 is None:
            name2 = _("(unknown person)")
        else:
            name2 = name_displayer.display(person2)
            if not name2:
                name2 = _("(person with unknown name)")

        name = _("%(name1)s and %(name2)s") % {
                'name1': name1,
                'name2': name2}

        has_marriage = False

        for event_ref in family.get_event_ref_list():
            event = self.dbstate.db.get_event_from_handle(event_ref.ref)
            if event.get_type() not in [EventType.MARRIAGE, EventType.DIVORCE]:
                continue
            missingbits.extend(self.__process_event(event))
            if event.get_type() == EventType.MARRIAGE:
                has_marriage = True

        if family.get_relationship() == FamilyRelType.MARRIED:
            if not has_marriage:
                missingbits.append(_("marriage event missing"))
        elif family.get_relationship() == FamilyRelType.UNKNOWN:
            missingbits.append(_("relation type unknown"))

        if missingbits:
            self.link(name, 'Family', family.get_handle())
            self.append_text(_(": %(list)s\n") % {
                'list': _(", ").join(missingbits)})
            self.__counter += 1

        append_list.append((family, person1, person2))
Beispiel #16
0
 def _createmap_for_one_family(self, family):
     """
     Create all markers for one family : all event's places with a lat/lon.
     """
     dbstate = self.dbstate
     self.message_layer.add_message(_("Family places for %s") % self.family_label(family))
     try:
         person = dbstate.db.get_person_from_handle(family.get_father_handle())
     except:
         return
     family_id = family.gramps_id
     if person is None:  # family without father ?
         person = dbstate.db.get_person_from_handle(family.get_mother_handle())
     if person is None:
         person = dbstate.db.get_person_from_handle(self.uistate.get_active("Person"))
     if person is not None:
         family_list = person.get_family_handle_list()
         if len(family_list) > 0:
             fhandle = family_list[0]  # first is primary
             fam = dbstate.db.get_family_from_handle(fhandle)
             handle = fam.get_father_handle()
             father = dbstate.db.get_person_from_handle(handle)
             if father:
                 comment = _("Father : %(id)s : %(name)s") % {"id": father.gramps_id, "name": _nd.display(father)}
                 self._createpersonmarkers(dbstate, father, comment, family_id)
             handle = fam.get_mother_handle()
             mother = dbstate.db.get_person_from_handle(handle)
             if mother:
                 comment = _("Mother : %(id)s : %(name)s") % {"id": mother.gramps_id, "name": _nd.display(mother)}
                 self._createpersonmarkers(dbstate, mother, comment, family_id)
             index = 0
             child_ref_list = fam.get_child_ref_list()
             if child_ref_list:
                 for child_ref in child_ref_list:
                     child = dbstate.db.get_person_from_handle(child_ref.ref)
                     if child:
                         index += 1
                         comment = _("Child : %(id)s - %(index)d " ": %(name)s") % {
                             "id": child.gramps_id,
                             "index": index,
                             "name": _nd.display(child),
                         }
                         self._createpersonmarkers(dbstate, child, comment, family_id)
         else:
             comment = _("Person : %(id)s %(name)s has no family.") % {
                 "id": person.gramps_id,
                 "name": _nd.display(person),
             }
             self._createpersonmarkers(dbstate, person, comment, family_id)
    def __init__(self, dbstate, user, options_class, name, callback=None):
        uistate = user.uistate
        self.label = _("Associations state tool")
        tool.Tool.__init__(self, dbstate, options_class, name)
        if uistate:
            ManagedWindow.__init__(self,uistate,[],
                                                 self.__class__)

        stats_list = []

        plist = dbstate.db.get_person_handles(sort_handles=True)

        for handle in plist:
            person = dbstate.db.get_person_from_handle(handle)
            name1 = name_displayer.display(person)
            refs = person.get_person_ref_list()
            if refs:
                for ref in person.serialize()[-1]:
                    (a, b, c, two, value) = ref
                    person2 = dbstate.db.get_person_from_handle(two)
                    name2 = name_displayer.display(person2)
                    stats_list.append((name1, value, name2))

        if uistate:
            titles = [
                (_('Name'), 0, 200),
                (_('Type of link'), 1, 200),
                (_('Of'), 2, 200),
                ]

            treeview = Gtk.TreeView()
            model = ListModel(treeview, titles)
            for entry in stats_list:
                model.add(entry, entry[0])

            window = Gtk.Window()
            window.set_default_size(800, 600)
            s = Gtk.ScrolledWindow()
            s.add(treeview)
            window.add(s)
            window.show_all()
            self.set_window(window, None, self.label)
            self.show()

        else:
            print('\t%s'*3 % ('Name','Type of link','Of'))
            print()
            for entry in stats_list:
                print('\t%s'*3 % entry)
Beispiel #18
0
 def goto_handle(self, handle=None):
     """
     Rebuild the tree with the given person handle as the root.
     """
     self.place_list_active = []
     self.place_list_ref = []
     self.all_place_list = []
     self.sort = []
     self.places_found = []
     self.nbmarkers = 0
     self.nbplaces = 0
     self.place_without_coordinates = []
     self.remove_all_gps()
     self.remove_all_markers()
     self.lifeway_layer.clear_ways()
     self.message_layer.clear_messages()
     active = self.get_active()
     if active:
         indiv1 = self.dbstate.db.get_person_from_handle(active)
         color = self._config.get('geography.color2')
         self._createmap(indiv1, color, self.place_list_active, False)
     if self.refperson:
         color = self._config.get('geography.color1')
         self.message_layer.add_message(
                      _("Reference : %(name)s ( %(birth)s - %(death)s )") % {
                              'name': _nd.display(self.refperson),
                              'birth': self.birth(self.refperson),
                              'death': self.death(self.refperson)})
         if indiv1:
             self.message_layer.add_message(
                      _("The other : %(name)s ( %(birth)s - %(death)s )") % {
                              'name': _nd.display(indiv1),
                              'birth': self.birth(indiv1),
                              'death': self.death(indiv1)})
         else:
             self.message_layer.add_message(_("The other person is unknown"))
         self._createmap(self.refperson, color, self.place_list_ref, True)
         if self.refperson_bookmark is None:
             self.refperson_bookmark = self.refperson.get_handle()
             self.add_bookmark_from_popup(None, self.refperson_bookmark)
     else:
         self.message_layer.add_message(
                                  _("You must choose one reference person."))
         self.message_layer.add_message(_("Go to the person view and select "
                                          "the people you want to compare. "
                                          "Return to this view and use the"
                                          " history."))
     self.possible_meeting(self.place_list_ref, self.place_list_active)
     self.uistate.modify_statusbar(self.dbstate)
Beispiel #19
0
 def log(self, ltype, action, handles):
     for handle in set(handles):
         if self.last_log == (ltype, action, handle):
             continue
         self.last_log = (ltype, action, handle)
         self.timestamp()
         # translators: needed for French, ignore otherwise
         self.append_text(_("%s: ") % _(action))
         if action == 'Deleted':
             transaction = self.dbstate.db.transaction
             if ltype == 'Person':
                 name = 'a person'
                 if transaction is not None:
                     for i in transaction.get_recnos(reverse=True):
                         (obj_type, trans_type, hndl, old_data, dummy) = \
                                 transaction.get_record(i)
                         if isinstance(hndl, bytes):
                             hndl = str(hndl, "utf-8")
                         if (obj_type == PERSON_KEY and trans_type == TXNDEL
                                 and hndl == handle):
                             person = Person()
                             person.unserialize(old_data)
                             name = name_displayer.display(person)
                             break
             elif ltype == 'Family':
                 name = 'a family'
                 if transaction is not None:
                     for i in transaction.get_recnos(reverse=True):
                         (obj_type, trans_type, hndl, old_data, dummy) = \
                                 transaction.get_record(i)
                         if isinstance(hndl, bytes):
                             hndl = str(hndl, "utf-8")
                         if (obj_type == FAMILY_KEY and trans_type == TXNDEL
                                 and hndl == handle):
                             family = Family()
                             family.unserialize(old_data)
                             name = family_name(family, self.dbstate.db, name)
                             break
             self.append_text(name)
         else:
             if ltype == 'Person':
                 person = self.dbstate.db.get_person_from_handle(handle)
                 name = name_displayer.display(person)
             elif ltype == 'Family':
                 family = self.dbstate.db.get_family_from_handle(handle)
                 name = family_name(family, self.dbstate.db, 'a family')
             self.link(name, ltype, handle)
         self.append_text("\n")
 def refresh_list(self):
     self.treestore.clear()
     for (i, region) in enumerate(self.regions, start=1):
         name = name_displayer.display(region.person) if region.person else ""
         thumbnail = self.selection_widget.get_thumbnail(region,
                                                         THUMBNAIL_IMAGE_SIZE)
         self.treestore.append(None, (i, thumbnail, name))
Beispiel #21
0
    def ok_clicked(self, obj):
        name = name_displayer.display(self.person)
        msg = _("Reorder Relationships: %s") % name
        with DbTxn(msg, self.dbstate.db) as trans:
            self.dbstate.db.commit_person(self.person, trans)

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

        person_list.sort()

        for person_data in person_list:
            row = person_data[1:2] # handle
            for attr in self.columns:
                if attr == _('Name'):
                    row.append(person_data[3].get(attr, person_data[2]))
                else:
                    row.append(person_data[3].get(attr))
            self.model.append(tuple(row))
Beispiel #23
0
    def __define_person_filters(self):
        """Add person filters if the active person is defined."""

        name = name_displayer.display(self.person)
        gramps_id = self.person.get_gramps_id()

        des = GenericFilter()
        # feature request 2356: avoid genitive form
        des.set_name(_("Descendants of %s") % name)
        des.add_rule(rules.person.IsDescendantOf([gramps_id, 1]))

        df = GenericFilter()
        # feature request 2356: avoid genitive form
        df.set_name(_("Descendant Families of %s") % name)
        df.add_rule(rules.person.IsDescendantFamilyOf([gramps_id, 1]))

        ans = GenericFilter()
        # feature request 2356: avoid genitive form
        ans.set_name(_("Ancestors of %s") % name)
        ans.add_rule(rules.person.IsAncestorOf([gramps_id, 1]))

        com = GenericFilter()
        com.set_name(_("People with common ancestor with %s") % name)
        com.add_rule(rules.person.HasCommonAncestorWith([gramps_id]))

        return [des, df, ans, com]
Beispiel #24
0
    def add_to_tree(self, parent_id, person_handle):
        person = self.dbstate.db.get_person_from_handle(person_handle)
        name = name_displayer.display(person)

        birth = get_birth_or_fallback(self.dbstate.db, person)
        death = get_death_or_fallback(self.dbstate.db, person)

        birth_text = birth_date = birth_sort = ''
        if birth:
            birth_date = get_date(birth)
            birth_sort = '%012d' % birth.get_date_object().get_sort_value()
            birth_text = _('%(abbr)s %(date)s') % \
                         {'abbr': birth.type.get_abbreviation(), 
                          'date': birth_date}

        death_date = death_sort = death_text = ''
        if death:
            death_date = get_date(death)
            death_sort = '%012d' % death.get_date_object().get_sort_value()
            death_text = _('%(abbr)s %(date)s') % \
                         {'abbr': death.type.get_abbreviation(), 
                          'date': death_date}

        tooltip = name + '\n' + birth_text + '\n' + death_text

        item_id = self.model.add([name, birth_date, birth_sort, 
                                  tooltip, person_handle], node=parent_id)

        for family_handle in person.get_family_handle_list():
            family = self.dbstate.db.get_family_from_handle(family_handle)
            for child_ref in family.get_child_ref_list():
                self.add_to_tree(item_id, child_ref.ref)
        return item_id
Beispiel #25
0
 def call_edit_childref(self, ref):
     p = self.dbstate.db.get_person_from_handle(ref.ref)
     n = name_displayer.display(p)
     try:
         EditChildRef(n, self.dbstate, self.uistate, self.track, ref, self.child_ref_edited)
     except WindowActiveError:
         pass
Beispiel #26
0
    def get_data(self):
        if not self._data or self.changed:
            self._data = [self.obj.get_event_ref_list()]
            self._groups = [(self.obj.get_handle(), self._WORKNAME, '')]
            # own family events
            family_handle_list = self.obj.get_family_handle_list()
            if family_handle_list:
                for family_handle in family_handle_list:
                    family = self.dbstate.db.get_family_from_handle(family_handle)
                    if family is None:
                        continue
                    father_handle = family.get_father_handle()
                    mother_handle = family.get_mother_handle()
                    if self.obj.get_handle()  == father_handle:
                        handlepartner = mother_handle
                    else:
                        handlepartner = father_handle
                    if handlepartner:
                        partner = self.dbstate.db.get_person_from_handle(
                                                    handlepartner)
                        groupname = name_displayer.display(partner)
                    else:
                        groupname = self._UNKNOWNNAME
                    self._data.append(family.get_event_ref_list())
                    self._groups.append((family_handle, self._FAMNAME,
                                         groupname))
            self.changed = False

        return self._data
    def prepare_context_menu(self):
        selected = self.selection_widget.get_current()
        self.context_button_add.set_sensitive(selected is not None)
        self.context_button_select.set_sensitive(selected is not None)
        self.context_button_clear.set_sensitive(
          selected is not None and selected.person is not None)
        self.context_button_remove.set_sensitive(selected is not None)

        # clear temporary items
        for item in self.additional_items:
            self.context_menu.remove(item)

        self.additional_items = []

        # populate the context menu
        persons = self.all_referenced_persons()
        if selected.person is not None:
            persons.remove(selected.person)
        if persons:
            self.additional_items.append(Gtk.SeparatorMenuItem())
            sorted_persons = sorted(list(persons), key=name_displayer.display)
            for person in sorted_persons:
                item = Gtk.MenuItem(
                  _("Replace {0}").format(name_displayer.display(person)))
                item.connect("activate", self.replace_reference, person)
                self.additional_items.append(item)
            for item in self.additional_items:
                self.context_menu.append(item)
    def save(self, trans):
        """
        Save the census details to the database.
        """
        # Update people on the census
        all_people = []    
        for order, row in enumerate(self.model):
            all_people.append(row[0])
            person = self.db.get_person_from_handle(row[0])
            event_ref = self.get_census_event_ref(person)
            if event_ref is None:
                # Add new link to census
                event_ref = EventRef()
                event_ref.ref = self.event.get_handle()
                event_ref.set_role(EventRoleType.PRIMARY)
                person.add_event_ref(event_ref)
            # Write attributes
            attrs = event_ref.get_attribute_list()
            set_attribute(event_ref, attrs, ORDER_ATTR, str(order + 1))
            for offset, name in enumerate(self.columns):
                value = row[offset + 1]
                if name == _('Name'):
                    if value != name_displayer.display(person):
                        set_attribute(event_ref, attrs, name, value)
                else:
                    set_attribute(event_ref, attrs, name, value)
            self.db.commit_person(person, trans)

        # Remove links to people no longer on census
        for handle in (set(self.initial_people) - set(all_people)):
            person = self.db.get_person_from_handle(handle)
            ref_list = [event_ref for event_ref in person.get_event_ref_list()
                                if event_ref.ref != self.event.handle]
            person.set_event_ref_list(ref_list)
            self.db.commit_person(person, trans)
Beispiel #29
0
 def _createmap(self, person):
     """
     Create all markers for each family's person in the database which has 
     a lat/lon.
     """
     dbstate = self.dbstate
     self.cal = config.get('preferences.calendar-format-report')
     self.place_list = []
     self.person_list = []
     self.count = dict()
     self.place_without_coordinates = []
     self.minlat = self.maxlat = self.minlon = self.maxlon = 0.0
     latitude = ""
     longitude = ""
     self.message_layer.clear_messages()
     self.place_without_coordinates = []
     self.minlat = self.maxlat = self.minlon = self.maxlon = 0.0
     if person is None:
         person = self.dbstate.db.get_person_from_handle(self.uistate.get_active('Person'))
         if not person:
             return
     self.message_layer.add_message(_("All descendance for %s") % _nd.display(person))
     color = Gdk.color_parse(self._config.get('geography.color_base'))
     GLib.timeout_add(int(self._config.get("geography.generation_interval")),
                      self.animate_moves, 0, person, color)
 def ask_and_set_person(self, region, person):
     if region and person:
         other_references = self.regions_referencing_person(person)
         ref_count = len(other_references)
         if ref_count > 0:
             person = other_references[0].person
             if REPLACE_WITHOUT_ASKING:
                 self.delete_regions(other_references)
             else:
                 if ref_count == 1:
                     message_text = _("Another region of this image is associated with {name}. Remove it?")
                 else:
                     message_text = _("{count} other regions of this image are associated with {name}. Remove them?")
                 message = message_text.format(
                             name=name_displayer.display(person),
                             count=ref_count)
                 dialog = Gtk.MessageDialog(
                             parent=None,
                             type=Gtk.MessageType.QUESTION, 
                             buttons=Gtk.ButtonsType.YES_NO, 
                             message_format=message)
                 response = dialog.run()
                 dialog.destroy()
                 if response == Gtk.ResponseType.YES:
                     self.delete_regions(other_references)
         self.set_person(region, person)
Beispiel #31
0
    def descendants(self, person_handle, pset):
        """
        Find the descendants of a given person.
        Returns False if a loop for the person is NOT found, True if loop found
        We use the return value to ensure a person is not put on done list if
        part of a loop
        """
        if person_handle in self.done:
            return False  # We have already verified no loops for this one
        if person_handle in pset:
            # We found one loop.
            # person_handle is child, self.parent, self.curr_fam valid
            # see if it has already been put into display
            person = self.db.get_person_from_handle(person_handle)
            pers_id = person.get_gramps_id()
            pers_name = _nd.display(person)
            parent_id = self.parent.get_gramps_id()
            parent_name = _nd.display(self.parent)
            value = (parent_id, parent_name, pers_id, pers_name, self.curr_fam)
            found = False
            for pth in range(len(self.model)):
                path = Gtk.TreePath(pth)
                treeiter = self.model.get_iter(path)
                find = (self.model.get_value(treeiter, 0),
                        self.model.get_value(treeiter, 1),
                        self.model.get_value(treeiter, 2),
                        self.model.get_value(treeiter, 3),
                        self.model.get_value(treeiter, 4))
                if find == value:
                    found = True  # This loop is in display model
                    break
            if not found:
                # Need to put loop in display model.
                self.loop += 1
                # place first node
                self.model.append(value + (str(self.loop), ))
                state = 0
                # Now search for loop beginning.
                for hndl in pset.keys():
                    if hndl != person_handle and state == 0:
                        continue  # beginning not found
                    if state == 0:
                        state = 1  # found beginning, get first item to display
                        continue
                    # we have a good handle, now put item on display list
                    self.parent = person
                    person = self.db.get_person_from_handle(hndl)
                    # Get the family that is both parent/person
                    for fam_h in person.get_parent_family_handle_list():
                        if fam_h in self.parent.get_family_handle_list():
                            break
                    family = self.db.get_family_from_handle(fam_h)
                    fam_id = family.get_gramps_id()
                    pers_id = person.get_gramps_id()
                    pers_name = _nd.display(person)
                    parent_id = self.parent.get_gramps_id()
                    parent_name = _nd.display(self.parent)
                    value = (parent_id, parent_name, pers_id, pers_name,
                             fam_id, str(self.loop))
                    self.model.append(value)
            return True
        # We are not part of loop (yet) so search descendents
        person = self.db.get_person_from_handle(person_handle)
        # put in the pset path list for recursive calls to find
        pset[person_handle] = None
        loop = False
        for family_handle in person.get_family_handle_list():
            family = self.db.get_family_from_handle(family_handle)
            if not family:
                # can happen with LivingProxyDb(PrivateProxyDb(db))
                continue
            for child_ref in family.get_child_ref_list():
                child_handle = child_ref.ref
                self.curr_fam = family.get_gramps_id()
                self.parent = person
                # if any descendants are part of loop, so is search person
                loop |= self.descendants(child_handle, pset)
        # we have completed search, we can pop the person off pset list
        person_handle, dummy = pset.popitem(last=True)

        if not loop:
            # person was not in loop, so add to done list and update progress
            self.done.add(person_handle)
            self.count += 1
            self.progress.set_header("%d/%d" % (self.count, self.total))
            self.progress.step()
            return False
        # person was in loop...
        return True
Beispiel #32
0
    def __init__(self, dbstate, uistate, handle1, handle2):
        ManagedWindow.__init__(self, uistate, [], self.__class__)
        self.database = dbstate.db
        self.fy1 = self.database.get_family_from_handle(handle1)
        self.fy2 = self.database.get_family_from_handle(handle2)

        self.define_glade('mergefamily', _GLADE_FILE)
        self.set_window(self._gladeobj.toplevel,
                        self.get_widget("family_title"),
                        _("Merge Families"))

        # Detailed selection widgets
        father1 = self.fy1.get_father_handle()
        father2 = self.fy2.get_father_handle()
        father1 = self.database.get_person_from_handle(father1)
        father2 = self.database.get_person_from_handle(father2)
        father_id1 = father1.get_gramps_id() if father1 else ""
        father_id2 = father2.get_gramps_id() if father2 else ""
        father1 = name_displayer.display(father1) if father1 else ""
        father2 = name_displayer.display(father2) if father2 else ""
        entry1 = self.get_widget("father1")
        entry2 = self.get_widget("father2")
        entry1.set_text("%s [%s]" % (father1, father_id1))
        entry2.set_text("%s [%s]" % (father2, father_id2))
        deactivate = False
        if father_id1 == "" and father_id2 == "":
            deactivate = True
        elif father_id2 == "":
            self.get_widget("father_btn1").set_active(True)
            deactivate = True
        elif father_id1 == "":
            self.get_widget("father_btn2").set_active(True)
            deactivate = True
        elif entry1.get_text() == entry2.get_text():
            deactivate = True
        if deactivate:
            for widget_name in ('father1', 'father2', 'father_btn1',
                    'father_btn2'):
                self.get_widget(widget_name).set_sensitive(False)

        mother1 = self.fy1.get_mother_handle()
        mother2 = self.fy2.get_mother_handle()
        mother1 = self.database.get_person_from_handle(mother1)
        mother2 = self.database.get_person_from_handle(mother2)
        mother_id1 = mother1.get_gramps_id() if mother1 else ""
        mother_id2 = mother2.get_gramps_id() if mother2 else ""
        mother1 = name_displayer.display(mother1) if mother1 else ""
        mother2 = name_displayer.display(mother2) if mother2 else ""
        entry1 = self.get_widget("mother1")
        entry2 = self.get_widget("mother2")
        entry1.set_text("%s [%s]" % (mother1, mother_id1))
        entry2.set_text("%s [%s]" % (mother2, mother_id2))
        deactivate = False
        if mother_id1 == "" and mother_id2 == "":
            deactivate = True
        elif mother_id1 == "":
            self.get_widget("mother_btn2").set_active(True)
            deactivate = True
        elif mother_id2 == "":
            self.get_widget("mother_btn1").set_active(True)
            deactivate = True
        elif entry1.get_text() == entry2.get_text():
            deactivate = True
        if deactivate:
            for widget_name in ('mother1', 'mother2', 'mother_btn1',
                    'mother_btn2'):
                self.get_widget(widget_name).set_sensitive(False)

        entry1 = self.get_widget("rel1")
        entry2 = self.get_widget("rel2")
        entry1.set_text(str(self.fy1.get_relationship()))
        entry2.set_text(str(self.fy2.get_relationship()))
        if entry1.get_text() == entry2.get_text():
            for widget_name in ('rel1', 'rel2', 'rel_btn1', 'rel_btn2'):
                self.get_widget(widget_name).set_sensitive(False)

        gramps1 = self.fy1.get_gramps_id()
        gramps2 = self.fy2.get_gramps_id()
        entry1 = self.get_widget("gramps1")
        entry2 = self.get_widget("gramps2")
        entry1.set_text(gramps1)
        entry2.set_text(gramps2)
        if entry1.get_text() == entry2.get_text():
            for widget_name in ('gramps1', 'gramps2', 'gramps_btn1',
                    'gramps_btn2'):
                self.get_widget(widget_name).set_sensitive(False)

        # Main window widgets that determine which handle survives
        rbutton1 = self.get_widget("handle_btn1")
        rbutton_label1 = self.get_widget("label_handle_btn1")
        rbutton_label2 = self.get_widget("label_handle_btn2")
        add = _("and")
        rbutton_label1.set_label("%s %s %s [%s]" %(father1, add, mother1, gramps1))
        rbutton_label2.set_label("%s %s %s [%s]" %(father2, add, mother2, gramps2))
        rbutton1.connect("toggled", self.on_handle1_toggled)

        self.connect_button("family_help", self.cb_help)
        self.connect_button("family_ok", self.cb_merge)
        self.connect_button("family_cancel", self.close)
        self.show()
Beispiel #33
0
 def _createmap_for_one_event(self, event):
     """
     Create all markers for each people's event in the database which has
     a lat/lon.
     """
     dbstate = self.dbstate
     if self.nbplaces >= self._config.get("geography.max_places"):
         return
     descr1 = descr2 = ""
     if event:
         place_handle = event.get_place_handle()
         eventyear = event.get_date_object().to_calendar(self.cal).get_year()
     else:
         place_handle = None
     if place_handle:
         place = dbstate.db.get_place_from_handle(place_handle)
         if place:
             descr1 = _pd.display(dbstate.db, place)
             longitude = place.get_longitude()
             latitude = place.get_latitude()
             latitude, longitude = conv_lat_lon(latitude, longitude, "D.D8")
             # place.get_longitude and place.get_latitude return
             # one string. We have coordinates when the two values
             # contains non null string.
             if longitude and latitude:
                 person_list = [
                     dbstate.db.get_person_from_handle(ref_handle)
                     for (ref_type, ref_handle) in
                         dbstate.db.find_backlink_handles(event.handle)
                             if ref_type == 'Person'
                               ]
                 if person_list:
                     for person in person_list:
                         if descr2 == "":
                             descr2 = ("%s") % _nd.display(person)
                         else:
                             descr2 = ("%s - %s") % (descr2,
                                                     _nd.display(person))
                 else:
                     # family list ?
                     family_list = [
                         dbstate.db.get_family_from_handle(ref_handle)
                         for (ref_type, ref_handle) in
                             dbstate.db.find_backlink_handles(event.handle)
                                 if ref_type == 'Family'
                                   ]
                     if family_list:
                         for family in family_list:
                             father = mother = None
                             hdle = family.get_father_handle()
                             if hdle:
                                 father = dbstate.db.get_person_from_handle(
                                                                        hdle)
                             hdle = family.get_mother_handle()
                             if hdle:
                                 mother = dbstate.db.get_person_from_handle(
                                                                        hdle)
                             descr2 = ("%(father)s - %(mother)s") % {
                'father': _nd.display(father) if father is not None else "?",
                'mother': _nd.display(mother) if mother is not None else "?"
                                           }
                     else:
                         descr2 = _("incomplete or unreferenced event ?")
                 self._append_to_places_list(descr1, None,
                                             None,
                                             latitude, longitude,
                                             descr2,
                                             eventyear,
                                             event.get_type(),
                                             None, # person.gramps_id
                                             place.gramps_id,
                                             event.gramps_id,
                                             None
                                             )
Beispiel #34
0
 def update_person(self, person):
     if person:
         self.obj.ref = person.get_handle()
         self.person_label.set_text(name_displayer.display(person))
     self._update_dnd_capability()
Beispiel #35
0
 def person_change(self, handles):
     # check to see if the handle matches the current object
     if self.obj.ref in handles:
         p = self.dbstate.db.get_person_from_handle(self.obj.ref)
         self.name = name_displayer.display(p)
         self.name_label.set_text(self.name)
Beispiel #36
0
 def _createmap_for_one_family(self, family):
     """
     Create all markers for one family : all event's places with a lat/lon.
     """
     dbstate = self.dbstate
     self.message_layer.add_message(
                       _("Family places for %s") % self.family_label(family))
     person = None
     if family:
         person = dbstate.db.get_person_from_handle(
                                                  family.get_father_handle())
     else:
         return
     family_id = family.gramps_id
     if person is None: # family without father ?
         handle = family.get_mother_handle()
         if handle:
             person = dbstate.db.get_person_from_handle(handle)
     if person is None:
         handle = self.uistate.get_active('Person')
         if handle:
             person = dbstate.db.get_person_from_handle(handle)
     if person is not None:
         family_list = person.get_family_handle_list()
         if len(family_list) > 0:
             fhandle = family_list[0] # first is primary
             fam = dbstate.db.get_family_from_handle(fhandle)
             father = mother = None
             handle = fam.get_father_handle()
             if handle:
                 father = dbstate.db.get_person_from_handle(handle)
             if father:
                 comment = _("Father : %(id)s : %(name)s") % {
                                                'id': father.gramps_id,
                                                'name': _nd.display(father)}
                 self._createpersonmarkers(dbstate, father,
                                           comment, family_id)
             handle = fam.get_mother_handle()
             if handle:
                 mother = dbstate.db.get_person_from_handle(handle)
             if mother:
                 comment = _("Mother : %(id)s : %(name)s") % {
                                                'id': mother.gramps_id,
                                                'name': _nd.display(mother)}
                 self._createpersonmarkers(dbstate, mother,
                                           comment, family_id)
             index = 0
             child_ref_list = fam.get_child_ref_list()
             if child_ref_list:
                 for child_ref in child_ref_list:
                     child = dbstate.db.get_person_from_handle(child_ref.ref)
                     if child:
                         index += 1
                         comment = _("Child : %(id)s - %(index)d "
                                     ": %(name)s") % {
                                         'id'    : child.gramps_id,
                                         'index' : index,
                                         'name'  : _nd.display(child)
                                      }
                         self._createpersonmarkers(dbstate, child,
                                                   comment, family_id)
         else:
             comment = _("Person : %(id)s %(name)s has no family.") % {
                             'id' : person.gramps_id,
                             'name' : _nd.display(person)
                             }
             self._createpersonmarkers(dbstate, person, comment, family_id)
Beispiel #37
0
 def _createpersonmarkers(self, dbstate, person, comment, fam_id):
     """
     Create all markers for the specified person.
     """
     self.cal = config.get('preferences.calendar-format-report')
     latitude = longitude = ""
     if person:
         # For each event, if we have a place, set a marker.
         for event_ref in person.get_event_ref_list():
             if not event_ref:
                 continue
             role = event_ref.get_role()
             event = dbstate.db.get_event_from_handle(event_ref.ref)
             eyear = event.get_date_object().to_calendar(self.cal).get_year()
             place_handle = event.get_place_handle()
             if place_handle:
                 place = dbstate.db.get_place_from_handle(place_handle)
                 if place:
                     longitude = place.get_longitude()
                     latitude = place.get_latitude()
                     latitude, longitude = conv_lat_lon(latitude,
                                                        longitude, "D.D8")
                     descr = _pd.display(dbstate.db, place)
                     evt = EventType(event.get_type())
                     descr1 = _("%(eventtype)s : %(name)s") % {
                                     'eventtype': evt,
                                     'name': _nd.display(person)}
                     # place.get_longitude and place.get_latitude return
                     # one string. We have coordinates when the two values
                     # contains non null string.
                     if longitude and latitude:
                         if not self._present_in_places_list(2,
                                             str(descr1 + descr + str(evt))):
                             self._append_to_places_list(descr,
                                 str(descr1 + descr + str(evt)),
                                 _nd.display(person),
                                 latitude, longitude,
                                 role, eyear,
                                 event.get_type(),
                                 person.gramps_id,
                                 place.gramps_id,
                                 event.gramps_id,
                                 fam_id
                                 )
                     else:
                         self._append_to_places_without_coord(
                                                     place.gramps_id, descr)
         family_list = person.get_family_handle_list()
         for family_hdl in family_list:
             family = self.dbstate.db.get_family_from_handle(family_hdl)
             if family is not None:
                 for event_ref in family.get_event_ref_list():
                     if event_ref:
                         event = dbstate.db.get_event_from_handle(
                                                               event_ref.ref)
                         role = event_ref.get_role()
                         if event.get_place_handle():
                             place_handle = event.get_place_handle()
                             if place_handle:
                                 place = dbstate.db.get_place_from_handle(
                                                                place_handle)
                                 if place:
                                     longitude = place.get_longitude()
                                     latitude = place.get_latitude()
                                     (latitude,
                                      longitude) = conv_lat_lon(latitude,
                                                                longitude,
                                                                "D.D8")
                                     descr = _pd.display(dbstate.db, place)
                                     evt = EventType(event.get_type())
                                     (father_name,
                       mother_name) = self._get_father_and_mother_name(event)
                                     descr1 = "%s : %s - " % (evt,
                                                              father_name)
                                     descr1 = "%s%s" % (descr1, mother_name)
                                     eyear = event.get_date_object().to_calendar(self.cal).get_year()
                                     if longitude and latitude:
                                         if not self._present_in_places_list(
                                          2, str(descr1 + descr + str(evt))):
                                             self._append_to_places_list(
                                              descr,
                                              str(descr1 + descr + str(evt)),
                                              _nd.display(person),
                                              latitude, longitude,
                                              role, eyear,
                                              event.get_type(),
                                              person.gramps_id,
                                              place.gramps_id,
                                              event.gramps_id,
                                              family.gramps_id
                                              )
                                     else:
                                         self._append_to_places_without_coord(place.gramps_id, descr)
Beispiel #38
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
Beispiel #39
0
 def _createmap_for_one_family(self, family, color, place_list, reference):
     """
     Create all markers for one family : all event's places with a lat/lon.
     """
     dbstate = self.dbstate
     try:
         person = dbstate.db.get_person_from_handle(
             family.get_father_handle())
     except:
         return
     family_id = family.gramps_id
     if person is None:  # family without father ?
         person = dbstate.db.get_person_from_handle(
             family.get_mother_handle())
     if person is None:
         person = dbstate.db.get_person_from_handle(
             self.uistate.get_active('Person'))
     if person is not None:
         family_list = person.get_family_handle_list()
         if len(family_list) > 0:
             fhandle = family_list[0]  # first is primary
             fam = dbstate.db.get_family_from_handle(fhandle)
             handle = fam.get_father_handle()
             father = dbstate.db.get_person_from_handle(handle)
             if father:
                 comment = _("Father : %(id)s : %(name)s") % {
                     'id': father.gramps_id,
                     'name': _nd.display(father)
                 }
                 self._createmap_for_one_person(father, color, place_list,
                                                reference)
             handle = fam.get_mother_handle()
             mother = dbstate.db.get_person_from_handle(handle)
             if mother:
                 comment = _("Mother : %(id)s : %(name)s") % {
                     'id': mother.gramps_id,
                     'name': _nd.display(mother)
                 }
                 self._createmap_for_one_person(mother, color, place_list,
                                                reference)
             index = 0
             child_ref_list = fam.get_child_ref_list()
             if child_ref_list:
                 for child_ref in child_ref_list:
                     child = dbstate.db.get_person_from_handle(
                         child_ref.ref)
                     if child:
                         index += 1
                         comment = _("Child : %(id)s - %(index)d "
                                     ": %(name)s") % {
                                         'id': child.gramps_id,
                                         'index': index,
                                         'name': _nd.display(child)
                                     }
                         self._createmap_for_one_person(
                             child, color, place_list, reference)
         else:
             comment = _("Person : %(id)s %(name)s has no family.") % {
                 'id': person.gramps_id,
                 'name': _nd.display(person)
             }
             self._createmap_for_one_person(person, color, place_list,
                                            reference)
Beispiel #40
0
 def init_report_options_help(self):
     """
     Initialize help for the options that are defined by each report.
     (And also any docgen options, if defined by the docgen.)
     """
     if not hasattr(self.option_class, "menu"):
         return
     menu = self.option_class.menu
     for name in menu.get_all_option_names():
         option = menu.get_option_by_name(name)
         self.options_help[name] = [ "", option.get_help() ]
         
         if isinstance(option, PersonOption):
             id_list = []
             for person_handle in self.database.get_person_handles(True):
                 person = self.database.get_person_from_handle(person_handle)
                 id_list.append("%s\t%s" % (
                     person.get_gramps_id(),
                     name_displayer.display(person)))
             self.options_help[name].append(id_list)
         elif isinstance(option, FamilyOption):
             id_list = []
             for family in self.database.iter_families():
                 mname = ""
                 fname = ""
                 mhandle = family.get_mother_handle()
                 if mhandle:
                     mother = self.database.get_person_from_handle(mhandle)
                     if mother:
                         mname = name_displayer.display(mother)
                 fhandle = family.get_father_handle()
                 if fhandle:
                     father = self.database.get_person_from_handle(fhandle)
                     if father:
                         fname = name_displayer.display(father)
                 text = "%s:\t%s, %s" % \
                     (family.get_gramps_id(), fname, mname)
                 id_list.append(text)
             self.options_help[name].append(id_list)
         elif isinstance(option, NoteOption):
             id_list = []
             for nhandle in self.database.get_note_handles():
                 note = self.database.get_note_from_handle(nhandle)
                 id_list.append(note.get_gramps_id())
             self.options_help[name].append(id_list)
         elif isinstance(option, MediaOption):
             id_list = []
             for mhandle in self.database.get_media_object_handles():
                 mobject = self.database.get_object_from_handle(mhandle)
                 id_list.append(mobject.get_gramps_id())
             self.options_help[name].append(id_list)
         elif isinstance(option, PersonListOption):
             self.options_help[name].append("")
         elif isinstance(option, NumberOption):
             self.options_help[name].append("A number")
         elif isinstance(option, BooleanOption):
             self.options_help[name].append(["False", "True"])
         elif isinstance(option, DestinationOption):
             self.options_help[name].append("A file system path")
         elif isinstance(option, StringOption):
             self.options_help[name].append("Any text")
         elif isinstance(option, TextOption):
             self.options_help[name].append(
                 "A list of text values. Each entry in the list "
                 "represents one line of text." )
         elif isinstance(option, EnumeratedListOption):
             ilist = []
             for (value, description) in option.get_items():
                 ilist.append("%s\t%s" % (value, description))
             self.options_help[name].append(ilist)
         elif isinstance(option, Option):
             self.options_help[name].append(option.get_help())
         else:
             print(_("Unknown option: %s") % option, file=sys.stderr)
             print(_("   Valid options are:") +
                   ", ".join(list(self.options_dict.keys())),
                                                     file=sys.stderr)
             print(_("   Use '%(donottranslate)s' to see description "
                     "and acceptable values")
                            % {'donottranslate' : "show=option"},
                                                     file=sys.stderr)
Beispiel #41
0
    def __init__(self, dbstate, user, options_class, name, callback=None):
        uistate = user.uistate
        """
        Relationship calculator class.
        """

        tool.Tool.__init__(self, dbstate, options_class, name)
        ManagedWindow.__init__(self,uistate,[],self.__class__)

        #set the columns to see
        for data in BasePersonView.CONFIGSETTINGS:
            if data[0] == 'columns.rank':
                colord = data[1]
            elif data[0] == 'columns.visible':
                colvis = data[1]
            elif data[0] == 'columns.size':
                colsize = data[1]
        self.colord = []
        for col, size in zip(colord, colsize):
            if col in colvis:
                self.colord.append((1, col, size))
            else:
                self.colord.append((0, col, size))

        self.dbstate = dbstate
        self.relationship = get_relationship_calculator(glocale)
        self.relationship.connect_db_signals(dbstate)

        self.glade = Glade()
        self.person = self.db.get_person_from_handle(
                                            uistate.get_active('Person'))
        name = ''
        if self.person:
            name = name_displayer.display(self.person)
        self.title = _('Relationship calculator: %(person_name)s'
                       ) % {'person_name' : name}
        window = self.glade.toplevel
        self.titlelabel = self.glade.get_object('title')
        self.set_window(window, self.titlelabel,
                        _('Relationship to %(person_name)s'
                          ) % {'person_name' : name},
                        self.title)
        self.setup_configs('interface.relcalc', 600, 400)

        self.tree = self.glade.get_object("peopleList")
        self.text = self.glade.get_object("text1")
        self.textbuffer = Gtk.TextBuffer()
        self.text.set_buffer(self.textbuffer)

        self.model = PersonTreeModel(self.db)
        self.tree.set_model(self.model)

        self.tree.connect('key-press-event', self._key_press)
        self.selection = self.tree.get_selection()
        self.selection.set_mode(Gtk.SelectionMode.SINGLE)

        #keep reference of column so garbage collection works
        self.columns = []
        for pair in self.colord:
            if not pair[0]:
                continue
            name = column_names[pair[1]]
            column = Gtk.TreeViewColumn(name, Gtk.CellRendererText(),
                                        markup=pair[1])
            column.set_resizable(True)
            column.set_min_width(60)
            column.set_sizing(Gtk.TreeViewColumnSizing.GROW_ONLY)
            self.tree.append_column(column)
            #keep reference of column so garbage collection works
            self.columns.append(column)

        self.sel = self.tree.get_selection()
        self.changedkey = self.sel.connect('changed',self.on_apply_clicked)
        self.closebtn = self.glade.get_object("button5")
        self.closebtn.connect('clicked', self.close)

        if not self.person:
            self.window.hide()
            ErrorDialog(_('Active person has not been set'),
                        _('You must select an active person for this '
                          'tool to work properly.'),
                        parent=uistate.window)
            self.close()
            return

        self.show()
 def person_name(self, person_handle):
     if not person_handle: return ""
     person = self.dbstate.db.get_person_from_handle(person_handle)
     return name_displayer.display(person)
Beispiel #43
0
    def _createmap(self):
        """
        Create all markers for each people's event in the database which has
        a lat/lon.
        """
        dbstate = self.dbstate
        self.cal = config.get('preferences.calendar-format-report')
        self.place_list = []
        self.place_without_coordinates = []
        self.places_found = []
        self.minlat = self.maxlat = self.minlon = self.maxlon = 0.0
        self.minyear = 9999
        self.maxyear = 0
        latitude = ""
        longitude = ""
        self.nbplaces = 0
        self.nbmarkers = 0
        self.message_layer.clear_messages()
        self.kml_layer.clear()
        person_handle = self.uistate.get_active('Person')
        person = None
        if person_handle:
            person = dbstate.db.get_person_from_handle(person_handle)
        if person is not None:
            # For each event, if we have a place, set a marker.
            self.load_kml_files(person)
            self.message_layer.add_message(
                _("Person places for %s") % _nd.display(person))
            for event_ref in person.get_event_ref_list():
                if not event_ref:
                    continue
                event = dbstate.db.get_event_from_handle(event_ref.ref)
                self.load_kml_files(event)
                role = event_ref.get_role()
                eyear = str("%04d" % event.get_date_object().to_calendar(self.cal).get_year()) + \
                          str("%02d" % event.get_date_object().to_calendar(self.cal).get_month()) + \
                          str("%02d" % event.get_date_object().to_calendar(self.cal).get_day())
                place_handle = event.get_place_handle()
                if place_handle:
                    place = dbstate.db.get_place_from_handle(place_handle)
                    if place:
                        longitude = place.get_longitude()
                        latitude = place.get_latitude()
                        latitude, longitude = conv_lat_lon(
                            latitude, longitude, "D.D8")
                        descr = _pd.display(dbstate.db, place)
                        evt = EventType(event.get_type())
                        descr1 = _("%(eventtype)s : %(name)s") % {
                            'eventtype': evt,
                            'name': _nd.display(person)
                        }
                        self.load_kml_files(place)
                        # place.get_longitude and place.get_latitude return
                        # one string. We have coordinates when the two values
                        # contains non null string.
                        if (longitude and latitude):
                            self._append_to_places_list(
                                descr, evt, _nd.display(person),
                                latitude, longitude, descr1, eyear,
                                event.get_type(), person.gramps_id,
                                place.gramps_id, event.gramps_id, role)
                        else:
                            self._append_to_places_without_coord(
                                place.gramps_id, descr)
            family_list = person.get_family_handle_list()
            for family_hdl in family_list:
                family = self.dbstate.db.get_family_from_handle(family_hdl)
                if family is not None:
                    fhandle = family_list[0]  # first is primary
                    fam = dbstate.db.get_family_from_handle(fhandle)
                    father = mother = None
                    handle = fam.get_father_handle()
                    if handle:
                        father = dbstate.db.get_person_from_handle(handle)
                    descr1 = " - "
                    if father:
                        descr1 = "%s - " % _nd.display(father)
                    handle = fam.get_mother_handle()
                    if handle:
                        mother = dbstate.db.get_person_from_handle(handle)
                    if mother:
                        descr1 = "%s%s" % (descr1, _nd.display(mother))
                    for event_ref in family.get_event_ref_list():
                        if event_ref:
                            event = dbstate.db.get_event_from_handle(
                                event_ref.ref)
                            self.load_kml_files(event)
                            role = event_ref.get_role()
                            if event.get_place_handle():
                                place_handle = event.get_place_handle()
                                if place_handle:
                                    place = dbstate.db.get_place_from_handle(
                                        place_handle)
                                    if place:
                                        longitude = place.get_longitude()
                                        latitude = place.get_latitude()
                                        latitude, longitude = conv_lat_lon(
                                            latitude, longitude, "D.D8")
                                        descr = _pd.display(dbstate.db, place)
                                        evt = EventType(event.get_type())
                                        eyear = str("%04d" % event.get_date_object().to_calendar(self.cal).get_year()) + \
                                                  str("%02d" % event.get_date_object().to_calendar(self.cal).get_month()) + \
                                                  str("%02d" % event.get_date_object().to_calendar(self.cal).get_day())
                                        self.load_kml_files(place)
                                        if (longitude and latitude):
                                            self._append_to_places_list(
                                                descr, evt,
                                                _nd.display(person), latitude,
                                                longitude, descr1, eyear,
                                                event.get_type(),
                                                person.gramps_id,
                                                place.gramps_id,
                                                event.gramps_id, role)
                                        else:
                                            self._append_to_places_without_coord(
                                                place.gramps_id, descr)

            self.sort = sorted(self.place_list, key=operator.itemgetter(6))
            self._create_markers()
Beispiel #44
0
    def __do_save(self):
        self.ok_button.set_sensitive(False)

        if not self.added:
            original = self.db.get_family_from_handle(self.obj.handle)
        else:
            original = None

        # do some basic checks

        child_list = [ref.ref for ref in self.obj.get_child_ref_list()]

        if self.obj.get_father_handle() in child_list:

            father = self.db.get_person_from_handle(
                self.obj.get_father_handle())
            name = "%s [%s]" % (name_displayer.display(father),
                                father.gramps_id)
            ErrorDialog(
                _("A father cannot be his own child"),
                _("%s is listed as both the father and child "
                  "of the family.") % name)
            self.ok_button.set_sensitive(True)
            return
        elif self.obj.get_mother_handle() in child_list:

            mother = self.db.get_person_from_handle(
                self.obj.get_mother_handle())
            name = "%s [%s]" % (name_displayer.display(mother),
                                mother.gramps_id)
            ErrorDialog(
                _("A mother cannot be her own child"),
                _("%s is listed as both the mother and child "
                  "of the family.") % name)
            self.ok_button.set_sensitive(True)
            return

        if not original and self.object_is_empty():
            ErrorDialog(
                _("Cannot save family"),
                _("No data exists for this family. "
                  "Please enter data or cancel the edit."))
            self.ok_button.set_sensitive(True)
            return

        (uses_dupe_id, id) = self._uses_duplicate_id()
        if uses_dupe_id:
            msg1 = _("Cannot save family. ID already exists.")
            msg2 = _("You have attempted to use the existing Gramps ID with "
                     "value %(id)s. This value is already used. Please "
                     "enter a different ID or leave "
                     "blank to get the next available ID value.") % {
                         'id': id
                     }
            ErrorDialog(msg1, msg2)
            self.ok_button.set_sensitive(True)
            return

        # We disconnect the callbacks to all signals we connected earlier.
        # This prevents the signals originating in any of the following
        # commits from being caught by us again.
        self._cleanup_callbacks()

        if not original and not self.object_is_empty():
            with DbTxn(_("Add Family"), self.db) as trans:

                # find the father, add the family handle to the father
                handle = self.obj.get_father_handle()
                if handle:
                    parent = self.db.get_person_from_handle(handle)
                    parent.add_family_handle(self.obj.handle)
                    self.db.commit_person(parent, trans)

                # find the mother, add the family handle to the mother
                handle = self.obj.get_mother_handle()
                if handle:
                    parent = self.db.get_person_from_handle(handle)
                    parent.add_family_handle(self.obj.handle)
                    self.db.commit_person(parent, trans)

                # for each child, add the family handle to the child
                for ref in self.obj.get_child_ref_list():
                    child = self.db.get_person_from_handle(ref.ref)
                    # fix - relationships need to be extracted from the list
                    child.add_parent_family_handle(self.obj.handle)
                    self.db.commit_person(child, trans)

                self.db.add_family(self.obj, trans)
        elif original.serialize() != self.obj.serialize():

            with DbTxn(_("Edit Family"), self.db) as trans:

                self.fix_parent_handles(original.get_father_handle(),
                                        self.obj.get_father_handle(), trans)
                self.fix_parent_handles(original.get_mother_handle(),
                                        self.obj.get_mother_handle(), trans)

                orig_set = set(original.get_child_ref_list())
                new_set = set(self.obj.get_child_ref_list())

                # remove the family from children which have been removed
                for ref in orig_set.difference(new_set):
                    person = self.db.get_person_from_handle(ref.ref)
                    person.remove_parent_family_handle(self.obj.handle)
                    self.db.commit_person(person, trans)

                # add the family to children which have been added
                for ref in new_set.difference(orig_set):
                    person = self.db.get_person_from_handle(ref.ref)
                    person.add_parent_family_handle(self.obj.handle)
                    self.db.commit_person(person, trans)

                if self.object_is_empty():
                    self.db.remove_family_relationships(self.obj.handle, trans)
                else:
                    if not self.obj.get_gramps_id():
                        self.obj.set_gramps_id(
                            self.db.find_next_family_gramps_id())
                    self.db.commit_family(self.obj, trans)

        self._do_close()
        if self.callback:
            self.callback(self.obj)
        self.callback = None
Beispiel #45
0
    def listpersonref(self):

        sc = {'source': 'S_ID',
              'citalist': 'C_ID' }
        stc = {}      
        citation_without_notes = 0
        EMPTY = " "

        def toYear(date):
            yeartext = date.get_year()
            return yeartext         

        def toNbr(text):
            text = text[1:]
            while text[0] == "0":
                text = text[1:]
            return text         


        genderlist = ['F','M','X']
     # build citasource dictionary  and cl list 
        
        sc = defaultdict(list)
        cl = []
        i=1
        for ci in self.__db.iter_citations():
            if ci.source_handle in self.source_handles:
                sc[ci.source_handle].append(ci.handle)
                cl.append(ci.handle)

        # build citations - event dic                       xy
        #(a,b): set([('Citation', 'c4a8c46041e08799b17')]) 
        # event: c4a8c4f95b01e38564a event: Taufe
        ci = defaultdict(list)
        for ev in self.__db.iter_events():
            refhandlelist = ev.get_referenced_handles()   
            for (a,b) in refhandlelist:
                if a == 'Citation':
                    if b in cl:                    #!
                        ci[ev.handle].append(b)
        ci_evkeys = ci.keys()                

#***********************************************************************
#       # build godparentsdict of all persons
#

        gpdic ={}
        gpdic = defaultdict(list)
        for pe in self.__db.get_person_handles():
            for eventref in self.__db.get_person_from_handle(pe).event_ref_list:
                if not eventref.get_role().is_primary():
                    if eventref.get_role() == "Pate":
                        gpdic[eventref.ref].append((eventref.get_role(),pe))
        gpdickeys = gpdic.keys()

        for i in gpdic.keys():
            print(self.__db.get_event_from_handle(i).get_date_object())
            for (a,b) in gpdic[i]:
                print("TEIL     ",a
                        ,name_displayer.display(self.__db.get_person_from_handle(b))
                        ,self.__db.get_person_from_handle(b).gramps_id)
        print("GPDIC   ",len(gpdickeys))



#***********************************************************************
#       # build family list of all families with familyevent in citation
#
#       a    family handle
#
        famlist =[]
#        famdic = {}
        for fh in self.__db.get_family_handles():
            for eventref in self.__db.get_family_from_handle(fh).event_ref_list:
                if eventref.ref in ci_evkeys:
                    famlist.append(fh)
        # Each family only once
        famlist = list(set(famlist))
#        for fi,f in enumerate(famlist):
#            famdic[f]=fi

#***********************************************************************
#       # build pedic of all persons in families with familyevent in citation
#
#       k    gramps_id
#       v    1...n

        pedic ={}

        self.doc.start_paragraph("SRC-SourceTitle")
        self.doc.write_text(_("Person with Citations"))
        self.doc.end_paragraph()       

        indexlist = list()


        self.doc.start_table("Corpus Attributes", "SRC-VISONETable")
        name_list =["Zeile 1", "Zeile 2"]
        self.progress.set_pass(_('Start Table Corpus'), len(name_list))
        for nl in name_list:
            self.doc.start_row()
            self.doc.start_cell("SRC-TableColumn")
            self.doc.start_paragraph("SRC-ColumnTitle")
            self.doc.write_text(nl)
            self.doc.end_paragraph()
            self.doc.end_cell()
            self.doc.end_row()                 
        self.doc.end_table()


        self.progress.set_pass(_('Start Table Families'), len(famlist))

        self.doc.start_table("Families", "SRC-VISONETable")
##        column_titles = [_("Prim_ID"), _("Gramps_ID"),  _("Role"), _("Relation"), _("LNr"), _("Ev ID"),_("Event"), _("Date"), _("Year"), _("Age Primary"), _("Age Person"), _("gender Primary"), _("gender Person") , _("Person"),_("Primary"), _("Person birth"), _("Person Clan"),_("Primary Clan"),_("Event Place"),_("FamID"),_("AnzKind")] 
        column_titles = [_("Id"), "Status", "FatherId", "MotherId", "Children", "HUSB_ORD", "WIFE_ORD", _("Fam_ID"), _("Father_ID"), _("Mother_ID"), _("Children_ID")] 

        i = 0
        self.doc.start_row()
        for title in column_titles:
            self.doc.start_cell("SRC-TableColumn")
            self.doc.start_paragraph("SRC-ColumnTitle")
            self.doc.write_text(title)
            self.doc.end_paragraph()
            self.doc.end_cell()
        self.doc.end_row()                 
        i=0 
        ii=0
        

        fid = 0
        for f in sorted(famlist):
            famidtext = ""
            fathernametxt = ""
            mothernametxt = ""
            fatheridtxt = ""
            motheridtxt = ""
            childtxt = ""
            fatherordertxt = ""
            motherordertxt = ""
            
            family = self.__db.get_family_from_handle(f)
            famidtxt = (" [%s]" % family.gramps_id)
            famreltxt = family.get_relationship()
            if famreltxt == "Verheiratet":
                famreltxt = "M"
            elif famreltxt == "Unverheiratet":
#                print(famreltxt)
                famreltxt = " "
#                print("FAM    ",famreltxt)
            elif famreltxt == "Unbekannt":
                famreltxt = " "
            if family.get_father_handle():
                fathernametxt = fathernametxt + self.__db.get_person_from_handle(family.get_father_handle()).primary_name.get_name()
                famhandlelist = self.__db.get_person_from_handle(family.get_father_handle()).get_family_handle_list()
                fatherordertxt = ("%s" % len(famhandlelist))
                fatheridtxt = self.__db.get_person_from_handle(family.get_father_handle()).gramps_id
                indexlist.append(fatheridtxt)
                fatheridtxt = toNbr(fatheridtxt)

            if family.get_mother_handle():
                mothernametxt = mothernametxt + self.__db.get_person_from_handle(family.get_mother_handle()).primary_name.get_name()
                famhandlelist = self.__db.get_person_from_handle(family.get_mother_handle()).get_family_handle_list()
                motheridtxt = self.__db.get_person_from_handle(family.get_mother_handle()).gramps_id
                motherordertxt = ("%s" % len(famhandlelist))
                indexlist.append(motheridtxt)
                motheridtxt = toNbr(motheridtxt)
                # BUG only count not order
            childtxt =""
            for ch in family.get_child_ref_list():
                child = self.__db.get_person_from_handle(ch.ref)
                if child:
                    childtxt1 = child.get_gramps_id()
                    childtxt1 = childtxt1 + ";"
                    indexlist.append(child.get_gramps_id())
                    childtxt1 = toNbr(childtxt1)
                    childtxt = childtxt + childtxt1
            fid += 1
            line = []
            line.append(fid)
            line.append(famreltxt)
            line.append(fatheridtxt)
            line.append(motheridtxt)
            line.append(childtxt)
            line.append(fatherordertxt)
            line.append(motherordertxt) 
            line.append(famidtxt)
            line.append(fathernametxt)
            line.append(mothernametxt)


            self.doc.start_row()
            for l in line:
                self.doc.start_cell("SRC-Cell")
                self.doc.start_paragraph("SRC-SourceDetails")
                self.doc.write_text(_("%s") %
                                    l)
                self.doc.end_paragraph()
                self.doc.end_cell()
            self.doc.end_row()
            self.progress.step()

        self.doc.end_table()

        self.doc.start_table("Individuals", "SRC-VISONETable")
        column_titles = [_("Id"), "Name", "Gender", "ORD", "BIRT_DATE", "BIRT_PLACE", "DEAT_DATE", "DEAT_PLACE", "OCCU", "PersonID2"]
#   Id	Name	Gender	ORD	BIRT_DATE	Rolle	PersonID2


        i = 0
        self.doc.start_row()
        for title in column_titles:
            self.doc.start_cell("SRC-TableColumn")
            self.doc.start_paragraph("SRC-ColumnTitle")
            self.doc.write_text(title)
            self.doc.end_paragraph()
            self.doc.end_cell()
        self.doc.end_row()                 


        l = len(indexlist)
        indexlist = list(set(indexlist))

        self.progress.set_pass(_('Start Table Individuals'), len(indexlist))

#        for m in indexlist:
#            print(m)
        pi = 1
        for il in indexlist:
            self.doc.start_row()
            person = self.__db.get_person_from_gramps_id(il)
            

# Id
            self.doc.start_cell("SRC-Cell")
            self.doc.start_paragraph("SRC-SourceDetails")
            self.doc.write_text(_("%s") %
                                toNbr(il))
            self.doc.end_paragraph()
            self.doc.end_cell()

# Name
            self.doc.start_cell("SRC-Cell")
            self.doc.start_paragraph("SRC-SourceDetails")
            self.doc.write_text(_("%s") %
                                person.primary_name.get_gedcom_name())
            self.doc.end_paragraph()
            self.doc.end_cell()

# Gender
            self.doc.start_cell("SRC-Cell")
            self.doc.start_paragraph("SRC-SourceDetails")
            self.doc.write_text(_("%s") %
                                    genderlist[person.get_gender()])
            self.doc.end_paragraph()
            self.doc.end_cell()

# Ord
            self.doc.start_cell("SRC-Cell")
            self.doc.start_paragraph("SRC-SourceDetails")
            self.doc.write_text(_("%s") %
                                " ")
#                                person.primary_name.get_name())
            self.doc.end_paragraph()
            self.doc.end_cell()

# Birth Date
            self.doc.start_cell("SRC-Cell")
            self.doc.start_paragraph("SRC-SourceDetails")
            birth_ref = person.get_birth_ref()
            birth_date = None
            birthtxt = " "
            birthplacetxt = " "
            if birth_ref:
                birthtxt = self.__format_date(self.__db.get_event_from_handle(birth_ref.ref).get_date_object())
#                birthplacetxt = self.find_place(self.__db.get_event_from_handle(birth_ref.ref).place)
                birthplacetxt = place_displayer.display_event(self.__db, self.__db.get_event_from_handle(birth_ref.ref), self.pl_format)

            self.doc.write_text(_("%s") %
                                birthtxt)
            self.doc.end_paragraph()
            self.doc.end_cell()
            


# Place of Event
            self.doc.start_cell("SRC-Cell")
            self.doc.start_paragraph("SRC-SourceDetails")
            self.doc.write_text(_("%s") %
                         birthplacetxt[4:-2])
            self.doc.end_paragraph()
            self.doc.end_cell()

# Death Date
            self.doc.start_cell("SRC-Cell")
            self.doc.start_paragraph("SRC-SourceDetails")
            death_ref = person.get_death_ref()
            death_date = None
            deathtxt = " "
            deathplacetxt = " "
            if death_ref:
                deathtxt = self.__format_date(self.__db.get_event_from_handle(death_ref.ref).get_date_object())
                deathplacetxt = place_displayer.display_event(self.__db, self.__db.get_event_from_handle(death_ref.ref), self.pl_format)
            self.doc.write_text(_("%s") %
                                deathtxt)
            self.doc.end_paragraph()
            self.doc.end_cell()


# Place of Event
            self.doc.start_cell("SRC-Cell")
            self.doc.start_paragraph("SRC-SourceDetails")
            self.doc.write_text(_("%s") %
                         deathplacetxt[4:-2])
            self.doc.end_paragraph()
            self.doc.end_cell()


# Occupation
            self.doc.start_cell("SRC-Cell")
            self.doc.start_paragraph("SRC-SourceDetails")
            self.doc.write_text(_("%s") %
                         self.find_occupation(person))
            self.doc.end_paragraph()
            self.doc.end_cell()


# Person_ID
            self.doc.start_cell("SRC-Cell")
            self.doc.start_paragraph("SRC-SourceDetails")
            self.doc.write_text(_("%s") %
                                il)
            self.doc.end_paragraph()
            self.doc.end_cell()


            self.doc.end_row()
            pi += 1

        print (l,len(indexlist))
        self.progress.step()
        self.doc.end_table()

        self.progress.set_pass(_('Start Table Relation'), len(indexlist))

        self.doc.start_table("Relation", "SRC-VISONETable")
        column_titles = [_("Id"), "Name", "Candidate", "Godparent", "#DATE"]
#_("Id"), "Name", "Candidate", "Godparent", "#DATE"
#
#
        self.doc.start_row()
        self.doc.start_cell("SRC-TableColumn")
        self.doc.start_paragraph("SRC-ColumnTitle")
        self.doc.write_text("Patenschaften")
        self.doc.end_paragraph()
        self.doc.end_cell()
        self.doc.end_row()
#
        i = 0
        self.doc.start_row()
        for title in column_titles:
            self.doc.start_cell("SRC-TableColumn")
            self.doc.start_paragraph("SRC-ColumnTitle")
            self.doc.write_text(title)
            self.doc.end_paragraph()
            self.doc.end_cell()
        self.doc.end_row()


        l = len(indexlist)
        indexlist = list(set(indexlist))
#        for m in indexlist:
#            print(m)
        pi = 1
        for il in indexlist:
            person = self.__db.get_person_from_gramps_id(il)
            for eventref in person.get_event_ref_list():
                event = self.__db.get_event_from_handle(eventref.ref)
##                if event and event.type.is_baptism():
                if event.type.is_baptism():

                    self.doc.start_row()
# EventId
                    self.doc.start_cell("SRC-Cell")
                    self.doc.start_paragraph("SRC-SourceDetails")
                    self.doc.write_text(_("%s") %
                                        toNbr(event.gramps_id))
                    self.doc.end_paragraph()
                    self.doc.end_cell()

# Name
                    self.doc.start_cell("SRC-Cell")
                    self.doc.start_paragraph("SRC-SourceDetails")
                    self.doc.write_text(_("Bapt %s") %
                                        event.get_description())
                    self.doc.end_paragraph()
                    self.doc.end_cell()

# Candidate
                    self.doc.start_cell("SRC-Cell")
                    self.doc.start_paragraph("SRC-SourceDetails")
                    self.doc.write_text(_("%s") %
                                        toNbr(il))
                    self.doc.end_paragraph()
                    self.doc.end_cell()

# Godparents


                    patentxt =""
                    for i in gpdickeys:
                        if self.__db.get_event_from_handle(i).gramps_id == event.gramps_id:
                            for (a,b) in gpdic[i]:
                                patentxt = patentxt + toNbr(self.__db.get_person_from_handle(b).gramps_id) +";"

                    self.doc.start_cell("SRC-Cell")
                    self.doc.start_paragraph("SRC-SourceDetails")
                    self.doc.write_text(_("%s") %
                                        patentxt)
                    self.doc.end_paragraph()
                    self.doc.end_cell()


# Date
                    self.doc.start_cell("SRC-Cell")
                    self.doc.start_paragraph("SRC-SourceDetails")
                    self.doc.write_text(_(" %s") %
                                 self.__format_date(event.get_date_object()))
                    self.doc.end_paragraph()
                    self.doc.end_cell()
                    self.doc.end_row()
                    pi += 1
            self.progress.step()
        print (l,len(indexlist))
        self.doc.end_table()
Beispiel #46
0
    def _createmap_for_one_person(self, person, color, place_list, reference):
        """
        Create all markers for each people's event in the database which has
        a lat/lon.
        """
        self.place_list = []
        dbstate = self.dbstate
        if person is not None:
            # For each event, if we have a place, set a marker.
            for event_ref in person.get_event_ref_list():
                if not event_ref:
                    continue
                event = dbstate.db.get_event_from_handle(event_ref.ref)
                role = event_ref.get_role()
                try:
                    date = event.get_date_object().to_calendar(self.cal)
                except:
                    continue
                eyear = str("%04d" % date.get_year()) + \
                        str("%02d" % date.get_month()) + \
                        str("%02d" % date.get_day())
                place_handle = event.get_place_handle()
                if place_handle:
                    place = dbstate.db.get_place_from_handle(place_handle)
                    if place:
                        longitude = place.get_longitude()
                        latitude = place.get_latitude()
                        latitude, longitude = conv_lat_lon(
                            latitude, longitude, "D.D8")
                        descr = _pd.display(dbstate.db, place)
                        evt = EventType(event.get_type())
                        descr1 = _("%(eventtype)s : %(name)s") % {
                            'eventtype': evt,
                            'name': _nd.display(person)
                        }
                        # place.get_longitude and place.get_latitude return
                        # one string. We have coordinates when the two values
                        # contains non null string.
                        if longitude and latitude:
                            self._append_to_places_list(
                                descr, evt, _nd.display(person),
                                latitude, longitude, descr1, eyear,
                                event.get_type(), person.gramps_id,
                                place.gramps_id, event.gramps_id, role)
                        else:
                            self._append_to_places_without_coord(
                                place.gramps_id, descr)
            family_list = person.get_family_handle_list()
            descr1 = " - "
            for family_hdl in family_list:
                family = self.dbstate.db.get_family_from_handle(family_hdl)
                if family is not None:
                    fhandle = family_list[0]  # first is primary
                    father = mother = None
                    fam = dbstate.db.get_family_from_handle(fhandle)
                    handle = fam.get_father_handle()
                    if handle:
                        father = dbstate.db.get_person_from_handle(handle)
                    if father:
                        descr1 = "%s - " % _nd.display(father)
                    handle = fam.get_mother_handle()
                    if handle:
                        mother = dbstate.db.get_person_from_handle(handle)
                    if mother:
                        descr1 = "%s%s" % (descr1, _nd.display(mother))
                    for event_ref in family.get_event_ref_list():
                        if event_ref:
                            event = dbstate.db.get_event_from_handle(
                                event_ref.ref)
                            role = event_ref.get_role()
                            if event.get_place_handle():
                                place_handle = event.get_place_handle()
                                if place_handle:
                                    place = dbstate.db.get_place_from_handle(
                                        place_handle)
                                    if place:
                                        longitude = place.get_longitude()
                                        latitude = place.get_latitude()
                                        latitude, longitude = conv_lat_lon(
                                            latitude, longitude, "D.D8")
                                        descr = _pd.display(dbstate.db, place)
                                        evt = EventType(event.get_type())
                                        eyear = str(
                                        "%04d" % event.get_date_object().to_calendar(self.cal).get_year()) + \
     str("%02d" % event.get_date_object().to_calendar(self.cal).get_month()) + \
     str("%02d" % event.get_date_object().to_calendar(self.cal).get_day())
                                        if longitude and latitude:
                                            self._append_to_places_list(
                                                descr, evt,
                                                _nd.display(person), latitude,
                                                longitude, descr1, eyear,
                                                event.get_type(),
                                                person.gramps_id,
                                                place.gramps_id,
                                                event.gramps_id, role)
                                        else:
                                            self._append_to_places_without_coord(
                                                place.gramps_id, descr)

            sort1 = sorted(self.place_list, key=operator.itemgetter(6))
            self.draw(None, sort1, color, reference)
            # merge with the last results
            merge_list = []
            for the_list in self.sort, sort1:
                merge_list += the_list
            self.sort = sorted(merge_list, key=operator.itemgetter(6))
Beispiel #47
0
 def get_subject(self):
     """ Return a string that describes the subject of the report. """
     from gramps.gen.display.name import displayer as _nd
     gid = self.__pid.get_value()
     person = self.__db.get_person_from_gramps_id(gid)
     return _nd.display(person)
Beispiel #48
0
def exportData(db, filename,
               error_dialog=None, option_box=None, callback=None):
    if not callable(callback):
        callback = lambda percent: None # dummy

    with OpenFileOrStdout(filename) as fp:

        total = (db.get_number_of_notes() +
                 db.get_number_of_people() +
                 db.get_number_of_events() +
                 db.get_number_of_families() +
                 db.get_number_of_repositories() +
                 db.get_number_of_places() +
                 db.get_number_of_media() +
                 db.get_number_of_sources())
        count = 0.0

        # GProlog ISO directives:
        # /number must match the number of arguments to functions:
        fp.write(":- discontiguous(data/2).\n")
        fp.write(":- discontiguous(is_alive/2).\n")
        fp.write(":- discontiguous(parent/2).\n")

        # Rules:
        fp.write("grandparent(X, Y) :- parent(X, Z), parent(Z, Y).\n")
        fp.write("ancestor(X, Y) :- parent(X, Y).\n")
        fp.write("ancestor(X, Y) :- parent(X, Z), ancestor(Z, Y).\n")
        fp.write("sibling(X, Y) :- parent(Z, X), parent(Z, Y), X \= Y.\n")

        # ---------------------------------
        # Notes
        # ---------------------------------
        for note in db.iter_notes():
            #write_line(fp, "note_details(%s, %s)" % (note.handle, note))
            count += 1
            callback(100 * count/total)

        # ---------------------------------
        # Event
        # ---------------------------------
        for event in db.iter_events():
            #write_line(fp, "event:", event.handle, event)
            count += 1
            callback(100 * count/total)

        # ---------------------------------
        # Person
        # ---------------------------------
        for person in db.iter_people():
            gid = person.gramps_id.lower()
            fp.write("data(%s, '%s').\n" % (gid, escape(name_displayer.display(person))))
            fp.write("is_alive(%s, '%s').\n" % (gid, probably_alive(person, database)))
            count += 1
            callback(100 * count/total)

        # ---------------------------------
        # Family
        # ---------------------------------
        for family in db.iter_families():
            father_handle = family.get_father_handle()
            mother_handle = family.get_mother_handle()
            parents = []
            if mother_handle:
                mother = database.get_person_from_handle(mother_handle)
                if mother:
                    parents.append(mother.gramps_id.lower())
            if father_handle:
                father = database.get_person_from_handle(father_handle)
                if father:
                    parents.append(father.gramps_id.lower())
            children = []
            for child_ref in family.get_child_ref_list():
                child_handle = child_ref.ref
                child = database.get_person_from_handle(child_handle)
                if child:
                    children.append(child.gramps_id.lower())
            for pid in parents:
                for cid in children:
                    fp.write("parent(%s, %s).\n" % (pid, cid))
            count += 1
            callback(100 * count/total)

        # ---------------------------------
        # Repository
        # ---------------------------------
        for repository in db.iter_repositories():
            #write_line(fp, "repository:", repository.handle, repository)
            count += 1
            callback(100 * count/total)

        # ---------------------------------
        # Place
        # ---------------------------------
        for place in db.iter_places():
            #write_line(fp, "place:", place.handle, place)
            count += 1
            callback(100 * count/total)

        # ---------------------------------
        # Source
        # ---------------------------------
        for source in db.iter_sources():
            #write_line(fp, "source:", source.handle, source)
            count += 1
            callback(100 * count/total)

        # ---------------------------------
        # Media
        # ---------------------------------
        for media in db.iter_media():
            #write_line(fp, "media:", media.handle, media)
            count += 1
            callback(100 * count/total)

    return True
Beispiel #49
0
def name_of(p):
    if not p:
        return ""
    return "%s (%s)" % (name_displayer.display(p), p.get_handle())
Beispiel #50
0
    def on_apply_clicked(self, obj):
        model, iter_ = self.tree.get_selection().get_selected()
        if not iter_:
            return

        other_person = None
        handle = model.get_handle_from_iter(iter_)
        if handle:
            other_person = self.db.get_person_from_handle(handle)
        if other_person is None:
            self.textbuffer.set_text("")
            return

        #now determine the relation, and print it out
        rel_strings, common_an = self.relationship.get_all_relationships(
                                            self.db, self.person, other_person)

        p1 = name_displayer.display(self.person)
        p2 = name_displayer.display(other_person)

        text = []
        if other_person is None:
            pass
        elif self.person.handle == other_person.handle:
            rstr = _("%(person)s and %(active_person)s are the same person.") % {
                        'person': p1,
                        'active_person': p2
                        }
            text.append((rstr, ""))
        elif len(rel_strings) == 0:
            rstr = _("%(person)s and %(active_person)s are not related.") % {
                            'person': p2,
                            'active_person': p1
                            }
            text.append((rstr, ""))

        for rel_string, common in zip(rel_strings, common_an):
            rstr = _("%(person)s is the %(relationship)s of %(active_person)s."
                        ) % {'person': p2,
                             'relationship': rel_string,
                             'active_person': p1
                            }
            length = len(common)
            if length == 1:
                person = self.db.get_person_from_handle(common[0])
                if common[0] in [other_person.handle, self.person.handle]:
                    commontext = ''
                else :
                    name = name_displayer.display(person)
                    commontext = " " + _("Their common ancestor is %s.") % name
            elif length == 2:
                p1c = self.db.get_person_from_handle(common[0])
                p2c = self.db.get_person_from_handle(common[1])
                p1str = name_displayer.display(p1c)
                p2str = name_displayer.display(p2c)
                commontext = " " + _("Their common ancestors are %(ancestor1)s and %(ancestor2)s.") % {
                                          'ancestor1': p1str,
                                          'ancestor2': p2str
                                          }
            elif length > 2:
                index = 0
                commontext = " " + _("Their common ancestors are: ")
                for person_handle in common:
                    person = self.db.get_person_from_handle(person_handle)
                    if index:
                        commontext += ", "
                    commontext += name_displayer.display(person)
                    index += 1
                commontext += "."
            else:
                commontext = ""
            text.append((rstr, commontext))

        textval = ""
        for val in text:
            textval += "%s %s\n" % (val[0], val[1])
        self.textbuffer.set_text(textval)
Beispiel #51
0
 def get_preview_name(self):
     prevname = name_displayer.display(self.obj)
     return prevname
Beispiel #52
0
 def get_subject(self):
     """ Return a string that describes the subject of the report. """
     gid = self.__pid.get_value()
     person = self.__db.get_person_from_gramps_id(gid)
     return displayer.display(person)
Beispiel #53
0
    def run(self):
        self.remove = self.options.menu.get_option_by_name('remove').get_value()
        if not self.remove:
            with DbTxn(_("Set Attribute"), self.db, batch=True) as self.trans:
                self.add_results_frame(_("Results"))
                self.results_write(_("Processing...\n"))
                self.db.disable_signals()

                self.filter_option =  self.options.menu.get_option_by_name('filter')
                self.filter = self.filter_option.get_filter() # the actual filter

                # FIXME: currently uses old style for gramps31 compatible
                #    people = self.filter.apply(self.db,
                #                               self.db.iter_person_handles())
                people = self.filter.apply(self.db,
                                     self.db.get_person_handles(sort_handles=False))

                # FIXME: currently uses old style for gramps31 compatible
                # num_people = self.db.get_number_of_people()
                num_people = len(people)
                self.progress.set_pass(_('Setting attributes...'),
                                       num_people)
                count = 0
                attribute_text = self.options.handler.options_dict['attribute_text']
                attribute_value = self.options.handler.options_dict['attribute_value']
                specified_type = gramps.gen.lib.AttributeType()
                specified_type.set(attribute_text)
                self.results_write(_("Setting '%s' attributes to '%s'...\n\n" %
                                     (attribute_text, attribute_value)))
                for person_handle in people:
                    count += 1
                    self.progress.step()
                    person = self.db.get_person_from_handle(person_handle)
                    done = False
                    for attr in person.get_attribute_list():
                        if attr.get_type() == specified_type:
                            self.results_write("  %d) Changed" % count)
                            self.results_write_link(name_displayer.display(person),
                                                    person, person_handle)
                            self.results_write(" from '%s'\n" % attr.get_value())
                            attr.set_value(attribute_value)
                            done = True
                            break
                    if not done:
                        attr = gramps.gen.lib.Attribute()
                        attr.set_type(specified_type)
                        attr.set_value(attribute_value)
                        person.add_attribute(attr)
                        # Update global attribute list:
                        if attr.type.is_custom() and str(attr.type):
                            self.db.individual_attributes.update([str(attr.type)])
                        self.results_write("  %d) Added attribute to" % count)
                        self.results_write_link(name_displayer.display(person),
                                                    person, person_handle)
                        self.results_write("\n")
                    self.db.commit_person(person, self.trans)
            self.db.enable_signals()
            self.db.request_rebuild()
            self.results_write(_("\nSet %d '%s' attributes to '%s'\n" %
                                 (count, attribute_text, attribute_value)))
            self.results_write(_("Done!\n"))
        else:
            with DbTxn(_("Remove Attribute"), self.db, batch=True) as self.trans:
                self.add_results_frame(_("Results"))
                self.results_write(_("Processing...\n"))
                self.db.disable_signals()

                self.filter_option =  self.options.menu.get_option_by_name('filter')
                self.filter = self.filter_option.get_filter() # the actual filter

                # FIXME: currently uses old style for gramps31 compatible
                #    people = self.filter.apply(self.db,
                #                               self.db.iter_person_handles())
                people = self.filter.apply(self.db,
                                     self.db.get_person_handles(sort_handles=False))

                # FIXME: currently uses old style for gramps31 compatible
                # num_people = self.db.get_number_of_people()
                num_people = len(people)
                self.progress.set_pass(_('Removing attributes...'),
                                       num_people)
                count = 0
                attribute_text = self.options.handler.options_dict['attribute_text']
                attribute_value = self.options.handler.options_dict['attribute_value']
                specified_type = gramps.gen.lib.AttributeType()
                specified_type.set(attribute_text)
                for person_handle in people:
                    count += 1
                    self.progress.step()
                    person = self.db.get_person_from_handle(person_handle)
                    done = False
                    for attr in person.get_attribute_list():
                        if attr.get_type() == specified_type and \
                            (attribute_value == '' or attr.get_value() == attribute_value):
                            person.remove_attribute(attr)
                            # Update global attribute list:
                            self.db.individual_attributes.update([str(attr.type)])
                            self.results_write("  %d) Changed" % count)
                            self.results_write_link(name_displayer.display(person),
                                                    person, person_handle)
                            self.results_write(" from '%s'\n" % attr.get_value())
                            done = True
                            break
                    if done:
                        self.results_write(_("\nRemoving %d '%s' attributes to '%s'\n" %
                                    (count, attribute_text, attribute_value)))
                        self.db.commit_person(person, self.trans)
            self.db.enable_signals()
            self.db.request_rebuild()
            self.results_write(_("Done!\n"))
Beispiel #54
0
    def on_draw(self, widget, cr, scale=1.):
        """
        The main method to do the drawing.
        If widget is given, we assume we draw in GTK3 and use the allocation. 
        To draw raw on the cairo context cr, set widget=None.
        """
        # first do size request of what we will need
        halfdist = self.halfdist()
        if widget:
            if self.form == FORM_CIRCLE:
                self.set_size_request(2 * halfdist, 2 * halfdist)
            elif self.form == FORM_HALFCIRCLE:
                self.set_size_request(2 * halfdist,
                                      halfdist + self.CENTER + PAD_PX)
            elif self.form == FORM_QUADRANT:
                self.set_size_request(halfdist + self.CENTER + PAD_PX,
                                      halfdist + self.CENTER + PAD_PX)

            #obtain the allocation
            alloc = self.get_allocation()
            x, y, w, h = alloc.x, alloc.y, alloc.width, alloc.height

        cr.scale(scale, scale)
        # when printing, we need not recalculate
        if widget:
            if self.form == FORM_CIRCLE:
                self.center_x = w / 2 - self.center_xy[0]
                self.center_y = h / 2 - self.center_xy[1]
            elif self.form == FORM_HALFCIRCLE:
                self.center_x = w / 2. - self.center_xy[0]
                self.center_y = h - self.CENTER - PAD_PX - self.center_xy[1]
            elif self.form == FORM_QUADRANT:
                self.center_x = self.CENTER + PAD_PX - self.center_xy[0]
                self.center_y = h - self.CENTER - PAD_PX - self.center_xy[1]
        cr.translate(self.center_x, self.center_y)

        cr.save()
        #draw center
        cr.set_source_rgb(1, 1, 1)  # white
        cr.move_to(0, 0)
        cr.arc(0, 0, self.CENTER - PIXELS_PER_GENFAMILY, 0, 2 * math.pi)
        cr.fill()
        cr.set_source_rgb(0, 0, 0)  # black
        cr.arc(0, 0, self.CENTER - PIXELS_PER_GENFAMILY, 0, 2 * math.pi)
        cr.stroke()
        cr.restore()
        # Draw center person:
        (person, dup, start, slice, text, parentfampos, nrfam, userdata, status) \
                = self.gen2people[0][0]
        if person:
            r, g, b, a = self.background_box(person, 0, userdata)
            cr.arc(0, 0, self.CENTER - PIXELS_PER_GENFAMILY, 0, 2 * math.pi)
            if self.parentsroot:
                cr.arc_negative(0, 0, TRANSLATE_PX + CHILDRING_WIDTH,
                                2 * math.pi, 0)
                cr.close_path()
            cr.set_source_rgba(r / 255, g / 255, b / 255, a)
            cr.fill()
            cr.save()
            name = name_displayer.display(person)
            self.draw_text(
                cr, name, self.CENTER - PIXELS_PER_GENFAMILY -
                (self.CENTER - PIXELS_PER_GENFAMILY -
                 (CHILDRING_WIDTH + TRANSLATE_PX)) / 2, 95, 455, 10, False,
                self.fontcolor(r, g, b, a), self.fontbold(a))
            cr.restore()
            #draw center to move chart
            cr.set_source_rgb(0, 0, 0)  # black
            cr.move_to(TRANSLATE_PX, 0)
            cr.arc(0, 0, TRANSLATE_PX, 0, 2 * math.pi)
            if self.parentsroot:  # has at least one parent
                cr.fill()
                self.draw_parentring(cr)
            else:
                cr.stroke()
        #now write all the families and children
        cr.save()
        cr.rotate(self.rotate_value * math.pi / 180)
        radstart = self.CENTER - PIXELS_PER_GENFAMILY - PIXELS_PER_GENPERSON
        for gen in range(self.generations - 1):
            radstart += PIXELS_PER_GENPERSON
            for famdata in self.gen2fam[gen]:
                # family, duplicate or not, start angle, slice size,
                #       text, spouse pos in gen, nrchildren, userdata, status
                fam, dup, start, slice, text, posfam, nrchild, userdata,\
                    partner, status = famdata
                if status != COLLAPSED:
                    self.draw_person(cr,
                                     text,
                                     start,
                                     slice,
                                     radstart,
                                     radstart + PIXELS_PER_GENFAMILY,
                                     gen,
                                     dup,
                                     partner,
                                     userdata,
                                     family=True,
                                     thick=status != NORMAL)
            radstart += PIXELS_PER_GENFAMILY
            for pdata in self.gen2people[gen + 1]:
                # person, duplicate or not, start angle, slice size,
                #             text, parent pos in fam, nrfam, userdata, status
                pers, dup, start, slice, text, pospar, nrfam, userdata, status = \
                    pdata
                if status != COLLAPSED:
                    self.draw_person(cr,
                                     text,
                                     start,
                                     slice,
                                     radstart,
                                     radstart + PIXELS_PER_GENPERSON,
                                     gen + 1,
                                     dup,
                                     pers,
                                     userdata,
                                     thick=status != NORMAL)
        cr.restore()

        if self.background in [BACKGROUND_GRAD_AGE, BACKGROUND_GRAD_PERIOD]:
            self.draw_gradient(cr, widget, halfdist)
Beispiel #55
0
    def load_model(self):
        """
        Objects can have very large backreferences. To avoid blocking the
        interface up to the moment that the model is created, this method is
        called via GLib.idle_add.
        WARNING: a consequence of above is that loading can still be happening
            while the GUI using this model is no longer used. Disconnect any
            methods before closing the GUI.
        """
        self.loading = True
        self.count = 0
        for ref in self.sref_list:
            self.count += 1
            dtype = ref[0]
            if dtype == 'Person':
                p = self.db.get_person_from_handle(ref[1])
                if not p:
                    continue
                gid = p.gramps_id
                handle = p.handle
                name = name_displayer.display(p)
            elif dtype == 'Family':
                p = self.db.get_family_from_handle(ref[1])
                if not p:
                    continue
                gid = p.gramps_id
                handle = p.handle
                name = family_name(p, self.db)
            elif dtype == 'Source':
                p = self.db.get_source_from_handle(ref[1])
                if not p:
                    continue
                gid = p.gramps_id
                handle = p.handle
                name = p.get_title()
            elif dtype == 'Citation':
                p = self.db.get_citation_from_handle(ref[1])
                if not p:
                    continue
                gid = p.gramps_id
                handle = p.handle
                name = p.get_page()
            elif dtype == 'Event':
                p = self.db.get_event_from_handle(ref[1])
                if not p:
                    continue
                gid = p.gramps_id
                handle = p.handle
                name = p.get_description()
                if name:
                    name = self.dispstr % {
                        'part1': str(p.get_type()),
                        'part2': name
                    }
                else:
                    name = str(p.get_type())
                part = get_participant_from_event(self.db, ref[1])
                if part:
                    name = self.dispstr % {'part1': name, 'part2': part}
            elif dtype == 'Place':
                p = self.db.get_place_from_handle(ref[1])
                if not p:
                    continue
                name = place_displayer.display(self.db, p)
                gid = p.gramps_id
                handle = p.handle
            elif dtype == 'Repository':
                p = self.db.get_repository_from_handle(ref[1])
                if not p:
                    continue
                name = p.get_name()
                gid = p.gramps_id
                handle = p.handle
            else:
                p = self.db.get_media_from_handle(ref[1])
                if not p:
                    continue
                name = p.get_description()
                gid = p.gramps_id
                handle = p.handle

            # dtype is the class name, i.e. is English
            # We need to use localized string in the model.
            # we also need to keep class names to get the object type,
            # but we don't need to show that in the view.
            self.append(row=[_(dtype), gid, name, handle, dtype])
            yield True
        self.loading = False
        yield False
Beispiel #56
0
    def display(self, tobj, person):
        """Fill text buffer tobj with detailed info on person person."""
        normal = tobj.create_tag()
        normal.set_property('indent', 10)
        normal.set_property('pixels-above-lines', 1)
        normal.set_property('pixels-below-lines', 1)
        indent = tobj.create_tag()
        indent.set_property('indent', 30)
        indent.set_property('pixels-above-lines', 1)
        indent.set_property('pixels-below-lines', 1)
        title = tobj.create_tag()
        title.set_property('weight', Pango.Weight.BOLD)
        title.set_property('scale', 1.2)
        self.add(tobj, title, name_displayer.display(person))
        self.add(tobj, normal, "%s:\t%s" % (_('ID'), person.get_gramps_id()))
        self.add(tobj, normal,
                 "%s:\t%s" % (_('Gender'), sex[person.get_gender()]))
        bref = person.get_birth_ref()
        if bref:
            self.add(tobj, normal,
                     "%s:\t%s" % (_('Birth'), self.get_event_info(bref.ref)))
        dref = person.get_death_ref()
        if dref:
            self.add(tobj, normal,
                     "%s:\t%s" % (_('Death'), self.get_event_info(dref.ref)))

        nlist = person.get_alternate_names()
        if len(nlist) > 0:
            self.add(tobj, title, _("Alternate Names"))
            for name in nlist:
                self.add(tobj, normal, name_displayer.display_name(name))

        elist = person.get_event_ref_list()
        if len(elist) > 0:
            self.add(tobj, title, _("Events"))
            for event_ref in person.get_event_ref_list():
                event_handle = event_ref.ref
                role = event_ref.get_role()
                name = str(
                    self.database.get_event_from_handle(
                        event_handle).get_type())
                if role.is_primary():
                    self.add(
                        tobj, normal,
                        "%s:\t%s" % (name, self.get_event_info(event_handle)))
                else:
                    self.add(
                        tobj, normal, "%s (%s):\t%s" %
                        (name, role, self.get_event_info(event_handle)))
        plist = person.get_parent_family_handle_list()

        if len(plist) > 0:
            self.add(tobj, title, _("Parents"))
            for fid in person.get_parent_family_handle_list():
                (fname, mname, gid) = self.get_parent_info(fid)
                self.add(tobj, normal, "%s:\t%s" % (_('Family ID'), gid))
                if fname:
                    self.add(tobj, indent, "%s:\t%s" % (_('Father'), fname))
                if mname:
                    self.add(tobj, indent, "%s:\t%s" % (_('Mother'), mname))
        else:
            self.add(tobj, normal, _("No parents found"))

        self.add(tobj, title, _("Spouses"))
        slist = person.get_family_handle_list()
        if len(slist) > 0:
            for fid in slist:
                (fname, mname, pid) = self.get_parent_info(fid)
                family = self.database.get_family_from_handle(fid)
                self.add(tobj, normal, "%s:\t%s" % (_('Family ID'), pid))
                spouse_id = utils.find_spouse(person, family)
                if spouse_id:
                    spouse = self.database.get_person_from_handle(spouse_id)
                    self.add(tobj, indent,
                             "%s:\t%s" % (_('Spouse'), name_of(spouse)))
                relstr = str(family.get_relationship())
                self.add(tobj, indent, "%s:\t%s" % (_('Type'), relstr))
                event = utils.find_marriage(self.database, family)
                if event:
                    self.add(
                        tobj, indent,
                        "%s:\t%s" % (_('Marriage'),
                                     self.get_event_info(event.get_handle())))
                for child_ref in family.get_child_ref_list():
                    child = self.database.get_person_from_handle(child_ref.ref)
                    self.add(tobj, indent,
                             "%s:\t%s" % (_('Child'), name_of(child)))
        else:
            self.add(tobj, normal, _("No spouses or children found"))

        alist = person.get_address_list()
        if len(alist) > 0:
            self.add(tobj, title, _("Addresses"))
            for addr in alist:
                location = ", ".join([
                    addr.get_street(),
                    addr.get_city(),
                    addr.get_state(),
                    addr.get_country(),
                    addr.get_postal_code(),
                    addr.get_phone()
                ])
                self.add(tobj, normal, location.strip())
    def main(self):
        # Write heading text to gramplet
        self.set_text(_("Relations of related people in your database:"))
        # Define basic variables
        database = self.dbstate.db
        rel_calc = get_relationship_calculator()
        family_handle_list = []  # Will keep list of families with no ancestors

        # Find all base families with no ancestors in the database.
        flist = database.iter_family_handles()
        for familyhandle in flist:
            family = database.get_family_from_handle(familyhandle)
            # Check if mother of this family is child of another family
            # If this is the case, skip this family
            ancestorHandle = family.get_mother_handle()
            if ancestorHandle:
                mother = database.get_person_from_handle(ancestorHandle)
                parent_handle_list = mother.get_parent_family_handle_list()
                if parent_handle_list:
                    continue
            # Check if father of this family is child of another family
            # If this is the case, skip this family
            ancestorHandle = family.get_father_handle()
            if ancestorHandle:
                father = database.get_person_from_handle(ancestorHandle)
                parent_handle_list = father.get_parent_family_handle_list()
                if parent_handle_list:
                    continue
            # Members of this family have no ancestors. Add family to base
            # family handle list
            family_handle_list.append(familyhandle)
            yield True

        # The base family handle list now contains all families that have
        # no ancestors. Now iterate through found families. For each family
        # first find all descendants and then check if one person in this
        # family tree is partner of another person in the same tree.
        #
        # Related relatives may be found more than once from different base
        # families. Therefore we hold a list of all found pairs to avoid
        # listing them more than once
        pair_p1_list = []  # List of all 1st related partners for all families
        pair_p2_list = []  # List of all 2nd related partners for all families
        for familyhandle in family_handle_list:
            # Build list of all related persons (descendants) of this family.
            self.person_handle_list = []
            family = database.get_family_from_handle(familyhandle)
            # Add all descendants of the father to person list of this family
            father_handle = family.get_father_handle()
            if father_handle:
                father = database.get_person_from_handle(father_handle)
                # Add all descendants of the father
                self.addDescendants(father_handle)
            mother_handle = family.get_mother_handle()
            # Add all descendants of the mother to person list of this family
            if mother_handle:
                mother = database.get_person_from_handle(mother_handle)
                # Add all descendants of the mother
                self.addDescendants(mother_handle)

            # The person list of all descendants for this family is complete.
            # Now check for every person in the list if it has a partner that
            # is also in this list
            for checkHandle in self.person_handle_list:
                person = database.get_person_from_handle(checkHandle)
                if person:
                    pfamily_handle_list = person.get_family_handle_list()
                    if pfamily_handle_list:
                        for family_handle in pfamily_handle_list:
                            # Skip the family if it is listed in the base
                            # families list (which should be quite short).
                            if family_handle in family_handle_list:
                                continue

                            # If current person is father or mother in a family
                            # find the handle of the partner
                            family = database.get_family_from_handle(
                                family_handle)
                            father_handle = family.get_father_handle()
                            mother_handle = family.get_mother_handle()
                            if checkHandle == father_handle:
                                handlepartner = mother_handle
                            else:
                                handlepartner = father_handle

                            # If the partner is in our list of persons of this
                            # family tree, both are related.
                            if handlepartner in self.person_handle_list:
                                newEntry = True
                                # Check if this pair is already in the lists of
                                # related partners. A and B will also appear as
                                # B and A. So we have to cross check
                                for ii in range(len(pair_p1_list)):
                                    if checkHandle == pair_p1_list[ii]:
                                        if handlepartner == pair_p2_list[ii]:
                                            newEntry = False
                                    if checkHandle == pair_p2_list[ii]:
                                        if handlepartner == pair_p1_list[ii]:
                                            newEntry = False

                                # If this pair is not yet listed, add them to
                                # the list and show their relationship in the
                                # gramplet window.
                                if newEntry:
                                    # Add pair to list of found related relatives
                                    pair_p1_list.append(checkHandle)
                                    pair_p2_list.append(handlepartner)
                                    partner = self.dbstate.db. \
                                        get_person_from_handle(handlepartner)
                                    # Find relation between the partners by use
                                    # of the relationship calculator. Print all
                                    # relationships A to B and B to A.
                                    rel_strings, common_an = \
                                        rel_calc.get_all_relationships(database,
                                                                       person,
                                                                       partner)
                                    rel_strings1, common_an1 = \
                                        rel_calc.get_all_relationships(database,
                                                                       partner,
                                                                       person)
                                    if len(rel_strings) > 1:
                                        # Output names of both partners as links
                                        p1name = name_displayer.display(person)
                                        self.append_text("\n\n")
                                        self.link(p1name, 'Person',
                                                  checkHandle)
                                        p2name = name_displayer.display(
                                            partner)
                                        self.append_text(" " + _("and") + " ")
                                        self.link(p2name, 'Person',
                                                  handlepartner)
                                        self.append_text(" " + \
                                                         _("are partners and") + \
                                                         ":")
                                        # Omit the first relationship from list
                                        for x in range(1, len(rel_strings)):
                                            self.append_text("\n%s" %
                                                             rel_strings[x])
                                            try:
                                                self.append_text(
                                                    " & %s" % rel_strings1[x])
                                            except:
                                                continue
                                            # Print list of common ancestors for
                                            # the found relation.
                                            # Remove duplicate ancestors
                                            anc_list = list(set(common_an[x]))
                                            for anc in anc_list:
                                                person = database. \
                                                    get_person_from_handle(anc)
                                                if person:
                                                    # Print ancestor as link
                                                    pname = name_displayer. \
                                                        display(person)
                                                    self.append_text("\n\t" \
                                                        + _("Common ancestor") \
                                                        + " ")
                                                    self.link(
                                                        pname, 'Person', anc)

                        # After the check for each persons family allow other
                        # threads to do some work.
                        yield True
        # If the list of related pairs is empty we did not find any related
        # relatives in the database.
        if len(pair_p1_list) == 0:
            self.append_text("\n" + _("No relatives in a relation found") +
                             ".\n")
        self.append_text("\n\n" + _("END") + "\n")
        return
Beispiel #58
0
def name_of(person):
    """Return string with name and ID of a person."""
    if not person:
        return ""
    return "%s [%s]" % (name_displayer.display(person), person.get_gramps_id())
 def get_person_title(self, obj):
     return "{gramps_id}: {name}".format(gramps_id=obj.get_gramps_id(),
                                         name=name_displayer.display(obj))
Beispiel #60
0
 def _message1_format(self, person):
     return _('Delete %s?') % (name_displayer.display(person) +
                               (" [%s]" % person.gramps_id))