python - How to set the color of a single cell in a pygtk treeview? -


i have pygtk treeview couple of columns. during runtime add new rows. each cell contains string. normaly, use gtk.cellrenderer each row, want set background color of each cell, according value inside cell.

i tried couple of solutions, seems have create cellrenderer each cell, set text attribute , background color. seems little oversized, asked myself if there nicer solution problem. suggestions?

you can define background , foreground treeview cells in fields of treeview data source. setup foreground , background attributes treeview columns values corresponding data source fields.

below small example:

import gtk  test_data = [     { 'column0' : 'test00', 'column1' : 'test01', 'f': '#000000', 'b': '#ff00ff' },     { 'column0' : 'test10', 'column1' : 'test11', 'f': '#ff0000', 'b': '#c9c9c9' },     { 'column0' : 'test20', 'column1' : 'test21', 'f': '#00ff00', 'b': '#ff0000' }]  class testwindow(gtk.window):     def __init__(self):         gtk.window.__init__(self)          # create list storage                 store = gtk.liststore(str, str, str, str)         in test_data:             store.append([i['column0'], i['column1'], i['f'], i['b']])         treeview = gtk.treeview(store)          # define columns         column0 = gtk.treeviewcolumn("column 0", gtk.cellrenderertext(), text=1, foreground=2, background=3)                 treeview.append_column(column0)                     column1 = gtk.treeviewcolumn("column 1", gtk.cellrenderertext(), text=1, foreground=2, background=3)                 treeview.append_column(column1)          self.connect("destroy", lambda w: gtk.main_quit())         self.connect("delete_event", lambda w, e: gtk.main_quit())          self.add(treeview)         self.show_all()  if __name__ == "__main__":     testwindow()     gtk.main()  

hope helps, regards


Comments

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

visual c++ - Using relative values in array sorting ( asm ) -