2002-10-20 19:55:16 +05:30
|
|
|
#
|
|
|
|
# Gramps - a GTK+/GNOME based genealogy program
|
|
|
|
#
|
2006-04-26 10:39:44 +05:30
|
|
|
# Copyright (C) 2000-2006 Donald N. Allingham
|
2008-05-19 00:54:28 +05:30
|
|
|
# Copyright (C) 2008 Brian G. Matherly
|
2010-05-01 09:42:42 +05:30
|
|
|
# Copyright (C) 2010 Jakim Friant
|
2002-10-20 19:55:16 +05:30
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
#
|
|
|
|
|
2004-05-09 22:02:13 +05:30
|
|
|
# $Id$
|
|
|
|
|
2008-03-02 04:17:48 +05:30
|
|
|
"""Tools/Database Processing/Extract Information from Names"""
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2003-01-15 10:55:50 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# python modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2002-10-20 19:55:16 +05:30
|
|
|
import re
|
|
|
|
|
2003-01-15 10:55:50 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# gnome/gtk
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2002-10-20 19:55:16 +05:30
|
|
|
import gtk
|
2008-01-22 03:33:43 +05:30
|
|
|
import gobject
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2003-01-15 10:55:50 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# gramps modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2009-02-26 15:38:38 +05:30
|
|
|
import const
|
2009-06-19 20:53:58 +05:30
|
|
|
from gui.utils import ProgressMeter
|
2010-05-01 09:42:42 +05:30
|
|
|
from gui.plug import tool
|
2003-01-15 10:55:50 +05:30
|
|
|
from QuestionDialog import OkDialog
|
2006-04-27 09:29:47 +05:30
|
|
|
import ManagedWindow
|
2006-05-11 05:36:43 +05:30
|
|
|
import GrampsDisplay
|
2007-10-08 22:11:39 +05:30
|
|
|
import gen.lib
|
2010-01-18 10:12:17 +05:30
|
|
|
from gen.ggettext import sgettext as _
|
2009-05-15 01:45:59 +05:30
|
|
|
from glade import Glade
|
2008-04-19 13:59:43 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Constants
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2009-02-26 15:38:38 +05:30
|
|
|
WIKI_HELP_PAGE = '%s_-_Tools' % const.URL_MANUAL_PAGE
|
2008-04-19 13:59:43 +05:30
|
|
|
WIKI_HELP_SEC = _('manual|Extract_Information_from_Names')
|
2003-01-15 10:55:50 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# constants
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2004-11-28 10:33:29 +05:30
|
|
|
|
2008-04-08 01:03:54 +05:30
|
|
|
# List of possible surname prefixes. Notice that you must run the tool
|
|
|
|
# multiple times for prefixes such as "van der".
|
2010-10-23 20:20:25 +05:30
|
|
|
PREFIX_LIST = [
|
2004-11-28 10:33:29 +05:30
|
|
|
"de", "van", "von", "di", "le", "du", "dela", "della",
|
|
|
|
"des", "vande", "ten", "da", "af", "den", "das", "dello",
|
|
|
|
"del", "en", "ein", "el" "et", "les", "lo", "los", "un",
|
2008-04-08 01:03:54 +05:30
|
|
|
"um", "una", "uno", "der", "ter", "te", "die",
|
2004-11-28 10:33:29 +05:30
|
|
|
]
|
|
|
|
|
2010-10-23 20:20:25 +05:30
|
|
|
CONNECTOR_LIST = ['e', 'y', ]
|
|
|
|
CONNECTOR_LIST_NONSPLIT = ['de', 'van']
|
2004-11-28 10:33:29 +05:30
|
|
|
|
2008-04-08 01:03:54 +05:30
|
|
|
_title_re = re.compile(r"^ ([A-Za-z][A-Za-z]+\.) \s+ (.+) $", re.VERBOSE)
|
|
|
|
_nick_re = re.compile(r"(.+) \s* [(\"] (.+) [)\"]", re.VERBOSE)
|
|
|
|
|
2008-04-08 00:57:52 +05:30
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Search each name in the database, and compare the firstname against the
|
|
|
|
# form of "Name (Nickname)". If it matches, change the first name entry
|
2008-04-08 01:03:54 +05:30
|
|
|
# to "Name" and add "Nickname" into the nickname field. Also, search for
|
|
|
|
# surname prefixes. If found, change the name entry and put the prefix in
|
|
|
|
# the name prefix field.
|
2002-10-20 19:55:16 +05:30
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
|
2008-04-08 00:57:52 +05:30
|
|
|
|
2010-05-01 09:42:42 +05:30
|
|
|
class PatchNames(tool.BatchTool, ManagedWindow.ManagedWindow):
|
2010-10-23 20:20:25 +05:30
|
|
|
titleid = 1
|
|
|
|
nickid = 2
|
|
|
|
pref1id = 3
|
|
|
|
compid = 4
|
|
|
|
|
2006-04-10 04:23:53 +05:30
|
|
|
def __init__(self, dbstate, uistate, options_class, name, callback=None):
|
2006-04-27 09:29:47 +05:30
|
|
|
self.label = _('Name and title extraction tool')
|
2008-04-08 00:57:52 +05:30
|
|
|
ManagedWindow.ManagedWindow.__init__(self, uistate, [], self.__class__)
|
|
|
|
self.set_window(gtk.Window(), gtk.Label(), '')
|
|
|
|
|
2010-05-01 09:42:42 +05:30
|
|
|
tool.BatchTool.__init__(self, dbstate, options_class, name)
|
2006-05-04 07:35:50 +05:30
|
|
|
if self.fail:
|
|
|
|
return
|
2010-10-23 20:20:25 +05:30
|
|
|
|
|
|
|
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()
|
2010-10-24 18:36:55 +05:30
|
|
|
hboxconns.pack_start(gtk.Label(_('Connectors not splitting surnames:')),
|
2010-10-23 20:20:25 +05:30
|
|
|
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()
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
self.cb = callback
|
2010-10-23 20:20:25 +05:30
|
|
|
self.handle_to_action = {}
|
2002-11-04 09:35:47 +05:30
|
|
|
|
2009-06-19 20:53:58 +05:30
|
|
|
self.progress = ProgressMeter(
|
2008-04-08 00:57:52 +05:30
|
|
|
_('Extracting Information from Names'), '')
|
2005-08-18 11:28:28 +05:30
|
|
|
self.progress.set_pass(_('Analyzing names'),
|
|
|
|
self.db.get_number_of_people())
|
|
|
|
|
2009-09-15 02:20:25 +05:30
|
|
|
for person in self.db.iter_people():
|
|
|
|
key = person.handle
|
2005-05-11 19:34:47 +05:30
|
|
|
name = person.get_primary_name()
|
|
|
|
first = name.get_first_name()
|
|
|
|
sname = name.get_surname()
|
2010-10-23 20:20:25 +05:30
|
|
|
|
|
|
|
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())
|
2005-05-11 19:34:47 +05:30
|
|
|
|
|
|
|
if name.get_title():
|
2006-03-01 01:24:35 +05:30
|
|
|
old_title = [name.get_title()]
|
2005-05-11 19:34:47 +05:30
|
|
|
else:
|
2006-03-01 01:24:35 +05:30
|
|
|
old_title = []
|
|
|
|
new_title = []
|
|
|
|
|
|
|
|
match = _title_re.match(first)
|
2005-05-11 19:34:47 +05:30
|
|
|
while match:
|
2002-10-20 19:55:16 +05:30
|
|
|
groups = match.groups()
|
2005-05-11 19:34:47 +05:30
|
|
|
first = groups[1]
|
2006-03-01 01:24:35 +05:30
|
|
|
new_title.append(groups[0])
|
2005-05-11 19:34:47 +05:30
|
|
|
match = _title_re.match(first)
|
2010-10-23 20:20:25 +05:30
|
|
|
matchnick = _nick_re.match(first)
|
2005-05-11 19:34:47 +05:30
|
|
|
|
2006-03-01 01:24:35 +05:30
|
|
|
if new_title:
|
2010-10-23 20:20:25 +05:30
|
|
|
titleval = (" ".join(old_title+new_title), first)
|
|
|
|
if key in self.handle_to_action:
|
|
|
|
self.handle_to_action[key][self.titleid] = titleval
|
2008-04-08 01:03:54 +05:30
|
|
|
else:
|
2010-10-23 20:20:25 +05:30
|
|
|
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
|
2008-04-08 01:03:54 +05:30
|
|
|
else:
|
2010-10-23 20:20:25 +05:30
|
|
|
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):
|
2010-10-24 18:36:55 +05:30
|
|
|
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)
|
2010-10-23 20:20:25 +05:30
|
|
|
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)
|
2010-10-24 18:36:55 +05:30
|
|
|
|
2010-10-23 20:20:25 +05:30
|
|
|
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
|
2010-10-24 18:36:55 +05:30
|
|
|
while cont and (val.lower() in self.connector_list_nonsplit):
|
2010-10-23 20:20:25 +05:30
|
|
|
#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
|
2011-01-24 21:57:23 +05:30
|
|
|
if cont and (new_surname_list[-1].split()[-1].lower()
|
|
|
|
in self.connector_list_nonsplit):
|
2010-10-23 20:20:25 +05:30
|
|
|
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:
|
2010-10-24 18:36:55 +05:30
|
|
|
new_connector_list[-1] = val
|
2010-10-23 20:20:25 +05:30
|
|
|
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}
|
2006-03-01 01:24:35 +05:30
|
|
|
|
2005-08-18 11:28:28 +05:30
|
|
|
self.progress.step()
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2010-10-23 20:20:25 +05:30
|
|
|
if self.handle_to_action:
|
2003-04-16 11:55:38 +05:30
|
|
|
self.display()
|
2002-10-20 19:55:16 +05:30
|
|
|
else:
|
2005-08-18 11:28:28 +05:30
|
|
|
self.progress.close()
|
2006-05-13 00:16:26 +05:30
|
|
|
self.close()
|
2003-03-19 09:57:34 +05:30
|
|
|
OkDialog(_('No modifications made'),
|
2008-04-08 01:03:54 +05:30
|
|
|
_("No titles, nicknames or prefixes were found"))
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2008-02-24 19:25:55 +05:30
|
|
|
def build_menu_names(self, obj):
|
2008-04-08 00:57:52 +05:30
|
|
|
return (self.label, None)
|
2006-04-26 10:39:44 +05:30
|
|
|
|
2008-04-08 00:57:52 +05:30
|
|
|
def toggled(self, cell, path_string):
|
2010-01-22 00:12:53 +05:30
|
|
|
path = tuple(map(int, path_string.split(':')))
|
2003-04-16 11:55:38 +05:30
|
|
|
row = self.model[path]
|
|
|
|
row[0] = not row[0]
|
2008-04-08 00:57:52 +05:30
|
|
|
self.model.row_changed(path, row.iter)
|
2003-04-16 11:55:38 +05:30
|
|
|
|
|
|
|
def display(self):
|
2004-05-10 10:24:10 +05:30
|
|
|
|
2009-05-15 01:45:59 +05:30
|
|
|
self.top = Glade()
|
|
|
|
window = self.top.toplevel
|
2009-04-10 00:34:38 +05:30
|
|
|
self.top.connect_signals({
|
2004-05-10 10:24:10 +05:30
|
|
|
"destroy_passed_object" : self.close,
|
|
|
|
"on_ok_clicked" : self.on_ok_clicked,
|
2006-10-04 08:16:32 +05:30
|
|
|
"on_help_clicked" : self.on_help_clicked,
|
2010-01-07 19:40:26 +05:30
|
|
|
"on_delete_event" : self.close,
|
2003-04-16 11:55:38 +05:30
|
|
|
})
|
2008-04-08 00:57:52 +05:30
|
|
|
|
2009-04-10 00:34:38 +05:30
|
|
|
self.list = self.top.get_object("list")
|
|
|
|
self.set_window(window, self.top.get_object('title'), self.label)
|
2003-04-16 11:55:38 +05:30
|
|
|
|
2008-04-08 00:57:52 +05:30
|
|
|
self.model = gtk.ListStore(gobject.TYPE_BOOLEAN, gobject.TYPE_STRING,
|
|
|
|
gobject.TYPE_STRING, gobject.TYPE_STRING,
|
2008-01-22 03:33:43 +05:30
|
|
|
gobject.TYPE_STRING)
|
2003-04-16 11:55:38 +05:30
|
|
|
|
|
|
|
r = gtk.CellRendererToggle()
|
2008-04-08 00:57:52 +05:30
|
|
|
r.connect('toggled', self.toggled)
|
|
|
|
c = gtk.TreeViewColumn(_('Select'), r, active=0)
|
2003-04-16 11:55:38 +05:30
|
|
|
self.list.append_column(c)
|
|
|
|
|
2008-04-08 00:57:52 +05:30
|
|
|
c = gtk.TreeViewColumn(_('ID'), gtk.CellRendererText(), text=1)
|
2003-04-16 11:55:38 +05:30
|
|
|
self.list.append_column(c)
|
|
|
|
|
2008-04-08 00:57:52 +05:30
|
|
|
c = gtk.TreeViewColumn(_('Type'), gtk.CellRendererText(), text=2)
|
2003-04-16 11:55:38 +05:30
|
|
|
self.list.append_column(c)
|
|
|
|
|
2008-04-08 00:57:52 +05:30
|
|
|
c = gtk.TreeViewColumn(_('Value'), gtk.CellRendererText(), text=3)
|
2003-04-16 11:55:38 +05:30
|
|
|
self.list.append_column(c)
|
|
|
|
|
2010-10-23 20:20:25 +05:30
|
|
|
c = gtk.TreeViewColumn(_('Current Name'), gtk.CellRendererText(), text=4)
|
2003-04-16 11:55:38 +05:30
|
|
|
self.list.append_column(c)
|
|
|
|
|
|
|
|
self.list.set_model(self.model)
|
|
|
|
|
|
|
|
self.nick_hash = {}
|
|
|
|
self.title_hash = {}
|
2004-11-28 10:33:29 +05:30
|
|
|
self.prefix1_hash = {}
|
2010-10-23 20:20:25 +05:30
|
|
|
self.compound_hash = {}
|
2005-08-18 11:28:28 +05:30
|
|
|
|
2008-04-08 01:03:54 +05:30
|
|
|
self.progress.set_pass(_('Building display'),
|
2010-10-23 20:20:25 +05:30
|
|
|
len(self.handle_to_action.keys()))
|
2004-11-28 10:33:29 +05:30
|
|
|
|
2010-10-23 20:20:25 +05:30
|
|
|
for key, data in self.handle_to_action.items():
|
|
|
|
p = self.db.get_person_from_handle(key)
|
2004-11-28 10:33:29 +05:30
|
|
|
gid = p.get_gramps_id()
|
2010-10-23 20:20:25 +05:30
|
|
|
if self.nickid in data:
|
|
|
|
given, nick = data[self.nickid]
|
|
|
|
handle = self.model.append()
|
|
|
|
self.model.set_value(handle, 0, 1)
|
|
|
|
self.model.set_value(handle, 1, gid)
|
|
|
|
self.model.set_value(handle, 2, _('Nickname'))
|
|
|
|
self.model.set_value(handle, 3, nick)
|
|
|
|
self.model.set_value(handle, 4, p.get_primary_name().get_name())
|
|
|
|
self.nick_hash[key] = handle
|
|
|
|
|
|
|
|
if self.titleid in data:
|
|
|
|
title, given = data[self.titleid]
|
|
|
|
handle = self.model.append()
|
|
|
|
self.model.set_value(handle, 0, 1)
|
|
|
|
self.model.set_value(handle, 1, gid)
|
|
|
|
self.model.set_value(handle, 2, _('Person|Title'))
|
|
|
|
self.model.set_value(handle, 3, title)
|
|
|
|
self.model.set_value(handle, 4, p.get_primary_name().get_name())
|
|
|
|
self.title_hash[key] = handle
|
|
|
|
|
|
|
|
if self.pref1id in data:
|
|
|
|
given, prefixtotal, new_prefix = data[self.pref1id]
|
|
|
|
handle = self.model.append()
|
|
|
|
self.model.set_value(handle, 0, 1)
|
|
|
|
self.model.set_value(handle, 1, gid)
|
|
|
|
self.model.set_value(handle, 2, _('Prefix in given name'))
|
|
|
|
self.model.set_value(handle, 3, prefixtotal)
|
|
|
|
self.model.set_value(handle, 4, p.get_primary_name().get_name())
|
|
|
|
self.prefix1_hash[key] = handle
|
|
|
|
|
|
|
|
if self.compid in data:
|
|
|
|
surn_list, pref_list, con_list, prims, origs = data[self.compid]
|
|
|
|
handle = self.model.append()
|
|
|
|
self.model.set_value(handle, 0, 1)
|
|
|
|
self.model.set_value(handle, 1, gid)
|
|
|
|
self.model.set_value(handle, 2, _('Compound surname'))
|
|
|
|
newval = ''
|
|
|
|
for sur, pre, con in zip(surn_list, pref_list, con_list):
|
|
|
|
if newval:
|
|
|
|
newval += '-['
|
|
|
|
else:
|
|
|
|
newval = '['
|
|
|
|
newval += pre + ',' + sur
|
|
|
|
if con:
|
|
|
|
newval += ',' + con + ']'
|
|
|
|
else:
|
|
|
|
newval += ']'
|
|
|
|
self.model.set_value(handle, 3, newval)
|
|
|
|
self.model.set_value(handle, 4, p.get_primary_name().get_name())
|
|
|
|
self.compound_hash[key] = handle
|
|
|
|
|
2005-08-18 11:28:28 +05:30
|
|
|
self.progress.step()
|
2004-11-28 10:33:29 +05:30
|
|
|
|
2005-08-18 11:28:28 +05:30
|
|
|
self.progress.close()
|
2006-04-10 04:23:53 +05:30
|
|
|
self.show()
|
2004-05-10 10:24:10 +05:30
|
|
|
|
2008-02-24 19:25:55 +05:30
|
|
|
def on_help_clicked(self, obj):
|
* src/gramps_main.py (tool_callback): Typo.
* src/QuestionDialog.py: Use gramps icon.
* src/plugins/EventCmp.py: HIG; single instance; help.
* src/plugins/eventcmp.glade: HIG; help.
* src/plugins/Desbrowser.py: HIG, help, rebuild model after edit.
* src/plugins/desbrowse.glade: help, info label.
* src/plugins/PatchNames.py: HIG, help, single instance.
* src/plugins/patchnames.glade: HIG, help.
* src/plugins/Merge.py: HIG, help, single instance.
* src/plugins/merge.glade: HIG, help.
* src/plugins/ChangeNames.py: HIG, help, single instance.
svn: r4230
2005-03-24 11:52:25 +05:30
|
|
|
"""Display the relevant portion of GRAMPS manual"""
|
2008-04-19 13:59:43 +05:30
|
|
|
GrampsDisplay.help(webpage=WIKI_HELP_PAGE, section=WIKI_HELP_SEC)
|
* src/gramps_main.py (tool_callback): Typo.
* src/QuestionDialog.py: Use gramps icon.
* src/plugins/EventCmp.py: HIG; single instance; help.
* src/plugins/eventcmp.glade: HIG; help.
* src/plugins/Desbrowser.py: HIG, help, rebuild model after edit.
* src/plugins/desbrowse.glade: help, info label.
* src/plugins/PatchNames.py: HIG, help, single instance.
* src/plugins/patchnames.glade: HIG, help.
* src/plugins/Merge.py: HIG, help, single instance.
* src/plugins/merge.glade: HIG, help.
* src/plugins/ChangeNames.py: HIG, help, single instance.
svn: r4230
2005-03-24 11:52:25 +05:30
|
|
|
|
2008-02-24 19:25:55 +05:30
|
|
|
def on_ok_clicked(self, obj):
|
2011-02-01 03:24:58 +05:30
|
|
|
with self.db.transaction_begin(_("Extract information from names"),
|
|
|
|
batch=True) as trans:
|
|
|
|
self.db.disable_signals()
|
|
|
|
|
|
|
|
for key, data in self.handle_to_action.items():
|
|
|
|
p = self.db.get_person_from_handle(key)
|
|
|
|
if self.nickid in data:
|
|
|
|
modelhandle = self.nick_hash[key]
|
|
|
|
val = self.model.get_value(modelhandle, 0)
|
|
|
|
if val:
|
|
|
|
given, nick = data[self.nickid]
|
|
|
|
name = p.get_primary_name()
|
|
|
|
name.set_first_name(given.strip())
|
|
|
|
name.set_nick_name(nick.strip())
|
2010-10-23 20:20:25 +05:30
|
|
|
|
2011-02-01 03:24:58 +05:30
|
|
|
if self.titleid in data:
|
|
|
|
modelhandle = self.title_hash[key]
|
|
|
|
val = self.model.get_value(modelhandle, 0)
|
|
|
|
if val:
|
|
|
|
title, given = data[self.titleid]
|
|
|
|
name = p.get_primary_name()
|
|
|
|
name.set_first_name(given.strip())
|
|
|
|
name.set_title(title.strip())
|
2010-10-23 20:20:25 +05:30
|
|
|
|
2011-02-01 03:24:58 +05:30
|
|
|
if self.pref1id in data:
|
|
|
|
modelhandle = self.prefix1_hash[key]
|
|
|
|
val = self.model.get_value(modelhandle, 0)
|
|
|
|
if val:
|
|
|
|
given, prefixtotal, prefix = data[self.pref1id]
|
|
|
|
name = p.get_primary_name()
|
|
|
|
name.set_first_name(given.strip())
|
|
|
|
oldpref = name.get_surname_list()[0].get_prefix().strip()
|
|
|
|
if oldpref == '' or oldpref == prefix.strip():
|
|
|
|
name.get_surname_list()[0].set_prefix(prefix)
|
|
|
|
else:
|
|
|
|
name.get_surname_list()[0].set_prefix('%s %s' % (prefix, oldpref))
|
|
|
|
|
|
|
|
if self.compid in data:
|
|
|
|
modelhandle = self.compound_hash[key]
|
|
|
|
val = self.model.get_value(modelhandle, 0)
|
|
|
|
if val:
|
|
|
|
surns, prefs, cons, prims, origs = data[self.compid]
|
|
|
|
name = p.get_primary_name()
|
|
|
|
new_surn_list = []
|
|
|
|
for surn, pref, con, prim, orig in zip(surns, prefs, cons,
|
|
|
|
prims, origs):
|
|
|
|
new_surn_list.append(gen.lib.Surname())
|
|
|
|
new_surn_list[-1].set_surname(surn.strip())
|
|
|
|
new_surn_list[-1].set_prefix(pref.strip())
|
|
|
|
new_surn_list[-1].set_connector(con.strip())
|
|
|
|
new_surn_list[-1].set_primary(prim)
|
|
|
|
new_surn_list[-1].set_origintype(orig)
|
|
|
|
name.set_surname_list(new_surn_list)
|
|
|
|
|
|
|
|
self.db.commit_person(p, trans)
|
|
|
|
|
2006-05-11 05:36:43 +05:30
|
|
|
self.db.enable_signals()
|
|
|
|
self.db.request_rebuild()
|
2006-04-22 09:36:10 +05:30
|
|
|
self.close()
|
2006-04-27 09:08:30 +05:30
|
|
|
self.cb()
|
2008-04-08 00:57:52 +05:30
|
|
|
|
2010-05-01 09:42:42 +05:30
|
|
|
class PatchNamesOptions(tool.ToolOptions):
|
2005-12-06 12:08:09 +05:30
|
|
|
"""
|
|
|
|
Defines options and provides handling interface.
|
|
|
|
"""
|
|
|
|
|
2008-04-08 00:57:52 +05:30
|
|
|
def __init__(self, name, person_id=None):
|
2010-05-01 09:42:42 +05:30
|
|
|
tool.ToolOptions.__init__(self, name, person_id)
|
2010-10-23 20:20:25 +05:30
|
|
|
|
|
|
|
def strip(arg):
|
|
|
|
return arg.strip()
|
|
|
|
|