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