2004-11-21 06:00:52 +05:30
|
|
|
#
|
|
|
|
# Gramps - a GTK+/GNOME based genealogy program
|
|
|
|
#
|
2007-02-01 22:56:51 +05:30
|
|
|
# Copyright (C) 2000-2007 Donald N. Allingham
|
2008-05-19 00:54:28 +05:30
|
|
|
# Copyright (C) 2008 Brian G. Matherly
|
2004-11-21 06:00:52 +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
|
|
|
|
#
|
|
|
|
|
|
|
|
# $Id$
|
|
|
|
|
2008-03-02 04:17:48 +05:30
|
|
|
"""Tools/Database Processing/Fix Capitalization of Family Names"""
|
2004-11-21 06:00:52 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# gnome/gtk
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
import gobject
|
|
|
|
import gtk
|
2009-09-24 01:37:58 +05:30
|
|
|
import cPickle
|
|
|
|
from bsddb.db import DB_CURRENT
|
2004-11-21 06:00:52 +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
|
2006-03-11 06:42:06 +05:30
|
|
|
import GrampsDisplay
|
2006-04-10 04:23:53 +05:30
|
|
|
import ManagedWindow
|
2009-09-24 01:37:58 +05:30
|
|
|
from gen.lib import Person
|
2006-04-10 04:23:53 +05:30
|
|
|
|
|
|
|
from QuestionDialog import OkDialog
|
2008-10-02 09:32:10 +05:30
|
|
|
from PluginUtils import Tool
|
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-01-29 21:17:24 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# constants
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
|
|
|
|
prefix_list = [
|
|
|
|
"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",
|
|
|
|
"um", "una", "uno",
|
|
|
|
]
|
|
|
|
|
2009-02-26 15:38:38 +05:30
|
|
|
WIKI_HELP_PAGE = '%s_-_Tools' % const.URL_MANUAL_PAGE
|
2008-03-10 17:40:35 +05:30
|
|
|
WIKI_HELP_SEC = _('manual|Fix_Capitalization_of_Family_Names...')
|
2008-01-29 21:17:24 +05:30
|
|
|
|
2004-11-21 06:00:52 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# ChangeNames
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2006-05-04 07:35:50 +05:30
|
|
|
class ChangeNames(Tool.BatchTool, ManagedWindow.ManagedWindow):
|
2005-12-06 12:08:09 +05:30
|
|
|
|
2006-04-10 04:23:53 +05:30
|
|
|
def __init__(self, dbstate, uistate, options_class, name, callback=None):
|
2006-04-27 05:40:07 +05:30
|
|
|
self.label = _('Capitalization changes')
|
2006-05-13 00:16:26 +05:30
|
|
|
self.cb = callback
|
2006-04-10 04:23:53 +05:30
|
|
|
|
2006-05-13 00:16:26 +05:30
|
|
|
ManagedWindow.ManagedWindow.__init__(self,uistate,[],self.__class__)
|
|
|
|
self.set_window(gtk.Window(),gtk.Label(),'')
|
|
|
|
|
2006-05-04 07:35:50 +05:30
|
|
|
Tool.BatchTool.__init__(self, dbstate, options_class, name)
|
|
|
|
if self.fail:
|
|
|
|
return
|
2006-04-10 04:23:53 +05:30
|
|
|
|
2009-06-19 20:53:58 +05:30
|
|
|
self.progress = ProgressMeter(_('Checking Family Names'),'')
|
2005-08-18 11:28:28 +05:30
|
|
|
self.progress.set_pass(_('Searching family names'),
|
|
|
|
len(self.db.get_surname_list()))
|
2005-12-06 12:08:09 +05:30
|
|
|
self.name_list = []
|
2006-04-10 04:23:53 +05:30
|
|
|
|
2004-11-21 06:00:52 +05:30
|
|
|
for name in self.db.get_surname_list():
|
2008-01-29 21:17:24 +05:30
|
|
|
name.strip()
|
|
|
|
namesplitSP= name.split()
|
|
|
|
lSP = len(namesplitSP)
|
|
|
|
namesplitHY= name.split('-')
|
|
|
|
lHY = len(namesplitHY)
|
2008-06-16 20:31:46 +05:30
|
|
|
if lSP == lHY == 1:
|
2008-01-29 21:17:24 +05:30
|
|
|
if name != name.capitalize():
|
|
|
|
# Single surname without hyphen(s)
|
|
|
|
self.name_list.append(name)
|
|
|
|
#if lSP == 1 and lHY > 1:
|
2008-02-24 19:25:55 +05:30
|
|
|
#print "LSP==1", name, name.capitalize()
|
2008-01-29 21:17:24 +05:30
|
|
|
#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
|
2009-07-04 01:53:41 +05:30
|
|
|
for x in xrange(len(namesplitSP)-s1):
|
2008-01-29 21:17:24 +05:30
|
|
|
# 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()
|
2009-07-04 01:53:41 +05:30
|
|
|
for x in xrange(len(namesplitHY)):
|
2008-01-29 21:17:24 +05:30
|
|
|
# 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)
|
|
|
|
|
2006-04-10 04:23:53 +05:30
|
|
|
if uistate:
|
2005-12-06 12:08:09 +05:30
|
|
|
self.progress.step()
|
2004-11-21 06:00:52 +05:30
|
|
|
|
|
|
|
if self.name_list:
|
|
|
|
self.display()
|
|
|
|
else:
|
2005-08-18 11:28:28 +05:30
|
|
|
self.progress.close()
|
2006-05-13 00:16:26 +05:30
|
|
|
self.close()
|
2004-11-21 06:00:52 +05:30
|
|
|
OkDialog(_('No modifications made'),
|
2005-04-26 21:34:21 +05:30
|
|
|
_("No capitalization changes were detected."))
|
2004-11-21 06:00:52 +05:30
|
|
|
|
2008-02-24 19:25:55 +05:30
|
|
|
def name_cap(self, name):
|
2008-01-29 21:17:24 +05:30
|
|
|
name.strip()
|
|
|
|
namesplitSP = name.split()
|
|
|
|
lSP = len(namesplitSP)
|
|
|
|
lHY = len(name.split('-'))
|
|
|
|
namesep = ' '
|
|
|
|
if lHY > 1:
|
|
|
|
namesep = '-'
|
|
|
|
namesplitSP = name.replace(namesep,' ').split()
|
|
|
|
lSP= len(namesplitSP)
|
2008-06-16 20:31:46 +05:30
|
|
|
if lSP == lHY == 1:
|
2008-01-29 21:17:24 +05:30
|
|
|
#if name != name.capitalize():
|
|
|
|
# Single surname without space(s) or hyphen(s), normal case
|
|
|
|
return name.capitalize()
|
|
|
|
else:
|
|
|
|
# more than one string in surname but no hyphen
|
|
|
|
# check if first string is in prefix_list, if so CAP the rest
|
|
|
|
# Names like (von) Kohl(-)Brandt
|
|
|
|
result = ""
|
|
|
|
s1 = 0
|
|
|
|
if namesplitSP[0].lower() in prefix_list:
|
|
|
|
s1 = 1
|
|
|
|
result = namesplitSP[0].lower()+ ' '
|
|
|
|
for x in range(lSP-s1):
|
|
|
|
# CAP all subsurnames
|
|
|
|
result = result + namesplitSP[s1+x].capitalize() + namesep
|
|
|
|
return result[:-1]
|
|
|
|
|
2004-11-21 06:00:52 +05:30
|
|
|
def display(self):
|
|
|
|
|
2009-05-15 01:45:59 +05:30
|
|
|
self.top = Glade()
|
|
|
|
window = self.top.toplevel
|
2009-04-09 19:58:22 +05:30
|
|
|
self.top.connect_signals({
|
2004-11-21 06:00:52 +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,
|
2004-11-21 06:00:52 +05:30
|
|
|
})
|
2006-10-04 08:16:32 +05:30
|
|
|
|
2009-04-09 19:58:22 +05:30
|
|
|
self.list = self.top.get_object("list")
|
|
|
|
self.set_window(window,self.top.get_object('title'),self.label)
|
2004-11-21 06:00:52 +05:30
|
|
|
|
2008-01-18 22:33:55 +05:30
|
|
|
self.model = gtk.ListStore(gobject.TYPE_BOOLEAN, gobject.TYPE_STRING,
|
|
|
|
gobject.TYPE_STRING)
|
2004-11-21 06:00:52 +05:30
|
|
|
|
|
|
|
r = gtk.CellRendererToggle()
|
2006-12-15 10:53:45 +05:30
|
|
|
r.connect('toggled',self.toggled)
|
2004-11-21 06:00:52 +05:30
|
|
|
c = gtk.TreeViewColumn(_('Select'),r,active=0)
|
|
|
|
self.list.append_column(c)
|
|
|
|
|
|
|
|
c = gtk.TreeViewColumn(_('Original Name'),
|
|
|
|
gtk.CellRendererText(),text=1)
|
|
|
|
self.list.append_column(c)
|
|
|
|
|
|
|
|
c = gtk.TreeViewColumn(_('Capitalization Change'),
|
|
|
|
gtk.CellRendererText(),text=2)
|
|
|
|
self.list.append_column(c)
|
|
|
|
|
|
|
|
self.list.set_model(self.model)
|
|
|
|
|
|
|
|
self.iter_list = []
|
2005-08-18 11:28:28 +05:30
|
|
|
self.progress.set_pass(_('Building display'),len(self.name_list))
|
2004-11-21 06:00:52 +05:30
|
|
|
for name in self.name_list:
|
|
|
|
handle = self.model.append()
|
2006-12-15 10:53:45 +05:30
|
|
|
self.model.set_value(handle,0,True)
|
2008-02-24 19:25:55 +05:30
|
|
|
self.model.set_value(handle,1, name)
|
2008-01-29 21:17:24 +05:30
|
|
|
namecap = self.name_cap(name)
|
2008-02-24 19:25:55 +05:30
|
|
|
self.model.set_value(handle,2, namecap)
|
2004-11-21 06:00:52 +05:30
|
|
|
self.iter_list.append(handle)
|
2005-08-18 11:28:28 +05:30
|
|
|
self.progress.step()
|
|
|
|
self.progress.close()
|
2004-11-21 06:00:52 +05:30
|
|
|
|
2006-04-10 04:23:53 +05:30
|
|
|
self.show()
|
2004-11-21 06:00:52 +05:30
|
|
|
|
2006-12-15 10:53:45 +05:30
|
|
|
def toggled(self,cell,path_string):
|
2010-01-22 00:12:53 +05:30
|
|
|
path = tuple(map(int, path_string.split(':')))
|
2006-12-15 10:53:45 +05:30
|
|
|
row = self.model[path]
|
|
|
|
row[0] = not row[0]
|
|
|
|
|
2008-02-24 19:25:55 +05:30
|
|
|
def build_menu_names(self, obj):
|
2006-04-27 05:40:07 +05:30
|
|
|
return (self.label,None)
|
|
|
|
|
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-05 19:47:15 +05:30
|
|
|
GrampsDisplay.help(WIKI_HELP_PAGE , 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):
|
2006-01-19 23:48:55 +05:30
|
|
|
self.trans = self.db.transaction_begin("",batch=True)
|
2005-04-06 15:52:18 +05:30
|
|
|
self.db.disable_signals()
|
2009-09-28 21:13:54 +05:30
|
|
|
changelist = set(self.model.get_value(node,1)
|
2009-10-02 02:12:52 +05:30
|
|
|
for node in self.iter_list
|
|
|
|
if self.model.get_value(node,0))
|
2004-11-21 06:00:52 +05:30
|
|
|
|
2009-09-28 21:13:54 +05:30
|
|
|
#with self.db.get_person_cursor(update=True, commit=True) as cursor:
|
|
|
|
# for handle, data in cursor:
|
|
|
|
for handle in self.db.get_person_handles(False):
|
|
|
|
person = self.db.get_person_from_handle(handle)
|
|
|
|
#person = Person(data)
|
2004-11-21 06:00:52 +05:30
|
|
|
change = False
|
|
|
|
for name in [person.get_primary_name()] + person.get_alternate_names():
|
|
|
|
sname = name.get_surname()
|
|
|
|
if sname in changelist:
|
|
|
|
change = True
|
2008-01-29 21:17:24 +05:30
|
|
|
sname = self.name_cap(sname)
|
|
|
|
name.set_surname(sname)
|
2004-11-21 06:00:52 +05:30
|
|
|
if change:
|
2009-09-28 21:13:54 +05:30
|
|
|
#cursor.update(handle, person.serialize())
|
|
|
|
self.db.commit_person(person, transaction=self.trans)
|
2004-11-21 06:00:52 +05:30
|
|
|
|
2005-04-06 15:52:18 +05:30
|
|
|
self.db.transaction_commit(self.trans,_("Capitalization changes"))
|
|
|
|
self.db.enable_signals()
|
|
|
|
self.db.request_rebuild()
|
2006-04-27 05:40:07 +05:30
|
|
|
# FIXME: this probably needs to be removed, and bookmarks
|
|
|
|
# should always be rebuilt on a commit_person via signals
|
|
|
|
# self.parent.bookmarks.redraw()
|
2006-04-22 09:36:10 +05:30
|
|
|
self.close()
|
2006-04-14 10:06:25 +05:30
|
|
|
self.cb()
|
2004-11-21 06:00:52 +05:30
|
|
|
|
2005-12-06 12:08:09 +05:30
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
class ChangeNamesOptions(Tool.ToolOptions):
|
|
|
|
"""
|
|
|
|
Defines options and provides handling interface.
|
|
|
|
"""
|
|
|
|
|
2008-02-24 19:25:55 +05:30
|
|
|
def __init__(self, name,person_id=None):
|
|
|
|
Tool.ToolOptions.__init__(self, name,person_id)
|