jarvisteach / appJar

Simple Tkinter GUIs in Python
http://appJar.info
Other
615 stars 68 forks source link

[Request] Configure spinBar direction #582

Closed eyeonus closed 4 years ago

eyeonus commented 5 years ago

Context


Currently the spinBar is hard-coded to behave in a, to me at least, very strange way:

Pressing the down arrow makes the number go up.

I noticed when trying to figure out why this was so that there is a variable that is not exposed called "reverse", and which is always set to True in the very few methods it is used in.

My request is to make this argument available at the API level, with the effect of toggling the execution of the indicated code in the snippet below.

Expected Behaviour


https://youtu.be/2lzCEWj6dac

This behaviour is achieved by making the following changes in appJar:

    def _populateSpinBox(self, spin, vals, reverse = True):
        # make sure it's a list
        #  reverse it, so the spin box functions properly
-->     # if reverse:
-->     #    vals = list(vals)
-->     #    vals.reverse()
        vals = tuple(vals)
        spin.config(values = vals)

    def setSpinBoxPos(self, title, pos, callFunction = True):
        spin = self.widgetManager.get(WIDGET_NAMES.SpinBox, title)
        vals = spin.cget("values")  # .split()
        vals = self._getSpinBoxValsAsList(vals)
        pos = int(pos)
        if pos < 0 or pos >= len(vals):
            raise Exception("Invalid position: " + str(pos) + ". No position in SpinBox: " + 
                        title + "=" + str(vals))
-->     #    pos = len(vals) - 1 - pos
        val = vals[pos]
        self._setSpinBoxVal(spin, val, callFunction)

Actual Behaviour


https://youtu.be/KZKaJ4yZARE

Sample code, demonstrating the issue


        win.spinBox('--debug', [0, 1, 2, 3], tooltip = 'Enable/raise level of diagnostic output.',
                      label = True, selected = 0, sticky = 'w', width = 1, row = 0, column = 1)

        win.spinBox('--detail', 0, endValue = 3, tooltip = 'Increase level of detail in output.',
                      label = True, selected = 0, sticky = 'w', width = 1, row = 0, column = 2)

What steps are needed to reproduce the bug


Create a SpinBox. Any SpinBox. This behaviour is intrinsic.

Version Information


pip install --upgrade appjar Requirement already satisfied: appjar in ...\python37\lib\site-packages (0.94.0)

jarvisteach commented 5 years ago

Sounds like a good idea!

I remember when I worked on this, debating which way it should spin - the issue was over "natural scrolling" on my MacBook - where the touchpad scroll direction matches the direction you get on a touchscreen device...

Anyway, I'll make the change you've requested.

eyeonus commented 5 years ago

Awesome-sauce.

jarvisteach commented 4 years ago

You can now set a reverse property when adding a spin box

ChrTall commented 4 years ago

After Commenting Out the lines as suggested by eyeonus it works for me. Can you explain to me how your solution works? I tried: .changeSpinBox(title, vals, reverse=True) Replaces the contents of the specified SpinBox with the new vals. Set reverse to False if you don;t ant to reverse the values.

from the docs but I could not get it working.

eyeonus commented 4 years ago

I think you have to do it when creating the SpinBox, but you're trying to modify an already existing one?