Question

I am drawing the GUI using GTK+ with PyGTK.

I've created a ComboBox within a TreeView. But the problem is that when I first click an item, the dropdown arrow is insensitive (grayed-out). I had to click another item and then return to the item again to for the dropdown arrow to be sensitive again.

Is this standard for ComboBox in TreeView? If you have a fix in any other language, I can accept it as well.

An example can be found here. He is facing some other issues but his code demonstrates the problem as well.

Was it helpful?

Solution

The problem with the code you are referring to above seems to be that the ComboBox actually only has 1 element when you start editing, which makes drop-down feature useless (and hence inactive). To make it behave as I suspect you wish, all you have to do is use another signal to execute self.populate_combo. I added two lines after the treeview was created to make it work:

    treeview = gtk.TreeView(liststore_hardware)
    sel = treeview.get_selection()
    sel.connect("changed", self.populate_combo)

That is, I made the changed selection cause population of the Combos, which implied that they had more than one element in them when control was returned to the main-loop. And hence drop-down worked.

I also commented out the previous editing-started signal since it added nothing with the current structure of the program.

    window.connect("destroy", lambda w: gtk.main_quit())
    #self.cellrenderer_combo.connect("editing-started", self.populate_combo)
    self.cellrenderer_combo.connect("edited", self.combo_changed, liststore_hardware)

Edit:

On second thought, the model is a None after __init__ has been run and not 1-length per row as I wrote above, which makes the lack of dropdown-features even more reasonable.

Comment:

The code you referred to and my change to it are both only rational if changing rows (or editing) causes a drastic need to rewrite the ListStore. I'm not really sure what type of scenario would demand that. If, on the other hand, the contents of the TreeView and the ComoBox' ListStore varies as a result of a search-action or filtering done else-where, then that search, rather than the change of rows should invoke populate_combo.

So an alternative solution in the scope of the code at hand, my suggested event above can also be commented out and a simple

    self.populate_combo()

be added as the last line of the init function.

Further, should there be a need to re-populate the combos during the run of the app, I would suggest that the current ListStore is modified rather than creating a new one each time, if the changes are not expected to be major (in which case make a new is probably fastest and simplest).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top