diff --git a/gramps/src/AddSpouse.py b/gramps/src/AddSpouse.py index 31be67aa1..c60fdab56 100644 --- a/gramps/src/AddSpouse.py +++ b/gramps/src/AddSpouse.py @@ -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 }) diff --git a/gramps/src/AttrEdit.py b/gramps/src/AttrEdit.py index 30a34936d..cd4ac1e1d 100644 --- a/gramps/src/AttrEdit.py +++ b/gramps/src/AttrEdit.py @@ -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 }) diff --git a/gramps/src/ChooseParents.py b/gramps/src/ChooseParents.py index 59d4538d4..b102d62c1 100644 --- a/gramps/src/ChooseParents.py +++ b/gramps/src/ChooseParents.py @@ -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 }) diff --git a/gramps/src/EditPerson.glade b/gramps/src/EditPerson.glade index 672e346e6..1e5aa78e2 100644 --- a/gramps/src/EditPerson.glade +++ b/gramps/src/EditPerson.glade @@ -368,6 +368,12 @@ GtkCombo:entry birthPlace True + + insert_text + on_combo_insert_text + bpcombo + Thu, 18 Oct 2001 01:13:13 GMT + True True 0 @@ -594,6 +600,12 @@ GtkCombo:entry deathPlace True + + insert_text + on_combo_insert_text + dpcombo + Thu, 18 Oct 2001 01:14:20 GMT + True True 0 @@ -939,6 +951,12 @@ GtkCombo:entry surname True + + insert_text + on_combo_insert_text + lastNameList + Fri, 19 Oct 2001 00:00:57 GMT + True True 0 @@ -4312,6 +4330,12 @@ GtkCombo:entry alt_last True + + insert_text + on_combo_insert_text + alt_surname_list + Fri, 19 Oct 2001 00:02:06 GMT + True True 0 diff --git a/gramps/src/EditPerson.py b/gramps/src/EditPerson.py index 4d3b61f06..e566a7506 100644 --- a/gramps/src/EditPerson.py +++ b/gramps/src/EditPerson.py @@ -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, diff --git a/gramps/src/EventEdit.py b/gramps/src/EventEdit.py index fd1ad4a68..b9a510707 100644 --- a/gramps/src/EventEdit.py +++ b/gramps/src/EventEdit.py @@ -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 }) diff --git a/gramps/src/Marriage.py b/gramps/src/Marriage.py index bf255826f..ba1d9b8f8 100644 --- a/gramps/src/Marriage.py +++ b/gramps/src/Marriage.py @@ -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, diff --git a/gramps/src/NameEdit.py b/gramps/src/NameEdit.py index cfdaec382..690277ce6 100644 --- a/gramps/src/NameEdit.py +++ b/gramps/src/NameEdit.py @@ -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 }) diff --git a/gramps/src/SelectChild.py b/gramps/src/SelectChild.py index 1ec5822e3..9c46c09ad 100644 --- a/gramps/src/SelectChild.py +++ b/gramps/src/SelectChild.py @@ -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 }) diff --git a/gramps/src/Sources.py b/gramps/src/Sources.py index adbf40cf5..157aca14c 100644 --- a/gramps/src/Sources.py +++ b/gramps/src/Sources.py @@ -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 diff --git a/gramps/src/dialog.glade b/gramps/src/dialog.glade index 77c4a2291..dddfe066b 100644 --- a/gramps/src/dialog.glade +++ b/gramps/src/dialog.glade @@ -265,6 +265,12 @@ GnomeEntry:entry eventDescription True + + insert_text + on_combo_insert_text + eDescBox + Thu, 18 Oct 2001 01:38:54 GMT + True True 0 @@ -301,6 +307,12 @@ GtkCombo:entry eventPlace True + + insert_text + on_combo_insert_text + eventPlace_combo + Thu, 18 Oct 2001 01:17:09 GMT + True True 0 @@ -338,6 +350,12 @@ eventName True True + + insert_text + on_combo_insert_text + personalEvents + Thu, 18 Oct 2001 01:38:28 GMT + True True 0 @@ -744,6 +762,12 @@ attr_type True True + + insert_text + on_combo_insert_text + attr_menu + Thu, 18 Oct 2001 01:44:15 GMT + True True 0 diff --git a/gramps/src/gramps.glade b/gramps/src/gramps.glade index c7c4c99dd..76259d689 100644 --- a/gramps/src/gramps.glade +++ b/gramps/src/gramps.glade @@ -3591,6 +3591,12 @@ on_rel_type_changed Sat, 14 Jul 2001 15:29:20 GMT + + insert_text + on_combo_insert_text + rel_combo + Thu, 18 Oct 2001 01:53:38 GMT + False True 0 @@ -3881,7 +3887,7 @@ GtkCombo - combo6 + mrel_combo True False True @@ -3905,6 +3911,12 @@ Unknown GtkCombo:entry mrel True + + insert_text + on_combo_insert_text + mrel_combo + Thu, 18 Oct 2001 01:46:06 GMT + True True 0 @@ -4074,7 +4086,7 @@ Unknown GtkCombo - combo5 + frel_combo True False True @@ -4098,6 +4110,12 @@ Unknown GtkCombo:entry frel True + + insert_text + on_combo_insert_text + frel_combo + Thu, 18 Oct 2001 01:47:01 GMT + True True 0 @@ -4169,6 +4187,12 @@ Unknown on_prel_changed Sun, 15 Jul 2001 14:33:47 GMT + + insert_text + on_combo_insert_text + prel_combo + Thu, 18 Oct 2001 01:47:51 GMT + False True 0 @@ -4448,7 +4472,7 @@ Unknown GtkCombo - combo3 + mrel_combo True False True @@ -4471,6 +4495,12 @@ Unknown GtkCombo:entry mrel True + + insert_text + on_combo_insert_text + mrel_combo + Thu, 18 Oct 2001 01:46:06 GMT + True True 0 @@ -4507,7 +4537,7 @@ Unknown GtkCombo - combo4 + frel_combo True False True @@ -4539,6 +4569,12 @@ Unknown GtkCombo:entry frel True + + insert_text + on_combo_insert_text + frel_combo + Thu, 18 Oct 2001 01:55:01 GMT + True True 0 @@ -5522,7 +5558,7 @@ Unknown GtkEntry GtkCombo:entry - combo-entry1 + source True True @@ -5531,6 +5567,12 @@ Unknown source_title Thu, 16 Aug 2001 19:46:31 GMT + + insert_text + on_combo_insert_text + source_title + Thu, 18 Oct 2001 01:57:50 GMT + False True 0 @@ -6190,6 +6232,12 @@ Unknown GtkCombo:entry mrel True + + insert_text + on_combo_insert_text + mcombo + Thu, 18 Oct 2001 01:59:11 GMT + True True 0 @@ -6284,6 +6332,12 @@ Unknown GtkCombo:entry frel True + + insert_text + on_combo_insert_text + fcombo + Thu, 18 Oct 2001 01:59:26 GMT + True True 0 diff --git a/gramps/src/marriage.glade b/gramps/src/marriage.glade index 4116872e8..48e4065d5 100644 --- a/gramps/src/marriage.glade +++ b/gramps/src/marriage.glade @@ -209,6 +209,12 @@ combo-entry1 True True + + insert_text + on_combo_insert_text + marriage_type + Fri, 19 Oct 2001 00:05:41 GMT + True True 0 diff --git a/gramps/src/utils.py b/gramps/src/utils.py index a63ee228b..7df0dc9b5 100644 --- a/gramps/src/utils.py +++ b/gramps/src/utils.py @@ -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