TAGS :Viewed: 3 - Published at: a few seconds ago

[ PyGTK treeview - same column - with checkbox or text ]

I wanted to ask, if someone knows how to create a treeview, which consists of two columns. The first column is a description column, and the second column consists depending on the leaf, of a text or checkbox. I have to program it with pygtk version 2.0 (!).


Column 1,          Column2
    RPM            2700
    Model          NameXXX
    Active         [X]
    RPM            1000
    Model          NameXXX
    Active         [ ]

How should I program column2?

test_data = [
        { 'column0' : 'test00', 'column1' : 'test01', 'f': '#000000', 'b': '#FF00FF' },..]
column0 = gtk.TreeViewColumn("Column 0", gtk.CellRendererText(), text=1, foreground=2, background=3)        

the code before allows the user to set the foreground and background depending the row. i would like to do the same with the cell renderer, i hope you can help me :/


Answer 1

To do this, you would have to create a renderer whom can render other renderers (renderception!)

So you create a dynamic renderer which holds a text renderer and a toggle renderer and some sort of type property to decide which one you want to use when rendering.

Connect all relevant signals to the custom renderer you just created and pass them through to the selected renderer.

For the values, create a property which can hold both values (boolean & text, I have no idea how to do this in python) and pass them through to the correct property for the selected renderer.

There is a example in C. I don't know if you'll understand it but hey, it's a start! https://github.com/matze/EggPropertyTreeView/blob/master/egg-property-cell-renderer.c