def find_or_make_source(self): """ Find or create a source. returns handle to source.""" for hndl in self.dbstate.db.get_source_handles(): if self.dbstate.db.get_raw_source_data(hndl)[2] == 'GeoNames': return hndl # No source found, lets add one with associated repo and note repo = Repository() repo.set_name("www.geonames.org") rtype = RepositoryType(RepositoryType.WEBSITE) repo.set_type(rtype) url = Url() url.set_path('http://www.geonames.org/') url.set_description(_('GeoNames web site')) url.set_type(UrlType(UrlType.WEB_HOME)) repo.add_url(url) url = Url() url.set_path('*****@*****.**') url.set_description(_('GeoNames author')) url.set_type(UrlType(UrlType.EMAIL)) repo.add_url(url) note_txt = StyledText( _('GeoNames was founded by Marc Wick. You can reach him at ')) note_txt += StyledText('*****@*****.**' + '\n') note_txt += StyledText( _('GeoNames is a project of Unxos GmbH, Weingartenstrasse 8,' ' 8708 Männedorf, Switzerland.\nThis work is licensed under a ')) note_txt += linkst( _('Creative Commons Attribution 3.0 License'), 'https://creativecommons.org/licenses/by/3.0/legalcode') new_note = Note() new_note.set_styledtext(note_txt) new_note.set_type(NoteType.REPO) src = Source() src.title = 'GeoNames' src.author = 'Marc Wick' repo_ref = RepoRef() mtype = SourceMediaType(SourceMediaType.ELECTRONIC) repo_ref.set_media_type(mtype) with DbTxn( _("Add Souce/Repo/Note (%s)") % "GeoNames", self.dbstate.db) as trans: self.dbstate.db.add_note(new_note, trans) repo.add_note(new_note.get_handle()) self.dbstate.db.add_repository(repo, trans) repo_ref.set_reference_handle(repo.handle) src.add_repo_reference(repo_ref) self.dbstate.db.add_source(src, trans) return src.handle
def find_or_make_source(self): """ Find or create a source. returns handle to source.""" for hndl in self.dbstate.db.get_source_handles(): if self.dbstate.db.get_raw_source_data(hndl)[2] == 'GeoNames': return hndl # No source found, lets add one with associated repo and note repo = Repository() repo.set_name("www.geonames.org") rtype = RepositoryType(RepositoryType.WEBSITE) repo.set_type(rtype) url = Url() url.set_path('http://www.geonames.org/') url.set_description(_('GeoNames web site')) url.set_type(UrlType(UrlType.WEB_HOME)) repo.add_url(url) url = Url() url.set_path('*****@*****.**') url.set_description(_('GeoNames author')) url.set_type(UrlType(UrlType.EMAIL)) repo.add_url(url) note_txt = StyledText(_( 'GeoNames was founded by Marc Wick. You can reach him at ')) note_txt += StyledText('*****@*****.**' + '\n') note_txt += StyledText(_( 'GeoNames is a project of Unxos GmbH, Weingartenstrasse 8,' ' 8708 Männedorf, Switzerland.\nThis work is licensed under a ')) note_txt += linkst( _('Creative Commons Attribution 3.0 License'), 'https://creativecommons.org/licenses/by/3.0/legalcode') new_note = Note() new_note.set_styledtext(note_txt) new_note.set_type(NoteType.REPO) src = Source() src.title = 'GeoNames' src.author = 'Marc Wick' repo_ref = RepoRef() mtype = SourceMediaType(SourceMediaType.ELECTRONIC) repo_ref.set_media_type(mtype) with DbTxn(_("Add Souce/Repo/Note (%s)") % "GeoNames", self.dbstate.db) as trans: self.dbstate.db.add_note(new_note, trans) repo.add_note(new_note.get_handle()) self.dbstate.db.add_repository(repo, trans) repo_ref.set_reference_handle(repo.handle) src.add_repo_reference(repo_ref) self.dbstate.db.add_source(src, trans) return src.handle
def on_ok_clicked(self): """ Method that is run when you click the OK button. The numbers of sources and citations are retrieved from the entry box and used to govern the amount of data generated """ num_sources_text = self.sources_entry.get_text() try: num_sources = int(num_sources_text) except: return num_citations_text = self.citations_entry.get_text() num_citations = int(num_citations_text) self.progress = ProgressMeter( 'Generating data', '', parent=self.uistate.window) self.progress.set_pass('Generating data', num_sources*num_citations) LOG.debug("sources %04d citations %04d" % (num_sources, num_citations)) source = Source() citation = Citation() self.db.disable_signals() with DbTxn('Populate sources and citations', self.db) as trans: for i in range(num_sources): source.gramps_id = None source.handle = None source.title = "Source %04d" % (i + 1) source_handle = self.db.add_source(source, trans) for j in range(num_citations): citation.gramps_id = None citation.handle = None citation.source_handle = source_handle citation.page = "Page %04d" % (j + 1) self.db.add_citation(citation, trans) self.progress.step() LOG.debug("sources and citations added") self.db.enable_signals() self.db.request_rebuild() self.progress.close() self.options.handler.options_dict['sources'] = num_sources self.options.handler.options_dict['citations'] = num_citations # Save options self.options.handler.save_options()
def on_ok_clicked(self): """ Method that is run when you click the OK button. The numbers of sources and citations are retrieved from the entry box and used to govern the amount of data generated """ num_sources_text = self.sources_entry.get_text() try: num_sources = int(num_sources_text) except: return num_citations_text = self.citations_entry.get_text() num_citations = int(num_citations_text) self.progress = ProgressMeter( 'Generating data', '') self.progress.set_pass('Generating data', num_sources*num_citations) LOG.debug("sources %04d citations %04d" % (num_sources, num_citations)) source = Source() citation = Citation() self.db.disable_signals() with DbTxn('Populate sources and citations', self.db) as trans: for i in range(num_sources): source.gramps_id = None source.handle = None source.title = "Source %04d" % (i + 1) source_handle = self.db.add_source(source, trans) for j in range(num_citations): citation.gramps_id = None citation.handle = None citation.source_handle = source_handle citation.page = "Page %04d" % (j + 1) self.db.add_citation(citation, trans) self.progress.step() LOG.debug("sources and citations added") self.db.enable_signals() self.db.request_rebuild() self.progress.close() self.options.handler.options_dict['sources'] = num_sources self.options.handler.options_dict['citations'] = num_citations # Save options self.options.handler.save_options()