1

I'm trying to add a custom GdkPixbuf into a ListStore in order to print a diferent image (if the model provides one) or a default .

    listmodel = Gtk.ListStore(str, str, str, GdkPixbuf.Pixbuf)
    datos = model.Workouts
    myDir = os.getcwd()


    for i in range(len(datos)):

        renderer_pixbuf = Gtk.CellRendererPixbuf()

        #If model provides a image, we use it, otherwise we're using a default one.
        if datos[i].get_image():
            imageDir = str(myDir + '/ipm1920-p1/images/' + datos[i].get_id())
            f = open(imageDir, mode='wb+')
            f.write(base64.b64decode(datos[i].get_image()))
        else:
            imageDir = str(myDir + '/ipm1920-p1/images/empty.jpg')

        #Creating the buffer from the image on disk
        renderer_pixbuf.props.pixbuf = GdkPixbuf.Pixbuf.new_from_file(imageDir)

        #Appending it
        fila = [datos[i].get_publishDate(), datos[i].get_name(), str(datos[i].get_description()),renderer_pixbuf]
        listmodel.append(fila)

    # a treeview to see the data stored in the model
    view = Gtk.TreeView(model=listmodel)

    # for each column
    for i, column in enumerate(columns):

        #...other columns definition omited
        #Cell with image
        imagecell = Gtk.CellRendererPixbuf()
        col = Gtk.TreeViewColumn("Image", imagecell)
        col.add_attribute(imagecell, "pixbuf", 3)

        view.append_column(col)

I'm getting:

RuntimeWarning: Expecting to marshal a borrowed reference for , but nothing in Python is holding a reference to this object. See: https://bugzilla.gnome.org/show_bug.cgi?id=687522

How can I provide the pixbufer to the ListStore in order to be able to print it?

Shaheryar.Akram
  • 722
  • 10
  • 19
  • 1
    Please provide a [MCVE](https://stackoverflow.com/help/minimal-reproducible-example) – theGtknerd Oct 19 '19 at 21:44
  • Refer to this [solution](https://stackoverflow.com/questions/19778003/how-do-i-dynamically-resize-a-pixbuf-cellrenderer-in-a-treeview) . It works for me. – C Zhang Sep 28 '20 at 03:54
  • This solution: https://stackoverflow.com/questions/39833792/python-gtk3-create-cell-of-treeview-with-a-color-field/39835802#39835802 does what is required. – Kingsley Oct 16 '21 at 00:28

0 Answers0