2002-10-20 14:25:16 +00:00
|
|
|
#
|
|
|
|
# Gramps - a GTK+/GNOME based genealogy program
|
|
|
|
#
|
2006-03-11 01:12:06 +00:00
|
|
|
# Copyright (C) 2000-2006 Donald N. Allingham
|
2008-05-18 19:24:28 +00:00
|
|
|
# Copyright (C) 2008 Brian G. Matherly
|
2010-05-01 04:12:42 +00:00
|
|
|
# Copyright (C) 2010 Jakim Friant
|
2002-10-20 14:25:16 +00:00
|
|
|
#
|
|
|
|
# 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
|
|
|
|
#
|
|
|
|
|
2003-12-17 16:06:36 +00:00
|
|
|
# $Id$
|
|
|
|
|
2008-02-14 11:02:39 +00:00
|
|
|
"""Tools/Utilities/Generate SoundEx Codes"""
|
2002-10-20 14:25:16 +00:00
|
|
|
|
2005-03-25 03:34:52 +00:00
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# GRAMPS modules
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
2009-02-26 10:08:38 +00:00
|
|
|
import const
|
2002-10-20 14:25:16 +00:00
|
|
|
import soundex
|
2006-04-09 22:53:53 +00:00
|
|
|
import GrampsDisplay
|
|
|
|
import ManagedWindow
|
2003-03-17 05:21:40 +00:00
|
|
|
import AutoComp
|
2010-01-18 04:42:17 +00:00
|
|
|
from gen.ggettext import sgettext as _
|
2010-05-01 04:12:42 +00:00
|
|
|
from gui.plug import tool
|
2009-05-14 20:15:59 +00:00
|
|
|
from glade import Glade
|
2003-03-17 05:21:40 +00:00
|
|
|
|
2002-10-20 14:25:16 +00:00
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
2008-02-27 19:17:34 +00:00
|
|
|
# Constants
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2009-02-26 10:08:38 +00:00
|
|
|
WIKI_HELP_PAGE = '%s_-_Tools' % const.URL_MANUAL_PAGE
|
2008-02-27 19:17:34 +00:00
|
|
|
WIKI_HELP_SEC = _('manual|Generate_SoundEx_codes')
|
2009-04-15 19:27:17 +00:00
|
|
|
|
2008-02-27 19:17:34 +00:00
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# SoundGen.py
|
2002-10-20 14:25:16 +00:00
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2008-02-27 19:17:34 +00:00
|
|
|
|
2010-05-01 04:12:42 +00:00
|
|
|
class SoundGen(tool.Tool, ManagedWindow.ManagedWindow):
|
2006-04-09 22:53:53 +00:00
|
|
|
|
|
|
|
def __init__(self, dbstate, uistate, options_class, name, callback=None):
|
2006-04-27 02:35:47 +00:00
|
|
|
self.label = _('SoundEx code generator')
|
2010-05-01 04:12:42 +00:00
|
|
|
tool.Tool.__init__(self, dbstate, options_class, name)
|
2006-04-27 02:35:47 +00:00
|
|
|
ManagedWindow.ManagedWindow.__init__(self,uistate,[],self.__class__)
|
2006-04-09 22:53:53 +00:00
|
|
|
|
2009-05-14 20:15:59 +00:00
|
|
|
self.glade = Glade()
|
2009-04-09 19:41:06 +00:00
|
|
|
self.glade.connect_signals({
|
2004-05-11 01:51:56 +00:00
|
|
|
"destroy_passed_object" : self.close,
|
2005-03-25 03:34:52 +00:00
|
|
|
"on_help_clicked" : self.on_help_clicked,
|
2010-01-07 14:10:26 +00:00
|
|
|
"on_delete_event" : self.close,
|
2002-10-20 14:25:16 +00:00
|
|
|
})
|
|
|
|
|
2009-05-14 20:15:59 +00:00
|
|
|
window = self.glade.toplevel
|
2009-04-09 19:41:06 +00:00
|
|
|
self.set_window(window,self.glade.get_object('title'),self.label)
|
2003-03-17 05:21:40 +00:00
|
|
|
|
2009-04-09 19:41:06 +00:00
|
|
|
self.value = self.glade.get_object("value")
|
|
|
|
self.autocomp = self.glade.get_object("name_list")
|
2004-08-06 03:08:27 +00:00
|
|
|
self.name = self.autocomp.child
|
2003-03-22 20:26:44 +00:00
|
|
|
|
|
|
|
self.name.connect('changed',self.on_apply_clicked)
|
|
|
|
|
2002-10-20 14:25:16 +00:00
|
|
|
names = []
|
2006-10-06 19:10:15 +00:00
|
|
|
person = None
|
2009-09-14 20:50:25 +00:00
|
|
|
for person in self.db.iter_people():
|
2004-02-14 05:40:30 +00:00
|
|
|
lastname = person.get_primary_name().get_surname()
|
2002-10-20 14:25:16 +00:00
|
|
|
if lastname not in names:
|
|
|
|
names.append(lastname)
|
|
|
|
|
|
|
|
names.sort()
|
2004-08-06 03:08:27 +00:00
|
|
|
|
|
|
|
AutoComp.fill_combo(self.autocomp, names)
|
2002-10-20 14:25:16 +00:00
|
|
|
|
2005-12-06 06:38:09 +00:00
|
|
|
if person:
|
|
|
|
n = person.get_primary_name().get_surname()
|
2002-10-20 14:25:16 +00:00
|
|
|
self.name.set_text(n)
|
2004-02-05 19:53:02 +00:00
|
|
|
try:
|
|
|
|
se_text = soundex.soundex(n)
|
|
|
|
except UnicodeEncodeError:
|
|
|
|
se_text = soundex.soundex('')
|
|
|
|
self.value.set_text(se_text)
|
2002-10-20 14:25:16 +00:00
|
|
|
else:
|
|
|
|
self.name.set_text("")
|
|
|
|
|
2006-04-09 22:53:53 +00:00
|
|
|
self.show()
|
2004-05-11 01:51:56 +00:00
|
|
|
|
2008-02-24 13:55:55 +00:00
|
|
|
def on_help_clicked(self, obj):
|
2005-03-25 03:34:52 +00:00
|
|
|
"""Display the relevant portion of GRAMPS manual"""
|
2008-04-05 14:17:15 +00:00
|
|
|
GrampsDisplay.help(WIKI_HELP_PAGE , WIKI_HELP_SEC)
|
2005-03-25 03:34:52 +00:00
|
|
|
|
2006-04-09 22:53:53 +00:00
|
|
|
def build_menu_names(self, obj):
|
2006-04-27 02:35:47 +00:00
|
|
|
return (self.label,None)
|
2002-10-20 14:25:16 +00:00
|
|
|
|
2008-02-24 13:55:55 +00:00
|
|
|
def on_apply_clicked(self, obj):
|
2004-02-05 19:53:02 +00:00
|
|
|
try:
|
|
|
|
se_text = soundex.soundex(unicode(obj.get_text()))
|
|
|
|
except UnicodeEncodeError:
|
|
|
|
se_text = soundex.soundex('')
|
|
|
|
self.value.set_text(se_text)
|
2002-10-20 14:25:16 +00:00
|
|
|
|
2005-12-06 06:38:09 +00:00
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
2010-05-01 04:12:42 +00:00
|
|
|
class SoundGenOptions(tool.ToolOptions):
|
2005-12-06 06:38:09 +00:00
|
|
|
"""
|
|
|
|
Defines options and provides handling interface.
|
|
|
|
"""
|
|
|
|
|
2008-02-24 13:55:55 +00:00
|
|
|
def __init__(self, name,person_id=None):
|
2010-05-01 04:12:42 +00:00
|
|
|
tool.ToolOptions.__init__(self, name,person_id)
|