Beispiel #1
0
 def __add_place(self, parent, plat, plon):
     """
     Add a new place using longitude and latitude of location centered
     on the map
     """
     self.select_fct.close()
     new_place = Place()
     new_place.set_latitude(str(plat))
     new_place.set_longitude(str(plon))
     if parent:
         if isinstance(parent, Place):
             placeref = PlaceRef()
             placeref.ref = parent
             new_place.add_placeref(placeref)
         else:
             found = None
             for place in self.dbstate.db.iter_places():
                 found = place
                 if place.name.get_value() == parent:
                     break
             placeref = PlaceRef()
             placeref.ref = found.get_handle()
             new_place.add_placeref(placeref)
     try:
         EditPlace(self.dbstate, self.uistate, [], new_place)
         self.add_marker(None, None, plat, plon, None, True, 0)
     except WindowActiveError:
         pass
Beispiel #2
0
    def __generate_hierarchy(self, place, original_enclosing_places):
        # Generates the hierarchy.
        # Returns the place at the top of the hierarchy or None if no hierarchy was generated
        original_name = place.get_name().get_value()
        if original_name == "":
            original_name = place.get_title()
        separator = ','
        if self.spaces.get_active():
            separator = None
            if ' ' not in original_name:
                return None
        else:
            if ',' not in original_name:
                return None

        names = [
            name.strip() for name in original_name.split(separator)
            if name.strip()
        ]
        if self.reverse.get_active():
            names.reverse()
        place_name = PlaceName()
        place_name.set_value(names[0])
        place.set_name(place_name)
        place.set_title('')

        parent_handle = None
        top_place = place
        for name, handle, new_place in self.find_hierarchy(
                names, original_enclosing_places)[:-1]:
            if handle is None:
                new_place = Place()
                place_name = PlaceName()
                place_name.set_value(name)
                new_place.set_name(place_name)
                if parent_handle is None:
                    top_place = new_place
                if parent_handle is not None:
                    placeref = PlaceRef()
                    placeref.ref = parent_handle
                    placeref.set_date_object(self.date_object)
                    new_place.add_placeref(placeref)
                parent_handle = self.dbstate.db.add_place(
                    new_place, self.trans)
            else:
                if parent_handle is None:
                    top_place = new_place
                parent_handle = handle

        if parent_handle is not None:
            placeref = PlaceRef()
            placeref.ref = parent_handle
            placeref.set_date_object(self.date_object)
            place.set_placeref_list([placeref
                                     ])  # this removes any previous parent
        return top_place
 def set_parents(self,handle,info):
     place = self.db.get_place_from_handle(handle)
     parent_ids = info["parents"]
     for parent_id in parent_ids:
         parent_handle,parent_info = self.places[parent_id]
         placeref = PlaceRef()
         placeref.ref = parent_handle
         place.add_placeref(placeref)
     #self.set_info(place,info) can be deleted here?
     self.db.commit_place(place, self.trans)
Beispiel #4
0
    def __get_places(self, obj):
        gov_id = self.entry.get_text()
        to_do = [gov_id]
        try:
            preferred_lang = config.get('preferences.place-lang')
        except AttributeError:
            fmt = config.get('preferences.place-format')
            pf = _pd.get_formats()[fmt]
            preferred_lang = pf.language
        if len(preferred_lang) != 2:
            preferred_lang = 'de'
        visited = {}

        type_dic = dict()
        type_url = 'http://gov.genealogy.net/types.owl/'
        response = urlopen(type_url)
        data = response.read()
        dom = parseString(data)
        for group in dom.getElementsByTagName('owl:Class'):
            url_value = group.attributes['rdf:about'].value
            group_number = 'j.0:' + url_value.split('#')[1]
            for element in dom.getElementsByTagName(group_number):
                type_number = element.attributes['rdf:about'].value.split(
                    '#')[1]
                for pname in element.getElementsByTagName('rdfs:label'):
                    type_lang = pname.attributes['xml:lang'].value
                    type_text = pname.childNodes[0].data
                    type_dic[type_number, type_lang] = type_text

        with DbTxn(_('Add GOV-id place %s') % gov_id,
                   self.dbstate.db) as trans:
            while to_do:
                gov_id = to_do.pop()
                place = self.dbstate.db.get_place_from_gramps_id(gov_id)
                if place is not None:
                    visited[gov_id] = (place, [])
                else:
                    place, ref_list = self.__get_place(gov_id, type_dic,
                                                       preferred_lang)
                    if place.get_name().get_value is not '':
                        self.dbstate.db.add_place(place, trans)
                        visited[gov_id] = (place, ref_list)
                        for ref, date in ref_list:
                            if (ref not in to_do) and (ref not in visited):
                                to_do.append(ref)

            for place, ref_list in visited.values():
                if len(ref_list) > 0:
                    for ref, date in ref_list:
                        handle = visited[ref][0].handle
                        place_ref = PlaceRef()
                        place_ref.ref = handle
                        place_ref.set_date_object(date)
                        place.add_placeref(place_ref)
                    self.dbstate.db.commit_place(place, trans)
Beispiel #5
0
    def __get_places(self, obj):
        gov_id = self.entry.get_text()
        to_do = [gov_id]
        try:
            preferred_lang = config.get('preferences.place-lang')
        except AttributeError:
            fmt = config.get('preferences.place-format')
            pf = _pd.get_formats()[fmt]
            preferred_lang = pf.language
        if len(preferred_lang) != 2:
            preferred_lang = 'de'
        visited = {}

        type_dic = dict()
        type_url = 'http://gov.genealogy.net/types.owl/'
        response = urlopen(type_url)
        data = response.read()
        dom = parseString(data)
        for group in dom.getElementsByTagName('owl:Class') :
            url_value = group.attributes['rdf:about'].value
            group_number = 'j.0:' + url_value.split('#')[1]
            for element in dom.getElementsByTagName(group_number):
                type_number = element.attributes['rdf:about'].value.split('#')[1]
                for pname in element.getElementsByTagName('rdfs:label'):
                    type_lang = pname.attributes['xml:lang'].value
                    type_text = pname.childNodes[0].data
                    type_dic[type_number,type_lang] = type_text

        with DbTxn(_('Add GOV-id place %s') % gov_id, self.dbstate.db) as trans:
            while to_do:
                gov_id = to_do.pop()
                place = self.dbstate.db.get_place_from_gramps_id(gov_id)
                if place is not None:
                    visited[gov_id] = (place, [])
                else:
                    place, ref_list = self.__get_place(gov_id, type_dic, preferred_lang)
                    if place.get_name().get_value is not '':
                        self.dbstate.db.add_place(place, trans)
                        visited[gov_id] = (place, ref_list)
                        for ref, date in ref_list:
                            if (ref not in to_do) and (ref not in visited):
                                to_do.append(ref)

            for place, ref_list in visited.values():
                if len(ref_list) > 0:
                    for ref, date in ref_list:
                        handle = visited[ref][0].handle
                        place_ref = PlaceRef()
                        place_ref.ref = handle
                        place_ref.set_date_object(date)
                        place.add_placeref(place_ref)
                    self.dbstate.db.commit_place(place, trans)
Beispiel #6
0
 def __set_enclosing_place(self,place):
     if not self.selected_handle: return
     if self.__encloses(place.get_handle(), self.selected_handle):  # place should not include itself
         print("Can't set",place.get_name().value,"inside",self.selected_name) 
         return
     pname = place.get_name().value
     if self.selected_handle in [r.ref for r in place.placeref_list]: 
         print(pname,"already enclosed by",self.selected_name)
         return # prevent duplicates
     print(pname,"<",self.selected_name)
     placeref = PlaceRef()
     placeref.ref = self.selected_handle
     place.add_placeref(placeref)
Beispiel #7
0
 def __add_place(self, name, type_num, parent, title, trans):
     """
     Add a missing place to the database.
     """
     place = Place()
     place.name = name
     place.title = title
     place.place_type = PlaceType(7 - type_num)
     if parent is not None:
         placeref = PlaceRef()
         placeref.ref = handle2internal(parent)
         place.set_placeref_list([placeref])
     handle = self.db.add_place(place, trans)
     self.db.commit_place(place, trans)
     return handle
Beispiel #8
0
 def __edit_place(self, parent, plat, plon):
     """
     Edit the selected place at the marker position
     """
     self.select_fct.close()
     place = self.dbstate.db.get_place_from_gramps_id(self.mark[9])
     place.set_latitude(str(plat))
     place.set_longitude(str(plon))
     if parent:
         placeref = PlaceRef()
         placeref.ref = parent
         place.add_placeref(placeref)
     try:
         EditPlace(self.dbstate, self.uistate, [], place)
     except WindowActiveError:
         pass
Beispiel #9
0
 def __edit_place(self, parent, plat, plon):
     """
     Edit the selected place at the marker position
     """
     self.select_fct.close()
     place = self.dbstate.db.get_place_from_gramps_id(self.mark[9])
     place.set_latitude(str(plat))
     place.set_longitude(str(plon))
     if parent:
         placeref = PlaceRef()
         placeref.ref = parent
         place.add_placeref(placeref)
     try:
         EditPlace(self.dbstate, self.uistate, [], place)
     except WindowActiveError:
         pass
Beispiel #10
0
 def __add_place(self, name, type_num, parent, title, trans):
     """
     Add a missing place to the database.
     """
     place = Place()
     place_name = PlaceName()
     place_name.set_value(name)
     place.name = place_name
     place.title = title
     place.place_type = PlaceType(7 - type_num)
     if parent is not None:
         placeref = PlaceRef()
         placeref.ref = parent.decode('utf-8')
         place.set_placeref_list([placeref])
     handle = self.db.add_place(place, trans)
     self.db.commit_place(place, trans)
     return handle
Beispiel #11
0
 def __add_place(self, name, type_num, parent, title, trans):
     """
     Add a missing place to the database.
     """
     place = Place()
     place_name = PlaceName()
     place_name.set_value(name)
     place.name = place_name
     place.title = title
     place.place_type = PlaceType(7-type_num)
     if parent is not None:
         placeref = PlaceRef()
         placeref.ref = handle2internal(parent)
         place.set_placeref_list([placeref])
     handle = self.db.add_place(place, trans)
     self.db.commit_place(place, trans)
     return handle
Beispiel #12
0
 def _parse_place(self, line_number, row, col):
     "Parse the content of a Place line."
     place_id = rd(line_number, row, col, "place")
     place_title = rd(line_number, row, col, "title")
     place_name = rd(line_number, row, col, "name")
     place_type_str = rd(line_number, row, col, "type")
     place_latitude = rd(line_number, row, col, "latitude")
     place_longitude = rd(line_number, row, col, "longitude")
     place_code = rd(line_number, row, col, "code")
     place_enclosed_by_id = rd(line_number, row, col, "enclosed_by")
     place_date = rd(line_number, row, col, "date")
     #########################################################
     # if this place already exists, don't create it
     place = self.lookup("place", place_id)
     if place is None:
         # new place
         place = self.create_place()
         if place_id is not None:
             if place_id.startswith("[") and place_id.endswith("]"):
                 place.gramps_id = self.db.pid2user_format(place_id[1:-1])
             self.storeup("place", place_id, place)
     if place_title is not None:
         place.title = place_title
     if place_name is not None:
         place.name = PlaceName(value=place_name)
     if place_type_str is not None:
         place.place_type = self.get_place_type(place_type_str)
     if place_latitude is not None:
         place.lat = place_latitude
     if place_longitude is not None:
         place.long = place_longitude
     if place_code is not None:
         place.code = place_code
     if place_enclosed_by_id is not None:
         place_enclosed_by = self.lookup("place", place_enclosed_by_id)
         if place_enclosed_by is None:
             raise Exception("cannot enclose %s in %s as it doesn't exist" %
                             (place.gramps_id, place_enclosed_by_id))
         if not place_enclosed_by.handle in place.placeref_list:
             placeref = PlaceRef()
             placeref.ref = place_enclosed_by.handle
             if place_date:
                 placeref.date = _dp.parse(place_date)
             place.placeref_list.append(placeref)
     #########################################################
     self.db.commit_place(place, self.trans)
 def add_button_clicked(self, obj):
     placeref = PlaceRef()
     try:
         from .. import EditPlaceRef
         EditPlaceRef(self.dbstate, self.uistate, self.track, 
                      placeref, self.handle, self.add_callback)
     except WindowActiveError:
         pass
Beispiel #14
0
 def _parse_place(self, line_number, row, col):
     "Parse the content of a Place line."
     place_id = rd(line_number, row, col, "place")
     place_title = rd(line_number, row, col, "title")
     place_name = rd(line_number, row, col, "name")
     place_type_str = rd(line_number, row, col, "type")
     place_latitude = rd(line_number, row, col, "latitude")
     place_longitude = rd(line_number, row, col, "longitude")
     place_code = rd(line_number, row, col, "code")
     place_enclosed_by_id = rd(line_number, row, col, "enclosed_by")
     place_date = rd(line_number, row, col, "date")
     #########################################################
     # if this place already exists, don't create it
     place = self.lookup("place", place_id)
     if place is None:
         # new place
         place = self.create_place()
         if place_id is not None:
             if place_id.startswith("[") and place_id.endswith("]"):
                 place.gramps_id = self.db.pid2user_format(place_id[1:-1])
             self.storeup("place", place_id, place)
     if place_title is not None:
         place.title = place_title
     if place_name is not None:
         place.name = PlaceName(value=place_name)
     if place_type_str is not None:
         place.place_type = self.get_place_type(place_type_str)
     if place_latitude is not None:
         place.lat = place_latitude
     if place_longitude is not None:
         place.long = place_longitude
     if place_code is not None:
         place.code = place_code
     if place_enclosed_by_id is not None:
         place_enclosed_by = self.lookup("place", place_enclosed_by_id)
         if place_enclosed_by is None:
             raise Exception("cannot enclose %s in %s as it doesn't exist" % (place.gramps_id, place_enclosed_by_id))
         if not place_enclosed_by.handle in place.placeref_list:
             placeref = PlaceRef()
             placeref.ref = place_enclosed_by.handle
             if place_date:
                 placeref.date = _dp.parse(place_date)
             place.placeref_list.append(placeref)
     #########################################################
     self.db.commit_place(place, self.trans)
Beispiel #15
0
 def __add_place(self, parent, plat, plon):
     """
     Add a new place using longitude and latitude of location centered
     on the map
     """
     self.select_fct.close()
     new_place = Place()
     new_place.set_latitude(str(plat))
     new_place.set_longitude(str(plon))
     if parent:
         placeref = PlaceRef()
         placeref.ref = parent
         new_place.add_placeref(placeref)
     try:
         EditPlace(self.dbstate, self.uistate, [], new_place)
         self.add_marker(None, None, plat, plon, None, True, 0)
     except WindowActiveError:
         pass
Beispiel #16
0
 def __add_place(self, parent, plat, plon):
     """
     Add a new place using longitude and latitude of location centered
     on the map
     """
     self.select_fct.close()
     new_place = Place()
     new_place.set_latitude(str(plat))
     new_place.set_longitude(str(plon))
     if parent:
         placeref = PlaceRef()
         placeref.ref = parent
         new_place.add_placeref(placeref)
     try:
         EditPlace(self.dbstate, self.uistate, [], new_place)
         self.add_marker(None, None, plat, plon, None, True, 0)
     except WindowActiveError:
         pass
Beispiel #17
0
    def add(self, obj):
        """
        Add a new place.  Use the currently selected rows as parent places.
        """
        parent_list = []
        for handle in self.selected_handles():
            placeref = PlaceRef()
            placeref.ref = handle
            parent_list.append(placeref)

        place = Place()
        if len(parent_list) > 0:
            place.placeref_list = parent_list

        try:
            EditPlace(self.dbstate, self.uistate, [], place)
        except WindowActiveError:
            pass
Beispiel #18
0
 def __set_enclosing_place(self, obj):
     if not self.selected_handle: return
     print(type(self.uistate.viewmanager.active_page))
     if type(self.uistate.viewmanager.active_page) == PlaceTreeView: return
     selected_handles = self.uistate.viewmanager.active_page.selected_handles(
     )
     num_places = len(selected_handles)
     with DbTxn(_("Setting ..."), self.dbstate.db) as trans:
         for handle in selected_handles:
             if handle == self.selected_handle:
                 continue  # place should not include itself
             place = self.dbstate.db.get_place_from_handle(handle)
             pname = place.get_name().value
             print(pname, "<", self.selected_name)
             placeref = PlaceRef()
             placeref.ref = self.selected_handle
             place.add_placeref(placeref)
             self.dbstate.db.commit_place(place, trans)
Beispiel #19
0
    def add(self, obj):
        """
        Add a new place.  Use the currently selected rows as parent places.
        """
        parent_list = []
        for handle in self.selected_handles():
            placeref = PlaceRef()
            placeref.ref = handle
            parent_list.append(placeref)

        place = Place()
        if len(parent_list) > 0:
            place.placeref_list = parent_list
        
        try:
            EditPlace(self.dbstate, self.uistate, [], place)
        except WindowActiveError:
            pass
Beispiel #20
0
    def addPlace(pname, ptype, refPlace=None):
        place = Place()
        placeName = PlaceName()
        placeName.set_value(pname)
        place.set_name(placeName)
        #        place.set_change_time(chgtime)
        place.set_type(ptype)
        place.add_tag(tags[ptype])
        if refPlace != None:
            placeRef = PlaceRef()
            placeRef.set_reference_handle(refPlace.get_handle())
            place.add_placeref(placeRef)
#        tag.set_color("#EF2929")
        with DbTxn(_("Add Place"), db) as trans:
            phandle = db.add_place(place, trans)
            LOG.debug('Place added: ' + place.get_name().get_value() + ' ' +
                      phandle)
        return place
Beispiel #21
0
 def __addPlace(self, pname, ptype, altNames=None, refPlace=None, tag=None):
     place = Place()
     placeName = PlaceName() 
     placeName.set_value(pname)
     place.set_name(placeName)
     if altNames:
         place.set_alternative_names(altNames)                
     place.set_type(ptype)
     if tag:
         place.add_tag(tag)
     if refPlace:
         placeRef = PlaceRef()
         placeRef.set_reference_handle(refPlace.get_handle())
         place.add_placeref(placeRef)
     with DbTxn(_("Add Place"), self.dbstate.db) as trans:
         handle = self.dbstate.db.add_place(place, trans)
         place = self.dbstate.db.get_place_from_handle(handle)
         self.dbstate.db.commit_place(place, trans)
     return place 
Beispiel #22
0
    def __get_places(self, _obj):
        gov_id = self.entry.get_text()
        to_do = [gov_id]
        try:
            preferred_lang = config.get('preferences.place-lang')
        except AttributeError:
            fmt = config.get('preferences.place-format')
            pf = _pd.get_formats()[fmt]
            preferred_lang = pf.language
        if len(preferred_lang) != 2:
            preferred_lang = glocale.lang
        visited = {}

        if not self.type_dic:
            self.__get_types()

        with DbTxn(_('Add GOV-id place %s') % gov_id,
                   self.dbstate.db) as trans:
            while to_do:
                gov_id = to_do.pop()
                place = self.dbstate.db.get_place_from_gramps_id(gov_id)
                if place is not None:
                    visited[gov_id] = (place, [])
                else:
                    place, ref_list = self.__get_place(gov_id, self.type_dic,
                                                       preferred_lang)
                    if place.get_name().get_value is not '':
                        self.dbstate.db.add_place(place, trans)
                        visited[gov_id] = (place, ref_list)
                        for ref, date in ref_list:
                            if (ref not in to_do) and (ref not in visited):
                                to_do.append(ref)

            for place, ref_list in visited.values():
                if len(ref_list) > 0:
                    for ref, date in ref_list:
                        handle = visited[ref][0].handle
                        place_ref = PlaceRef()
                        place_ref.ref = handle
                        place_ref.set_date_object(date)
                        place.add_placeref(place_ref)
                    self.dbstate.db.commit_place(place, trans)
        self.dbstate.db.save_place_types()
Beispiel #23
0
 def __link_place(self, parent, plat, plon):
     """
     Link an existing place using longitude and latitude of location centered
     on the map
     """
     selector = SelectPlace(self.dbstate, self.uistate, [])
     place = selector.run()
     if place:
         self.select_fct.close()
         place.set_latitude(str(plat))
         place.set_longitude(str(plon))
         if parent:
             placeref = PlaceRef()
             placeref.ref = parent
             place.add_placeref(placeref)
         try:
             EditPlace(self.dbstate, self.uistate, [], place)
             self.add_marker(None, None, plat, plon, None, True, 0)
         except WindowActiveError:
             pass
Beispiel #24
0
 def __link_place(self, parent, plat, plon):
     """
     Link an existing place using longitude and latitude of location centered
     on the map
     """
     selector = SelectPlace(self.dbstate, self.uistate, [])
     place = selector.run()
     if place:
         self.select_fct.close()
         place.set_latitude(str(plat))
         place.set_longitude(str(plon))
         if parent:
             placeref = PlaceRef()
             placeref.ref = parent
             place.add_placeref(placeref)
         try:
             EditPlace(self.dbstate, self.uistate, [], place)
             self.add_marker(None, None, plat, plon, None, True, 0)
         except WindowActiveError:
             pass
Beispiel #25
0
 def __add_place(self, parent, plat, plon):
     """
     Add a new place using longitude and latitude of location centered
     on the map
     """
     self.select_fct.close()
     new_place = Place()
     new_place.set_latitude(str(plat))
     new_place.set_longitude(str(plon))
     if parent:
         if isinstance(parent, Place):
             placeref = PlaceRef()
             placeref.ref = parent
             new_place.add_placeref(placeref)
         elif isinstance(parent, gi.overrides.Gtk.TreeModelRow):
             # We are here because we selected a place from geocoding
             # parent[0] : country
             # parent[1] : state
             # parent[2] : town
             # parent[3] : name
             value = PlaceSelection.untag_text(parent[2], 1)
             plname = PlaceName()
             plname.set_value(value)
             handle = self.place_exists(value)
             if handle:
                 # The town already exists. We create a place with name
                 placeref = PlaceRef()
                 placeref.ref = handle
                 new_place.add_placeref(placeref)
                 value = PlaceSelection.untag_text(parent[3], 1)
                 plname.set_value(value)
             new_place.set_name(plname)
         else:
             found = None
             for place in self.dbstate.db.iter_places():
                 found = place
                 if place.name.get_value() == parent:
                     break
             placeref = PlaceRef()
             placeref.ref = found.get_handle()
             new_place.add_placeref(placeref)
     try:
         EditPlace(self.dbstate, self.uistate, [], new_place)
         self.add_marker(None, None, plat, plon, None, True, 0)
     except WindowActiveError:
         pass
Beispiel #26
0
    def enclosed_by(self, parent, end, start):
        parent_ent = self.dbstate.db.get_place_from_gramps_id(parent)
        parent_ref = PlaceRef()
        parent_ref.set_reference_handle(parent_ent.get_handle())
        if start is not None:
            if end is not None:
                date = Date()

                start_dict = start.get_parsed_datetime_dict()
                end_dict = end.get_parsed_datetime_dict()
                slash2 = False
                date.set(quality=None,
                         modifier=Date.MOD_SPAN,
                         calendar=None,
                         value=((start_dict['day']), (start_dict['month']),
                                (start_dict['year']), False, (end_dict['day']),
                                (end_dict['month']), (end_dict['year']),
                                slash2),
                         text=None)
                parent_ref.set_date_object(date=date)
            else:
                date = Date()
                start_dict = start.get_parsed_datetime_dict()
                date.set(quality=None,
                         modifier=Date.MOD_AFTER,
                         calendar=None,
                         value=((start_dict['day']), (start_dict['month']),
                                (start_dict['year']), False),
                         text=None)
                parent_ref.set_date_object(date=date)
        elif end is not None:
            date = Date()
            end_dict = end.get_parsed_datetime_dict()
            date.set(quality=None,
                     modifier=Date.MOD_BEFORE,
                     calendar=None,
                     value=((end_dict['day']), (end_dict['month']),
                            (end_dict['year']), False),
                     text=None)
            parent_ref.set_date_object(date=date)
        return parent_ref
Beispiel #27
0
    def generate_hierarchy(self, trans):
        """
        Generate missing places in the place hierarchy.
        """
        for handle, location in self.handle2loc.items():

            # find title and type
            for type_num, name in enumerate(location):
                if name:
                    break

            loc = list(location)
            loc[type_num] = ''

            # find top parent
            parent = None
            for n in range(7):
                if loc[n]:
                    tup = tuple([''] * n + loc[n:])
                    parent = self.loc2handle.get(tup)
                    if parent:
                        break

            # create missing parent places
            if parent:
                n -= 1
            while n > type_num:
                if loc[n]:
                    # TODO for Arabic, should the next comma be translated?
                    title = ', '.join([item for item in loc[n:] if item])
                    parent = self.__add_place(loc[n], n, parent, title, trans)
                    self.loc2handle[tuple([''] * n + loc[n:])] = parent
                n -= 1

            # link to existing place
            if parent:
                place = self.db.get_place_from_handle(handle)
                placeref = PlaceRef()
                placeref.ref = parent
                place.set_placeref_list([placeref])
                self.db.commit_place(place, trans, place.get_change_time())
Beispiel #28
0
    def __get_places(self, obj):
        gov_id = self.entry.get_text()
        to_do = [gov_id]
        try:
            preferred_lang = config.get('preferences.place-lang')
        except AttributeError:
            fmt = config.get('preferences.place-format')
            pf = _pd.get_formats()[fmt]
            preferred_lang = pf.language
        if len(preferred_lang) != 2:
            preferred_lang = 'de'
        visited = {}

        if not self.type_dic:
            self.__get_types()

        with DbTxn(_('Add GOV-id place %s') % gov_id, self.dbstate.db) as trans:
            while to_do:
                gov_id = to_do.pop()
                place = self.dbstate.db.get_place_from_gramps_id(gov_id)
                if place is not None:
                    visited[gov_id] = (place, [])
                else:
                    place, ref_list = self.__get_place(gov_id, self.type_dic,
                                                       preferred_lang)
                    if place.get_name().get_value is not '':
                        self.dbstate.db.add_place(place, trans)
                        visited[gov_id] = (place, ref_list)
                        for ref, date in ref_list:
                            if (ref not in to_do) and (ref not in visited):
                                to_do.append(ref)

            for place, ref_list in visited.values():
                if len(ref_list) > 0:
                    for ref, date in ref_list:
                        handle = visited[ref][0].handle
                        place_ref = PlaceRef()
                        place_ref.ref = handle
                        place_ref.set_date_object(date)
                        place.add_placeref(place_ref)
                    self.dbstate.db.commit_place(place, trans)
Beispiel #29
0
    def generate_hierarchy(self, trans):
        """
        Generate missing places in the place hierarchy.
        """
        for handle, location in self.handle2loc.items():

            # find title and type
            for type_num, name in enumerate(location):
                if name:
                    break

            loc = list(location)
            loc[type_num] = ''

            # find top parent
            parent = None
            for n in range(7):
                if loc[n]:
                    tup = tuple([''] * n + loc[n:])
                    parent = self.loc2handle.get(tup)
                    if parent:
                        break

            # create missing parent places
            if parent:
                n -= 1
            while n > type_num:
                if loc[n]:
                    # TODO for Arabic, should the next comma be translated?
                    title = ', '.join([item for item in loc[n:] if item])
                    parent = self.__add_place(loc[n], n, parent, title, trans)
                    self.loc2handle[tuple([''] * n + loc[n:])] = parent
                n -= 1

            # link to existing place
            if parent:
                place = self.db.get_place_from_handle(handle)
                placeref = PlaceRef()
                placeref.ref = parent
                place.set_placeref_list([placeref])
                self.db.commit_place(place, trans, place.get_change_time())
 def __add_place(self, parent, plat, plon):
     """
     Add a new place using longitude and latitude of location centered
     on the map
     """
     self.select_fct.close()
     new_place = Place()
     new_place.set_latitude(str(plat))
     new_place.set_longitude(str(plon))
     if parent:
         if isinstance(parent, Place):
             placeref = PlaceRef()
             placeref.ref = parent
             new_place.add_placeref(placeref)
         else:
             found = None
             for place in self.dbstate.db.iter_places():
                 found = place
                 if place.name.get_value() == parent:
                     break
             placeref = PlaceRef()
             placeref.ref = found.get_handle()
             new_place.add_placeref(placeref)
     try:
         EditPlace(self.dbstate, self.uistate, [], new_place)
         self.add_marker(None, None, plat, plon, None, True, 0)
     except WindowActiveError:
         pass
Beispiel #31
0
 def handle_extra_type(self, objtype, obj):
     if obj in self.get_skip_list(self.handle):
         ErrorDialog(_("Place cycle detected"),
                     _("The place you are adding is already enclosed by "
                       "this place"))
         return
     place = self.dbstate.db.get_place_from_handle(obj)
     placeref = PlaceRef()
     try:
         from .. import EditPlaceRef
         EditPlaceRef(self.dbstate, self.uistate, self.track,
                      place, placeref, self.add_callback)
     except WindowActiveError:
         pass
    def addPlace(priName, altNames, ptype, refPlace=None):
        place = Place()
        placeName = PlaceName() 
        placeName.set_value(priName[0])
        placeName.set_language(priName[1])
        place.set_name(placeName)

        if len(altNames) > 0:
            place.set_alternative_names(altNames)                
#        place.set_change_time(chgtime)
        place.set_type(ptype)
#        place.add_tag(tags[ptype])
        place.add_tag(reftag)
        if refPlace != None:
            placeRef = PlaceRef()
            placeRef.set_reference_handle(refPlace.get_handle())
            place.add_placeref(placeRef)
#        tag.set_color("#EF2929")
        with DbTxn(_("Add Place"), db) as trans:
            phandle = db.add_place(place, trans)

            LOG.debug('Place added: ' + place.get_name().get_value() + ' ' + phandle)
        return place 
Beispiel #33
0
    def share_button_clicked(self, obj):
        SelectPlace = SelectorFactory('Place')

        sel = SelectPlace(self.dbstate, self.uistate, self.track,
                          skip=self.get_skip_list(self.handle))
        place = sel.run()
        if place:
            ref = PlaceRef()
            try:
                from .. import EditPlaceRef
                EditPlaceRef(self.dbstate, self.uistate, self.track,
                             place, ref, self.add_callback)
            except WindowActiveError:
                pass
Beispiel #34
0
    def __addPlace(self, pname, ptype, altNames=None, refPlace=None, tag=None):
        place = Place()
        placeName = PlaceName()
        placeName.set_value(pname)
        #        placeName.set_language(priName[1])
        place.set_name(placeName)
        print(pname)
        if altNames:
            place.set_alternative_names(altNames)
#        place.set_change_time(chgtime)
        place.set_type(ptype)
        print(ptype)
        if tag:
            place.add_tag(tag)
        if refPlace:
            placeRef = PlaceRef()
            placeRef.set_reference_handle(refPlace.get_handle())
            place.add_placeref(placeRef)
        with DbTxn(_("Add Place"), self.dbstate.db) as trans:
            handle = self.dbstate.db.add_place(place, trans)
            place = self.dbstate.db.get_place_from_handle(handle)
            self.dbstate.db.commit_place(place, trans)
#            print('Place added: ' + place.get_name().get_value() + ' ' + phandle)
        return place
Beispiel #35
0
    def run(self):
        """
        Generate the hierarchy.
        """
        with self.user.progress(_("Generating hierarchy"), '',
                                self.db.get_number_of_places()) as step:

            for handle in self.db.get_place_handles():
                step()
                place = self.db.get_place_from_handle(handle)

                if (int(place.get_type()) != PlaceType.UNKNOWN
                        or ',' not in place.get_title()):
                    # Only process places with a type of Unknown.
                    continue

                names = [
                    name.strip() for name in place.get_title().split(',')
                    if name.strip()
                ]
                place_name = PlaceName()
                place_name.set_value(names[0])
                place.set_name(place_name)
                place.set_title('')

                parent_handle = None
                for name, handle in self.find_hierarchy(names)[:-1]:
                    if handle is None:
                        new_place = Place()
                        place_name = PlaceName()
                        place_name.set_value(name)
                        new_place.set_name(place_name)
                        if parent_handle is None:
                            new_place.set_type(PlaceType.COUNTRY)
                        if parent_handle is not None:
                            placeref = PlaceRef()
                            placeref.ref = parent_handle
                            new_place.add_placeref(placeref)
                        with DbTxn(_("Add Place"), self.db) as trans:
                            parent_handle = self.db.add_place(new_place, trans)
                    else:
                        parent_handle = handle

                if parent_handle is not None:
                    placeref = PlaceRef()
                    placeref.ref = parent_handle
                    place.add_placeref(placeref)
                with DbTxn(_("Edit Place"), self.db) as trans:
                    self.db.commit_place(place, trans)
Beispiel #36
0
 def __add_place(self, parent, plat, plon):
     """
     Add a new place using longitude and latitude of location centered
     on the map
     """
     self.select_fct.close()
     new_place = Place()
     new_place.set_latitude(str(plat))
     new_place.set_longitude(str(plon))
     if parent:
         if isinstance(parent, Place):
             placeref = PlaceRef()
             placeref.ref = parent
             new_place.add_placeref(placeref)
         elif isinstance(parent, gi.overrides.Gtk.TreeModelRow):
             # We are here because we selected a place from geocoding
             # parent[0] : country
             # parent[1] : state
             # parent[2] : town
             # parent[3] : name
             value = PlaceSelection.untag_text(parent[2], 1)
             plname = PlaceName()
             plname.set_value(value)
             handle = self.place_exists(value)
             if handle:
                 # The town already exists. We create a place with name
                 placeref = PlaceRef()
                 placeref.ref = handle
                 new_place.add_placeref(placeref)
                 value = PlaceSelection.untag_text(parent[3], 1)
                 plname.set_value(value)
             new_place.set_name(plname)
         else:
             found = None
             for place in self.dbstate.db.iter_places():
                 found = place
                 if place.name.get_value() == parent:
                     break
             placeref = PlaceRef()
             placeref.ref = found.get_handle()
             new_place.add_placeref(placeref)
     try:
         EditPlace(self.dbstate, self.uistate, [], new_place)
         self.add_marker(None, None, plat, plon, None, True, 0)
     except WindowActiveError:
         pass
 def on_res_ok_clicked(self, dummy):
     """ Accept changes displayed and commit to place.
     Also find or create a new enclosing place from parent. """
     # do the names
     namelist = []
     for row in self.alt_store:
         if row[0] == 'P':
             self.place.name = self.newplace.names[row[4]]
         elif row[0] == '\u2714':
             namelist.append(self.newplace.names[row[4]])
     self.place.alt_names = namelist
     # Lat/lon/ID/code/type
     self.place.lat = self.top.get_object('latitude').get_text()
     self.place.long = self.top.get_object('longitude').get_text()
     self.place.gramps_id = self.top.get_object('grampsid').get_text()
     self.place.code = self.top.get_object('postal').get_text()
     self.place.place_type.set(self.type_combo.get_values())
     # Add in URLs if wanted
     if self.keepweb:
         for url in self.newplace.links:
             self.place.add_url(url)
     # Enclose in the next level place
     next_place = False
     parent = None
     if not self.keep_enclosure or not self.place.placeref_list:
         if self.newplace.parent_ids:
             # we might have a parent with geo id 'GEO12345'
             parent = self.dbstate.db.get_place_from_gramps_id(
                 self.newplace.parent_ids[0])
         if not parent and self.newplace.parent_names:
             # make one, will have to be examined/cleaned later
             parent = Place()
             parent.title = ', '.join(self.newplace.parent_names)
             name = PlaceName()
             name.value = parent.title
             parent.name = name
             parent.gramps_id = self.newplace.parent_ids[0]
             with DbTxn(
                     _("Add Place (%s)") % parent.title,
                     self.dbstate.db) as trans:
                 self.dbstate.db.add_place(parent, trans)
                 next_place = True
         if parent:
             if located_in(self.dbstate.db, parent.handle,
                           self.place.handle):
                 # attempting to create a place loop, not good!
                 ErrorDialog(_('Place cycle detected'),
                             msg2=_("The place you chose is enclosed in the"
                                    " place you are workin on!\n"
                                    "Please cancel and choose another "
                                    "place."),
                             parent=self.uistate.window)
                 return
             # check to see if we already have the enclosing place
             already_there = False
             for pref in self.place.placeref_list:
                 if parent.handle == pref.ref:
                     already_there = True
                     break
             if not already_there:
                 placeref = PlaceRef()
                 placeref.set_reference_handle(parent.handle)
                 self.place.set_placeref_list([placeref])
     # Add in Citation/Source if wanted
     if self.addcitation and self.newplace.geoid:
         src_hndl = self.find_or_make_source()
         cit = Citation()
         cit.set_reference_handle(src_hndl)
         cit.set_page("GeoNames ID: %s" %
                      self.newplace.geoid.replace('GEO', ''))
         with DbTxn(_("Add Citation (%s)") % "GeoNames",
                    self.dbstate.db) as trans:
             self.dbstate.db.add_citation(cit, trans)
         self.place.add_citation(cit.handle)
     # We're finally ready to commit the updated place
     with DbTxn(_("Edit Place (%s)") % self.place.title,
                self.dbstate.db) as trans:
         self.dbstate.db.commit_place(self.place, trans)
     # Jump to enclosing place to clean it if necessary
     if next_place:
         self.set_active('Place', parent.handle)
         self.place = parent
         # if geoparse fails, leave us at main view
         if self.newplace.parent_ids and \
             self.geoparse(self.newplace.parent_ids[0],
                           _(", ").join(self.newplace.parent_names),
                           self.newplace.parent_ids,
                           self.newplace.parent_names):
             # geoparse worked, lets put up the results view
             self.gui.get_child().remove(self.mainwin)
             self.gui.get_child().add(self.results_win)
             self.res_gui()
             return
     self.reset_main()
     if self.gui.get_child().get_child() == self.results_win:
         self.gui.get_child().remove(self.results_win)
         self.gui.get_child().add(self.mainwin)
Beispiel #38
0
 def on_res_ok_clicked(self, dummy):
     """ Accept changes displayed and commit to place.
     Also find or create a new enclosing place from parent. """
     # do the names
     namelist = []
     for row in self.alt_store:
         if row[0] == 'P':
             self.place.name = self.newplace.names[row[4]]
         elif row[0] == '\u2714':
             namelist.append(self.newplace.names[row[4]])
     self.place.alt_names = namelist
     # Lat/lon/ID/code/type
     self.place.lat = self.top.get_object('latitude').get_text()
     self.place.long = self.top.get_object('longitude').get_text()
     self.place.gramps_id = self.top.get_object('grampsid').get_text()
     self.place.code = self.top.get_object('postal').get_text()
     self.place.place_type.set(self.type_combo.get_values())
     # Add in URLs if wanted
     if self.keepweb:
         for url in self.newplace.links:
             self.place.add_url(url)
     # Enclose in the next level place
     next_place = False
     parent = None
     if not self.keep_enclosure or not self.place.placeref_list:
         if self.newplace.parent_ids:
             # we might have a parent with geo id 'GEO12345'
             parent = self.dbstate.db.get_place_from_gramps_id(
                 self.newplace.parent_ids[0])
         if not parent and self.newplace.parent_names:
             # make one, will have to be examined/cleaned later
             parent = Place()
             parent.title = ', '.join(self.newplace.parent_names)
             name = PlaceName()
             name.value = parent.title
             parent.name = name
             parent.gramps_id = self.newplace.parent_ids[0]
             with DbTxn(_("Add Place (%s)") % parent.title,
                        self.dbstate.db) as trans:
                 self.dbstate.db.add_place(parent, trans)
                 next_place = True
         if parent:
             if located_in(self.dbstate.db, parent.handle,
                           self.place.handle):
                 # attempting to create a place loop, not good!
                 ErrorDialog(_('Place cycle detected'),
                             msg2=_("The place you chose is enclosed in the"
                                    " place you are workin on!\n"
                                    "Please cancel and choose another "
                                    "place."),
                             parent=self.uistate.window)
                 return
             # check to see if we already have the enclosing place
             already_there = False
             for pref in self.place.placeref_list:
                 if parent.handle == pref.ref:
                     already_there = True
                     break
             if not already_there:
                 placeref = PlaceRef()
                 placeref.set_reference_handle(parent.handle)
                 self.place.set_placeref_list([placeref])
     # Add in Citation/Source if wanted
     if self.addcitation and self.newplace.geoid:
         src_hndl = self.find_or_make_source()
         cit = Citation()
         cit.set_reference_handle(src_hndl)
         cit.set_page("GeoNames ID: %s" %
                      self.newplace.geoid.replace('GEO', ''))
         with DbTxn(_("Add Citation (%s)") % "GeoNames",
                    self.dbstate.db) as trans:
             self.dbstate.db.add_citation(cit, trans)
         self.place.add_citation(cit.handle)
     # We're finally ready to commit the updated place
     with DbTxn(_("Edit Place (%s)") % self.place.title,
                self.dbstate.db) as trans:
         self.dbstate.db.commit_place(self.place, trans)
     # Jump to enclosing place to clean it if necessary
     if next_place:
         self.set_active('Place', parent.handle)
         self.place = parent
         # if geoparse fails, leave us at main view
         if self.newplace.parent_ids and \
             self.geoparse(self.newplace.parent_ids[0],
                           _(", ").join(self.newplace.parent_names),
                           self.newplace.parent_ids,
                           self.newplace.parent_names):
             # geoparse worked, lets put up the results view
             self.gui.get_child().remove(self.mainwin)
             self.gui.get_child().add(self.results_win)
             self.res_gui()
             return
     self.reset_main()
     if self.gui.get_child().get_child() == self.results_win:
         self.gui.get_child().remove(self.results_win)
         self.gui.get_child().add(self.mainwin)