Today’s random trivia: when using the match-completed
signal of a
gtk.EntryCompletion
in pygtk,
you may be confused into thinking the model
argument passed to your
handler is the same
gtk.TreeModel
that you passed the EntryCompletion
when you set it up.
It is not. It is not a copy of your model, though if you foolishly
picked the first item in your model to test the completer with then
you may be duped into thinking it is. But it isn’t! The model you’re
given contains only the values presented to you in the completer
popdown list, which means if you want to associate the selection made
from that list to one in the big model, you’re shit out of luck. The
TreeIter
has no meaning in your full model.
Unless there’s a better way of finding the matching iter in your full
model of the iter given to you that I don’t know about, try this:
1
2
3
4
5
6
| def on_match_selected(self, comp, model, i):
row_id = model[i][0]
for r in self.cbe.get_model():
if r[0] == row_id:
# set the cbe active row
self.cbe.set_active_iter(r.iter)
|
(Assuming your handler is part of a class, and that your class
contains a gtk.ComboBoxEntry
with whom you are trying to do the
completion and selection. Also, we assume that the 0th column
contains a unique identifier for your row, out-of-band of the model,
which isn’t displayed (i.e. set_text_column(1) or sommat).)
The docs on
match-selected
fail to mention the nature of the model being passed in, only that it
is a model pointed to by the TreeIter
also passed in.
Documentation is never going to get better, so rather than fight it, I
introduce a new paradigm in programming: ADVENTURE PROGRAMMING! Like
Indiana Jones hacking through the jungle with a machete, you hack
through APIs on a quest for Inca Gold… with a machete.