views:

54

answers:

2

Is it possible to make a ComboBox searchable ? If yes, how ?

I want to be able, when the ComboBox is active and a letter is typed with the keyboard, to select the first item beginning with this letter inside the ComboBox and so on with the next letters.

The is the same functionality of a ComboBox inside a webpage, for example.

I can't find any option the achieve this on the ComboBox or on the ListStore containing the data in the same way as the TreeView has the methods set_enable_search and set_search_column.

A: 

I finally decided to write my own completion function :

def func(menu, user_data, (widget, window)):
        return (widget.get_allocation().x + window.get_position()[0],widget.get_allocation().y + window.get_position()[1],True)

def completion(self, widget, event):
        alphanum = re.compile(r'[a-zA-Z0-9-]')
        keyval = event.keyval
        key = event.string
        if keyval == 65288:
            #DEL
            self.text = self.text[:-1]
        elif alphanum.match(key):
            self.text = self.text+key
        else:
            self.yTree.get_widget("comp_menu").popdown()
            self.text = ''
            return
        self.yTree.get_widget("comp_menu").popup( None, None, self.func, 1, event.time, (widget, self.wTree.get_widget('main_window')))

        widget.grab_focus()
        m = widget.get_model()
        j = 0
        for i in m:
            if i[0].lower().startswith(self.text):
                widget.set_active(j)
                return
            j+=1
Studer