* 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
This commit is contained in:
Don Allingham 2004-11-21 00:30:52 +00:00
parent d1bdabf5fc
commit 5b5db96852
6 changed files with 362 additions and 14 deletions

View File

@ -1,3 +1,10 @@
2004-11-20 Don Allingham <dallingham@users.sourceforge.net>
* 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 <shura@alex.neuro.umn.edu>
* src/Plugins.py: Remove redundant list of failed plugins.
Properly reload plugins. Work around what seems to be a Python bug.

View File

@ -975,9 +975,9 @@
<child>
<widget class="GtkLabel" id="side_people_label">
<property name="visible">True</property>
<property name="label" translatable="yes">People</property>
<property name="label" translatable="yes">&lt;b&gt;People&lt;/b&gt;</property>
<property name="use_underline">False</property>
<property name="use_markup">False</property>
<property name="use_markup">True</property>
<property name="justify">GTK_JUSTIFY_LEFT</property>
<property name="wrap">False</property>
<property name="selectable">False</property>
@ -1023,9 +1023,9 @@
<child>
<widget class="GtkLabel" id="label318">
<property name="visible">True</property>
<property name="label" translatable="yes">Family</property>
<property name="label" translatable="yes">&lt;b&gt;Family&lt;/b&gt;</property>
<property name="use_underline">True</property>
<property name="use_markup">False</property>
<property name="use_markup">True</property>
<property name="justify">GTK_JUSTIFY_LEFT</property>
<property name="wrap">False</property>
<property name="selectable">False</property>
@ -1071,9 +1071,9 @@
<child>
<widget class="GtkLabel" id="label316">
<property name="visible">True</property>
<property name="label" translatable="yes">Pedigree</property>
<property name="label" translatable="yes">&lt;b&gt;Pedigree&lt;/b&gt;</property>
<property name="use_underline">True</property>
<property name="use_markup">False</property>
<property name="use_markup">True</property>
<property name="justify">GTK_JUSTIFY_LEFT</property>
<property name="wrap">False</property>
<property name="selectable">False</property>
@ -1119,9 +1119,9 @@
<child>
<widget class="GtkLabel" id="label319">
<property name="visible">True</property>
<property name="label" translatable="yes">Sources</property>
<property name="label" translatable="yes">&lt;b&gt;Sources&lt;/b&gt;</property>
<property name="use_underline">True</property>
<property name="use_markup">False</property>
<property name="use_markup">True</property>
<property name="justify">GTK_JUSTIFY_LEFT</property>
<property name="wrap">False</property>
<property name="selectable">False</property>
@ -1167,9 +1167,9 @@
<child>
<widget class="GtkLabel" id="label320">
<property name="visible">True</property>
<property name="label" translatable="yes">Places</property>
<property name="label" translatable="yes">&lt;b&gt;Places&lt;/b&gt;</property>
<property name="use_underline">True</property>
<property name="use_markup">False</property>
<property name="use_markup">True</property>
<property name="justify">GTK_JUSTIFY_LEFT</property>
<property name="wrap">False</property>
<property name="selectable">False</property>
@ -1215,9 +1215,9 @@
<child>
<widget class="GtkLabel" id="label321">
<property name="visible">True</property>
<property name="label" translatable="yes">Media</property>
<property name="label" translatable="yes">&lt;b&gt;Media&lt;/b&gt;</property>
<property name="use_underline">True</property>
<property name="use_markup">False</property>
<property name="use_markup">True</property>
<property name="justify">GTK_JUSTIFY_LEFT</property>
<property name="wrap">False</property>
<property name="selectable">False</property>

194
src/plugins/ChangeNames.py Normal file
View File

@ -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.")
)

View File

@ -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\

View File

@ -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())

View File

@ -0,0 +1,143 @@
<?xml version="1.0" standalone="no"?> <!--*- mode: xml -*-->
<!DOCTYPE glade-interface SYSTEM "http://glade.gnome.org/glade-2.0.dtd">
<glade-interface>
<widget class="GtkWindow" id="top">
<property name="visible">True</property>
<property name="title" translatable="yes"></property>
<property name="type">GTK_WINDOW_TOPLEVEL</property>
<property name="window_position">GTK_WIN_POS_NONE</property>
<property name="modal">False</property>
<property name="default_width">500</property>
<property name="default_height">450</property>
<property name="resizable">True</property>
<property name="destroy_with_parent">False</property>
<property name="decorated">True</property>
<property name="skip_taskbar_hint">False</property>
<property name="skip_pager_hint">False</property>
<property name="type_hint">GDK_WINDOW_TYPE_HINT_NORMAL</property>
<property name="gravity">GDK_GRAVITY_NORTH_WEST</property>
<signal name="delete_event" handler="on_delete_event" last_modification_time="Mon, 10 May 2004 00:32:54 GMT"/>
<child>
<widget class="GtkVBox" id="vbox2">
<property name="border_width">6</property>
<property name="visible">True</property>
<property name="homogeneous">False</property>
<property name="spacing">0</property>
<child>
<widget class="GtkLabel" id="title">
<property name="visible">True</property>
<property name="label" translatable="yes"></property>
<property name="use_underline">False</property>
<property name="use_markup">False</property>
<property name="justify">GTK_JUSTIFY_LEFT</property>
<property name="wrap">False</property>
<property name="selectable">False</property>
<property name="xalign">0.5</property>
<property name="yalign">0.5</property>
<property name="xpad">0</property>
<property name="ypad">0</property>
</widget>
<packing>
<property name="padding">6</property>
<property name="expand">False</property>
<property name="fill">False</property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label3">
<property name="visible">True</property>
<property name="label" translatable="yes">Below is a list of the family names that
GRAMPS can convert to correct capitalization.
Select the names you which GRAMPS to convert. </property>
<property name="use_underline">False</property>
<property name="use_markup">False</property>
<property name="justify">GTK_JUSTIFY_LEFT</property>
<property name="wrap">False</property>
<property name="selectable">False</property>
<property name="xalign">0.5</property>
<property name="yalign">0.5</property>
<property name="xpad">0</property>
<property name="ypad">10</property>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">False</property>
<property name="fill">False</property>
</packing>
</child>
<child>
<widget class="GtkScrolledWindow" id="scrolledwindow2">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="hscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
<property name="vscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
<property name="shadow_type">GTK_SHADOW_IN</property>
<property name="window_placement">GTK_CORNER_TOP_LEFT</property>
<child>
<widget class="GtkTreeView" id="list">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="headers_visible">True</property>
<property name="rules_hint">False</property>
<property name="reorderable">False</property>
<property name="enable_search">True</property>
</widget>
</child>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">True</property>
<property name="fill">True</property>
</packing>
</child>
<child>
<widget class="GtkHButtonBox" id="hbuttonbox2">
<property name="visible">True</property>
<property name="layout_style">GTK_BUTTONBOX_END</property>
<property name="spacing">6</property>
<child>
<widget class="GtkButton" id="button6">
<property name="visible">True</property>
<property name="can_default">True</property>
<property name="can_focus">True</property>
<property name="label">gtk-cancel</property>
<property name="use_stock">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
<property name="focus_on_click">True</property>
<signal name="clicked" handler="destroy_passed_object" object="top" last_modification_time="Wed, 16 Apr 2003 05:06:50 GMT"/>
</widget>
</child>
<child>
<widget class="GtkButton" id="button5">
<property name="visible">True</property>
<property name="can_default">True</property>
<property name="can_focus">True</property>
<property name="label" translatable="yes">_Accept changes and close</property>
<property name="use_underline">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
<property name="focus_on_click">True</property>
<signal name="clicked" handler="on_ok_clicked" object="top" last_modification_time="Wed, 16 Apr 2003 05:07:24 GMT"/>
</widget>
</child>
</widget>
<packing>
<property name="padding">6</property>
<property name="expand">False</property>
<property name="fill">True</property>
</packing>
</child>
</widget>
</child>
</widget>
</glade-interface>