Hi Rolf - I really like your GTK spinners but am designing for a 7" touchscreen. So spins and sliders too are way too small for fingertip operation. My workarounds look clumsy. If anyone is addressing problems like this, I would really like to know. Thanks, Graham.
Hi Rolf, thank you, this is an excellent solution to an issue that bothered me for ages and caused endless pages of spam warnings āgtk_box_gadget_distribute: assertion āsize >= 0ā failed in GtkSpinButtonā. One tweak Iād suggest, when replacing the number you want to be able to highlight the contents and start typing which should then replace whatever you have selected. The change below is needed to do this.
#create replacement text comprising old text and the new character
# Allowing for the insertion point being changed by the keys
# Delete, Backspace and Left, Right arrow keys
lsel = obj.GetSelection()[0]; rsel = obj.GetSelection()[1]
selected = rsel - lsel
if selected == 0:
new_text = curr_text[:pos]+chr(key)+curr_text[pos:]
#Remove whole string if selected
elif selected == len(curr_text):
new_text = chr(key)
#Otherwise remove selected bit
else:
new_text = curr_text[:lsel]+chr(key)+curr_text[rsel:]
@edwardsmith999 I have added your requested tweak
Iāve also amended the insertion point, so that when replacing, the next input character is inserted in the right place. Previously, it always jumped to the end.
Give it a test and let me know if Iāve introduced any issues.
Regards,
Rolf minispinctrl.py (28.4 KB) minifloatspin.py (31.5 KB) minispinbutton.py (21.3 KB)
After you brought it to my attention again, I found a glitch of my own.
Changelog:
1.1
Ability to replace highlighted numbers in the control suggested by edwardsmith999
Given the above change, adjust the insertion point, so that when replacing, the next input character is inserted in the right place
Override SetBackgroundColour and SetForegroundColour to ensure that the text colour changes automatically to black or white depending on the background colour and the scroll arrow image changes appropriately as well.
Hi @rolfofsaxony, thanks for the update, this might be worth putting on git to increase visibility (as well as track these changes). I sure this forum didnāt come up when I looked for solutions to this previously.
In the interest of developing this further, I also had to add the following function to swap out for spinctrl with integers.
def GetInt(self):
"""
Retrieve the integer of the control at the time
this event was generated."""
return int(self.value)
Out of interest, how does this differ from GetValue()?
Unless you are referring specifically to minifloatspin and even then, getting the integer from the float, if you need it, is straightforward.
Iāll add it if there is a compelling reason, as Iāve found a small bug that will result in an update anyway. Bug you can input a digit before the minus sign, resulting in a Value error
Changelog:
1.3 Fix bug which allowed input like 2-7, typing a digit in front of minus sign
1.2 Subclassing migrates from wx.Control to wx.Panel to enable Tab_Traversal.
`Alignment` Left, if desired should by performed with SetStyle()
Iām not sure, I guess just GetValue with rounding so it ensures output is an integer. It was part of the API for the SpinCtrl so I used it as I wanted integers (and given spin control goes in increments, I guess integer increments are the most common so maybe people would expect this).
@edwardsmith999 It isnāt a problem, I simply canāt find the API you are referring to.
Here are the updated versions with minifloatspin.py having a GetInt() function.
There are a few more improvements: minifloatspin
Changelog:
1.4 Change formatting from old style % modulo to f-strings (formatted string literals)
This change requires you run python3 but given that even python3.6 reached end of life
at the end of 2021, I think that is a resonable position to take.
Added a new function GetInt() return the integer in the control, because it was requested
The halfway click point for the image is calculated more accurately, by basing image size on the textctrl
after it has been assigned text.
Click and hold the SpinCtrl image, will repeat the increment, whilst Left Mouse button is held down.
(The Ctrl Key x 10 adjustment is still honoured)
Changelog:
1.4 The halfway click point for the image is calculated more accurately, by basing image size on the textctrl
after it has been assigned text.
Click and hold the SpinCtrl image, will repeat the increment, whilst Left Mouse button is held down.
minispinbutton
minispinbutton.py gets the same Click and hold the SpinCtrl image treatment, which will repeat the increment, whilst Left Mouse button is held down. minispinbutton.py (21.4 KB)
Let me know if Iāve introduced issues.
Regards,
Rolf