Home Software Hardware Misc About

SpinCtrl

vs. 0.1 (07/07/2020)

It is time to show spin controls some love: this is SpinCtrl, a drop-in replacement for wxPython's wx.SpinCtrl.

gtk2 comparison

GTK2 spins work as long as you don't try to change their sizes. The arrow buttons are not resized with the control, they rather seem to resize when the text font used by the control is resized.

gtk3 comparison
And as for their GTK3 variants, well you cannot even try to resize them. You're stuck with their atrocious sizes and that's it. Even when you only want just a small, honest control to allow users to change some little values. Well, that's what spin controls were created for.

So this is my take on trying to make them visually appealing on GTK2 and on having, in fact, a SpinCtrl on GTK3. And no, two giant buttons stacked side by side don't make a SpinCtrl.

It is fully resizable. Its buttons are animated whether you use mouse buttons or mouse wheel or keyboard to interact and should work well under light and dark desktop themes. It generates one event, EVT_SPIN: bind it and check for event.value to get the current value of the control.

The control buttons have a class of their own, SpinButton. Should you ever have a need to instantiate only the buttons instead of the full control, they're also available. SpinButton reacts only to mouse clicks and wheel and generates one event, EVT_SPIN_BUTTON. In this case, event.value will simply return a 1 or -1 depending on the button activated.

Their public methods are pretty straighforward; please see the code for more details.

This compressed file contains the classes. Extract it somewhere and test with

python3 spinctrl.py
or
python3 spinbutton.py

Tested on wxPython 4.1.0 (gtk3) on Python 3.7.3 on Raspberry Pi OS and on wxPython 4.1.0 (gtk2) on Python 3.8.2 on Mint (Mate). Distributed under the BSD-3-Clause License.