python - Get active item of Gtk ComboBox after searching -


i created gtk.combobox in pygtk entry completion using following code:

completer = gtk.entrycompletion() completer.set_model(combo.get_model()) completer.set_text_column(0) combo.get_child().set_completion(completer) 

i have few items (>400), scrolling through combobox looking specific 1 rather tedious. when use entry input text, search items , select item, calling get_active() in response changed signal returns -1...? works expected when scrolling item without searching , selecting it.

i can text in entry using combo.get_child().get_text() can't search model because every entry may appear several items.

how can search text, select item, , selected row of original model?

#!/usr/bin/python gi.repository import gtk  class mywindow(gtk.window):      def __init__(self):         gtk.window.__init__(self)         self.add_combo()      def add_combo(self):         store = gtk.liststore(str)         combo = gtk.combobox(model=store, has_entry=true)         combo.set_entry_text_column(0)         store.append(('hello',))         store.append(('world',))          completer = gtk.entrycompletion()         completer.set_model(combo.get_model())         completer.set_text_column(0)         combo.get_child().set_completion(completer)          combo.connect('changed', self.changed)          self.add(combo)      def changed(self, combo):         print 'active', combo.get_active()  win = mywindow() win.connect("delete-event", gtk.main_quit) win.show_all() gtk.main() 

to reproduce: type w in entry, select world, active -1, expect active 1.

the completion doesn't know combo (and combo doesn't know completion) can't update active value. think should it:

# in initialization: completer.connect("match-selected", self.match_selected) self.combo = combo  def match_selected(self, completion, model, iter):     self.combo.set_active_iter (iter) 

that said, still doesn't cover possibility of writing matching string...


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -