views:

39

answers:

2

I have a dialog which contains a pygtk.treeview for listing tasks by priority. Each row has the background colour set based on that priority, so for example the highest priority has a light red background.

The row selection color is not so easy to change. I can set it using treeview.modify_base(gtk.STATE_SELECTED, "#C4C4C4"), but no colours work well with the colours used to enhance the concept of priority.

I had the idea to change the selection colour to be a slightly darker version of the colour used as the normal row background, so in the example above, that would be a darker red. I tried calling the function above in response to the treeselection changed signal, and it works, but with heavy flickering.

Another idea was to change the selection to transparent and put a border around it instead, but as far as I can tell, this isn't possible.

  1. How can I change the selection colour in the way described above without the flickering?
  2. Can I change show the selection by having only a border around the row?

Note: I'm aware that this violates the theme selected by the user. I feel I have a good reason for it. Having the priority indicated by colour makes it instantly recognisable. The selection colour hides this. If you have alternative suggestions, I am open to them, but it needs to retain the ease at which a user can identify the priority.

A: 

Not sure what you mean by flickering. A border would require subclassing TreeView.

I'd make the STATE_SELECTED color identical to STATE_NORMAL to disable the built-in highlighting. Then set a data_func on each column and change some color on the cell renderer depending on whether it's in the selection or not.

You're probably already doing this for your priority, so just multiply the color with something to highlight a row.

Tobias
When I set the STATE_SELECTED to the STATE_NORMAL colour, it doesn't disable it but instead sets the colour to be the same, in this case, white.
rioch
Sorry, didn't try. I don't think transparent colors exist at that point.
Tobias
+1  A: 

You could add a separate pixbuf cell (say, the same size as a small icon) to the far left to indicate selection. Selected rows could fill this with a more "solid" (saturated) version of the colour used for the background. For example. if you use a pink background for high priority, you could use red for the selection indicator. Or you could use an icon.

To implement this with the colour filling method:

  1. Disable the built-in highlighting as per Tobias' suggestion ("make the STATE_SELECTED color identical to STATE_NORMAL").
  2. Create a widget based on gtk.gdk.Pixbuf that allows you to create a solid area of colour, perhaps using the fill method.
  3. Use a CellRendererPixbuf for your "selection" cell.

You can then color or uncolour the "selection cell" upon selection changes to indicate which row is selected, or display an icon (eg. a stock symbol).

Note that I haven't implemented this, it's just an idea. It departs significantly from the usual GTK selection indication, so (obviously) use your judgement as to whether it's useable.

detly
He could also use the pixbuf to indicate priority and not fiddle with row colors at all. Most Mac applications combine both: selecting overrides the background except for a dot in one column.
Tobias
I had completely failed to think of that :P I remember a mail reader I used once had little "up", "down", "double up" and "double down" arrow symbols in one column to indicate priority.
detly
I also thought of using the pixbuf to show the colour. It might be the best option since I expect that the selection won't cover the image.
rioch