2004-11-21 06:00:52 +05:30
|
|
|
#
|
|
|
|
# Gramps - a GTK+/GNOME based genealogy program
|
|
|
|
#
|
2006-01-19 10:00:40 +05:30
|
|
|
# Copyright (C) 2000-2006 Donald N. Allingham
|
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$
|
|
|
|
|
|
|
|
"Database Processing/Extract information from names"
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# python modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
import os
|
|
|
|
import re
|
2006-04-07 03:32:46 +05:30
|
|
|
from gettext import gettext as _
|
2004-11-21 06:00:52 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# gnome/gtk
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
import gobject
|
|
|
|
import gtk
|
|
|
|
import gtk.glade
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# gramps modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
import Utils
|
2006-03-11 06:42:06 +05:30
|
|
|
import GrampsDisplay
|
2006-04-10 04:23:53 +05:30
|
|
|
import ManagedWindow
|
|
|
|
|
|
|
|
from QuestionDialog import OkDialog
|
2006-03-11 06:42:06 +05:30
|
|
|
from PluginUtils import Tool, register_tool
|
2004-11-21 06:00:52 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# ChangeNames
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2006-04-14 10:06:25 +05:30
|
|
|
class ChangeNames(Tool.Tool, 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-04-10 04:23:53 +05:30
|
|
|
|
|
|
|
Tool.Tool.__init__(self, dbstate, options_class, name)
|
2006-04-27 05:40:07 +05:30
|
|
|
ManagedWindow.ManagedWindow.__init__(self, uistate, [], self.__class__)
|
2004-11-21 06:00:52 +05:30
|
|
|
|
|
|
|
self.cb = callback
|
2006-04-10 04:23:53 +05:30
|
|
|
|
2005-12-06 12:08:09 +05:30
|
|
|
self.progress = Utils.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():
|
|
|
|
if name != name.capitalize():
|
|
|
|
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()
|
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
|
|
|
|
|
|
|
def display(self):
|
|
|
|
|
|
|
|
base = os.path.dirname(__file__)
|
|
|
|
glade_file = base + os.sep + "patchnames.glade"
|
|
|
|
|
|
|
|
self.top = gtk.glade.XML(glade_file,"top","gramps")
|
2006-04-27 05:40:07 +05:30
|
|
|
window = self.top.get_widget('top')
|
2004-11-21 06:00:52 +05:30
|
|
|
self.top.signal_autoconnect({
|
|
|
|
"destroy_passed_object" : self.close,
|
|
|
|
"on_ok_clicked" : self.on_ok_clicked,
|
* 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
|
|
|
"on_help_clicked" : self.on_help_clicked,
|
2004-11-21 06:00:52 +05:30
|
|
|
})
|
|
|
|
self.list = self.top.get_widget("list")
|
2006-04-27 05:40:07 +05:30
|
|
|
self.set_window(window,self.top.get_widget('title'),self.label)
|
2004-11-21 06:00:52 +05:30
|
|
|
|
|
|
|
self.model = gtk.ListStore(gobject.TYPE_BOOLEAN, gobject.TYPE_STRING,
|
|
|
|
gobject.TYPE_STRING)
|
|
|
|
|
|
|
|
r = gtk.CellRendererToggle()
|
|
|
|
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()
|
|
|
|
self.model.set_value(handle,0,1)
|
|
|
|
self.model.set_value(handle,1,name)
|
|
|
|
self.model.set_value(handle,2,name.capitalize())
|
|
|
|
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-04-27 05:40:07 +05:30
|
|
|
def build_menu_names(self,obj):
|
|
|
|
return (self.label,None)
|
|
|
|
|
* 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
|
|
|
def on_help_clicked(self,obj):
|
|
|
|
"""Display the relevant portion of GRAMPS manual"""
|
2005-12-13 07:37:16 +05:30
|
|
|
GrampsDisplay.help('tools-db')
|
* 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
|
|
|
|
2004-11-21 06:00:52 +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()
|
2004-11-21 06:00:52 +05:30
|
|
|
changelist = []
|
|
|
|
for node in self.iter_list:
|
|
|
|
if self.model.get_value(node,0):
|
|
|
|
changelist.append(self.model.get_value(node,1))
|
|
|
|
|
|
|
|
anychange = False
|
|
|
|
for handle in self.db.get_person_handles():
|
|
|
|
change = False
|
|
|
|
person = self.db.get_person_from_handle(handle)
|
|
|
|
for name in [person.get_primary_name()] + person.get_alternate_names():
|
|
|
|
sname = name.get_surname()
|
|
|
|
if sname in changelist:
|
|
|
|
change = True
|
|
|
|
anychange = True
|
|
|
|
name.set_surname(sname.capitalize())
|
|
|
|
if change:
|
|
|
|
self.db.commit_person(person,self.trans)
|
|
|
|
|
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.
|
|
|
|
"""
|
|
|
|
|
|
|
|
def __init__(self,name,person_id=None):
|
|
|
|
Tool.ToolOptions.__init__(self,name,person_id)
|
|
|
|
|
2004-11-21 06:00:52 +05:30
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
register_tool(
|
2005-12-06 12:08:09 +05:30
|
|
|
name = 'chname',
|
|
|
|
category = Tool.TOOL_DBPROC,
|
|
|
|
tool_class = ChangeNames,
|
|
|
|
options_class = ChangeNamesOptions,
|
|
|
|
modes = Tool.MODE_GUI,
|
|
|
|
translated_name = _("Fix capitalization of family names"),
|
|
|
|
status = _("Stable"),
|
|
|
|
author_name = "Donald N. Allingham",
|
|
|
|
author_email = "don@gramps-project.org",
|
|
|
|
description = _("Searches the entire database and attempts to "
|
|
|
|
"fix capitalization of the names.")
|
2004-11-21 06:00:52 +05:30
|
|
|
)
|