Hi,

   I want to color single cells in a TreeView (totals of a table).
   Since I'm using cell_data_func to set value of property text I tried
   using that same function to set colors but it turns out all cells get
   colored... 

    def dict_cell_data_func(self, column, cell, model, iter, (col_num, name)):
        obj = model.get_value(iter, col_num) 
        value = getattr(obj, name)
        cell.set_property("text", value)
        if value == 'venice':
            cell.set_property("cell-background", 'yellow')
   

   can anybody help me understanding why?

   I attach the complete example.

   thanks in advance
   sandro
   *:-)
import gtk
import sys

class A(object):
    def __init__(self, name):
        self.name = name



class Tree(object):
    def __init__(self):
        window = gtk.Window()
        self.model = gtk.ListStore(object)
        tree_view = gtk.TreeView(self.model)
        window.add(tree_view)
        window.show_all()

        renderer = gtk.CellRendererText()
        column = gtk.TreeViewColumn("Foo", renderer)
        column.set_cell_data_func(
            renderer, self.dict_cell_data_func, (0, 'name'))
        tree_view.append_column(column)
        self.fill_model()

    def dict_cell_data_func(self, column, cell, model, iter, (col_num, name)):
        obj = model.get_value(iter, col_num) 
        value = getattr(obj, name)
        cell.set_property("text", value)
        if value == 'venice':
            cell.set_property("cell-background", 'yellow')

    def fill_model(self):
        cities = 'rome venice florence'

        for city in cities.split():
            self.model.append(  [ A(city) ]  )


try:
    Tree()
    gtk.main()
except KeyboardInterrupt:
    sys.exit()
_______________________________________________
pygtk mailing list   [email protected]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/

Reply via email to