[pygtk] retrieving TreeView markup
Renee Yang
reneey at gmail.com
Thu Jul 19 01:02:58 WST 2007
Hi,
I have a gtk.TreeView with cells that are color-coded. Since the
colors are determined by the contents of the cell and there could be
more than one value in a cell, I'm using a data function
(TreeViewColumn.set_cell_data_func). Here's a (contrived) example:
def fruit_cell(self, col, cell, model, iter):
fruits = cell.get_property('text').split(', ')
format = '<span foreground="%s">%s</span>'
color_coded = []
for fruit in fruits:
color = 'black'
if fruit == 'apple':
color = 'green'
elif fruit == 'grape'
color = 'purple'
elif fruit == 'strawberry':
color = 'red'
color_coded.append(format % (color, fruit))
markup = ', '.join(color_coded)
cell.set_property('markup', markup)
I'd like to be able to export the data that's in this TreeView into
HTML format with the colors intact, but I'm running into issues
getting markup out of the cells. My initial thought was to get the
"markup" property from the CellRendererText, but this property is
write-only. Also, CellRenderers apply to columns and not individual
cells.
The only option I could think of was to mimic the original rendering
of the TreeView and accumulate the markup as it's being rendered. I
might as well gather the markup the first time the TreeView is
rendered, but that would also mean doing extra work for an export
option that probably won't be used 99% of the time. While this could
work, I'm wondering if there's a simpler solution I'm just not seeing.
Has anyone dealt with this before? Any help very much appreciated.
Renee
More information about the pygtk
mailing list