Updated dialogs
svn: r1314
This commit is contained in:
96
src/Utils.py
96
src/Utils.py
@ -412,102 +412,6 @@ def thumb_path(dir,mobj):
|
||||
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.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 Combo 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 List in the combo box
|
||||
for item in combo.list.get_children():
|
||||
# Each item is a ListItem, whose first and only child is a
|
||||
# Label. This is the magic.
|
||||
label = item.get_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
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
#
|
||||
|
Reference in New Issue
Block a user