Reputation: 1325
I have the file size in bytes stored in a Gtk.ListStore
and want them to be rendered in a human-readable format by a Gtk.CellRendererText
. Reading the documentation, it seems like Gtk.TreeViewColumn.set_cell_data_func()
is the way to achieve this. Setting it up works without errors, but as soon as a cell is to be rendered, the whole application crashes after several failed assertions.
This is the code I'm using:
self._builder.get_object("ContentList.Size").set_cell_data_func(
Gtk.CellRendererText(),
self.render_formatted_size
)
And this is what's printed to stderr:
/usr/lib/python3.7/site-packages/gi/overrides/Gio.py:44: Warning: g_object_freeze_notify: assertion 'G_IS_OBJECT (object)' failed
return Gio.Application.run(self, *args, **kwargs)
/usr/lib/python3.7/site-packages/gi/overrides/Gio.py:44: Warning: g_object_get: assertion 'G_IS_OBJECT (object)' failed
return Gio.Application.run(self, *args, **kwargs)
/usr/lib/python3.7/site-packages/gi/overrides/Gio.py:44: Warning: g_object_set: assertion 'G_IS_OBJECT (object)' failed
return Gio.Application.run(self, *args, **kwargs)
/usr/lib/python3.7/site-packages/gi/overrides/Gio.py:44: Warning: g_object_is_floating: assertion 'G_IS_OBJECT (object)' failed
return Gio.Application.run(self, *args, **kwargs)
/usr/lib/python3.7/site-packages/gi/overrides/Gio.py:44: Warning: g_object_get_qdata: assertion 'G_IS_OBJECT (object)' failed
return Gio.Application.run(self, *args, **kwargs)
Content of self.render_formatted_size
should not matter here. It seems like it's never executed.
PS: Adding additional string columns to the model is not an option, as I want to be able to change display units (SI, IEC) at any time.
Upvotes: 0
Views: 284
Reputation: 2525
You pass a newly created CellRenderer, not an existing one. Something like this should be done instead:
rend = Gtk.CellRendererText()
column = Gtk.TreeViewColumn("title", rend)
column.set_cell_data_func (rend, cell_fn, None);
tree.append_column(column)
Upvotes: 1