From e3f7028adceccd0e7c3a0d665afdcb38dbaa34e2 Mon Sep 17 00:00:00 2001 From: Don Allingham Date: Sun, 12 Aug 2001 17:41:49 +0000 Subject: [PATCH] Changed name extraction svn: r331 --- gramps/src/gramps_main.py | 28 +++-- gramps/src/plugins/PatchNames.py | 86 ++++++++++---- gramps/src/plugins/patchnames.glade | 170 ++++++++++++++++++++++++++++ 3 files changed, 249 insertions(+), 35 deletions(-) create mode 100644 gramps/src/plugins/patchnames.glade diff --git a/gramps/src/gramps_main.py b/gramps/src/gramps_main.py index 84729bfff..8da470257 100755 --- a/gramps/src/gramps_main.py +++ b/gramps/src/gramps_main.py @@ -759,12 +759,25 @@ def new_database_response(val): def marriage_edit(family): Marriage.Marriage(family,database) +#------------------------------------------------------------------------- +# +# +# +#------------------------------------------------------------------------- +def tool_callback(val): + if val: + full_update() + #------------------------------------------------------------------------- # # # #------------------------------------------------------------------------- def full_update(): + global id2col + + id2col = {} + person_list.clear() gtop.get_widget(NOTEBOOK).set_show_tabs(Config.usetabs) clist = gtop.get_widget("child_list") clist.set_column_visibility(4,Config.show_detail) @@ -898,7 +911,7 @@ def update_source_after_edit(source): #------------------------------------------------------------------------- def on_tools_clicked(obj): if active_person: - Plugins.ToolPlugins(database,active_person,update_display) + Plugins.ToolPlugins(database,active_person,tool_callback) #------------------------------------------------------------------------- # @@ -2333,16 +2346,6 @@ def apply_filter(): global id2col global alt2col - people = database.getPersonMap().values() - - names = [] - altnames = [] - for person in people: - names.append((person.getPrimaryName(),person,0)) - if Config.hide_altnames == 0: - for name in person.getAlternateNames(): - names.append((name,person,1)) - person_list.freeze() datacomp = DataFilter.compare @@ -2378,6 +2381,9 @@ def apply_filter(): sort.build_sort_name(name),sort_bday,sort_dday]) person_list.set_row_data(0,pos) + if Config.hide_altnames: + continue + for name in person.getAlternateNames(): pos = (person,1) new_alt2col[person].append(pos) diff --git a/gramps/src/plugins/PatchNames.py b/gramps/src/plugins/PatchNames.py index d9e6c46fe..af8a53d86 100644 --- a/gramps/src/plugins/PatchNames.py +++ b/gramps/src/plugins/PatchNames.py @@ -23,13 +23,20 @@ import os import re import intl +import utils + _ = intl.gettext from gnome.ui import * +import libglade import RelLib import utils +title_list = [] +nick_list = [] +cb = None + #------------------------------------------------------------------------- # # Search each name in the database, and compare the firstname against the @@ -39,46 +46,72 @@ import utils #------------------------------------------------------------------------- def runTool(database,active_person,callback): + global cb + + cb = callback title_re = re.compile(r"^([A-Za-z][A-Za-z]+\.)\s+(.*)$") nick_re = re.compile(r"(.+)[(\"](.*)[)\"]") - title_count = 0 - nick_count = 0 personMap = database.getPersonMap() for key in personMap.keys(): - person = personMap[key] - name = person.getPrimaryName() - first = name.getFirstName() + person = personMap[key] + first = person.getPrimaryName().getFirstName() match = title_re.match(first) if match: groups = match.groups() - name.setFirstName(groups[1]) - name.setTitle(groups[0]) - title_count = title_count + 1 + title_list.append((person,groups[0],groups[1])) + match = nick_re.match(first) if match: groups = match.groups() - name.setFirstName(groups[0]) - person.setNickName(groups[1]) - nick_count = nick_count + 1 + nick_list.append((person,groups[0],groups[1])) - if nick_count == 1: - msg = _("1 nickname was extracted") + msg = "" + if len(nick_list) > 0 or len(title_list) > 0: + if len(nick_list) > 0: + for name in nick_list: + msg = msg + _("%s will be extracted as a nickname from %s\n") % \ + (name[2],name[0].getPrimaryName().getName()) + + if len(title_list) > 0: + for name in title_list: + msg = msg + _("%s will be extracted as a title from %s\n") % \ + (name[0].getPrimaryName().getName(),name[1]) + + base = os.path.dirname(__file__) + glade_file = base + os.sep + "patchnames.glade" + + top = libglade.GladeXML(glade_file,"summary") + top.signal_autoconnect({ + "destroy_passed_object" : utils.destroy_passed_object, + "on_ok_clicked" : on_ok_clicked + }) + top.get_widget("textwindow").show_string(msg) else: - msg = _("%d nicknames were extracted\n") % nick_count + GnomeOkDialog(_("No titles or nicknames were found")) + callback(0) - if title_count == 1: - msg = msg + "\n" + _("1 title was extracted") - else: - msg = msg + "\n" + _("%d titles were extracted") % title_count - - if nick_count > 0 or title_count > 0: +#------------------------------------------------------------------------- +# +# +# +#------------------------------------------------------------------------- +def on_ok_clicked(obj): + for grp in nick_list: + name = grp[0].getPrimaryName() + name.setFirstName(grp[1]) + grp[0].setNickName(grp[2]) utils.modified() - - box = GnomeOkDialog(msg) - box.show() - callback(1) + + for grp in title_list: + name = grp[0].getPrimaryName() + name.setFirstName(grp[2]) + name.setTitle(grp[1]) + utils.modified() + + utils.destroy_passed_object(obj) + cb(1) #------------------------------------------------------------------------- # @@ -88,6 +121,11 @@ def runTool(database,active_person,callback): def get_description(): return _("Searches the entire database and attempts to extract titles and nicknames that may be embedded in a person's given name field.") +#------------------------------------------------------------------------- +# +# +# +#------------------------------------------------------------------------- def get_name(): return _("Database Processing/Extract information from names") diff --git a/gramps/src/plugins/patchnames.glade b/gramps/src/plugins/patchnames.glade new file mode 100644 index 000000000..718a56fe7 --- /dev/null +++ b/gramps/src/plugins/patchnames.glade @@ -0,0 +1,170 @@ + + + + + summary + summary + + src + pixmaps + C + True + True + + + + GtkDialog + summary + Gramps - Name and Title Extraction Tool + GTK_WINDOW_TOPLEVEL + GTK_WIN_POS_NONE + False + True + True + False + + + GtkVBox + Dialog:vbox + dialog-vbox1 + False + 0 + + + GtkHBox + Dialog:action_area + dialog-action_area1 + 10 + True + 5 + + 0 + False + True + GTK_PACK_END + + + + GtkHButtonBox + hbuttonbox1 + GTK_BUTTONBOX_END + 30 + 85 + 27 + 7 + 0 + + 0 + True + True + + + + GtkButton + button3 + True + True + + clicked + on_ok_clicked + summary + Sun, 12 Aug 2001 17:26:36 GMT + + GNOME_STOCK_BUTTON_YES + GTK_RELIEF_NORMAL + + + + GtkButton + button4 + True + True + + clicked + destroy_passed_object + summary + Sun, 12 Aug 2001 17:26:57 GMT + + GNOME_STOCK_BUTTON_NO + GTK_RELIEF_NORMAL + + + + + + GtkVBox + vbox1 + False + 0 + + 0 + True + True + + + + GtkLabel + summaryTitle + 500 + 16 + + GTK_JUSTIFY_CENTER + False + 0.5 + 0.5 + 0 + 0 + + 8 + False + False + + + + + GtkHSeparator + hseparator1 + + 4 + False + True + + + + + GtkLabel + label1 + + GTK_JUSTIFY_LEFT + False + 0.5 + 0.5 + 0 + 10 + + 0 + False + False + + + + + GnomeLess + textwindow + 250 + + 0 + True + True + + + + + + +