Add autocompletion to combo boxes

svn: r490
This commit is contained in:
David Hampton 2001-10-19 01:34:51 +00:00
parent 55c0635d4e
commit 0ab3849def
14 changed files with 222 additions and 5 deletions

View File

@ -82,6 +82,7 @@ class AddSpouse:
"on_select_spouse_clicked" : self.on_select_spouse_clicked,
"on_new_spouse_clicked" : self.on_new_spouse_clicked,
"on_rel_type_changed" : self.on_rel_type_changed,
"on_combo_insert_text" : utils.combo_insert_text,
"destroy_passed_object" : utils.destroy_passed_object
})

View File

@ -94,6 +94,7 @@ class AttributeEditor:
self.top.signal_autoconnect({
"destroy_passed_object" : utils.destroy_passed_object,
"on_attr_edit_ok_clicked" : self.on_attrib_edit_ok_clicked,
"on_combo_insert_text" : utils.combo_insert_text,
"on_source_clicked" : self.on_attrib_source_clicked
})

View File

@ -107,6 +107,7 @@ class ChooseParents:
"on_addmother_clicked" : self.on_addmother_clicked,
"on_addfather_clicked" : self.on_addfather_clicked,
"on_prel_changed" : self.on_prel_changed,
"on_combo_insert_text" : utils.combo_insert_text,
"destroy_passed_object" : utils.destroy_passed_object
})

View File

@ -368,6 +368,12 @@
<child_name>GtkCombo:entry</child_name>
<name>birthPlace</name>
<can_focus>True</can_focus>
<signal>
<name>insert_text</name>
<handler>on_combo_insert_text</handler>
<object>bpcombo</object>
<last_modification_time>Thu, 18 Oct 2001 01:13:13 GMT</last_modification_time>
</signal>
<editable>True</editable>
<text_visible>True</text_visible>
<text_max_length>0</text_max_length>
@ -594,6 +600,12 @@
<child_name>GtkCombo:entry</child_name>
<name>deathPlace</name>
<can_focus>True</can_focus>
<signal>
<name>insert_text</name>
<handler>on_combo_insert_text</handler>
<object>dpcombo</object>
<last_modification_time>Thu, 18 Oct 2001 01:14:20 GMT</last_modification_time>
</signal>
<editable>True</editable>
<text_visible>True</text_visible>
<text_max_length>0</text_max_length>
@ -939,6 +951,12 @@
<child_name>GtkCombo:entry</child_name>
<name>surname</name>
<can_focus>True</can_focus>
<signal>
<name>insert_text</name>
<handler>on_combo_insert_text</handler>
<object>lastNameList</object>
<last_modification_time>Fri, 19 Oct 2001 00:00:57 GMT</last_modification_time>
</signal>
<editable>True</editable>
<text_visible>True</text_visible>
<text_max_length>0</text_max_length>
@ -4312,6 +4330,12 @@
<child_name>GtkCombo:entry</child_name>
<name>alt_last</name>
<can_focus>True</can_focus>
<signal>
<name>insert_text</name>
<handler>on_combo_insert_text</handler>
<object>alt_surname_list</object>
<last_modification_time>Fri, 19 Oct 2001 00:02:06 GMT</last_modification_time>
</signal>
<editable>True</editable>
<text_visible>True</text_visible>
<text_max_length>0</text_max_length>

View File

@ -89,6 +89,7 @@ class EditPerson:
"on_aka_update_clicked" : self.on_aka_update_clicked,
"on_apply_person_clicked" : self.on_apply_person_clicked,
"on_attr_list_select_row" : self.on_attr_list_select_row,
"on_combo_insert_text" : utils.combo_insert_text,
"on_edit_birth_clicked" : self.on_edit_birth_clicked,
"on_edit_death_clicked" : self.on_edit_death_clicked,
"on_delete_address_clicked" : self.on_delete_addr_clicked,

View File

@ -99,6 +99,7 @@ class EventEditor:
self.window.set_data("o",self)
self.top.signal_autoconnect({
"destroy_passed_object" : utils.destroy_passed_object,
"on_combo_insert_text" : utils.combo_insert_text,
"on_event_edit_ok_clicked" : self.on_event_edit_ok_clicked,
"on_source_clicked" : self.on_edit_source_clicked
})

View File

@ -77,6 +77,7 @@ class Marriage:
"on_add_attr_clicked" : self.on_add_attr_clicked,
"on_addphoto_clicked" : self.gallery.on_add_photo_clicked,
"on_attr_list_select_row" : self.on_attr_list_select_row,
"on_combo_insert_text" : utils.combo_insert_text,
"on_close_marriage_editor" : self.on_close_marriage_editor,
"on_delete_attr_clicked" : self.on_delete_attr_clicked,
"on_delete_event" : self.on_delete_event,

View File

@ -91,6 +91,7 @@ class NameEditor:
self.top.signal_autoconnect({
"destroy_passed_object" : utils.destroy_passed_object,
"on_combo_insert_text" : utils.combo_insert_text,
"on_name_edit_ok_clicked" : self.on_name_edit_ok_clicked,
"on_source_clicked" : self.on_name_source_clicked
})

View File

@ -65,6 +65,7 @@ class SelectChild:
self.xml = libglade.GladeXML(const.gladeFile,"selectChild")
self.xml.signal_autoconnect({
"on_combo_insert_text" : utils.combo_insert_text,
"on_save_child_clicked" : self.on_save_child_clicked,
"on_show_toggled" : self.on_show_toggled,
"destroy_passed_object" : utils.destroy_passed_object
@ -222,6 +223,7 @@ class NewChild:
self.xml = libglade.GladeXML(const.gladeFile,"addChild")
self.xml.signal_autoconnect({
"on_addchild_ok_clicked" : self.on_addchild_ok_clicked,
"on_combo_insert_text" : utils.combo_insert_text,
"destroy_passed_object" : utils.destroy_passed_object
})

View File

@ -120,6 +120,7 @@ class SourceEditor:
self.source_ref = srcref
self.showSource = libglade.GladeXML(const.gladeFile, "sourceDisplay")
self.showSource.signal_autoconnect({
"on_combo_insert_text" : utils.combo_insert_text,
"on_sourceok_clicked" : self.on_sourceok_clicked,
"on_source_changed" : self.on_source_changed,
"destroy_passed_object" : utils.destroy_passed_object

View File

@ -265,6 +265,12 @@
<child_name>GnomeEntry:entry</child_name>
<name>eventDescription</name>
<can_focus>True</can_focus>
<signal>
<name>insert_text</name>
<handler>on_combo_insert_text</handler>
<object>eDescBox</object>
<last_modification_time>Thu, 18 Oct 2001 01:38:54 GMT</last_modification_time>
</signal>
<editable>True</editable>
<text_visible>True</text_visible>
<text_max_length>0</text_max_length>
@ -301,6 +307,12 @@
<child_name>GtkCombo:entry</child_name>
<name>eventPlace</name>
<can_focus>True</can_focus>
<signal>
<name>insert_text</name>
<handler>on_combo_insert_text</handler>
<object>eventPlace_combo</object>
<last_modification_time>Thu, 18 Oct 2001 01:17:09 GMT</last_modification_time>
</signal>
<editable>True</editable>
<text_visible>True</text_visible>
<text_max_length>0</text_max_length>
@ -338,6 +350,12 @@
<name>eventName</name>
<can_focus>True</can_focus>
<has_focus>True</has_focus>
<signal>
<name>insert_text</name>
<handler>on_combo_insert_text</handler>
<object>personalEvents</object>
<last_modification_time>Thu, 18 Oct 2001 01:38:28 GMT</last_modification_time>
</signal>
<editable>True</editable>
<text_visible>True</text_visible>
<text_max_length>0</text_max_length>
@ -744,6 +762,12 @@
<name>attr_type</name>
<can_focus>True</can_focus>
<has_focus>True</has_focus>
<signal>
<name>insert_text</name>
<handler>on_combo_insert_text</handler>
<object>attr_menu</object>
<last_modification_time>Thu, 18 Oct 2001 01:44:15 GMT</last_modification_time>
</signal>
<editable>True</editable>
<text_visible>True</text_visible>
<text_max_length>0</text_max_length>

View File

@ -3591,6 +3591,12 @@
<handler>on_rel_type_changed</handler>
<last_modification_time>Sat, 14 Jul 2001 15:29:20 GMT</last_modification_time>
</signal>
<signal>
<name>insert_text</name>
<handler>on_combo_insert_text</handler>
<object>rel_combo</object>
<last_modification_time>Thu, 18 Oct 2001 01:53:38 GMT</last_modification_time>
</signal>
<editable>False</editable>
<text_visible>True</text_visible>
<text_max_length>0</text_max_length>
@ -3881,7 +3887,7 @@
<widget>
<class>GtkCombo</class>
<name>combo6</name>
<name>mrel_combo</name>
<value_in_list>True</value_in_list>
<ok_if_empty>False</ok_if_empty>
<case_sensitive>True</case_sensitive>
@ -3905,6 +3911,12 @@ Unknown
<child_name>GtkCombo:entry</child_name>
<name>mrel</name>
<can_focus>True</can_focus>
<signal>
<name>insert_text</name>
<handler>on_combo_insert_text</handler>
<object>mrel_combo</object>
<last_modification_time>Thu, 18 Oct 2001 01:46:06 GMT</last_modification_time>
</signal>
<editable>True</editable>
<text_visible>True</text_visible>
<text_max_length>0</text_max_length>
@ -4074,7 +4086,7 @@ Unknown
<widget>
<class>GtkCombo</class>
<name>combo5</name>
<name>frel_combo</name>
<value_in_list>True</value_in_list>
<ok_if_empty>False</ok_if_empty>
<case_sensitive>True</case_sensitive>
@ -4098,6 +4110,12 @@ Unknown
<child_name>GtkCombo:entry</child_name>
<name>frel</name>
<can_focus>True</can_focus>
<signal>
<name>insert_text</name>
<handler>on_combo_insert_text</handler>
<object>frel_combo</object>
<last_modification_time>Thu, 18 Oct 2001 01:47:01 GMT</last_modification_time>
</signal>
<editable>True</editable>
<text_visible>True</text_visible>
<text_max_length>0</text_max_length>
@ -4169,6 +4187,12 @@ Unknown
<handler>on_prel_changed</handler>
<last_modification_time>Sun, 15 Jul 2001 14:33:47 GMT</last_modification_time>
</signal>
<signal>
<name>insert_text</name>
<handler>on_combo_insert_text</handler>
<object>prel_combo</object>
<last_modification_time>Thu, 18 Oct 2001 01:47:51 GMT</last_modification_time>
</signal>
<editable>False</editable>
<text_visible>True</text_visible>
<text_max_length>0</text_max_length>
@ -4448,7 +4472,7 @@ Unknown
<widget>
<class>GtkCombo</class>
<name>combo3</name>
<name>mrel_combo</name>
<value_in_list>True</value_in_list>
<ok_if_empty>False</ok_if_empty>
<case_sensitive>True</case_sensitive>
@ -4471,6 +4495,12 @@ Unknown
<child_name>GtkCombo:entry</child_name>
<name>mrel</name>
<can_focus>True</can_focus>
<signal>
<name>insert_text</name>
<handler>on_combo_insert_text</handler>
<object>mrel_combo</object>
<last_modification_time>Thu, 18 Oct 2001 01:46:06 GMT</last_modification_time>
</signal>
<editable>True</editable>
<text_visible>True</text_visible>
<text_max_length>0</text_max_length>
@ -4507,7 +4537,7 @@ Unknown
<widget>
<class>GtkCombo</class>
<name>combo4</name>
<name>frel_combo</name>
<value_in_list>True</value_in_list>
<ok_if_empty>False</ok_if_empty>
<case_sensitive>True</case_sensitive>
@ -4539,6 +4569,12 @@ Unknown
<child_name>GtkCombo:entry</child_name>
<name>frel</name>
<can_focus>True</can_focus>
<signal>
<name>insert_text</name>
<handler>on_combo_insert_text</handler>
<object>frel_combo</object>
<last_modification_time>Thu, 18 Oct 2001 01:55:01 GMT</last_modification_time>
</signal>
<editable>True</editable>
<text_visible>True</text_visible>
<text_max_length>0</text_max_length>
@ -5522,7 +5558,7 @@ Unknown
<widget>
<class>GtkEntry</class>
<child_name>GtkCombo:entry</child_name>
<name>combo-entry1</name>
<name>source</name>
<can_focus>True</can_focus>
<has_focus>True</has_focus>
<signal>
@ -5531,6 +5567,12 @@ Unknown
<object>source_title</object>
<last_modification_time>Thu, 16 Aug 2001 19:46:31 GMT</last_modification_time>
</signal>
<signal>
<name>insert_text</name>
<handler>on_combo_insert_text</handler>
<object>source_title</object>
<last_modification_time>Thu, 18 Oct 2001 01:57:50 GMT</last_modification_time>
</signal>
<editable>False</editable>
<text_visible>True</text_visible>
<text_max_length>0</text_max_length>
@ -6190,6 +6232,12 @@ Unknown
<child_name>GtkCombo:entry</child_name>
<name>mrel</name>
<can_focus>True</can_focus>
<signal>
<name>insert_text</name>
<handler>on_combo_insert_text</handler>
<object>mcombo</object>
<last_modification_time>Thu, 18 Oct 2001 01:59:11 GMT</last_modification_time>
</signal>
<editable>True</editable>
<text_visible>True</text_visible>
<text_max_length>0</text_max_length>
@ -6284,6 +6332,12 @@ Unknown
<child_name>GtkCombo:entry</child_name>
<name>frel</name>
<can_focus>True</can_focus>
<signal>
<name>insert_text</name>
<handler>on_combo_insert_text</handler>
<object>fcombo</object>
<last_modification_time>Thu, 18 Oct 2001 01:59:26 GMT</last_modification_time>
</signal>
<editable>True</editable>
<text_visible>True</text_visible>
<text_max_length>0</text_max_length>

View File

@ -209,6 +209,12 @@
<name>combo-entry1</name>
<can_focus>True</can_focus>
<has_focus>True</has_focus>
<signal>
<name>insert_text</name>
<handler>on_combo_insert_text</handler>
<object>marriage_type</object>
<last_modification_time>Fri, 19 Oct 2001 00:05:41 GMT</last_modification_time>
</signal>
<editable>True</editable>
<text_visible>True</text_visible>
<text_max_length>0</text_max_length>

View File

@ -393,3 +393,102 @@ def thumb_path(dir,mobj):
return thumb
else:
return find_icon(type)
#-------------------------------------------------------------------------
#
# Sets up a delayed (0.005 sec) handler for text completion. Text
# completion cannot be handled directly in this routine because, for
# some reason, the select_region() function doesn't work when called
# from signal handlers. Go figure.
#
# Thanks to iain@nodata.demon.co.uk (in mail from 1999) for the idea
# to use a timer to get away from the problems with signal handlers
# and the select_region function.
#
#-------------------------------------------------------------------------
def combo_insert_text(combo,new_text,new_text_len,i_dont_care):
# One time setup to clear selected region when user moves on
if (not combo.get_data("signal_set")):
combo.set_data("signal_set",1)
combo.entry.signal_connect("focus_out_event", combo_lost_focus, combo)
# Nuke the current timer if the user types fast enough
timer = combo.get_data("timer");
if (timer):
gtk.timeout_remove(timer)
# Setup a callback timer so we can operate outside of a signal handler
timer = gtk.timeout_add(5, combo_timer_callback, combo)
combo.set_data("timer", timer);
#-------------------------------------------------------------------------
#
# The combo box entry field lost focus. Go clear any selection. Why
# this form of a select_region() call works in a signal handler and
# the other form doesn't is a mystery.
#
#-------------------------------------------------------------------------
def combo_lost_focus(entry,a,b):
entry.select_region(0, 0)
#-------------------------------------------------------------------------
#
# The workhorse routine of file completion. This routine grabs the
# current text of the entry box, and grubs through the list item
# looking for any case insensitive matches. This routine relies on
# public knowledge of the GtkCombo data structure, not on any private
# data.
#
# These three completion routines have only one gramps specific hook,
# and can be easily ported to any program.
#
#-------------------------------------------------------------------------
def combo_timer_callback(combo):
# Clear any timer
timer = combo.get_data("timer");
if (timer):
gtk.timeout_remove(timer)
# Get the user's text
entry = combo.entry
typed = entry.get_text()
if (not typed):
return
typed_lc = string.lower(typed)
# Walk the GtkList in the combo box
for item in combo.list.children():
# Each item is a GtkListItem, whose first and only child is a
# GtkLabel. This is the magic.
label = item.children()[0]
label_text = label.get()
if (not label_text):
continue
# Gramps specific code to remove trailing '[id]' from the
# label.
index = string.rfind(label_text,'[')
if (index > 0):
label_text = label_text[:index]
label_text = string.rstrip(label_text)
# Back to the generic code. Convert to lower case
label_text_lc = string.lower(label_text)
# If equal, no need to add any text
if (typed_lc == label_text_lc):
return
# If typed text is a substring of the label text, then fill in
# the entry field with the full text (and correcting
# capitalization), and then select all the characters that
# don't match. With the user's enxt keystroke these will be
# replaced if they are incorrect.
if (string.find(label_text_lc,typed_lc) == 0):
entry.set_text(label_text)
entry.set_position(len(typed))
entry.select_region(len(typed), -1)
return