From 04c39a72e00c11c6224c2e3524864f8522475487 Mon Sep 17 00:00:00 2001 From: SNoiraud Date: Sat, 26 Dec 2015 17:09:02 +0100 Subject: [PATCH] 9126 : Better place levels handling in geography view. --- gramps/plugins/lib/maps/geography.py | 16 ++++++++-- gramps/plugins/lib/maps/placeselection.py | 36 +++++++++++++++++------ 2 files changed, 40 insertions(+), 12 deletions(-) diff --git a/gramps/plugins/lib/maps/geography.py b/gramps/plugins/lib/maps/geography.py index f52a17ea1..8da297ea2 100644 --- a/gramps/plugins/lib/maps/geography.py +++ b/gramps/plugins/lib/maps/geography.py @@ -1033,9 +1033,19 @@ class GeoGraphyView(OsmGps, NavigationView): new_place.set_latitude(str(plat)) new_place.set_longitude(str(plon)) if parent: - placeref = PlaceRef() - placeref.ref = parent - new_place.add_placeref(placeref) + 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) diff --git a/gramps/plugins/lib/maps/placeselection.py b/gramps/plugins/lib/maps/placeselection.py index 3bfb6fb19..f241bf8f7 100644 --- a/gramps/plugins/lib/maps/placeselection.py +++ b/gramps/plugins/lib/maps/placeselection.py @@ -56,6 +56,7 @@ from gramps.gui.managedwindow import ManagedWindow from .osmgps import OsmGps from gramps.gen.utils.location import get_main_location from gramps.gen.lib import PlaceType +from gramps.gen.display.place import displayer as place_displayer #------------------------------------------------------------------------- # @@ -77,9 +78,18 @@ def match(self, lat, lon, radius): if (math.hypot(lat-float(entry[3]), lon-float(entry[4])) <= rds) == True: # Do we already have this place ? avoid duplicates - country, state, county, place = self.get_location(entry[9]) - if not [country, state, county, place] in self.places: - self.places.append([country, state, county, place]) + country, state, county, place, other = self.get_location(entry[9]) + if not [country, state, county, place, other] in self.places: + self.places.append([country, state, county, place, other]) + for place in self.dbstate.db.iter_places(): + latn = place.get_latitude() + lonn = place.get_longitude() + if latn and lonn: + if (math.hypot(lat-float(latn), + lon-float(lonn)) <= rds) == True: + country, state, county, place, other = self.get_location(place.get_gramps_id()) + if not [country, state, county, place, other] in self.places: + self.places.append([country, state, county, place, other]) return self.places #------------------------------------------------------------------------- @@ -137,19 +147,22 @@ class PlaceSelection(ManagedWindow, OsmGps): self.scroll = Gtk.ScrolledWindow(self.vadjust) self.scroll.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC) self.scroll.set_shadow_type(Gtk.ShadowType.IN) - self.plist = Gtk.ListStore(str, str, str, str) + self.plist = Gtk.ListStore(str, str, str, str, str) self.choices = Gtk.TreeView(self.plist) self.scroll.add(self.choices) self.renderer = Gtk.CellRendererText() self.tvcol1 = Gtk.TreeViewColumn(_('Country'), self.renderer, markup=0) self.tvcol2 = Gtk.TreeViewColumn(_('State'), self.renderer, markup=1) self.tvcol3 = Gtk.TreeViewColumn(_('County'), self.renderer, markup=2) + self.tvcol4 = Gtk.TreeViewColumn(_('Other'), self.renderer, markup=3) self.tvcol1.set_sort_column_id(0) self.tvcol2.set_sort_column_id(1) self.tvcol3.set_sort_column_id(2) + self.tvcol4.set_sort_column_id(3) self.choices.append_column(self.tvcol1) self.choices.append_column(self.tvcol2) self.choices.append_column(self.tvcol3) + self.choices.append_column(self.tvcol4) self.window.vbox.pack_start(self.scroll, True, True, 0) self.label2 = Gtk.Label() self.label2.set_markup('