def install_addons(self, obj): """ Process all of the selected addons. """ self.update_dialog.hide() model = self.list.model iter = model.get_iter_first() length = 0 while iter: iter = model.iter_next(iter) if iter: length += model.iter_n_children(iter) longop = LongOpStatus( _("Downloading and installing selected addons..."), length, 1, # total, increment-by can_cancel=True) pm = ProgressMonitor(GtkProgressDialog, ("Title", self.window, gtk.DIALOG_MODAL)) pm.add_op(longop) count = 0 if not config.get('behavior.do-not-show-previously-seen-updates'): # reset list config.get('behavior.previously-seen-updates')[:] = [] iter = model.get_iter_first() while iter: for rowcnt in range(model.iter_n_children(iter)): child = model.iter_nth_child(iter, rowcnt) row = [model.get_value(child, n) for n in range(6)] if longop.should_cancel(): break elif row[0]: # toggle on load_addon_file(row[4], callback=LOG.debug) count += 1 else: # add to list of previously seen, but not installed if row[5] not in config.get( 'behavior.previously-seen-updates'): config.get('behavior.previously-seen-updates').append( row[5]) longop.heartbeat() pm._get_dlg()._process_events() iter = model.iter_next(iter) if not longop.was_cancelled(): longop.end() if count: OkDialog( _("Done downloading and installing addons"), "%s %s" % (ngettext("%d addon was installed.", "%d addons were installed.", count) % count, _("You need to restart Gramps to see new views.")), self.window) else: OkDialog(_("Done downloading and installing addons"), _("No addons were installed."), self.window) self.close()
def __init__(self, dbstate, uistate, options_class, name, callback=None): tool.Tool.__init__(self, dbstate, options_class, name) if self.db.readonly: return self.db.disable_signals() if uistate: self.callback = uistate.pulse_progressbar uistate.set_busy_cursor(1) uistate.progress.show() uistate.push_message(dbstate, _("Rebuilding secondary indices...")) UpdateCallback.__init__(self, self.callback) self.set_total(12) self.db.rebuild_secondary(self.update) self.reset() uistate.set_busy_cursor(0) uistate.progress.hide() OkDialog(_("Secondary indices rebuilt"), _('All secondary indices have been rebuilt.'), parent=uistate.window) else: print "Rebuilding Secondary Indices..." self.db.rebuild_secondary(self.update_empty) print "All secondary indices have been rebuilt." self.db.enable_signals()
def __init__(self, dbstate, uistate, options_class, name, callback=None): tool.Tool.__init__(self, dbstate, options_class, name) if self.db.readonly: return person_event_types = [] family_event_types = [] for handle in self.db.get_event_handles(): event = self.db.get_event_from_handle(handle) if event.get_type().is_custom(): links = [x[0] for x in self.db.find_backlink_handles(handle)] type_str = str(event.get_type()) if 'Person' in links and type_str not in person_event_types: person_event_types.append(type_str) if 'Family' in links and type_str not in family_event_types: family_event_types.append(type_str) self.db.individual_event_names.update(person_event_types) self.db.family_event_names.update(family_event_types) total = len(person_event_types) + len(family_event_types) OkDialog(_("Gramps Types rebuilt"), _('Found %d custom event types') % total, parent=uistate.window)
def __init__(self, dbstate, uistate, options_class, name, callback=None): tool.Tool.__init__(self, dbstate, options_class, name) if self.db.readonly: return self.db.disable_signals() if uistate: self.callback = uistate.pulse_progressbar uistate.set_busy_cursor(1) uistate.progress.show() uistate.push_message(dbstate, _("Rebuilding reference maps...")) else: self.callback = None print "Rebuilding reference maps..." UpdateCallback.__init__(self, self.callback) self.set_total(6) self.db.reindex_reference_map(self.update) self.reset() if uistate: uistate.set_busy_cursor(0) uistate.progress.hide() OkDialog(_("Reference maps rebuilt"), _('All reference maps have been rebuilt.'), parent=uistate.window) else: print "All reference maps have been rebuilt." self.db.enable_signals()
def run(self): """ Perform the actual extraction of information. """ with DbTxn(_("Event name changes"), self.db, batch=True) as trans: self.db.disable_signals() self.change = False counter = 0 for person in self.db.iter_people(): for event_ref in person.get_event_ref_list(): if event_ref.get_role() == gen.lib.EventRoleType.PRIMARY: event_handle = event_ref.ref event = self.db.get_event_from_handle(event_handle) if event.get_description() == "": person_event_name(event, person) self.db.commit_event(event, trans) self.change = True counter += 1 for family in self.db.iter_families(): for event_ref in family.get_event_ref_list(): if event_ref.get_role() == gen.lib.EventRoleType.FAMILY: event_handle = event_ref.ref event = self.db.get_event_from_handle(event_handle) if event.get_description() == "": family_event_name(event, family, self.db) self.db.commit_event(event, trans) self.change = True counter += 1 self.db.enable_signals() self.db.request_rebuild() if self.change == True: OkDialog(_('Modifications made'), ngettext("%s event description has been added", "%s event descriptions have been added", counter) % counter) else: OkDialog(_('No modifications made'), _("No event description has been added."))
def on_apply_clicked(self, obj): # Need to store English names for later comparison the_type = EventType() the_type.set(self.auto1.child.get_text()) self.options.handler.options_dict['fromtype'] = the_type.xml_str() the_type.set(self.auto2.child.get_text()) self.options.handler.options_dict['totype'] = the_type.xml_str() modified, msg = self.run_tool(cli=False) OkDialog(_('Change types'), msg, self.window) # Save options self.options.handler.save_options() self.close()
def __init__(self, dbstate, uistate, options_class, name, callback=None): self.label = _('Capitalization changes') self.cb = callback ManagedWindow.ManagedWindow.__init__(self, uistate, [], self.__class__) self.set_window(gtk.Window(), gtk.Label(), '') tool.BatchTool.__init__(self, dbstate, uistate, options_class, name) if self.fail: return self.progress = ProgressMeter(_('Checking Family Names'), '') self.progress.set_pass(_('Searching family names'), len(self.db.get_surname_list())) self.name_list = [] for name in self.db.get_surname_list(): name.strip() namesplitSP = name.split() lSP = len(namesplitSP) namesplitHY = name.split('-') lHY = len(namesplitHY) if lSP == lHY == 1: if name != name.capitalize(): # Single surname without hyphen(s) self.name_list.append(name) #if lSP == 1 and lHY > 1: #print "LSP==1", name, name.capitalize() #if name != name.capitalize(): # Single surname with hyphen(s) #self.name_list.append(name) if lSP > 1 and lHY == 1: # more than one string in surname but no hyphen # check if first string is in prefix_list, if so test for cap in rest s1 = 0 if namesplitSP[0].lower() in prefix_list: s1 = 1 for x in xrange(len(namesplitSP) - s1): # check if any subsurname is not cap notcap = False if namesplitSP[s1 + x] != namesplitSP[s1 + x].capitalize(): notcap = True break if notcap: # Multiple surnames possibly after prefix self.name_list.append(name) if lHY > 1: # more than one string in surname but hyphen(s) exists # check if first string is in prefix_list, if so test for cap if namesplitSP[0].lower() in prefix_list: namesplitHY[0] = namesplitHY[0].replace( namesplitSP[0], '').strip() for x in xrange(len(namesplitHY)): # check if any subsurname is not cap notcap = False if namesplitHY[x] != namesplitHY[x].capitalize(): notcap = True break if notcap: # Multiple surnames possibly after frefix self.name_list.append(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 on_merge_ok_clicked(self, obj): """ Performs the actual merge of citations (Derived from ExtractCity) """ fields = self.menu.get_model()[self.menu.get_active()][1] dont_merge_notes = int(self.notes_obj.get_active()) LOG.debug("fields %d dont_merge_notes %d" % (fields, dont_merge_notes)) self.options.handler.options_dict['fields'] = fields self.options.handler.options_dict['dont_merge_notes'] = dont_merge_notes # Save options self.options.handler.save_options() self.progress = ProgressMeter(_('Checking Sources'), '') self.progress.set_pass(_('Looking for citation fields'), self.db.get_number_of_citations()) db = self.dbstate.db db.disable_signals() num_merges = 0 for handle in db.iter_source_handles(): dict = {} citation_handle_list = list(db.find_backlink_handles(handle)) for (class_name, citation_handle) in citation_handle_list: if class_name <> Citation.__name__: raise MergeError("Encountered an object of type %s " "that has a citation reference." % class_name) citation = db.get_citation_from_handle(citation_handle) key = citation.get_page() if fields <> IGNORE_DATE and fields <> IGNORE_BOTH: key += "\n" + DateHandler.get_date(citation) if fields <> IGNORE_CONFIDENCE and fields <> IGNORE_BOTH: key += "\n" + \ confidence[citation.get_confidence_level()] if key in dict and \ (not dont_merge_notes or len(citation.note_list) == 0): citation_match_handle = dict[key] citation_match = \ db.get_citation_from_handle(citation_match_handle) try: query = MergeCitationQuery( self.dbstate, citation_match, citation) query.execute() except AssertionError: print "Tool/Family Tree processing/MergeCitations", \ "citation1 gramps_id", citation_match.get_gramps_id(), \ "citation2 gramps_id", citation.get_gramps_id() , \ "citation backlink handles", \ list(db.find_backlink_handles(citation.get_handle())) num_merges += 1 elif (not dont_merge_notes or len(citation.note_list) == 0): dict[key] = citation_handle self.progress.step() db.enable_signals() db.request_rebuild() self.progress.close() OkDialog( _("Number of merges done"), ngettext("%(num)d citation merged", "%(num)d citations merged", num_merges) % {'num': num_merges}) self.close(obj)
def __init__(self, dbstate, uistate, options_class, name, callback=None): self.label = _('Name and title extraction tool') ManagedWindow.ManagedWindow.__init__(self, uistate, [], self.__class__) self.set_window(gtk.Window(), gtk.Label(), '') tool.BatchTool.__init__(self, dbstate, uistate, options_class, name) if self.fail: return winprefix = gtk.Dialog( _("Default prefix and connector settings"), self.uistate.window, gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, (gtk.STOCK_OK, gtk.RESPONSE_ACCEPT)) winprefix.set_has_separator(False) winprefix.vbox.set_spacing(5) hboxpref = gtk.HBox() hboxpref.pack_start(gtk.Label(_('Prefixes to search for:')), expand=False, padding=5) self.prefixbox = gtk.Entry() self.prefixbox.set_text(', '.join(PREFIX_LIST)) hboxpref.pack_start(self.prefixbox) winprefix.vbox.pack_start(hboxpref) hboxcon = gtk.HBox() hboxcon.pack_start(gtk.Label(_('Connectors splitting surnames:')), expand=False, padding=5) self.conbox = gtk.Entry() self.conbox.set_text(', '.join(CONNECTOR_LIST)) hboxcon.pack_start(self.conbox) winprefix.vbox.pack_start(hboxcon) hboxconns = gtk.HBox() hboxconns.pack_start(gtk.Label( _('Connectors not splitting surnames:')), expand=False, padding=5) self.connsbox = gtk.Entry() self.connsbox.set_text(', '.join(CONNECTOR_LIST_NONSPLIT)) hboxconns.pack_start(self.connsbox) winprefix.vbox.pack_start(hboxconns) winprefix.show_all() winprefix.resize(700, 100) response = winprefix.run() self.prefix_list = self.prefixbox.get_text().split(',') self.prefix_list = map(strip, self.prefix_list) self.prefixbox = None self.connector_list = self.conbox.get_text().split(',') self.connector_list = map(strip, self.connector_list) self.conbox = None self.connector_list_nonsplit = self.connsbox.get_text().split(',') self.connector_list_nonsplit = map(strip, self.connector_list_nonsplit) self.connsbox = None # Find a prefix in the first_name self._fn_prefix_re = re.compile( "(\S+)\s+(%s)\s*$" % '|'.join(self.prefix_list), re.IGNORECASE) # Find a prefix in the surname self._sn_prefix_re = re.compile( "^\s*(%s)\s+(.+)" % '|'.join(self.prefix_list), re.IGNORECASE) # Find a connector in the surname self._sn_con_re = re.compile( "^\s*(.+)\s+(%s)\s+(.+)" % '|'.join(self.connector_list), re.IGNORECASE) winprefix.destroy() self.cb = callback self.handle_to_action = {} self.progress = ProgressMeter(_('Extracting Information from Names'), '') self.progress.set_pass(_('Analyzing names'), self.db.get_number_of_people()) for person in self.db.iter_people(): key = person.handle name = person.get_primary_name() first = name.get_first_name() sname = name.get_surname() old_prefix = [] old_surn = [] old_con = [] old_prim = [] old_orig = [] for surn in name.get_surname_list(): old_prefix.append(surn.get_prefix()) old_surn.append(surn.get_surname()) old_con.append(surn.get_connector()) old_prim.append(surn.get_primary()) old_orig.append(surn.get_origintype()) if name.get_title(): old_title = [name.get_title()] else: old_title = [] new_title = [] match = _title_re.match(first) while match: groups = match.groups() first = groups[1] new_title.append(groups[0]) match = _title_re.match(first) matchnick = _nick_re.match(first) if new_title: titleval = (" ".join(old_title + new_title), first) if key in self.handle_to_action: self.handle_to_action[key][self.titleid] = titleval else: self.handle_to_action[key] = {self.titleid: titleval} elif matchnick: # we check for nick, which changes given name like title groups = matchnick.groups() nickval = (groups[0], groups[1]) if key in self.handle_to_action: self.handle_to_action[key][self.nickid] = nickval else: self.handle_to_action[key] = {self.nickid: nickval} else: # Try to find the name prefix in the given name, also this # changes given name match = self._fn_prefix_re.match(first) if match: groups = match.groups() if old_prefix[0]: # Put the found prefix before the old prefix new_prefix = " ".join([groups[1], old_prefix[0]]) else: new_prefix = groups[1] pref1val = (groups[0], new_prefix, groups[1]) if key in self.handle_to_action: self.handle_to_action[key][self.pref1id] = pref1val else: self.handle_to_action[key] = {self.pref1id: pref1val} #check for Gedcom import of compound surnames if len(old_surn) == 1 and old_con[0] == '': prefixes = old_prefix[0].split(',') surnames = old_surn[0].split(',') if len(prefixes) > 1 and len(prefixes) == len(surnames): #assume a list of prefix and a list of surnames prefixes = map(strip, prefixes) surnames = map(strip, surnames) primaries = [False] * len(prefixes) primaries[0] = True origs = [] for ind in range(len(prefixes)): origs.append(gen.lib.NameOriginType()) origs[0] = old_orig[0] compoundval = (surnames, prefixes, [''] * len(prefixes), primaries, origs) if key in self.handle_to_action: self.handle_to_action[key][self.compid] = compoundval else: self.handle_to_action[key] = {self.compid: compoundval} #we cannot check compound surnames, so continue the loop continue # Next, try to split surname in compounds: prefix surname connector found = False new_prefix_list = [] new_surname_list = [] new_connector_list = [] new_prim_list = [] new_orig_list = [] ind = 0 cont = True for pref, surn, con, prim, orig in zip(old_prefix, old_surn, old_con, old_prim, old_orig): surnval = surn.split() if surnval == []: new_prefix_list.append(pref) new_surname_list.append('') new_connector_list.append(con) new_prim_list.append(prim) new_orig_list.append(orig) cont = False continue val = surnval.pop(0) while cont: new_prefix_list.append(pref) new_surname_list.append('') new_connector_list.append(con) new_prim_list.append(prim) new_orig_list.append(orig) while cont and (val.lower() in self.prefix_list): found = True if new_prefix_list[-1]: new_prefix_list[-1] += ' ' + val else: new_prefix_list[-1] = val try: val = surnval.pop(0) except IndexError: val = '' cont = False #after prefix we have a surname if cont: new_surname_list[-1] = val try: val = surnval.pop(0) except IndexError: val = '' cont = False #if value after surname indicates continue, then continue while cont and (val.lower() in self.connector_list_nonsplit): #add this val to the current surname new_surname_list[-1] += ' ' + val try: val = surnval.pop(0) except IndexError: val = '' cont = False # if previous is non-splitting connector, then add new val to # current surname if cont and (new_surname_list[-1].split()[-1].lower() in self.connector_list_nonsplit): new_surname_list[-1] += ' ' + val try: val = surnval.pop(0) except IndexError: val = '' cont = False #if next is a connector, add it to the surname if cont and val.lower() in self.connector_list: found = True if new_connector_list[-1]: new_connector_list[-1] = ' ' + val else: new_connector_list[-1] = val try: val = surnval.pop(0) except IndexError: val = '' cont = False #initialize for a next surname in case there are still #val if cont: found = True # we split surname pref = '' con = '' prim = False orig = gen.lib.NameOriginType() ind += 1 if found: compoundval = (new_surname_list, new_prefix_list, new_connector_list, new_prim_list, new_orig_list) if key in self.handle_to_action: self.handle_to_action[key][self.compid] = compoundval else: self.handle_to_action[key] = {self.compid: compoundval} self.progress.step() if self.handle_to_action: self.display() else: self.progress.close() self.close() OkDialog(_('No modifications made'), _("No titles, nicknames or prefixes were found"))
def run(self, db): """ Performs the actual extraction of information """ self.progress = ProgressMeter(_('Checking Place Titles'), '') self.progress.set_pass(_('Looking for place fields'), self.db.get_number_of_places()) self.name_list = [] for place in db.iter_places(): descr = place.get_title() loc = place.get_main_location() self.progress.step() if loc.get_street() == loc.get_city() == \ loc.get_state() == loc.get_postal_code() == "": match = CITY_STATE_ZIP.match(descr.strip()) if match: data = match.groups() city = data[0] state = data[2] postal = data[5] val = " ".join(state.strip().split()).upper() if state: new_state = STATE_MAP.get(val.upper()) if new_state: self.name_list.append( (place.handle, (city, new_state[0], postal, COUNTRY[new_state[1]]))) continue # Check if there is a left parant. in the string, might be Swedish laen. match = CITY_LAEN.match(descr.strip().replace(","," ")) if match: data = match.groups() city = data[0] state = '(' + data[1] + ')' postal = None val = " ".join(state.strip().split()).upper() if state: new_state = STATE_MAP.get(val.upper()) if new_state: self.name_list.append( (place.handle, (city, new_state[0], postal, COUNTRY[new_state[1]]))) continue match = CITY_STATE.match(descr.strip()) if match: data = match.groups() city = data[0] state = data[1] postal = None if state: m0 = STATE_ZIP.match(state) if m0: (state, postal) = m0.groups() val = " ".join(state.strip().split()).upper() if state: new_state = STATE_MAP.get(val.upper()) if new_state: self.name_list.append( (place.handle, (city, new_state[0], postal, COUNTRY[new_state[1]]))) continue val = " ".join(descr.strip().split()).upper() new_state = STATE_MAP.get(val) if new_state: self.name_list.append( (place.handle, (None, new_state[0], None, COUNTRY[new_state[1]]))) self.progress.close() if self.name_list: self.display() else: self.close() from QuestionDialog import OkDialog OkDialog(_('No modifications made'), _("No place information could be extracted."))