I am having difficulty loading a file or displaying a colour in one of the columns of a Gtk TreeView (Python binding of GTK3). An example taken from QGIS shows a icon in the first row and a blue circle in the second row. The colour is taken from the layer properties:
My code looks like this but does not load the icon.png file in the same directory:
#!/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()
The documentation for GTK3 pixbuf is here:
Older examples for PyGTK are here, but something has really changed in how this is handled: