GIMP 3/ Python3 how to use Switch instead of checkbuttons (original) (raw)
The docs here
say we can use aswitch instead of acheckbuttons.
How can I do it ?
Jehan (Jehan) March 4, 2025, 8:53pm 2
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.
nelo March 5, 2025, 8:03am 3
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)
nelo March 5, 2025, 2:54pm 5
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!
JimDee2 (Jim Denney) March 7, 2025, 4:46pm 7
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
nelo March 7, 2025, 6:38pm 8
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?
Jehan (Jehan) March 7, 2025, 7:08pm 9
Probably some pygobject magic which converts things automatically.
system (system) Closed April 21, 2025, 7:09pm 10
This topic was automatically closed 45 days after the last reply. New replies are no longer allowed.