Passing a cairo.Surface in a TreeStore to a GtkCellRendererPixbuf fails
Problem description
Passing a cairo.ImageSurface
stored in a Gtk.TreeStore
to a GtkCellRendererPixbuf
fails currently (pygobject 3.27.2).
Different approaches
-
Passing a
cairo.ImageSurface
in aGtk.TreeStore
doesn not work if you set the column type tocairo.Surface
:import gi gi.require_foreign('cairo') import cairo from gi.repository import GObject, Gtk surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, 10, 10) model = Gtk.TreeStore( cairo.Surface ) model.insert_with_values(None, -1, [0], [surface])
This fails with
TypeError: Item 0: Must be gobject.GType, not type
. -
Changing the
cairo.Surface
toobject
makes it work, however passing the resultingGtk.TreeStore
object to aGtk.Treeview
with aGtk.PixbufCellRenderer
then fails as follows./usr/lib64/python3.6/site-packages/gi/overrides/Gio.py:42: Warning: unable to set property 'surface' of type 'CairoSurface' from value of type 'PyObject' return Gio.Application.run(self, *args, **kwargs)
-
Another seemingly correct option would be:
import gi gi.require_foreign('cairo') import cairo from gi.repository import GObject, Gtk, cairo as pycairo surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, 10, 10) model = Gtk.TreeStore( pycairo.Surface ) model.insert_with_values(None, -1, [0], [surface])
This fails with
Unable to convert from PyObject to CairoSurface
in gtktreestore.c .