I am not using Pango, but in my sources I do that to highlight mandatory
fields of my treeview:
cell = gtk.CellRendererText()
if (itMand == 'Y'):
cell.set_property('background-gdk',
gtk.gdk.color_parse(COLOR_MAND_FIELDS))
col = gtk.TreeViewColumn(None, cell)
...
John Hunter-4 wrote:
>
> I have a gtk.Treeview and I want to format negative numbers in red, as
> you can do in excel for example. I tried to use pango markup, as in
> the example below, but was unsuccessful -- what is the best way to do
> this?
>
> import gobject
> import gtk
>
> mydata = [('GOOG', 0.05, -0.025), ('MSFT', 0.1, -0.1), ('AAPL', -0.05,
> 0.10)]
> model = gtk.ListStore(gobject.TYPE_STRING, gobject.TYPE_STRING,
> gobject.TYPE_STRING)
>
>
> def tostr(gain):
> if gain<0: return '%1.1f'%(100*gain)
> else: return '%1.1f'%(100*gain)
>
> for ticker, gain1, gain2 in mydata:
> iter = model.append()
> model.set(iter, 0, ticker, 1, tostr(gain1), 2, tostr(gain2))
>
> treeview = gtk.TreeView(model)
> treeview.set_rules_hint(True)
>
> column = gtk.TreeViewColumn('Ticker', gtk.CellRendererText(),
> text=0)
> treeview.append_column(column)
>
> column = gtk.TreeViewColumn('Gain1', gtk.CellRendererText(),
> text=1)
> treeview.append_column(column)
>
> column = gtk.TreeViewColumn('Gain2', gtk.CellRendererText(),
> text=2)
> treeview.append_column(column)
>
>
>
> win = gtk.Window()
> win.connect('destroy', lambda win: gtk.main_quit())
> win.set_title('treeview demo')
> win.add(treeview)
>
>
> win.show_all()
> gtk.main()
> ___
> pygtk mailing list pygtk@daa.com.au
> http://www.daa.com.au/mailman/listinfo/pygtk
> Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
>
>
--
View this message in context:
http://www.nabble.com/colored-cell-tf4528708.html#a12977587
Sent from the Gtk+ - Python mailing list archive at Nabble.com.
___
pygtk mailing list pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/