From 5b5db96852ed9cfe66e96463a266c16a27a5d8bf Mon Sep 17 00:00:00 2001 From: Don Allingham Date: Sun, 21 Nov 2004 00:30:52 +0000 Subject: [PATCH] * src/plugins/ChangeNames.py: Add a plugin to change capitalization of family names * src/plugins/changenames.glade: interface for ChangeNames plugin * src/plugins/Makefile.am: Added new files * src/plugins/PatchNames.py: display GRAMPS id instead of internal id svn: r3744 --- ChangeLog | 7 ++ src/gramps.glade | 24 ++--- src/plugins/ChangeNames.py | 194 ++++++++++++++++++++++++++++++++++ src/plugins/Makefile.am | 2 + src/plugins/PatchNames.py | 6 +- src/plugins/changenames.glade | 143 +++++++++++++++++++++++++ 6 files changed, 362 insertions(+), 14 deletions(-) create mode 100644 src/plugins/ChangeNames.py create mode 100644 src/plugins/changenames.glade diff --git a/ChangeLog b/ChangeLog index a89fe28ce..d6eaaa3e1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2004-11-20 Don Allingham + * src/plugins/ChangeNames.py: Add a plugin to change capitalization + of family names + * src/plugins/changenames.glade: interface for ChangeNames plugin + * src/plugins/Makefile.am: Added new files + * src/plugins/PatchNames.py: display GRAMPS id instead of internal id + 2004-11-19 Alex Roitman * src/Plugins.py: Remove redundant list of failed plugins. Properly reload plugins. Work around what seems to be a Python bug. diff --git a/src/gramps.glade b/src/gramps.glade index 0fee3e8bb..e2c0895e7 100644 --- a/src/gramps.glade +++ b/src/gramps.glade @@ -975,9 +975,9 @@ True - People + <b>People</b> False - False + True GTK_JUSTIFY_LEFT False False @@ -1023,9 +1023,9 @@ True - Family + <b>Family</b> True - False + True GTK_JUSTIFY_LEFT False False @@ -1071,9 +1071,9 @@ True - Pedigree + <b>Pedigree</b> True - False + True GTK_JUSTIFY_LEFT False False @@ -1119,9 +1119,9 @@ True - Sources + <b>Sources</b> True - False + True GTK_JUSTIFY_LEFT False False @@ -1167,9 +1167,9 @@ True - Places + <b>Places</b> True - False + True GTK_JUSTIFY_LEFT False False @@ -1215,9 +1215,9 @@ True - Media + <b>Media</b> True - False + True GTK_JUSTIFY_LEFT False False diff --git a/src/plugins/ChangeNames.py b/src/plugins/ChangeNames.py new file mode 100644 index 000000000..0c927b6a4 --- /dev/null +++ b/src/plugins/ChangeNames.py @@ -0,0 +1,194 @@ +# +# Gramps - a GTK+/GNOME based genealogy program +# +# Copyright (C) 2000-2004 Donald N. Allingham +# +# 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 + +#------------------------------------------------------------------------- +# +# gnome/gtk +# +#------------------------------------------------------------------------- +import gobject +import gtk +import gtk.glade + +#------------------------------------------------------------------------- +# +# gramps modules +# +#------------------------------------------------------------------------- +import Utils +from QuestionDialog import OkDialog +from gettext import gettext as _ + +#------------------------------------------------------------------------- +# +# Search each name in the database, and compare the firstname against the +# form of "Name (Nickname)". If it matches, change the first name entry +# to "Name" and add "Nickname" into the nickname field. +# +#------------------------------------------------------------------------- +def runTool(database,active_person,callback,parent=None): + try: + ChangeNames(database,callback,parent) + except: + import DisplayTrace + DisplayTrace.DisplayTrace() + +#------------------------------------------------------------------------- +# +# ChangeNames +# +#------------------------------------------------------------------------- +class ChangeNames: + + def __init__(self,db,callback,parent): + self.cb = callback + self.db = db + self.parent = parent + self.trans = db.transaction_begin() + self.win_key = self + self.child_windows = {} + self.name_list = [] + + for name in self.db.get_surname_list(): + if name != name.capitalize(): + self.name_list.append(name) + + if self.name_list: + self.display() + else: + OkDialog(_('No modifications made'), + _("No capitalization changes where detected.")) + + def display(self): + + base = os.path.dirname(__file__) + glade_file = base + os.sep + "patchnames.glade" + + self.top = gtk.glade.XML(glade_file,"top","gramps") + self.window = self.top.get_widget('top') + self.top.signal_autoconnect({ + "destroy_passed_object" : self.close, + "on_ok_clicked" : self.on_ok_clicked, + "on_delete_event" : self.on_delete_event + }) + self.list = self.top.get_widget("list") + self.label = _('Capitalization changes') + Utils.set_titles(self.window,self.top.get_widget('title'),self.label) + + 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 = [] + 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) + + self.add_itself_to_menu() + self.window.show() + + def on_delete_event(self,obj,b): + self.remove_itself_from_menu() + + def close(self,obj): + self.remove_itself_from_menu() + self.window.destroy() + + def add_itself_to_menu(self): + self.parent.child_windows[self.win_key] = self + self.parent_menu_item = gtk.MenuItem(self.label) + self.parent_menu_item.connect("activate",self.present) + self.parent_menu_item.show() + self.parent.winsmenu.append(self.parent_menu_item) + + def remove_itself_from_menu(self): + del self.parent.child_windows[self.win_key] + self.parent_menu_item.destroy() + + def present(self,obj): + self.window.present() + + def on_ok_clicked(self,obj): + 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) + + if anychange: + self.db.transaction_commit(self.trans,_("Capitalization changes")) + self.close(obj) + self.cb(1) + +#------------------------------------------------------------------------ +# +# +# +#------------------------------------------------------------------------ +from Plugins import register_tool + +register_tool( + runTool, + _("Fix capitalization of family names"), + category=_("Database Processing"), + description=_("Searches the entire database and attempts to " + "extract titles and nicknames that may be embedded " + "in a person's given name field.") + ) diff --git a/src/plugins/Makefile.am b/src/plugins/Makefile.am index 67886fbeb..2ac99ee41 100644 --- a/src/plugins/Makefile.am +++ b/src/plugins/Makefile.am @@ -12,6 +12,7 @@ pkgdata_PYTHON = \ Ancestors.py\ BookReport.py\ ChangeTypes.py\ + ChangeNames.py\ Check.py\ CountAncestors.py\ Desbrowser.py\ @@ -70,6 +71,7 @@ GLADEFILES = \ eventcmp.glade\ merge.glade\ patchnames.glade\ + changenames.glade\ relcalc.glade\ soundex.glade\ summary.glade\ diff --git a/src/plugins/PatchNames.py b/src/plugins/PatchNames.py index 9450b2055..d801dba73 100644 --- a/src/plugins/PatchNames.py +++ b/src/plugins/PatchNames.py @@ -156,9 +156,10 @@ class PatchNames: for (id,name,nick) in self.nick_list: p = self.db.get_person_from_handle(id) + gid = p.get_gramps_id() handle = self.model.append() self.model.set_value(handle,0,1) - self.model.set_value(handle,1,id) + 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()) @@ -166,9 +167,10 @@ class PatchNames: for (id,title,nick) in self.title_list: p = self.db.get_person_from_handle(id) + gid = p.get_gramps_id() handle = self.model.append() self.model.set_value(handle,0,1) - self.model.set_value(handle,1,id) + self.model.set_value(handle,1,gid) self.model.set_value(handle,2,_('Title')) self.model.set_value(handle,3,nick) self.model.set_value(handle,4,p.get_primary_name().get_name()) diff --git a/src/plugins/changenames.glade b/src/plugins/changenames.glade new file mode 100644 index 000000000..64c476d9a --- /dev/null +++ b/src/plugins/changenames.glade @@ -0,0 +1,143 @@ + + + + + + + True + + GTK_WINDOW_TOPLEVEL + GTK_WIN_POS_NONE + False + 500 + 450 + True + False + True + False + False + GDK_WINDOW_TYPE_HINT_NORMAL + GDK_GRAVITY_NORTH_WEST + + + + + 6 + True + False + 0 + + + + True + + False + False + GTK_JUSTIFY_LEFT + False + False + 0.5 + 0.5 + 0 + 0 + + + 6 + False + False + + + + + + True + Below is a list of the family names that +GRAMPS can convert to correct capitalization. +Select the names you which GRAMPS to convert. + False + False + GTK_JUSTIFY_LEFT + False + False + 0.5 + 0.5 + 0 + 10 + + + 0 + False + False + + + + + + True + True + GTK_POLICY_AUTOMATIC + GTK_POLICY_AUTOMATIC + GTK_SHADOW_IN + GTK_CORNER_TOP_LEFT + + + + True + True + True + False + False + True + + + + + 0 + True + True + + + + + + True + GTK_BUTTONBOX_END + 6 + + + + True + True + True + gtk-cancel + True + GTK_RELIEF_NORMAL + True + + + + + + + True + True + True + _Accept changes and close + True + GTK_RELIEF_NORMAL + True + + + + + + 6 + False + True + + + + + + +