Bogus warning using set_cell_data_func with XML specification

The included test program produces the following warning:

Warning: unable to set property ‘text’ of type ‘gchararray’ from value of type ‘PyObject’

GTK then proceeds to set property ‘text’ from value of type ‘PyObject’ perfectly. I get the warning one time no matter how many rows I append. If I clear the liststore and start over, I do not get another warning. If I make appropriate changes so that the second value is a simple string (still using the cell_data_func, though), I do not get the warning. If I create the GUI manually and leave the second value a list, I do not get the warning. Is there something in my test program that triggers the warning?

import gi
gi.require_version('Gtk', '3.0')
gi.require_version('GLib', '2.0')
from gi.repository import Gtk, GLib

xml_data = """<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.22.1 -->
<requires lib="gtk+" version="3.20"/>
<object class="GtkListStore" id="liststore">
    <column type="gchararray"/>
    <column type="PyObject"/>
<template class="window" parent="GtkWindow">
    <object class="GtkTreeView" id="treeview">
        <property name="visible">True</property>
        <property name="model">liststore</property>
        <property name="headers_visible">False</property>
        <object class="GtkTreeViewColumn" id="treeviewcolumn_key">
            <object class="GtkCellRendererText" id="cellrenderer_key"/>
                <attribute name="text">0</attribute>
        <object class="GtkTreeViewColumn" id="treeviewcolumn_val">
            <object class="GtkCellRendererText" id="cellrenderer_val"/>
                <attribute name="text">1</attribute>

class Tester(Gtk.Window):
    __gtype_name__ = 'window'

    liststore = Gtk.Template.Child()
    cellrenderer_val = Gtk.Template.Child()
    treeviewcolumn_val = Gtk.Template.Child()

    def __init__(self):

        self.connect_after('destroy', self.on_destroy)

        self.liststore.append(('one', ['first value']))

        def func(column, cell, model, treeiter, user):
            val = model.get_value(treeiter, 1) # val is a list, as it should be
            val_str = val[0]
            cell.set_property('text', val_str)
        self.treeviewcolumn_val.set_cell_data_func(self.cellrenderer_val, func)

    def on_destroy(self, obj):

tester = Tester()
loop = GLib.MainLoop()

In your UI XML (at line 37) you configure the cell renderer to fetch its data from the 1st column of the store; but that column holds a list, as you know. You then set the text property again in your custom cell data function, so it ends up working.

What you should do is not configure the cell renderer to fetch its data itself from the store, because the store doesn’t contain the data in a form it can it can process directly. Basically, remove lines 36 to 38 from your UI XML.

1 Like

Brilliant. Thank you very much.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.