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
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
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
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
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
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)