1

我正在尝试将自定义 GdkPixbuf 添加到 ListStore 中,以打印不同的图像(如果模型提供)或默认的 .

    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)

我越来越:

RuntimeWarning:期望编组借用的引用,但 Python 中没有任何内容持有对该对象的引用。请参阅: https ://bugzilla.gnome.org/show_bug.cgi?id=687522

如何将 pixbufer 提供给 ListStore 以便能够打印它?

4

0 回答 0