The docs here
say we can use aswitch instead of acheckbuttons.
How can I do it ?
The docs here
say we can use aswitch instead of acheckbuttons.
How can I do it ?
The docs you point out lists all the available types (depending on argument type), and as you see, GTK_TYPE_SWITCH
is indeed supported. Just use it for the last argument.
As for using a GType
in the Python binding, this was already explained to you here: GIMP3/Python3 Sliders instead of spinners? - #2 by JimDee2
It’s the same thing here, except that it will be Gtk.Switch.__gtype__
in this case.
If I do
toggle = dialog.get_widget("yes_no", GimpUi.Switch)
similar to what I did with the other widgets
GIMP tells me:
AttributeError: ‘gi.repository.GimpUi’ object has no attribute ‘Switch’
So that can’t be it. What am I doing wrong?
Hi! We don’t have a GimpUi type for switch, so like @Jehan said, you’ll want to use the generic GTK type. I just tried this and it worked fine.
toggle = dialog.get_widget("yes_no", Gtk.Switch.gtype)
This again told me:
AttributeError: type object ‘Switch’ has no attribute ‘gtype’
But it works like this here:
toggle = dialog.get_widget("yes_no", Gtk.Switch)
Some things are not self explanatory for people without C programming experience …
Odd, it worked fine for me - perhaps we have different versions of Python? Oh well - glad you got it working!
Isn’t the “gtype” supposed to have double underscores each side? I think this is a Python but not C thing. It is a pygobject binding specific field used to report the GType of a class. What is expected in dialog.get_widget is a Gtype not an object.
JimDee2
Oh yes, you’re right.
And then it works …
The forum just swallowed the underscores if there have been any.
I just copied @CmykStudent’s code, forgot about the underscores seen in my other question’s answer. My bad.
Why does it also work without the gtype thing?
Probably some pygobject magic which converts things automatically.
This topic was automatically closed 45 days after the last reply. New replies are no longer allowed.