def on_find_clicked(self, dummy): """ find a matching place. First try in the db, then try in the GeoNames. """ self.res_store.clear() self.top.get_object("select_but").set_sensitive(False) if self.geo_stage: self.search_geo() else: self.geo_stage = True item = self.top.get_object("title_entry") title = item.get_text() self.places = self.lookup_places_by_name(title) for index, place in enumerate(self.places): # make sure the place found isn't self, or a place # enclosed by the working place if place.handle != self.place.handle and not located_in( self.dbstate.db, place.handle, self.place.handle): title = _pd.display(self.dbstate.db, place) self.res_store.append(row=(index, title, str(place.place_type))) if len(self.res_store) > 0: self.res_lbl.set_text(_('%s\nLocal\nMatches') % len(self.res_store)) self.find_but.set_label(_("Find GeoNames")) else: self.search_geo()
def on_find_clicked(self, dummy): """ find a matching place. First try in the db, then try in the GeoNames. """ self.res_store.clear() self.top.get_object("select_but").set_sensitive(False) if self.geo_stage: self.search_geo() else: self.geo_stage = True item = self.top.get_object("title_entry") title = item.get_text() self.places = self.lookup_places_by_name(title) for index, place in enumerate(self.places): # make sure the place found isn't self, or a place # enclosed by the working place if place.handle != self.place.handle and not located_in( self.dbstate.db, place.handle, self.place.handle): title = _pd.display(self.dbstate.db, place) self.res_store.append(row=(index, title, str(place.place_type))) if len(self.res_store) > 0: self.res_lbl.set_text( _('%s\nLocal\nMatches') % len(self.res_store)) self.find_but.set_label(_("Find GeoNames")) else: self.search_geo()
def on_select_clicked(self, *dummy): """ If the selected place is mergable, merge it, otherwise Open completion screen """ model, _iter = self.res_selection.get_selected() if not _iter: return (index, ) = model.get(_iter, 0) place = self.places[index] if not isinstance(place, Place): # we have a geoname_id if place[4]: return # check if we might already have it in db t_place = self.dbstate.db.get_place_from_gramps_id(place[0]) if not t_place or t_place.handle == self.place.handle: # need to process the GeoNames ID for result self.gui.get_child().remove(self.mainwin) self.gui.get_child().add(self.results_win) if not self.geoparse(*place): return self.res_gui() return else: # turns out we already have this place, under different name! place = t_place # we have a Gramps Place, need to merge if place.handle == self.place.handle: # found self, nothing to do. return if(located_in(self.dbstate.db, place.handle, self.place.handle) or located_in(self.dbstate.db, self.place.handle, place.handle)): # attempting to create a place loop, not good! ErrorDialog(_('Place cycle detected'), msg2=_("One of the places you are merging encloses " "the other!\n" "Please choose another place."), parent=self.uistate.window) return # lets clean up the place name self.place.name.value = self.place.name.value.split(',')[0].strip() place_merge = MergePlaceQuery(self.dbstate, place, self.place) place_merge.execute() # after merge we should select merged result self.set_active('Place', place.handle)
def on_select_clicked(self, *dummy): """ If the selected place is mergable, merge it, otherwise Open completion screen """ model, _iter = self.res_selection.get_selected() if not _iter: return (index, ) = model.get(_iter, 0) place = self.places[index] if not isinstance(place, Place): # we have a geoname_id if place[4]: return # check if we might already have it in db t_place = self.dbstate.db.get_place_from_gramps_id(place[0]) if not t_place or t_place.handle == self.place.handle: # need to process the GeoNames ID for result self.gui.get_child().remove(self.mainwin) self.gui.get_child().add(self.results_win) if not self.geoparse(*place): return self.res_gui() return else: # turns out we already have this place, under different name! place = t_place # we have a Gramps Place, need to merge if place.handle == self.place.handle: # found self, nothing to do. return if (located_in(self.dbstate.db, place.handle, self.place.handle) or located_in(self.dbstate.db, self.place.handle, place.handle)): # attempting to create a place loop, not good! ErrorDialog(_('Place cycle detected'), msg2=_("One of the places you are merging encloses " "the other!\n" "Please choose another place."), parent=self.uistate.window) return # lets clean up the place name self.place.name.value = self.place.name.value.split(',')[0].strip() place_merge = MergePlaceQuery(self.dbstate, place, self.place) place_merge.execute() # after merge we should select merged result self.set_active('Place', place.handle)
def merge(self, obj): """ Merge the selected places. """ mlist = self.selected_handles() if len(mlist) != 2: msg = _("Cannot merge places.") msg2 = _("Exactly two places must be selected to perform a merge. " "A second place can be selected by holding down the " "control key while clicking on the desired place.") ErrorDialog(msg, msg2, parent=self.uistate.window) else: if (located_in(self.dbstate.db, mlist[0], mlist[1]) or located_in(self.dbstate.db, mlist[1], mlist[0])): msg = _("Cannot merge places.") msg2 = _("Merging these places would create a cycle in the " "place hierarchy.") ErrorDialog(msg, msg2, parent=self.uistate.window) else: MergePlace(self.dbstate, self.uistate, [], mlist[0], mlist[1], self.merged)
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)
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)