[pygtk] TreeView - Making whole row colored

Stephen George steve_geo at optusnet.com.au
Wed Jan 30 15:59:43 WST 2008


Hi,

I am trying to get a treeview (with liststore model) to display rows in =

different colors based on content in the list.

 From what I've read in GTK+ 2.0 Tree View Tutorial - Tim-Philipp Muller =

( c code based)

"The most suitable approach for most cases is that you add two columns =

to your model, one for
the property itself (e.g. a column COL_ROW_COLOR of type G_TYPE_STRING), =

and one for the boolean flag of
the property (e.g. a column COL_ROW_COLOR_SET of type G_TYPE_BOOLEAN). =

You would then connect these
columns with the "foreground" and "foreground-set" properties of each =

renderer. Now, whenever you set
a row=92s COL_ROW_COLOR field to a colour, and set that row=92s =

COL_ROW_COLOR_SET field to TRUE, then
this column will be rendered in the colour of your choice. If you only =

want either the default text colour or one
special other colour, you could even achieve the same thing with just =

one extra model column: in this case you
could just set all renderer=92s "foreground" property to whatever special =

color you want, and only connect the
COL_ROW_COLOR_SET column to all renderer=92s "foreground-set" property =

using attributes."

Which I've implemented as attached.

The setting of foreground seems to be working (half list blue, half red)
However my implementation seems to be ignoring the foreground-set flag.

I am expecting to ONLY see my 'special' foreground color when the =

modified flag is also set to true, and grey/black writing when the =

foreground-set flag is False.

I can get grey writing by setting the foreground to None, but I don't =

belive this was the intent of the above description.

Am I mis-understanding how this functionality should work, .. or made =

some errors in my code?

Thanks for any suggestions.
Steve
-------------- next part --------------
A non-text attachment was scrubbed...
Name: exampleList.py
Type: text/x-python
Size: 4464 bytes
Desc: not available
Url : http://www.daa.com.au/pipermail/pygtk/attachments/20080130/7eb03919/e=
xampleList.py


More information about the pygtk mailing list