[POS-commit] Kiwi/Kiwi Basic.py,1.45,1.46
bt at async.com.br
bt at async.com.br
Mon May 26 23:56:40 BRST 2003
Update of /usr/local/cvssrc/Kiwi/Kiwi
In directory anthem:/tmp/cvs-serv26663/Kiwi
Modified Files:
Basic.py
Log Message:
Fix three problems with AutoCombo:
* <Escape> when the popwin was open was propagating to close the main
window.
* The blank item on the top of the list is now gone (and a hideous
hack is now present to make that happen :-( )
* The callback is now called correctly when the mouse button is
clicked. This regressed yesterday when I changed the selection mode
on the list, and I had to add a proxy method to get around it. Since
that was necessary, I decided to pass in the text of the selected
item and save the end-user a call.
Index: Basic.py
===================================================================
RCS file: /usr/local/cvssrc/Kiwi/Kiwi/Basic.py,v
retrieving revision 1.45
retrieving revision 1.46
diff -u -d -r1.45 -r1.46
--- Basic.py 26 May 2003 04:06:33 -0000 1.45
+++ Basic.py 27 May 2003 02:56:38 -0000 1.46
@@ -175,7 +175,8 @@
# TODO/Laundry list
#
-# - bizarre bug -- prefill, select, ctrl-U, enter -- empty item on top
+# - popping up list with mouse doesn't allow keyboard nav. Popping up list
+# with keyboard doesn't allow mouse nav. Isn't life fun?
# - prefill() needs to be fixed up or forbidden. To do this correct will
# require us to return data when data is set on prefill, which means
# making the string list a bit smarter about what is stored in the
@@ -214,6 +215,7 @@
# Store ids of selection changed callback
self._callback_ids = None
+ self._callback = None
self.get_button().connect("button_press_event", self._on_button_pressed)
@@ -258,19 +260,30 @@
def set_callback(self, callback):
"""Sets a custom callback to be called whenever an item is
-selected from the list (via keyboard and enter or mouse). Navigating
+selected from the list (via keyboard <enter> or mouse). Navigating
through the list with keyboard will *not* fire this callback. The
-callback is responsible for calling combo.entry.get_text() to find out
-the currently selected item -- it is not passed in as an argument."""
+callback takes a single argument, which is the text of the item
+selected."""
if not callable(callback):
- raise TypeError, "Callback must be a callable"
+ raise TypeError, "Callback must be a callable object"
# For typing <enter> in the entry
- id1 = self.entry.connect_after("activate", callback)
+ id1 = self.entry.connect_after("activate", self._callback_proxy)
# For mouse events on the popwin
id2 = self.get_popwin().connect_after("button_press_event",
- callback)
+ self._callback_proxy)
+ self._callback = callback
self._callback_ids = (id1, id2)
+ def _callback_proxy(self, *args):
+ # We need a proxy method because the selection mode *must* be set
+ # back to browse before the callback is called. If it isn't, then
+ # the callback is run before the item is actually selected in the
+ # list and you get an empty string in it.
+ self.list.set_selection_mode(gtk.SELECTION_BROWSE)
+ # Be nice and send the text in since we have it already
+ text = self.entry.get_text()
+ self._callback(text)
+
def _attach_keypress(self):
"""This method should be run when the AutoCombo is actually inside a
toplevel window. By default it connects a special handler to the
@@ -396,7 +409,8 @@
self._block_entry = TRUE
self.entry.set_text(self._last_text)
self._block_entry = FALSE
- return
+ window.emit_stop_by_name('key_press_event')
+ return TRUE
# The list is not visible.
else:
@@ -419,13 +433,14 @@
else:
self._on_entry_changed(self.entry)
+ self._ensure_no_blank_item()
self.popup_list()
window.emit_stop_by_name('key_press_event')
return TRUE
def _on_entry_changed(self, entry):
# Called whenever text in the entry changes. Happens when typing
- # into entry. Selecion changes also trigger this, but we use
+ # into entry. Selection changes also trigger this, but we use
# _block_entry to avoid loops.
# If we are blocked, widget isn't `ready' or is empty and
@@ -504,6 +519,18 @@
# After this handler runs, the default handler makes the window
# pop up.
+
+ def _ensure_no_blank_item(self):
+ # This is a damned hack. For some reason, activate adds a blank
+ # item to the top of the list, and it's totally incorrect. I
+ # remove the blank item here and life goes on, but it's so ugly I
+ # might go to jail for it.
+ children = self.list.children()
+ if children:
+ item = children[0]
+ text = item.children()[0].get()
+ if not text:
+ self.list.remove(item)
def get_filtered_list(self, text):
"""
More information about the POS-commit
mailing list