Ejemplo n.º 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
Ejemplo n.º 2
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
Ejemplo n.º 3
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
Ejemplo n.º 4
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)
Ejemplo n.º 5
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
Ejemplo n.º 6
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
Ejemplo n.º 7
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
Ejemplo n.º 8
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 
Ejemplo n.º 9
0
    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 
Ejemplo n.º 10
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
Ejemplo n.º 11
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
Ejemplo n.º 12
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