Gestion d'un widget ComboBox

Tagged:

Bon j'y suis j'y reste ;)

Le ComboBox est presque similaire ... J'ai essayé d'hériter de TreeView mais c'est un bordel qu'il vaut mieux solutionner en recréant une classe que voici :

class ComboBox:
    def __init__(self,combobox):
        self.combobox = combobox
        self.store = gtk.ListStore(str)
        self.combobox.set_model(self.store)
        cell = gtk.CellRendererText()
        self.combobox.pack_start(cell, True)
        self.combobox.add_attribute(cell, 'text', 0)  
    
    def append(self,what):
        self.combobox.append_text(what)
    
    def select(self,which):
        self.combobox.set_active(which)
    
    def getSelectedIndex(self):
        return self.combobox.get_active()
    
    def getSelected(self):
        model = self.combobox.get_model()
        return model[self.getSelectedIndex()][0]

Pour l'utilisation c'est toujours aussi simpliste :

        cbx = self.widgets.get_widget('cbxMonCombo')
        self.combo = ComboBox(cbx)
        self.combo.append('Selectionnez un élément')
        self.combo.append('-----')
        for elt in maListe:
             self.combo.append(elt)
 
        self.combo.select(0)
        print self.combo.getSelectedIndex(), self.combo.getSelected()