Mostrar icono o color en el árbol Gtk TreeView
Tengo dificultades para cargar un archivo o mostrar un color en una de las columnas de un Gtk TreeView (enlace Python de GTK3). Un ejemplo tomado de QGIS muestra un icono en la primera fila y un círculo azul en la segunda fila. El color se toma de las propiedades de la capa:
Mi código se ve así pero no carga el archivo icon.png en el mismo directorio:
#!/usr/bin/python3
from gi.repository import Gtk, Gdk, GdkPixbuf
class MyWindow(Gtk.Window):
def __init__(self):
Gtk.Window.__init__(self)
self.set_default_size(200, 200)
self.liststore = Gtk.ListStore(GdkPixbuf.Pixbuf, str)
self.treeview = Gtk.TreeView(model=self.liststore)
symbol1 = GdkPixbuf.Pixbuf.new_from_file("icon.png")
self.liststore.append([symbol1, "This is a symbol1"])
symbol2 = Gtk.IconTheme.get_default().load_icon("gtk-cut", 64, 0)
self.liststore.append([symbol2, "This is symbol2"])
px_renderer = Gtk.CellRendererPixbuf()
px_column = Gtk.TreeViewColumn("Icon", px_renderer)
self.treeview.append_column(px_column)
str_renderer = Gtk.CellRendererText()
str_column = Gtk.TreeViewColumn("Name", str_renderer, text=1)
self.treeview.append_column(str_column)
self.add(self.treeview)
win = MyWindow()
win.connect("delete-event", Gtk.main_quit)
win.show_all()
Gtk.main()
La documentación para GTK3 pixbuf está aquí:
https://lazka.github.io/pgi-docs/index.html#GdkPixbuf-2.0/classes/Pixbuf.htmlAquí hay ejemplos más antiguos de PyGTK, pero algo realmente ha cambiado en cómo se maneja esto:
http://faq.pygtk.org/index.py?file=faq13.006.htp&req=showhttp://www.daa.com.au/pipermail/pygtk/2003-August/005644.html