def _createmap(self, obj): """ Create all markers for each people's event in the database which has a lat/lon. """ if self.osm is None: return dbstate = self.dbstate self.place_list = [] self.places_found = [] self.place_without_coordinates = [] self.minlat = self.maxlat = self.minlon = self.maxlon = 0.0 self.minyear = 9999 self.maxyear = 0 self.nbmarkers = 0 self.nbplaces = 0 self.without = 0 self.cal = config.get('preferences.calendar-format-report') self.message_layer.clear_messages() self.message_layer.clear_font_attributes() self.no_show_places_in_status_bar = False if self.show_all: self.show_all = False events_handle = dbstate.db.get_event_handles() progress = ProgressMeter(self.window_name, can_cancel=False, parent=self.uistate.window) length = len(events_handle) progress.set_pass(_('Selecting all events'), length) for event_hdl in events_handle: event = dbstate.db.get_event_from_handle(event_hdl) self._createmap_for_one_event(event) progress.step() progress.close() elif self.generic_filter: user = self.uistate.viewmanager.user events_list = self.generic_filter.apply(dbstate.db, user=user) progress = ProgressMeter(self.window_name, can_cancel=False, parent=self.uistate.window) length = len(events_list) progress.set_pass(_('Selecting all events'), length) for event_handle in events_list: event = dbstate.db.get_event_from_handle(event_handle) self._createmap_for_one_event(event) progress.step() progress.close() else: if obj: event = dbstate.db.get_event_from_handle(obj) self._createmap_for_one_event(event) self.message_layer.add_message( _("Right click on the map and select 'show all events'" " to show all known events with coordinates. " "You can use the history to navigate on the map. " "You can use filtering.")) self.sort = sorted(self.place_list, key=operator.itemgetter(3, 4, 6)) if self.nbmarkers > 500: # performance issue. Is it the good value ? self.no_show_places_in_status_bar = True self._create_markers()
def _createmap(self, obj): """ Create all markers for each people's event in the database which has a lat/lon. """ dbstate = self.dbstate self.place_list = [] self.places_found = [] self.place_without_coordinates = [] self.minlat = self.maxlat = self.minlon = self.maxlon = 0.0 self.minyear = 9999 self.maxyear = 0 self.nbmarkers = 0 self.nbplaces = 0 latitude = "" longitude = "" self.without = 0 self.cal = config.get('preferences.calendar-format-report') self.no_show_places_in_status_bar = False if self.show_all: self.show_all = False events_handle = dbstate.db.get_event_handles() progress = ProgressMeter(self.window_name, can_cancel=False, parent=self.uistate.window) length = len(events_handle) progress.set_pass(_('Selecting all events'), length) for event_hdl in events_handle: event = dbstate.db.get_event_from_handle(event_hdl) self._createmap_for_one_event(event) progress.step() progress.close() elif self.generic_filter: events_list = self.generic_filter.apply(dbstate.db) progress = ProgressMeter(self.window_name, can_cancel=False, parent=self.uistate.window) length = len(events_list) progress.set_pass(_('Selecting all events'), length) for event_handle in events_list: event = dbstate.db.get_event_from_handle(event_handle) self._createmap_for_one_event(event) progress.step() progress.close() elif obj: event = dbstate.db.get_event_from_handle(obj) self._createmap_for_one_event(event) self.sort = sorted(self.place_list, key=operator.itemgetter(3, 4, 6)) if self.nbmarkers > 500: # performance issue. Is it the good value ? self.no_show_places_in_status_bar = True self._create_markers()
def draw_page(self, operation, context, page_nr): if page_nr == 0: self.progress = ProgressMeter(_("Printing the tree"), can_cancel=True, cancel_callback=self.cancel_print, parent=self.uistate.window) message = _('Need to print %(pages)s pages (%(format)s format)') self.progress.set_pass( message % { 'pages': self.nb_pages, 'format': self.format }, self.nb_pages) cr = context.get_cairo_context() x = y = 0 x = ((page_nr % self.pages_per_row) * self.width_used) if page_nr > 0 else 0 y = (int(page_nr / self.pages_per_row) * self.height_used) cr.save() cr.translate(-x, -y) cr.scale(self.print_zoom, self.print_zoom) self.canvas.draw(cr) cr.restore() if page_nr == self.nb_pages - 1: self.progress.close() self.progress.step()
def on_accept_all(self, dummy, easy=False): """ Button: Accept all or all the 'easy' ones, depending """ self.progress = ProgressMeter(TITLE, '', parent=self.window) length = self.easy_count if easy else len(self.fam_liststore) self.progress.set_pass(_("Processing..."), length) with DbTxn(_("Edit Families"), self.db) as trans: for row in self.fam_liststore: self.progress.step() if easy and not row[0]: continue self.fam_h = row[4] self.family = self.db.get_family_from_handle(self.fam_h) dummy, sorted_ch_list = self.sort_family_pr(self.fam_h) orig_refs = self.family.get_child_ref_list() sort_ref_list = list(orig_refs[ch[3]] for ch in sorted_ch_list) self.family.set_child_ref_list(sort_ref_list) self.db.commit_family(self.family, trans) self.fam_liststore.remove(row.iter) self.progress.close() spath = Gtk.TreePath.new_first() self.fam_sel.select_path(spath) if len(self.fam_liststore) == 0: self.kill_buttons() self.ch_liststore.clear() self.ch_liststore_s.clear()
def saveit(self, button): """ Commit the changes to the database """ self.update_changelist() progress = ProgressMeter(self.window_name, can_cancel=True, parent=self.window) length = len(self.changelist) progress.set_pass(_('Saving Notes'), length) with DbTxn(_("Saving Cleaned Notes"), self.db, batch=False) as trans: for changed in self.changelist: note = self.db.get_note_from_handle(changed[0]) note.set_styledtext(changed[2]) self.db.commit_note(note, trans) msg = _("Note Cleanup") trans.set_description(msg) progress.step() if progress.get_cancelled(): break self.clear_models() self.show_tabs() progress.close()
def progress(self, title1, title2, count): self._progress = ProgressMeter(title1, can_cancel=True) self._progress.set_pass(title2, count, ProgressMeter.MODE_FRACTION) try: yield self._progress.step finally: self._progress.close()
def _execute(self): """ execute all primary objects and reorder if neccessary """ # Update progress calculation if self.uistate: self.progress = ProgressMeter(_('Reorder Gramps IDs'), '') else: total_objs = 0 for prim_obj, tmp in self.xobjects: if self.obj_values[prim_obj].active_obj: total_objs += self.obj_values[prim_obj].quant_id self.set_total(total_objs) # Update database self.dbstate.disable_signals() for prim_obj, prim_objs in self.xobjects: with DbTxn(_('Reorder %s IDs ...') % prim_obj, self.dbstate, batch=True) \ as self.trans: if self.obj_values[prim_obj].active_obj: if self.uistate: self.progress.set_pass(_('Reorder %s IDs ...') % \ _(prim_objs.title()), \ self.obj_values[prim_obj].quant_id) # Process reordering self._reorder(prim_obj) self.dbstate.enable_signals() self.dbstate.request_rebuild() # Update progress calculation if self.uistate: self.progress.close() else: print('\nDone.')
def generate_md5(self, button): """ Generate md5 hashes for media files. """ self.clear_models() progress = ProgressMeter(self.window_name, can_cancel=True, parent=self.window) length = self.db.get_number_of_media() progress.set_pass(_('Generating media hashes'), length) with DbTxn(_("Set media hashes"), self.db, batch=True) as trans: for handle in self.db.get_media_handles(): media = self.db.get_media_from_handle(handle) full_path = media_path_full(self.db, media.get_path()) md5sum = create_checksum(full_path) if not md5sum: error_msg = 'IOError: %s' % full_path self.models[5].append((error_msg, None)) progress.step() continue media.set_checksum(md5sum) self.db.commit_media(media, trans) progress.step() if progress.get_cancelled(): break self.show_tabs() progress.close()
def model_load(self): """ populate the tree with types """ r_indx = 0 self.model.clear() for (attr, name, _obj, _srcobj) in self.t_table: # 99 is indicator that row is a title row row = (name, 0, 99) iter_ = self.model.append(None, row) # get custom types from db types = getattr(self.db, attr, None) if types is None: continue for indx, cust_type in enumerate(types): # update right model row = (cust_type, indx, r_indx) self.model.append(iter_, row) # create refs list for the custom type self.types_dict[_obj][cust_type] = [] r_indx += 1 progress = ProgressMeter(self.window_name, can_cancel=False, parent=self.window) # find total of db objects total = 0 for obj_type in self.primary_objects_pl: total += self.db.method('get_number_of_%s', obj_type)() # scan db objects and record all custom GrampsTypes found as references progress.set_pass(_("Reading database..."), total) for obj_type in self.primary_objects: for hndl in self.db.method('get_%s_handles', obj_type)(): obj = self.db.method('get_%s_from_handle', obj_type)(hndl) self.do_recurse(obj, obj_type, hndl) progress.step() progress.close()
def display(self): try: from bsddb3.db import DBError except: class DBError(Exception): """ Dummy. """ self.parent = self.top.get_toplevel() progress = ProgressMeter( _('Updating display...'), '', parent=self.parent, can_cancel=True) self.model.clear() self.junk = [] gc.collect(2) self.junk = gc.garbage self.label.set_text(_('Uncollected Objects: %s') % str(len(self.junk))) progress.set_pass(_('Updating display...'), len(self.junk)) for count in range(0, len(self.junk)): if progress.step(): break try: refs = [] referrers = gc.get_referrers(self.junk[count]) for referrer in referrers: try: if referrer is not self.junk: for indx in range(0, len(self.junk)): if referrer is self.junk[indx]: refs.append(str(indx) + ' ') break except: print(sys.exc_info()) if len(refs) > 3: ref = ' '.join(refs[0:2]) + "..." else: ref = ' '.join(refs) try: self.model.append((count, ref, str(self.junk[count]))) except DBError: self.model.append((count, ref, 'db.DB instance at %s' % id(self.junk[count]))) except ReferenceError: self.model.append(( count, ref, 'weakly-referenced object no longer exists %s' % type(self.junk[count]))) except TypeError: self.model.append(( count, ref, 'Object cannot be displayed %s' % type(self.junk[count]))) except: print(sys.exc_info()) except ReferenceError: InfoDialog(_('Reference Error'), "Refresh to correct", parent=self.parent) progress.close()
def applyTagClicked(self, button): progress = None rows = self.treeSelection.count_selected_rows() tag_name = str(self.tagcombo.get_active_text()) # start the db transaction with DbTxn("Tag not related", self.db) as transaction: tag = self.db.get_tag_from_name(tag_name) if not tag: # create the tag if it doesn't already exist tag = Tag() tag.set_name(tag_name) tag.set_priority(self.db.get_number_of_tags()) tag_handle = self.db.add_tag(tag, transaction) else: tag_handle = tag.get_handle() # if more than 1 person is selected, use a progress indicator if rows > 1: progress = ProgressMeter(self.title, _('Starting')) progress.set_pass( # translators: leave all/any {...} untranslated #TRANS: no singular form needed, as rows is always > 1 ngettext("Setting tag for {number_of} person", "Setting tag for {number_of} people", rows).format(number_of=rows), rows) # iterate through all of the selected rows (model, paths) = self.treeSelection.get_selected_rows() for path in paths: if progress: progress.step() # for the current row, get the GID and the person from the database iter = self.model.get_iter(path) personGid = self.model.get_value(iter, 1) person = self.db.get_person_from_gramps_id(personGid) # add the tag to the person person.add_tag(tag_handle) # save this change self.db.commit_person(person, transaction) # refresh the tags column self.treeView.set_model(None) for path in paths: iter = self.model.get_iter(path) personGid = self.model.get_value(iter, 1) person = self.db.get_person_from_gramps_id(personGid) self.model.set_value(iter, 3, self.get_tag_list(person)) self.treeView.set_model(self.model) self.treeView.expand_all() if progress: progress.close()
def on_ok_clicked(self): """ Method that is run when you click the OK button. """ downloaded = {} # Get a directory to put the media files in. If the media path in # preferences is not just the user's home, then we will use that. If it # is the user's home, we create a new directory below that, so we don't # splatter files into home. media_path = self.db.get_mediapath() if media_path == USER_HOME or media_path == "" or media_path == None: media_path = os.path.join(USER_HOME, "mediadir") if not os.path.isdir(media_path): os.makedirs(media_path) # Many thanks to 'sirex' from whom I have taken the code he submitted as # part of bug 0003553: Import media files from GEDCOM file_pattern = re.compile(r'.*\.(png|jpg|jpeg|gif)$') def fetch_file(url, filename): LOG.debug("Downloading url %s to file %s" % (url, filename)) fr = urlopen(url) fw = open(filename, 'wb') for block in fr: fw.write(block) fw.close() fr.close() self.progress = ProgressMeter(_('Downloading files'), '') self.progress.set_pass(_('Downloading files'), self.db.get_number_of_media_objects()) self.db.disable_signals() with DbTxn('Download files', self.db) as trans: for media_handle in self.db.media_map.keys(): media = self.db.get_object_from_handle(media_handle) url = media.get_path() res = urlparse(url) LOG.debug(res) if res.scheme == "http" or res.scheme == "https": if file_pattern.match(url): if url in downloaded: full_path = downloaded[url] else: filename = url.split('/')[-1] full_path = os.path.join(media_path, filename) fetch_file(url, full_path) downloaded[url] = full_path self.num_downloads += 1 media.set_path(full_path) media.set_mime_type(get_type(full_path)) self.db.commit_media_object(media, trans) self.progress.step() self.db.enable_signals() self.db.request_rebuild() self.progress.close()
def begin_progress(self, title, message, steps): # Parameter "can_cancel" added to ProgressMeter creation. from gramps.gui.utils import ProgressMeter self._progress = ProgressMeter(title, parent=self.parent, can_cancel=True) if steps > 0: self._progress.set_pass(message, steps, ProgressMeter.MODE_FRACTION) else: self._progress.set_pass(message, mode=ProgressMeter.MODE_ACTIVITY)
def cleanup(self, _button): """ Cleanup Notes. """ self.clear_models() StyledText.__getitem__ = MyStyled.__getitem__ # patch in slice func progress = ProgressMeter(self.window_name, can_cancel=True, parent=self.window) length = self.db.get_number_of_notes() progress.set_pass(_('Scanning Notes'), length) for handle in self.db.get_note_handles(): note = self.db.get_note_from_handle(handle) g_id = note.gramps_id stext = note.get_styledtext() optype = -1 # find the notes and do cleanup #if not stext.tags: text = StyledText(stext._string, stext._tags) # make a copy result = self.convert_to_styled(text) indx = len(self.changelist) for styledtext_tag in result.tags: if (int(styledtext_tag.name) == StyledTextTagType.HIGHLIGHT and '#FFFF00' == styledtext_tag.value): optype = ISSUE break elif int(styledtext_tag.name) == StyledTextTagType.LINK: optype = LINK while True: if optype == ISSUE: # make list of notes with errors self.models[ISSUE].append((self.preview(stext, g_id), indx)) elif stext._string != result._string: # Make list of edited notes self.models[CLEANED].append((self.preview(stext, g_id), indx)) elif optype == LINK: # make list of notes with only links self.models[LINK].append((self.preview(stext, g_id), indx)) else: break self.changelist.append((handle, stext, result)) break progress.step() if progress.get_cancelled(): break self.show_tabs() progress.close()
def find_potentials(self): """ look for possible out of order families """ self.progress = ProgressMeter(TITLE, _('Looking for children birth order'), parent=self.window) length = self.db.get_number_of_families() self.progress.set_pass(_('Pass 1: Building preliminary lists'), length) self.easy_count = 0 for fam_h in self.db.iter_family_handles(): self.progress.step() fam = self.db.get_family_from_handle(fam_h) child_ref_list = fam.get_child_ref_list() prev_date = 0 need_sort = False easy = '*' for child_ref in child_ref_list: child = self.db.get_person_from_handle(child_ref.ref) b_date = 0 birth = get_birth_or_fallback(self.db, child) if birth: b_date = birth.get_date_object().get_sort_value() if not b_date: easy = '' continue elif b_date >= prev_date: prev_date = b_date continue else: # we need to put this one in list need_sort = True if not need_sort: continue if easy: self.easy_count += 1 fam_f = fam.get_father_handle() fam_m = fam.get_mother_handle() if fam_f: father = self.db.get_person_from_handle(fam_f) father_name = name_displayer.display(father) else: father_name = '' if fam_m: mother = self.db.get_person_from_handle(fam_m) mother_name = name_displayer.display(mother) else: mother_name = '' fam_data = (easy, fam.get_gramps_id(), father_name, mother_name, fam_h) self.fam_liststore.append(row=fam_data) if len(self.fam_liststore) != 0: spath = Gtk.TreePath.new_first() self.fam_sel.select_path(spath) self.ch_s_sel.select_path(spath) self.progress.close()
def build_row_data(self): self.progress_bar = ProgressMeter(_('Comparing Events'), '', parent=self.uistate.window) self.progress_bar.set_pass(_('Building data'), len(self.my_list)) for individual_id in self.my_list: individual = self.db.get_person_from_handle(individual_id) name = individual.get_primary_name().get_name() gid = individual.get_gramps_id() the_map = defaultdict(list) for ievent_ref in individual.get_event_ref_list(): ievent = self.db.get_event_from_handle(ievent_ref.ref) event_name = str(ievent.get_type()) the_map[event_name].append(ievent_ref.ref) first = True done = False while not done: added = False tlist = [name, gid] if first else ["", ""] for ename in self.event_titles: if ename in the_map and len(the_map[ename]) > 0: event_handle = the_map[ename][0] del the_map[ename][0] date = place = "" if event_handle: event = self.db.get_event_from_handle(event_handle) date = get_date(event) sortdate = "%09d" % ( event.get_date_object().get_sort_value()) place_handle = event.get_place_handle() if place_handle: place = self.db.get_place_from_handle( place_handle).get_title() tlist += [date, sortdate, place] added = True else: tlist += [""] * 3 if first: first = False self.row_data.append(tlist) elif not added: done = True else: self.row_data.append(tlist) self.progress_bar.step()
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()
def __init__(self, dbstate, user, options_class, name, callback=None): uistate = user.uistate self.label = _('Check Place title') tool.BatchTool.__init__(self, dbstate, user, options_class, name) if self.fail: return ManagedWindow.__init__(self, uistate, [], self.__class__) self.set_window(Gtk.Window(), Gtk.Label(), '') # retrieve options CLI? #copy = self.options.handler.options_dict['copy'] #clean = self.options.handler.options_dict['clean'] self.db = dbstate.db self.total = self.db.get_number_of_places() self.progress = ProgressMeter(_('Checking Place Titles'), '', parent=uistate.window) self.progress.set_pass(_('Looking for place fields'), self.total) self.name_list = [] count = 0 for handle in self.db.get_place_handles(True): self.progress.step() place = self.db.get_place_from_handle(handle) title = place.title descr = place_displayer.display(self.db, place) if title != (descr and ""): count += 1 if title != "": self.name_list.append((handle.decode('utf8'), title, descr)) self.progress.close() if self.name_list: self.display() OkDialog(_('Differences'), '%s/%s' % (count, self.total), parent=uistate.window) else: self.progress.close() self.close() OkDialog(_('No need modifications'), _("No changes need."), parent=uistate.window)
def __init__(self, dbstate, user, options_class, name, callback=None): uistate = user.uistate tool.BatchTool.__init__(self, dbstate, user, options_class, name) if self.fail: return if dbstate.db.readonly: return self.progress = ProgressMeter(_("Fix Coordinates"), _('Starting'), parent=uistate.window) uistate.set_busy_cursor(True) dbstate.db.disable_signals() steps = dbstate.db.get_number_of_places() self.progress.set_pass( _('Looking for possible coords with ","' ' characters'), steps) with DbTxn(_("Fix coords"), dbstate.db, batch=False) as trans: for place_handle in dbstate.db.get_place_handles(): self.progress.step() place = dbstate.db.get_place_from_handle(place_handle) place_name = place.get_name() pname = place_name.get_value() found = False if pname != pname.strip(): found = True place_name.set_value(pname.strip()) plat = place.get_latitude() if plat != plat.strip().replace(',', '.'): found = True place.set_latitude(plat.strip().replace(',', '.')) plon = place.get_longitude() if plon != plon.strip().replace(',', '.'): found = True place.set_longitude(plon.strip().replace(',', '.')) if found: dbstate.db.commit_place(place, trans) uistate.set_busy_cursor(False) # close the progress bar self.progress.close() dbstate.db.enable_signals() dbstate.db.request_rebuild()
def on_apply_clicked(self, obj): cfilter = self.filter_model[self.filters.get_active()][1] progress_bar = ProgressMeter(_('Comparing events'), '') progress_bar.set_pass(_('Selecting people'), 1) plist = cfilter.apply(self.db, self.db.iter_person_handles()) progress_bar.step() progress_bar.close() self.options.handler.options_dict['filter'] = self.filters.get_active() # Save options self.options.handler.save_options() if len(plist) == 0: WarningDialog(_("No matches were found")) else: DisplayChart(self.dbstate, self.uistate, plist, self.track)
def prepare(self, db): # FIXME: this should user the User class from gramps.gui.utils import ProgressMeter root_person_id = self.list[0] root_person = db.get_person_from_gramps_id(root_person_id) progress = ProgressMeter(_('Finding relationship paths')) progress.set_pass(header=_('Evaluating people'), mode=ProgressMeter.MODE_ACTIVITY) filter_name = self.list[1] target_people = filter_database(db, progress, filter_name) paths = find_deep_relations(db, progress, root_person, [], [], target_people) progress.close() progress = None self.__matches = set() list(map(self.__matches.update, paths))
def _createmap(self): """ Create all markers for each people's event in the database which has a lat/lon. """ dbstate = self.dbstate self.cal = config.get('preferences.calendar-format-report') self.place_list = [] self.event_list = [] self.place_without_coordinates = [] self.places_found = [] self.minlat = self.maxlat = self.minlon = self.maxlon = 0.0 self.minyear = 9999 self.maxyear = 0 self.already_done = [] self.nbplaces = 0 self.nbmarkers = 0 self.message_layer.clear_messages() self.kml_layer.clear() person_handle = self.uistate.get_active('Person') person = None if person_handle: person = dbstate.db.get_person_from_handle(person_handle) if person is not None: # For each event, if we have a place, set a marker. self.window_name = _("Ancestors places for %s" % _nd.display(person)) self.message_layer.add_message(self.window_name) self.nb_evts = 0 self.progress = ProgressMeter(self.window_name, can_cancel=False, parent=self.uistate.window) self.progress.set_pass(_('Counting all places'), self.nb_evts) self.person_count(person) self.event_list = [] self.progress.set_pass(_('Showing all places'), self.nb_evts) self.show_one_person(person) self.progress.close() self.sort = sorted(self.place_list, key=operator.itemgetter(3, 4, 6)) self._create_markers()
def write_report(self): """ The routine the actually creates the report. At this point, the document is opened and ready for writing. """ # Create progress meter bar self.progress = ProgressMeter(_("Liste Eclair"), '') # Write the title line. Set in INDEX marker so that this section will be # identified as a major category if this is included in a Book report. title = _("Liste Eclair") mark = IndexMark(title, INDEX_TYPE_TOC, 1) self.doc.start_paragraph("Eclair-ReportTitle") self.doc.write_text(title, mark) self.doc.end_paragraph() self.__write_all_places() # Close the progress meter self.progress.close()
def fix_media(self, button): """ Fix paths to moved media files. """ progress = ProgressMeter(self.window_name, can_cancel=True, parent=self.window) progress.set_pass(_('Fixing file paths'), len(self.moved_files)) with DbTxn(_("Fix media paths"), self.db, batch=True) as trans: for handle, new_path in self.moved_files: media = self.db.get_media_from_handle(handle) media.set_path(new_path) self.db.commit_media(media, trans) progress.step() if progress.get_cancelled(): break self.models[0].clear() self.show_tabs() progress.close()
def __init__(self, dbstate, user, options_class, name, callback=None): uistate = user.uistate self.label = _('Capitalization changes') self.dbstate = dbstate self.uistate = uistate self.cb = callback ManagedWindow.__init__(self, uistate, [], self.__class__) self.set_window(Gtk.Window(), Gtk.Label(), '') tool.BatchTool.__init__(self, dbstate, user, options_class, name) if self.fail: return given_name_dict = self.get_given_name_dict() self.progress = ProgressMeter(_('Checking Given Names'), '', parent=uistate.window) self.progress.set_pass(_('Searching given names'), len(given_name_dict.keys())) self.name_list = [] for name in given_name_dict.keys(): if name != capitalize(name): self.name_list.append((name, given_name_dict[name])) if uistate: self.progress.step() if self.name_list: self.display() else: self.progress.close() self.close() OkDialog(_('No modifications made'), _("No capitalization changes were detected."), parent=uistate.window)
def write_report(self): """ Overridden function to generate the report. """ self.progress = ProgressMeter(_("PUK Export"), '') self.doc.start_paragraph("SRC-ReportTitle") title = self.title_string mark = IndexMark(title, INDEX_TYPE_TOC, 1) self.doc.write_text(title, mark) self.doc.end_paragraph() self.doc.start_paragraph("SRC-ReportTitle") title = self.subtitle_string mark = IndexMark(title, INDEX_TYPE_TOC, 1) self.doc.write_text(title, mark) self.doc.end_paragraph() self.listpersonref() self.doc.start_paragraph('SRC-Footer') self.doc.write_text(self.footer_string) self.doc.end_paragraph() self.progress.close()
def _execute(self): """ execute all primary objects and reorder if neccessary """ # Update progress calculation if self.uistate: self.progress = ProgressMeter(_('Reorder Gramps IDs'), '') else: total_objs = 0 for prim_obj, dummy in self.xobjects: if self.obj_values[prim_obj].active_obj: total_objs += self.obj_values[prim_obj].quant_id self.set_total(total_objs) # Update database self.db.disable_signals() for prim_obj, prim_objs in self.xobjects: with DbTxn(_('Reorder %s IDs ...') % prim_obj, self.db, batch=True) as self.trans: if self.obj_values[prim_obj].active_obj: if self.uistate: self.progress.set_pass( _('Reorder %s IDs ...') % _(prim_objs.title()), self.obj_values[prim_obj].quant_id) # reset the db next_id index to zero so we restart new IDs # at lowest possible position setattr(self.db, DB_INDXES[prim_obj] + 'map_index', 0) # Process reordering self._reorder(prim_obj) self.db.enable_signals() self.db.request_rebuild() # Update progress calculation if self.uistate: self.progress.close() else: print('\nDone.')
def generate_md5(self, button): """ Generate md5 hashes for media files. """ self.clear_models() progress = ProgressMeter(self.window_name, can_cancel=True, parent=self.window) length = self.db.get_number_of_media() progress.set_pass(_('Generating media hashes'), length) with DbTxn(_("Set media hashes"), self.db, batch=True) as trans: for handle in self.db.get_media_handles(): media = self.db.get_media_from_handle(handle) full_path = media_path_full(self.db, media.get_path()) try: with io.open(full_path, 'rb') as media_file: md5sum = hashlib.md5(media_file.read()).hexdigest() except IOError as err: error_msg = '%s: %s' % (err.strerror, full_path) self.models[5].append((error_msg, None)) progress.step() continue media.set_checksum(md5sum) self.db.commit_media(media, trans) progress.step() if progress.get_cancelled(): break self.show_tabs() progress.close()
def _createmap(self, place_x): """ Create all markers for each people's event in the database which has a lat/lon. """ dbstate = self.dbstate self.place_list = [] self.places_found = [] self.place_without_coordinates = [] self.minlat = 0.0 self.maxlat = 0.0 self.minlon = 0.0 self.maxlon = 0.0 self.minyear = 9999 self.maxyear = 0 self.without = 0 latitude = "" longitude = "" self.nbmarkers = 0 self.nbplaces = 0 self.remove_all_markers() self.message_layer.clear_messages() self.message_layer.clear_font_attributes() self.kml_layer.clear() self.no_show_places_in_status_bar = False _col = self._config.get self.plc_color = [ (PlaceType.UNKNOWN, _col('geography.color.unknown')), (PlaceType.CUSTOM, _col('geography.color.custom')), (PlaceType.COUNTRY, _col('geography.color.country')), (PlaceType.STATE, _col('geography.color.state')), (PlaceType.COUNTY, _col('geography.color.county')), (PlaceType.CITY, _col('geography.color.city')), (PlaceType.PARISH, _col('geography.color.parish')), (PlaceType.LOCALITY, _col('geography.color.locality')), (PlaceType.STREET, _col('geography.color.street')), (PlaceType.PROVINCE, _col('geography.color.province')), (PlaceType.REGION, _col('geography.color.region')), (PlaceType.DEPARTMENT, _col('geography.color.department')), (PlaceType.NEIGHBORHOOD, _col('geography.color.neighborhood')), (PlaceType.DISTRICT, _col('geography.color.district')), (PlaceType.BOROUGH, _col('geography.color.borough')), (PlaceType.MUNICIPALITY, _col('geography.color.municipality')), (PlaceType.TOWN, _col('geography.color.town')), (PlaceType.VILLAGE, _col('geography.color.village')), (PlaceType.HAMLET, _col('geography.color.hamlet')), (PlaceType.FARM, _col('geography.color.farm')), (PlaceType.BUILDING, _col('geography.color.building')), (PlaceType.NUMBER, _col('geography.color.number')) ] # base "villes de france" : 38101 places : # createmap : 8'50"; create_markers : 1'23" # base "villes de france" : 38101 places : # createmap : 8'50"; create_markers : 0'07" with pixbuf optimization # base "villes de france" : 38101 places : # gramps 3.4 python 2.7 (draw_markers are estimated when moving the map) # 38101 places: createmap: 04'32"; # create_markers: 0'04"; draw markers: N/A :: 0'03" # 65598 places: createmap: 10'03"; # create_markers: 0'07"; draw markers: N/A :: 0'05" # gramps 3.5 python 2.7 new marker layer # 38101 places: createmap: 03'09"; # create_markers: 0'01"; draw markers: 0'04" # 65598 places: createmap: 08'48"; # create_markers: 0'01"; draw markers: 0'07" _LOG.debug( "%s", time.strftime("start createmap : " "%a %d %b %Y %H:%M:%S", time.gmtime())) self.custom_places() if self.show_all: self.show_all = False try: places_handle = dbstate.db.get_place_handles() except: return progress = ProgressMeter(self.window_name, can_cancel=False, parent=self.uistate.window) length = len(places_handle) progress.set_pass(_('Selecting all places'), length) for place_hdl in places_handle: place = dbstate.db.get_place_from_handle(place_hdl) self._create_one_place(place) progress.step() progress.close() elif self.generic_filter: user = self.uistate.viewmanager.user place_list = self.generic_filter.apply(dbstate.db, user=user) progress = ProgressMeter(self.window_name, can_cancel=False, parent=self.uistate.window) length = len(place_list) progress.set_pass(_('Selecting all places'), length) for place_handle in place_list: place = dbstate.db.get_place_from_handle(place_handle) self._create_one_place(place) progress.step() progress.close() # reset completely the filter. It will be recreated next time. self.generic_filter = None elif place_x != None: place = dbstate.db.get_place_from_handle(place_x) self._create_one_place(place) self.message_layer.add_message( _("Right click on the map and select 'show all places'" " to show all known places with coordinates. " "You can change the markers color depending on place type. " "You can use filtering.")) if place.get_latitude() != "" and place.get_longitude() != "": latitude, longitude = conv_lat_lon(place.get_latitude(), place.get_longitude(), "D.D8") if latitude and longitude: self.osm.set_center_and_zoom( float(latitude), float(longitude), int(config.get("geography.zoom_when_center"))) else: self.message_layer.add_message( _("Right click on the map and select 'show all places'" " to show all known places with coordinates. " "You can use the history to navigate on the map. " "You can change the markers color depending on place type. " "You can use filtering.")) _LOG.debug(" stop createmap.") _LOG.debug( "%s", time.strftime("begin sort : " "%a %d %b %Y %H:%M:%S", time.gmtime())) self.sort = sorted(self.place_list, key=operator.itemgetter(0)) _LOG.debug( "%s", time.strftime(" end sort : " "%a %d %b %Y %H:%M:%S", time.gmtime())) if self.nbmarkers > 500: # performance issue. Is it the good value ? self.message_layer.add_message( _("The place name in the status bar is disabled.")) self.no_show_places_in_status_bar = True if self.nbplaces >= self._config.get("geography.max_places"): self.message_layer.set_font_attributes(None, None, "red") self.message_layer.add_message( _("The maximum number of places is reached (%d).") % self._config.get("geography.max_places")) self.message_layer.add_message(_("Some information are missing.")) self.message_layer.add_message( _("Please, use filtering to reduce this number.")) self.message_layer.add_message( _("You can modify this value in the geography option.")) self.message_layer.add_message( _("In this case, it may take time to show all markers.")) self._create_markers()
def find_potentials(self, thresh): self.progress = ProgressMeter(_('Find Duplicates'), _('Looking for duplicate people'), parent=self.window) index = 0 males = {} females = {} self.map = {} length = self.db.get_number_of_people() self.progress.set_pass(_('Pass 1: Building preliminary lists'), length) for p1_id in self.db.iter_person_handles(): self.progress.step() p1 = self.db.get_person_from_handle(p1_id) key = self.gen_key(get_surnames(p1.get_primary_name())) if p1.get_gender() == Person.MALE: if key in males: males[key].append(p1_id) else: males[key] = [p1_id] else: if key in females: females[key].append(p1_id) else: females[key] = [p1_id] self.progress.set_pass(_('Pass 2: Calculating potential matches'), length) for p1key in self.db.iter_person_handles(): self.progress.step() p1 = self.db.get_person_from_handle(p1key) key = self.gen_key(get_surnames(p1.get_primary_name())) if p1.get_gender() == Person.MALE: remaining = males[key] else: remaining = females[key] #index = 0 for p2key in remaining: #index += 1 if p1key == p2key: continue p2 = self.db.get_person_from_handle(p2key) if p2key in self.map: (v, c) = self.map[p2key] if v == p1key: continue chance = self.compare_people(p1, p2) if chance >= thresh: if p1key in self.map: val = self.map[p1key] if val[1] > chance: self.map[p1key] = (p2key, chance) else: self.map[p1key] = (p2key, chance) self.list = sorted(self.map) self.length = len(self.list) self.progress.close()