Convert SoundEx Generator tool into a gramplet

svn: r23246
This commit is contained in:
Nick Hall 2013-10-03 21:11:05 +00:00
parent 543fda3d5d
commit 905e6a5993
4 changed files with 60 additions and 256 deletions

View File

@ -1210,3 +1210,16 @@ register(GRAMPLET,
gramplet = 'Leak', gramplet = 'Leak',
gramplet_title=_("Uncollected Objects"), gramplet_title=_("Uncollected Objects"),
) )
register(GRAMPLET,
id="SoundEx Generator",
name=_("SoundEx Generator"),
description = _("Gramplet to generate SoundEx codes"),
version="1.0.0",
gramps_target_version="4.1",
status = STABLE,
fname="soundgen.py",
height=80,
gramplet = 'SoundGen',
gramplet_title=_("SoundEx"),
)

View File

@ -24,63 +24,72 @@
"""Tools/Utilities/Generate SoundEx Codes""" """Tools/Utilities/Generate SoundEx Codes"""
#-------------------------------------------------------------------------
#
# Gtk modules
#
#-------------------------------------------------------------------------
from gi.repository import Gtk
#------------------------------------------------------------------------ #------------------------------------------------------------------------
# #
# GRAMPS modules # Gramps modules
# #
#------------------------------------------------------------------------ #------------------------------------------------------------------------
from gramps.gen.const import URL_MANUAL_PAGE
from gramps.gen.soundex import soundex from gramps.gen.soundex import soundex
from gramps.gui.display import display_help
from gramps.gui.managedwindow import ManagedWindow
from gramps.gui.autocomp import fill_combo from gramps.gui.autocomp import fill_combo
from gramps.gen.plug import Gramplet
from gramps.gen.constfunc import cuni
from gramps.gen.const import GRAMPS_LOCALE as glocale from gramps.gen.const import GRAMPS_LOCALE as glocale
_ = glocale.translation.sgettext _ = glocale.translation.sgettext
from gramps.gui.plug import tool
from gramps.gui.glade import Glade
from gramps.gen.constfunc import cuni
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
# Constants # SoundGen
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
WIKI_HELP_PAGE = '%s_-_Tools' % URL_MANUAL_PAGE class SoundGen(Gramplet):
WIKI_HELP_SEC = _('manual|Generate_SoundEx_codes') """
Generates SoundEx codes.
"""
def init(self):
self.gui.WIDGET = self.build_gui()
self.gui.get_container_widget().remove(self.gui.textview)
self.gui.get_container_widget().add_with_viewport(self.gui.WIDGET)
#------------------------------------------------------------------------- def build_gui(self):
# """
# SoundGen.py Build the GUI interface.
# """
#------------------------------------------------------------------------- grid = Gtk.Grid()
grid.set_border_width(6)
class SoundGen(tool.Tool, ManagedWindow): grid.set_row_spacing(6)
grid.set_column_spacing(20)
def __init__(self, dbstate, user, options_class, name, callback=None): label1 = Gtk.Label(_("Name:"))
uistate = user.uistate label1.set_alignment(0, 0.5)
self.label = _('SoundEx code generator') grid.attach(label1, 0, 0, 1, 1)
tool.Tool.__init__(self, dbstate, options_class, name) label2 = Gtk.Label(_("SoundEx code:"))
ManagedWindow.__init__(self,uistate,[],self.__class__) label2.set_alignment(0, 0.5)
grid.attach(label2, 0, 1, 1, 1)
self.glade = Glade() self.autocomp = Gtk.ComboBox.new_with_entry()
self.glade.connect_signals({ grid.attach(self.autocomp, 1, 0, 1, 1)
"destroy_passed_object" : self.close, self.value = Gtk.Label()
"on_help_clicked" : self.on_help_clicked, self.value.set_alignment(0, 0.5)
"on_delete_event" : self.close, grid.attach(self.value, 1, 1, 1, 1)
})
window = self.glade.toplevel
self.set_window(window,self.glade.get_object('title'),self.label)
self.value = self.glade.get_object("value")
self.autocomp = self.glade.get_object("name_list")
self.name = self.autocomp.get_child() self.name = self.autocomp.get_child()
self.name.connect('changed',self.on_apply_clicked) self.name.connect('changed', self.on_apply_clicked)
grid.show_all()
return grid
def db_changed(self):
if not self.dbstate.open:
return
names = [] names = []
person = None person = None
for person in self.db.iter_people(): for person in self.dbstate.db.iter_people():
lastname = person.get_primary_name().get_surname() lastname = person.get_primary_name().get_surname()
if lastname not in names: if lastname not in names:
names.append(lastname) names.append(lastname)
@ -100,31 +109,9 @@ class SoundGen(tool.Tool, ManagedWindow):
else: else:
self.name.set_text("") self.name.set_text("")
self.show()
def on_help_clicked(self, obj):
"""Display the relevant portion of GRAMPS manual"""
display_help(WIKI_HELP_PAGE , WIKI_HELP_SEC)
def build_menu_names(self, obj):
return (self.label,None)
def on_apply_clicked(self, obj): def on_apply_clicked(self, obj):
try: try:
se_text = soundex(cuni(obj.get_text())) se_text = soundex(cuni(obj.get_text()))
except UnicodeEncodeError: except UnicodeEncodeError:
se_text = soundex('') se_text = soundex('')
self.value.set_text(se_text) self.value.set_text(se_text)
#------------------------------------------------------------------------
#
#
#
#------------------------------------------------------------------------
class SoundGenOptions(tool.ToolOptions):
"""
Defines options and provides handling interface.
"""
def __init__(self, name,person_id=None):
tool.ToolOptions.__init__(self, name,person_id)

View File

@ -1,174 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<!-- interface-requires gtk+ 3.0 -->
<object class="GtkDialog" id="soundgen">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="type_hint">dialog</property>
<signal name="delete-event" handler="on_delete_event" swapped="no"/>
<child internal-child="vbox">
<object class="GtkBox" id="dialog-vbox1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="spacing">8</property>
<child internal-child="action_area">
<object class="GtkButtonBox" id="dialog-action_area1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="layout_style">end</property>
<child>
<object class="GtkButton" id="button3">
<property name="label">gtk-close</property>
<property name="use_action_appearance">False</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="can_default">True</property>
<property name="receives_default">False</property>
<property name="tooltip_text" translatable="yes">Close Window</property>
<property name="use_action_appearance">False</property>
<property name="use_stock">True</property>
<signal name="clicked" handler="destroy_passed_object" object="soundgen" swapped="yes"/>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="button4">
<property name="label">gtk-help</property>
<property name="use_action_appearance">False</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="can_default">True</property>
<property name="receives_default">False</property>
<property name="use_action_appearance">False</property>
<property name="use_stock">True</property>
<signal name="clicked" handler="on_help_clicked" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="pack_type">end</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkVBox" id="vbox1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkLabel" id="title">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="ypad">6</property>
<property name="justify">center</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkTable" id="table1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="border_width">12</property>
<property name="n_rows">2</property>
<property name="n_columns">2</property>
<property name="column_spacing">12</property>
<property name="row_spacing">6</property>
<child>
<object class="GtkLabel" id="label2">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">Name:</property>
<property name="justify">center</property>
</object>
<packing>
<property name="x_options">GTK_FILL</property>
<property name="y_options"/>
</packing>
</child>
<child>
<object class="GtkLabel" id="label3">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="xalign">1</property>
<property name="label" translatable="yes">SoundEx code:</property>
<property name="justify">center</property>
</object>
<packing>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
<property name="x_options">GTK_FILL</property>
<property name="y_options"/>
</packing>
</child>
<child>
<object class="GtkLabel" id="value">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="xalign">0</property>
<property name="justify">center</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
<property name="x_options">GTK_FILL</property>
<property name="y_options"/>
</packing>
</child>
<child>
<object class="GtkComboBox" id="name_list">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="has_entry">True</property>
<child internal-child="entry">
<object class="GtkEntry" id="name_list-entry">
<property name="can_focus">True</property>
<property name="overwrite_mode">True</property>
</object>
</child>
</object>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="x_options">GTK_FILL</property>
<property name="y_options">GTK_FILL</property>
</packing>
</child>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
</child>
<action-widgets>
<action-widget response="0">button3</action-widget>
<action-widget response="-11">button4</action-widget>
</action-widgets>
</object>
</interface>

View File

@ -429,28 +429,6 @@ optionclass = 'SortEventOptions',
tool_modes = [TOOL_MODE_GUI] tool_modes = [TOOL_MODE_GUI]
) )
#------------------------------------------------------------------------
#
# Generate SoundEx Codes
#
#------------------------------------------------------------------------
register(TOOL,
id = 'soundgen',
name = _("Generate SoundEx Codes"),
description = _("Generates SoundEx codes for names"),
version = '1.0',
gramps_target_version = '4.1',
status = STABLE,
fname = 'soundgen.py',
authors = ["Donald N. Allingham"],
authors_email = ["don@gramps-project.org"],
category = TOOL_UTILS,
toolclass = 'SoundGen',
optionclass = 'SoundGenOptions',
tool_modes = [TOOL_MODE_GUI]
)
#------------------------------------------------------------------------ #------------------------------------------------------------------------
# #
# Verify the Data # Verify the Data