Merge pull request #350 from prculley/extractname
Fix 'Extract Information from names' tool
This commit is contained in:
commit
4b313694fc
@ -3,10 +3,8 @@
|
|||||||
<interface>
|
<interface>
|
||||||
<requires lib="gtk+" version="3.10"/>
|
<requires lib="gtk+" version="3.10"/>
|
||||||
<object class="GtkDialog" id="patchnames">
|
<object class="GtkDialog" id="patchnames">
|
||||||
<property name="visible">True</property>
|
<property name="visible">False</property>
|
||||||
<property name="can_focus">False</property>
|
<property name="can_focus">False</property>
|
||||||
<property name="default_width">500</property>
|
|
||||||
<property name="default_height">450</property>
|
|
||||||
<property name="type_hint">dialog</property>
|
<property name="type_hint">dialog</property>
|
||||||
<signal name="delete-event" handler="on_delete_event" swapped="no"/>
|
<signal name="delete-event" handler="on_delete_event" swapped="no"/>
|
||||||
<child internal-child="vbox">
|
<child internal-child="vbox">
|
||||||
|
@ -48,11 +48,11 @@ from gramps.gui.plug import tool
|
|||||||
from gramps.gui.dialog import OkDialog
|
from gramps.gui.dialog import OkDialog
|
||||||
from gramps.gui.managedwindow import ManagedWindow
|
from gramps.gui.managedwindow import ManagedWindow
|
||||||
from gramps.gui.display import display_help
|
from gramps.gui.display import display_help
|
||||||
|
from gramps.gui.glade import Glade
|
||||||
from gramps.gen.lib import NameOriginType, Surname
|
from gramps.gen.lib import NameOriginType, Surname
|
||||||
from gramps.gen.db import DbTxn
|
from gramps.gen.db import DbTxn
|
||||||
from gramps.gen.const import GRAMPS_LOCALE as glocale
|
from gramps.gen.const import GRAMPS_LOCALE as glocale
|
||||||
_ = glocale.translation.sgettext
|
_ = glocale.translation.sgettext
|
||||||
from gramps.gui.glade import Glade
|
|
||||||
|
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
#
|
#
|
||||||
@ -74,8 +74,7 @@ PREFIX_LIST = [
|
|||||||
"de", "van", "von", "di", "le", "du", "dela", "della",
|
"de", "van", "von", "di", "le", "du", "dela", "della",
|
||||||
"des", "vande", "ten", "da", "af", "den", "das", "dello",
|
"des", "vande", "ten", "da", "af", "den", "das", "dello",
|
||||||
"del", "en", "ein", "el" "et", "les", "lo", "los", "un",
|
"del", "en", "ein", "el" "et", "les", "lo", "los", "un",
|
||||||
"um", "una", "uno", "der", "ter", "te", "die",
|
"um", "una", "uno", "der", "ter", "te", "die"]
|
||||||
]
|
|
||||||
|
|
||||||
CONNECTOR_LIST = ['e', 'y', ]
|
CONNECTOR_LIST = ['e', 'y', ]
|
||||||
CONNECTOR_LIST_NONSPLIT = ['de', 'van']
|
CONNECTOR_LIST_NONSPLIT = ['de', 'van']
|
||||||
@ -109,13 +108,14 @@ class PatchNames(tool.BatchTool, ManagedWindow):
|
|||||||
|
|
||||||
tool.BatchTool.__init__(self, dbstate, user, options_class, name)
|
tool.BatchTool.__init__(self, dbstate, user, options_class, name)
|
||||||
if self.fail:
|
if self.fail:
|
||||||
|
self.close()
|
||||||
return
|
return
|
||||||
|
|
||||||
winprefix = Gtk.Dialog(_("Default prefix and connector settings"),
|
winprefix = Gtk.Dialog(
|
||||||
self.uistate.window,
|
title=_("Default prefix and connector settings"),
|
||||||
Gtk.DialogFlags.MODAL|Gtk.DialogFlags.DESTROY_WITH_PARENT,
|
transient_for=self.uistate.window, modal=True,
|
||||||
(_('_OK'), Gtk.ResponseType.ACCEPT))
|
destroy_with_parent=True)
|
||||||
|
winprefix.add_button(_('_OK'), Gtk.ResponseType.ACCEPT)
|
||||||
winprefix.vbox.set_spacing(5)
|
winprefix.vbox.set_spacing(5)
|
||||||
hboxpref = Gtk.Box()
|
hboxpref = Gtk.Box()
|
||||||
label = Gtk.Label(label=_('Prefixes to search for:'))
|
label = Gtk.Label(label=_('Prefixes to search for:'))
|
||||||
@ -138,8 +138,8 @@ class PatchNames(tool.BatchTool, ManagedWindow):
|
|||||||
self.connsbox.set_text(', '.join(CONNECTOR_LIST_NONSPLIT))
|
self.connsbox.set_text(', '.join(CONNECTOR_LIST_NONSPLIT))
|
||||||
hboxconns.pack_start(self.connsbox, True, True, 0)
|
hboxconns.pack_start(self.connsbox, True, True, 0)
|
||||||
winprefix.vbox.pack_start(hboxconns, True, True, 0)
|
winprefix.vbox.pack_start(hboxconns, True, True, 0)
|
||||||
winprefix.show_all()
|
|
||||||
winprefix.resize(700, 100)
|
winprefix.resize(700, 100)
|
||||||
|
winprefix.show_all()
|
||||||
|
|
||||||
response = winprefix.run()
|
response = winprefix.run()
|
||||||
self.prefix_list = self.prefixbox.get_text().split(',')
|
self.prefix_list = self.prefixbox.get_text().split(',')
|
||||||
@ -149,19 +149,21 @@ class PatchNames(tool.BatchTool, ManagedWindow):
|
|||||||
self.connector_list = list(map(strip, self.connector_list))
|
self.connector_list = list(map(strip, self.connector_list))
|
||||||
self.conbox = None
|
self.conbox = None
|
||||||
self.connector_list_nonsplit = self.connsbox.get_text().split(',')
|
self.connector_list_nonsplit = self.connsbox.get_text().split(',')
|
||||||
self.connector_list_nonsplit = list(map(strip, self.connector_list_nonsplit))
|
self.connector_list_nonsplit = list(
|
||||||
|
map(strip, self.connector_list_nonsplit))
|
||||||
self.connsbox = None
|
self.connsbox = None
|
||||||
|
|
||||||
# Find a prefix in the first_name
|
# Find a prefix in the first_name
|
||||||
self._fn_prefix_re = re.compile("(\S+)\s+(%s)\s*$" % '|'.join(self.prefix_list),
|
self._fn_prefix_re = re.compile(
|
||||||
re.IGNORECASE)
|
r"(\S+)\s+(%s)\s*$" % '|'.join(self.prefix_list), re.IGNORECASE)
|
||||||
|
|
||||||
# Find a prefix in the surname
|
# Find a prefix in the surname
|
||||||
self._sn_prefix_re = re.compile("^\s*(%s)\s+(.+)" % '|'.join(self.prefix_list),
|
self._sn_prefix_re = re.compile(
|
||||||
re.IGNORECASE)
|
r"^\s*(%s)\s+(.+)" % '|'.join(self.prefix_list), re.IGNORECASE)
|
||||||
# Find a connector in the surname
|
# Find a connector in the surname
|
||||||
self._sn_con_re = re.compile("^\s*(.+)\s+(%s)\s+(.+)" % '|'.join(self.connector_list),
|
self._sn_con_re = re.compile(
|
||||||
re.IGNORECASE)
|
r"^\s*(.+)\s+(%s)\s+(.+)" % '|'.join(self.connector_list),
|
||||||
|
re.IGNORECASE)
|
||||||
winprefix.destroy()
|
winprefix.destroy()
|
||||||
|
|
||||||
self.cb = callback
|
self.cb = callback
|
||||||
@ -206,7 +208,7 @@ class PatchNames(tool.BatchTool, ManagedWindow):
|
|||||||
matchnick = _nick_re.match(first)
|
matchnick = _nick_re.match(first)
|
||||||
|
|
||||||
if new_title:
|
if new_title:
|
||||||
titleval = (" ".join(old_title+new_title), first)
|
titleval = (" ".join(old_title + new_title), first)
|
||||||
if key in self.handle_to_action:
|
if key in self.handle_to_action:
|
||||||
self.handle_to_action[key][self.titleid] = titleval
|
self.handle_to_action[key][self.titleid] = titleval
|
||||||
else:
|
else:
|
||||||
@ -250,8 +252,8 @@ class PatchNames(tool.BatchTool, ManagedWindow):
|
|||||||
for ind in range(len(prefixes)):
|
for ind in range(len(prefixes)):
|
||||||
origs.append(NameOriginType())
|
origs.append(NameOriginType())
|
||||||
origs[0] = old_orig[0]
|
origs[0] = old_orig[0]
|
||||||
compoundval = (surnames, prefixes, ['']*len(prefixes),
|
compoundval = (surnames, prefixes, [''] * len(prefixes),
|
||||||
primaries, origs)
|
primaries, origs)
|
||||||
if key in self.handle_to_action:
|
if key in self.handle_to_action:
|
||||||
self.handle_to_action[key][self.compid] = compoundval
|
self.handle_to_action[key][self.compid] = compoundval
|
||||||
else:
|
else:
|
||||||
@ -268,8 +270,8 @@ class PatchNames(tool.BatchTool, ManagedWindow):
|
|||||||
new_orig_list = []
|
new_orig_list = []
|
||||||
ind = 0
|
ind = 0
|
||||||
cont = True
|
cont = True
|
||||||
for pref, surn, con, prim, orig in zip(old_prefix, old_surn,
|
for pref, surn, con, prim, orig in zip(
|
||||||
old_con, old_prim, old_orig):
|
old_prefix, old_surn, old_con, old_prim, old_orig):
|
||||||
surnval = surn.split()
|
surnval = surn.split()
|
||||||
if surnval == []:
|
if surnval == []:
|
||||||
new_prefix_list.append(pref)
|
new_prefix_list.append(pref)
|
||||||
@ -307,7 +309,8 @@ class PatchNames(tool.BatchTool, ManagedWindow):
|
|||||||
val = ''
|
val = ''
|
||||||
cont = False
|
cont = False
|
||||||
#if value after surname indicates continue, then continue
|
#if value after surname indicates continue, then continue
|
||||||
while cont and (val.lower() in self.connector_list_nonsplit):
|
while cont and (
|
||||||
|
val.lower() in self.connector_list_nonsplit):
|
||||||
#add this val to the current surname
|
#add this val to the current surname
|
||||||
new_surname_list[-1] += ' ' + val
|
new_surname_list[-1] += ' ' + val
|
||||||
try:
|
try:
|
||||||
@ -315,10 +318,10 @@ class PatchNames(tool.BatchTool, ManagedWindow):
|
|||||||
except IndexError:
|
except IndexError:
|
||||||
val = ''
|
val = ''
|
||||||
cont = False
|
cont = False
|
||||||
# if previous is non-splitting connector, then add new val to
|
# if previous is non-splitting connector, then add new val
|
||||||
# current surname
|
# to current surname
|
||||||
if cont and (new_surname_list[-1].split()[-1].lower()
|
if cont and (new_surname_list[-1].split()[-1].lower()
|
||||||
in self.connector_list_nonsplit):
|
in self.connector_list_nonsplit):
|
||||||
new_surname_list[-1] += ' ' + val
|
new_surname_list[-1] += ' ' + val
|
||||||
try:
|
try:
|
||||||
val = surnval.pop(0)
|
val = surnval.pop(0)
|
||||||
@ -337,18 +340,19 @@ class PatchNames(tool.BatchTool, ManagedWindow):
|
|||||||
except IndexError:
|
except IndexError:
|
||||||
val = ''
|
val = ''
|
||||||
cont = False
|
cont = False
|
||||||
#initialize for a next surname in case there are still
|
# initialize for a next surname in case there are still
|
||||||
#val
|
# val
|
||||||
if cont:
|
if cont:
|
||||||
found = True # we split surname
|
found = True # we split surname
|
||||||
pref=''
|
pref = ''
|
||||||
con = ''
|
con = ''
|
||||||
prim = False
|
prim = False
|
||||||
orig = NameOriginType()
|
orig = NameOriginType()
|
||||||
ind += 1
|
ind += 1
|
||||||
if found:
|
if found:
|
||||||
compoundval = (new_surname_list, new_prefix_list,
|
compoundval = (new_surname_list, new_prefix_list,
|
||||||
new_connector_list, new_prim_list, new_orig_list)
|
new_connector_list, new_prim_list,
|
||||||
|
new_orig_list)
|
||||||
if key in self.handle_to_action:
|
if key in self.handle_to_action:
|
||||||
self.handle_to_action[key][self.compid] = compoundval
|
self.handle_to_action[key][self.compid] = compoundval
|
||||||
else:
|
else:
|
||||||
@ -379,14 +383,14 @@ class PatchNames(tool.BatchTool, ManagedWindow):
|
|||||||
self.top = Glade()
|
self.top = Glade()
|
||||||
window = self.top.toplevel
|
window = self.top.toplevel
|
||||||
self.top.connect_signals({
|
self.top.connect_signals({
|
||||||
"destroy_passed_object" : self.close,
|
"destroy_passed_object": self.close,
|
||||||
"on_ok_clicked" : self.on_ok_clicked,
|
"on_ok_clicked": self.on_ok_clicked,
|
||||||
"on_help_clicked" : self.on_help_clicked,
|
"on_help_clicked": self.on_help_clicked,
|
||||||
"on_delete_event" : self.close,
|
"on_delete_event": self.close})
|
||||||
})
|
|
||||||
|
|
||||||
self.list = self.top.get_object("list")
|
self.list = self.top.get_object("list")
|
||||||
self.set_window(window, self.top.get_object('title'), self.label)
|
self.set_window(window, self.top.get_object('title'), self.label)
|
||||||
|
self.setup_configs("interface.patchnames", 680, 400)
|
||||||
|
|
||||||
self.model = Gtk.ListStore(GObject.TYPE_BOOLEAN, GObject.TYPE_STRING,
|
self.model = Gtk.ListStore(GObject.TYPE_BOOLEAN, GObject.TYPE_STRING,
|
||||||
GObject.TYPE_STRING, GObject.TYPE_STRING,
|
GObject.TYPE_STRING, GObject.TYPE_STRING,
|
||||||
@ -406,7 +410,8 @@ class PatchNames(tool.BatchTool, ManagedWindow):
|
|||||||
c = Gtk.TreeViewColumn(_('Value'), Gtk.CellRendererText(), text=3)
|
c = Gtk.TreeViewColumn(_('Value'), Gtk.CellRendererText(), text=3)
|
||||||
self.list.append_column(c)
|
self.list.append_column(c)
|
||||||
|
|
||||||
c = Gtk.TreeViewColumn(_('Current Name'), Gtk.CellRendererText(), text=4)
|
c = Gtk.TreeViewColumn(_('Current Name'), Gtk.CellRendererText(),
|
||||||
|
text=4)
|
||||||
self.list.append_column(c)
|
self.list.append_column(c)
|
||||||
|
|
||||||
self.list.set_model(self.model)
|
self.list.set_model(self.model)
|
||||||
@ -429,7 +434,8 @@ class PatchNames(tool.BatchTool, ManagedWindow):
|
|||||||
self.model.set_value(handle, 1, gid)
|
self.model.set_value(handle, 1, gid)
|
||||||
self.model.set_value(handle, 2, _('Nickname'))
|
self.model.set_value(handle, 2, _('Nickname'))
|
||||||
self.model.set_value(handle, 3, nick)
|
self.model.set_value(handle, 3, nick)
|
||||||
self.model.set_value(handle, 4, p.get_primary_name().get_name())
|
self.model.set_value(handle, 4,
|
||||||
|
p.get_primary_name().get_name())
|
||||||
self.nick_hash[key] = handle
|
self.nick_hash[key] = handle
|
||||||
|
|
||||||
if self.titleid in data:
|
if self.titleid in data:
|
||||||
@ -439,7 +445,8 @@ class PatchNames(tool.BatchTool, ManagedWindow):
|
|||||||
self.model.set_value(handle, 1, gid)
|
self.model.set_value(handle, 1, gid)
|
||||||
self.model.set_value(handle, 2, _('Person|Title'))
|
self.model.set_value(handle, 2, _('Person|Title'))
|
||||||
self.model.set_value(handle, 3, title)
|
self.model.set_value(handle, 3, title)
|
||||||
self.model.set_value(handle, 4, p.get_primary_name().get_name())
|
self.model.set_value(
|
||||||
|
handle, 4, p.get_primary_name().get_name())
|
||||||
self.title_hash[key] = handle
|
self.title_hash[key] = handle
|
||||||
|
|
||||||
if self.pref1id in data:
|
if self.pref1id in data:
|
||||||
@ -449,11 +456,13 @@ class PatchNames(tool.BatchTool, ManagedWindow):
|
|||||||
self.model.set_value(handle, 1, gid)
|
self.model.set_value(handle, 1, gid)
|
||||||
self.model.set_value(handle, 2, _('Prefix in given name'))
|
self.model.set_value(handle, 2, _('Prefix in given name'))
|
||||||
self.model.set_value(handle, 3, prefixtotal)
|
self.model.set_value(handle, 3, prefixtotal)
|
||||||
self.model.set_value(handle, 4, p.get_primary_name().get_name())
|
self.model.set_value(
|
||||||
|
handle, 4, p.get_primary_name().get_name())
|
||||||
self.prefix1_hash[key] = handle
|
self.prefix1_hash[key] = handle
|
||||||
|
|
||||||
if self.compid in data:
|
if self.compid in data:
|
||||||
surn_list, pref_list, con_list, prims, origs = data[self.compid]
|
surn_list, pref_list, con_list, prims, origs =\
|
||||||
|
data[self.compid]
|
||||||
handle = self.model.append()
|
handle = self.model.append()
|
||||||
self.model.set_value(handle, 0, 1)
|
self.model.set_value(handle, 0, 1)
|
||||||
self.model.set_value(handle, 1, gid)
|
self.model.set_value(handle, 1, gid)
|
||||||
@ -463,14 +472,15 @@ class PatchNames(tool.BatchTool, ManagedWindow):
|
|||||||
if newval:
|
if newval:
|
||||||
newval += '-['
|
newval += '-['
|
||||||
else:
|
else:
|
||||||
newval = '['
|
newval = '['
|
||||||
newval += pre + ',' + sur
|
newval += pre + ',' + sur
|
||||||
if con:
|
if con:
|
||||||
newval += ',' + con + ']'
|
newval += ',' + con + ']'
|
||||||
else:
|
else:
|
||||||
newval += ']'
|
newval += ']'
|
||||||
self.model.set_value(handle, 3, newval)
|
self.model.set_value(handle, 3, newval)
|
||||||
self.model.set_value(handle, 4, p.get_primary_name().get_name())
|
self.model.set_value(handle, 4,
|
||||||
|
p.get_primary_name().get_name())
|
||||||
self.compound_hash[key] = handle
|
self.compound_hash[key] = handle
|
||||||
|
|
||||||
self.progress.step()
|
self.progress.step()
|
||||||
@ -518,7 +528,8 @@ class PatchNames(tool.BatchTool, ManagedWindow):
|
|||||||
if oldpref == '' or oldpref == prefix.strip():
|
if oldpref == '' or oldpref == prefix.strip():
|
||||||
name.get_surname_list()[0].set_prefix(prefix)
|
name.get_surname_list()[0].set_prefix(prefix)
|
||||||
else:
|
else:
|
||||||
name.get_surname_list()[0].set_prefix('%s %s' % (prefix, oldpref))
|
name.get_surname_list()[0].set_prefix(
|
||||||
|
'%s %s' % (prefix, oldpref))
|
||||||
|
|
||||||
if self.compid in data:
|
if self.compid in data:
|
||||||
modelhandle = self.compound_hash[key]
|
modelhandle = self.compound_hash[key]
|
||||||
@ -527,8 +538,8 @@ class PatchNames(tool.BatchTool, ManagedWindow):
|
|||||||
surns, prefs, cons, prims, origs = data[self.compid]
|
surns, prefs, cons, prims, origs = data[self.compid]
|
||||||
name = p.get_primary_name()
|
name = p.get_primary_name()
|
||||||
new_surn_list = []
|
new_surn_list = []
|
||||||
for surn, pref, con, prim, orig in zip(surns, prefs, cons,
|
for surn, pref, con, prim, orig in zip(
|
||||||
prims, origs):
|
surns, prefs, cons, prims, origs):
|
||||||
new_surn_list.append(Surname())
|
new_surn_list.append(Surname())
|
||||||
new_surn_list[-1].set_surname(surn.strip())
|
new_surn_list[-1].set_surname(surn.strip())
|
||||||
new_surn_list[-1].set_prefix(pref.strip())
|
new_surn_list[-1].set_prefix(pref.strip())
|
||||||
@ -544,6 +555,7 @@ class PatchNames(tool.BatchTool, ManagedWindow):
|
|||||||
self.close()
|
self.close()
|
||||||
self.cb()
|
self.cb()
|
||||||
|
|
||||||
|
|
||||||
class PatchNamesOptions(tool.ToolOptions):
|
class PatchNamesOptions(tool.ToolOptions):
|
||||||
"""
|
"""
|
||||||
Defines options and provides handling interface.
|
Defines options and provides handling interface.
|
||||||
@ -552,6 +564,6 @@ class PatchNamesOptions(tool.ToolOptions):
|
|||||||
def __init__(self, name, person_id=None):
|
def __init__(self, name, person_id=None):
|
||||||
tool.ToolOptions.__init__(self, name, person_id)
|
tool.ToolOptions.__init__(self, name, person_id)
|
||||||
|
|
||||||
|
|
||||||
def strip(arg):
|
def strip(arg):
|
||||||
return arg.strip()
|
return arg.strip()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user