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)
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)
def __init__(self, uistate, dbstate, track, callback): self.title = _('Place Format Editor') ManagedWindow.__init__(self, uistate, track, EditPlaceFormat) self.callback = callback self.top = Glade() self.set_window(self.top.toplevel, None, self.title, None) self.setup_configs('interface.editplaceformat', 600, 400) self.top.get_object('add').connect('clicked', self.__add) self.top.get_object('remove').connect('clicked', self.__remove) self.top.get_object('name').connect('changed', self.__name_changed) self.top.get_object('levels').connect('validate', self._validate) self.window.connect('response', self.__close) self.model = None self.formats = _pd.get_formats() self.current_format = None self.__populate_format_list() self.show()
def __init__(self, uistate, dbstate, track, callback): self.title = _('Place Format Editor') ManagedWindow.__init__(self, uistate, track, EditPlaceFormat) self.callback = callback self.top = Glade() self.set_window(self.top.toplevel, None, self.title, None) self.setup_configs('interface.editplaceformat', 600, 400) self.top.get_object('add').connect('clicked', self.__add) self.top.get_object('remove').connect('clicked', self.__remove) self.top.get_object('name').connect('changed', self.__name_changed) self.top.get_object('levels').connect('validate', self._validate) self.window.connect('response', self.__close) self.model = None self.formats = _pd.get_formats() self.current_format = None self.__populate_format_list() self.show()
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()
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)
def search_geo(self): """ find a matching place in the geonames, if possible """ self.res_store.clear() if not self.geonames_id: ErrorDialog(_('Need to set GeoNames ID'), msg2=_('Use the Help button for more information'), parent=self.uistate.window) return # lets get a preferred language fmt = config.get('preferences.place-format') placef = _pd.get_formats()[fmt] self.lang = placef.language if len(self.lang) != 2: self.lang = 'en' if self.lang not in self.allowed_languages: self.allowed_languages.append(self.lang) # now lets search for a place in GeoNames item = self.top.get_object("title_entry") title = quote(item.get_text().lower().replace('co.', 'county')) adm = self.top.get_object('adm_check').get_active() ppl = self.top.get_object('ppl_check').get_active() spot = self.top.get_object('spot_check').get_active() geo_url = ( 'http://api.geonames.org/search?q=%s' '&maxRows=10&style=SHORT&lang=en&isNameRequired=True' '%s%s%s&username=%s&startRow=%s' % (title, '&featureClass=A' if adm else '', '&featureClass=P' if ppl else '', '&featureClass=S' if spot else '', self.geonames_id, self.start_row)) dom = self.get_geo_data(geo_url) if not dom: return g_names = dom.getElementsByTagName('geoname') if not g_names: WarningDialog(_('No matches were found'), msg2=_('Try changing the Title, or use the "Edit"' ' button to finish this level of the place' ' manually.'), parent=self.uistate.window) return # let's check the total results; if too many, warn user and set up for # another pass through the search. value = dom.getElementsByTagName('totalResultsCount') if value: totalresults = int(value[0].childNodes[0].data) self.res_lbl.set_text(_("%s\nGeoNames\nMatches") % totalresults) if totalresults > 10: self.start_row += 10 if self.matches_warn: self.matches_warn = False WarningDialog( _('%s matches were found') % totalresults, msg2=_('Only 10 matches are shown.\n' 'To see additional results, press the' ' search button again.\n' 'Or try changing the Title with' ' more detail, such as a country.'), parent=self.uistate.window) index = 0 self.places = [] for g_name in g_names: # got a match, now get its hierarchy for display. value = g_name.getElementsByTagName('geonameId') geoid = value[0].childNodes[0].data value = g_name.getElementsByTagName('fcl') fcl = value[0].childNodes[0].data value = g_name.getElementsByTagName('fcode') _type = fcl + ':' + value[0].childNodes[0].data geo_url = ('http://api.geonames.org/hierarchy?geonameId=%s' '&lang=%s&username=%s' % (geoid, self.lang, self.geonames_id)) hier = self.get_geo_data(geo_url) if not hier: return h_names = hier.getElementsByTagName('geoname') h_name_list = [] h_geoid_list = [] for h_name in h_names: value = h_name.getElementsByTagName('fcl') fcl = value[0].childNodes[0].data if fcl not in 'APS': # We don't care about Earth or continent (yet) continue value = h_name.getElementsByTagName('name') h_name_list.append(value[0].childNodes[0].data) value = h_name.getElementsByTagName('geonameId') h_geoid_list.append('GEO' + value[0].childNodes[0].data) # make sure that this place isn't already enclosed by our place. bad = self.place.gramps_id in h_geoid_list[:-1] # assemble a title for the result h_name_list.reverse() h_geoid_list.reverse() if bad: title = ('<span strikethrough="true" strikethrough_color=' '"red">' + _(', ').join(h_name_list) + '</span>') else: title = _(', ').join(h_name_list) row = (index, title, _type) self.res_store.append(row=row) self.places.append(('GEO' + geoid, title, h_geoid_list, h_name_list, bad)) index += 1 while Gtk.events_pending(): Gtk.main_iteration()
def search_geo(self): """ find a matching place in the geonames, if possible """ self.res_store.clear() if not self.geonames_id: ErrorDialog(_('Need to set GeoNames ID'), msg2=_('Use the Help button for more information'), parent=self.uistate.window) return # lets get a preferred language fmt = config.get('preferences.place-format') placef = _pd.get_formats()[fmt] self.lang = placef.language if len(self.lang) != 2: self.lang = 'en' if self.lang not in self.allowed_languages: self.allowed_languages.append(self.lang) # now lets search for a place in GeoNames item = self.top.get_object("title_entry") title = quote(item.get_text().lower().replace('co.', 'county')) adm = self.top.get_object('adm_check').get_active() ppl = self.top.get_object('ppl_check').get_active() spot = self.top.get_object('spot_check').get_active() geo_url = ('http://api.geonames.org/search?q=%s' '&maxRows=10&style=SHORT&lang=en&isNameRequired=True' '%s%s%s&username=%s&startRow=%s' % (title, '&featureClass=A' if adm else '', '&featureClass=P' if ppl else '', '&featureClass=S' if spot else '', self.geonames_id, self.start_row)) dom = self.get_geo_data(geo_url) if not dom: return g_names = dom.getElementsByTagName('geoname') if not g_names: WarningDialog(_('No matches were found'), msg2=_('Try changing the Title, or use the "Edit"' ' button to finish this level of the place' ' manually.'), parent=self.uistate.window) return # let's check the total results; if too many, warn user and set up for # another pass through the search. value = dom.getElementsByTagName('totalResultsCount') if value: totalresults = int(value[0].childNodes[0].data) self.res_lbl.set_text(_("%s\nGeoNames\nMatches") % totalresults) if totalresults > 10: self.start_row += 10 if self.matches_warn: self.matches_warn = False WarningDialog(_('%s matches were found') % totalresults, msg2=_('Only 10 matches are shown.\n' 'To see additional results, press the' ' search button again.\n' 'Or try changing the Title with' ' more detail, such as a country.'), parent=self.uistate.window) index = 0 self.places = [] for g_name in g_names: # got a match, now get its hierarchy for display. value = g_name.getElementsByTagName('geonameId') geoid = value[0].childNodes[0].data value = g_name.getElementsByTagName('fcl') fcl = value[0].childNodes[0].data value = g_name.getElementsByTagName('fcode') _type = fcl + ':' + value[0].childNodes[0].data geo_url = ('http://api.geonames.org/hierarchy?geonameId=%s' '&lang=%s&username=%s' % (geoid, self.lang, self.geonames_id)) hier = self.get_geo_data(geo_url) if not hier: return h_names = hier.getElementsByTagName('geoname') h_name_list = [] h_geoid_list = [] for h_name in h_names: value = h_name.getElementsByTagName('fcl') fcl = value[0].childNodes[0].data if fcl not in 'APS': # We don't care about Earth or continent (yet) continue value = h_name.getElementsByTagName('name') h_name_list.append(value[0].childNodes[0].data) value = h_name.getElementsByTagName('geonameId') h_geoid_list.append('GEO' + value[0].childNodes[0].data) # make sure that this place isn't already enclosed by our place. bad = self.place.gramps_id in h_geoid_list[:-1] # assemble a title for the result h_name_list.reverse() h_geoid_list.reverse() if bad: title = ('<span strikethrough="true" strikethrough_color=' '"red">' + _(', ').join(h_name_list) + '</span>') else: title = _(', ').join(h_name_list) row = (index, title, _type) self.res_store.append(row=row) self.places.append( ('GEO' + geoid, title, h_geoid_list, h_name_list, bad)) index += 1 while Gtk.events_pending(): Gtk.main_iteration()
def listpersonref(self): sc = {'source': 'S_ID', 'citalist': 'C_ID'} stc = {} citation_without_notes = 0 EMPTY = " " def toYear(date): yeartext = date.get_year() return yeartext genderlist = ['w', 'm', 'u'] self.doc.start_paragraph("SRC-SourceTitle") self.doc.write_text(_("Person with Citations")) self.doc.end_paragraph() self.doc.start_table("VISONETable", "SRC-VISONETable") column_titles = [ _("Gramps_ID"), _("Gramps_ID"), _("LNr"), _("Birthdate"), _("Deathdate"), _("Birthyear"), _("Deathyear"), _("Age on Death"), _("gender"), _("Name"), _("Surname"), _("LabelID"), _("LabelGT"), _("Clan"), _("Birth Place"), _("Death Place"), _("Birth Country"), _("Death Country"), _("Birth Lat"), _("Birth Lon") ] i = 0 self.doc.start_row() for title in column_titles: self.doc.start_cell("SRC-TableColumn") self.doc.start_paragraph("SRC-ColumnTitle") self.doc.write_text(title) self.doc.end_paragraph() self.doc.end_cell() self.doc.end_row() i = 0 ii = 0 pe_list = [] for pe in self.__db.get_person_handles(): pe_index = [self.__db.get_person_from_handle(pe).gramps_id, pe] pe_list.append(pe_index) with self._user.progress(_("VIS ATTR Report"), _("Generating report"), len(pe_list)) as step: for pedet in sorted(pe_list, key=lambda t: (t[1])): # for pe in self.__db.get_person_handles(sort_handles=True): i += 1 # increment progress bar step() # print (i, pedet) person = self.__db.get_person_from_handle(pedet[1]) birth = get_birth_or_fallback(self.__db, person) birth_date, birth_sort, birth_place = self.get_date_place( birth) #birth_country = _pd.display_event(self.__db, birth, fmt=self.place_fmt) birth_country = _pd.display_event(self.__db, birth, fmt=6) #print(birth_country) death = get_death_or_fallback(self.__db, person) death_date, death_sort, death_place = self.get_date_place( death) death_country = _pd.display_event(self.__db, death, fmt=6) print(death_country) #print('formats ', _pd.get_formats().levels) for l in _pd.get_formats(): print(l.name, l.levels) age = get_age(self.__db, person) birth_year = "" death_year = "" if birth: birth_year = birth.get_date_object().get_year() if death: death_year = death.get_date_object().get_year() self.doc.start_row() # Person ID self.doc.start_cell("SRC-Cell") self.doc.start_paragraph("SRC-SourceDetails") self.doc.write_text(_("%s") % person.gramps_id) self.doc.end_paragraph() self.doc.end_cell() # Person ID 2nd time self.doc.start_cell("SRC-Cell") self.doc.start_paragraph("SRC-SourceDetails") self.doc.write_text(_("%s") % person.gramps_id) self.doc.end_paragraph() self.doc.end_cell() # LNR self.doc.start_cell("SRC-Cell") self.doc.start_paragraph("SRC-SourceDetails") self.doc.write_text(_("%s") % i) self.doc.end_paragraph() self.doc.end_cell() # Birth Date self.doc.start_cell("SRC-Cell") self.doc.start_paragraph("SRC-SourceDetails") birth = get_birth_or_fallback(self.__db, person) self.doc.write_text(_(" %s") % birth_date) self.doc.end_paragraph() self.doc.end_cell() # Death Date self.doc.start_cell("SRC-Cell") self.doc.start_paragraph("SRC-SourceDetails") self.doc.write_text(_(" %s") % death_date) self.doc.end_paragraph() self.doc.end_cell() # Birth year self.doc.start_cell("SRC-Cell") self.doc.start_paragraph("SRC-SourceDetails") self.doc.write_text(_(" %s") % birth_year) self.doc.end_paragraph() self.doc.end_cell() # Death year self.doc.start_cell("SRC-Cell") self.doc.start_paragraph("SRC-SourceDetails") self.doc.write_text(_(" %s") % death_year) self.doc.end_paragraph() self.doc.end_cell() # Age on death self.doc.start_cell("SRC-TableColumn") self.doc.start_paragraph("SRC-SourceDetails") if age: if age[0] > 0: self.doc.write_text(_("%s") % age[0]) else: if age[1] > 0: self.doc.write_text(_("%s M.") % age[1]) else: if age[2] > 0: self.doc.write_text(_("%s T.") % age[2]) self.doc.end_paragraph() self.doc.end_cell() # Person gender self.doc.start_cell("SRC-Cell") self.doc.start_paragraph("SRC-SourceDetails") self.doc.write_text(_("%s") % genderlist[person.gender]) self.doc.end_paragraph() self.doc.end_cell() # Person Name self.doc.start_cell("SRC-Cell") self.doc.start_paragraph("SRC-SourceDetails") self.doc.write_text( _("%s") % person.get_primary_name().get_regular_name()) self.doc.end_paragraph() self.doc.end_cell() # Person Surname, givenname self.doc.start_cell("SRC-Cell") self.doc.start_paragraph("SRC-SourceDetails") self.doc.write_text( _("%s") % person.get_primary_name().get_name()) self.doc.end_paragraph() self.doc.end_cell() # Label Name (ID) self.doc.start_cell("SRC-Cell") self.doc.start_paragraph("SRC-SourceDetails") label = "" label = _(" %s") % person.get_primary_name().get_regular_name() label = label + _(" [%s]") % person.gramps_id self.doc.write_text(_("%s") % label) self.doc.end_paragraph() self.doc.end_cell() # Label Name (geb-to) self.doc.start_cell("SRC-Cell") self.doc.start_paragraph("SRC-SourceDetails") label = "" label = _(" %s") % person.get_primary_name().get_regular_name() label = label + _(" (%s") % birth_year label = label + _("-%s)") % death_year if label[-3:] == "(-)": label = label[:-3] self.doc.write_text(_("%s") % label) self.doc.end_paragraph() self.doc.end_cell() # Clan Name self.doc.start_cell("SRC-Cell") self.doc.start_paragraph("SRC-SourceDetails") self.doc.write_text(_("%s") % self.find_clan(pe)) self.doc.end_paragraph() self.doc.end_cell() #Place of birth self.doc.start_cell("SRC-Cell") self.doc.start_paragraph("SRC-SourceDetails") self.doc.write_text(_("%s") % birth_place) self.doc.end_paragraph() self.doc.end_cell() #Place of death self.doc.start_cell("SRC-Cell") self.doc.start_paragraph("SRC-SourceDetails") self.doc.write_text(_("%s") % death_place) self.doc.end_paragraph() self.doc.end_cell() #Country of birth self.doc.start_cell("SRC-Cell") self.doc.start_paragraph("SRC-SourceDetails") self.doc.write_text(_("%s") % birth_country) self.doc.end_paragraph() self.doc.end_cell() #Country of death self.doc.start_cell("SRC-Cell") self.doc.start_paragraph("SRC-SourceDetails") self.doc.write_text(_("%s") % death_country) # death_country[4:]) self.doc.end_paragraph() self.doc.end_cell() #Latitude of Place of Birth self.doc.start_cell("SRC-Cell") self.doc.start_paragraph("SRC-SourceDetails") lat_txt = "" lon_txt = "" if birth: lat_txt, lon_txt = self.find_place_lat_lon(birth) self.doc.write_text(_("%s") % lat_txt) self.doc.end_paragraph() self.doc.end_cell() #Longitude of Place of Birth self.doc.start_cell("SRC-Cell") self.doc.start_paragraph("SRC-SourceDetails") lat_txt = "" lon_txt = "" if birth: lat_txt, lon_txt = self.find_place_lat_lon(birth) self.doc.write_text(_("%s") % lon_txt) self.doc.end_paragraph() self.doc.end_cell() self.doc.end_row() self.doc.end_table()