I need to write a custom Gtk.CellRenderer
(let's call it CellRendererToogleWithNone
) that behaves similar to Gtk.CellRendererToggle
, but instead of only supporting True
and False
I also want it to support None
which should be displayed as inconsistent state like this:
On toggle I want to rotate in some defined order, for example like so: True -> False -> None (But that's probably the easy part, I still thought I mention that)
I also don't know how to make it work with TreeStore because if I do
self.treestore = Gtk.TreeStore.new(types = (bool,))
iter = self.treestore.append(parent = None, row = (None,))
it will convert any None
value to False
because bool
seems not to allow for None
values
I failed to find any helpful custom Gtk.CellRenderer
examples online.
I want to do it by inheriting from Gtk.CellRenderer
and NOT from Gtk.CellRendererToggle
because this should also serve me as a helpful example to implement more cell renderers like this.
I can only guess that I have to define some custom data type for the TreeStore
, something like bool_or_none
instead of bool
(no idea how to do that either) and hold my own Gtk.ToggleButton
inside of my custom CellRendererToogleWithNone
.
Edit 0:
This post about how to write custom Gtk.CellRenderer
gives a couple of hints which maybe can be reused but does not solve my problem. It doesn't show how to make Gtk.TreeStore
accept None
values for bool
variables and I don't understand everything there. It doesn't even use a Gtk.Button, instead it seems to paint a box inside of a widget that I'm guessing may be the parent. I don't want to paint my own Toggle, I want to reuse Gtk.ToggleButton
and its inconsistent
property
Edit 1:
Since it seems custom cell renderers are not easy, I think it would be especially useful to see a minimal working example in python. I should also mention that I want to display the data as compactly as possible which excludes suggested workarounds such as having two toggles for one value.