Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bold/Unbold rows in PyGTK TreeView

I want to make some rows in my TreeView bold, and some not as I append them to TreeView, later on, I want to unbold rows on click.

What is the easiest way to do this?

like image 540
umpirsky Avatar asked Dec 13 '11 15:12

umpirsky


1 Answers

I assume that you have a model that contains a column with some text and that a gtk.CellRendererText widget has a text property set to the column index in that model.

If you add a new column to that model you can use it to set the font weight used in every cell renderer. To do that just set the gtk.CellRendererText widget weight property to the new column index in the model and weight-set to True.

After that, you just need to set the font weight in the model using any of the pango.WEIGHT constants such as pango.WEIGHT_NORMAL and pango.WEIGHT_BOLD.

As an example, let's say that these are your model columns (one for the text, one for the font weight):

Model columns

and these are a couple of rows that you've added for testing:

Model rows

(Note that pango.WEIGHT_NORMAL=400 and pango.WEIGHT_BOLD=700)

With this model, you create a gtk.TreeView with a column and a text renderer:

Treeview hierarchy

In the renderer you set the text property to the text column in the model:

Cell renderer text

and the weight property to the weight column in the model:

Cell renderer weight

The result that you obtain with the test data that you added to your model is:

Final result

Where you can see that the text is displayed with the font weight that is set in the model.

like image 102
jcollado Avatar answered Sep 17 '22 20:09

jcollado