Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unexpected behaviour with the method "step" in the class "Meter" #605

Open
Aguillares opened this issue Nov 13, 2024 · 1 comment
Open
Assignees
Labels
enhancement New feature or request

Comments

@Aguillares
Copy link

Is your feature request related to a problem? Please describe.

ttkbootstrap Version 1.10.1

The unexpected behaviour is that we got negative numbers and larger numbers than the "maximum limit", this happens when we are binding the mouse wheel to "step" method.

First of all, if we put positive numbers in step, we are decreasing at the beginning and when we reach the 0, it starts increasing, which it is not expected, I mean at the beginning if we are using positive numbers in "step" we should increase not decrease, and after we reach 100, now we should decrease the number.

Also, when we got 100, and we start to decrease the number with positive numbers, and suddenly we change the "step" to a negative number, we can increase larger numbers than 100, which is an annoying bug.

Here it is my code:

import ttkbootstrap as ttk
from ttkbootstrap.constants import *
app2 = ttk.Window()
app2.title("Mirrow app")


def meter_limits(e):
    print(f"Meter = {meter.amountusedvar.get()}, delta = {e.delta/12}")
    meter.step(e.delta/12)
    

meter = ttk.Meter(
    metersize = 100,
    padding = 10,
    amountused = 40,
    metertype = "semi",
    subtext = "Miles per hour",
    interactive = True,
    amounttotal = 100
)
meter.pack()
meter.configure(amountused = 50)
get_value = ttk.Entry(textvariable= meter.amountusedvar)
get_value.pack(fill=X)

app2.bind('<MouseWheel>',  meter_limits)
meter.step(10)
meter.step(-10)
meter.configure(subtext = "Loading...")
app2.mainloop()

This when we run the code
image

I got a positive delta:
image
And we decrease instead of increasing (in the documentation says the opposite)
image

We got zero if we continue giving positive numbers
image
Now increasing with positive numbers
image
Now we are going to change to negative numbers (decreasing)
image
We continue giving negative numbers
image
Here it is the bug, we shouldn't decrease more than zero.
image
Similar logic with the greater numbers than 100.
image

This is the thing.

Describe the solution you'd like

I would like that the maximum number is "maximum" and then not to have greater numbers, and I don't want to get negative numbers infinitely. And also if I use a positive number in step I want to increase, not to decrease if I haven't reached the "maximum" number

Describe alternatives you've considered

I have improved the code to have the expected behaviour.

We just need to change the conditions a little.

Before

        amountused = self.amountusedvar.get()
        amounttotal = self.amounttotalvar.get()
        if amountused >= amounttotal:
            self._towardsmaximum = True
            self.amountusedvar.set(amountused - delta)
        elif amountused <= 0:
            self._towardsmaximum = False
            self.amountusedvar.set(amountused + delta)
        elif self._towardsmaximum:
            self.amountusedvar.set(amountused - delta)
        else:
            self.amountusedvar.set(amountused + delta)

After

        amountused = self.amountusedvar.get()
        amounttotal = self.amounttotalvar.get()
        
        if (amountused >= amounttotal and delta > 0) or (amountused <= 0 and delta < 0):
            self._towardsmaximum = False
            self.amountusedvar.set(amountused - delta)
        elif (amountused <= 0 and delta>0) or (amountused >= amounttotal and delta<0):
            self._towardsmaximum = True
            self.amountusedvar.set(amountused + delta)
        elif self._towardsmaximum:
            self.amountusedvar.set(amountused + delta)
        else:
            self.amountusedvar.set(amountused - delta)

Results
Giving positive numbers.
image
Increasing as expected
image
We reach 100
image
We continue with positive delta, and we got that we are decreasing as expected.
image
Now we are going to give negative numbers and we are increasing the amountused
image
image
We reached 100 again but with negative numbers.
image
We continue giving negative numbers and now it is decreasing as expected.
image
image
In similar way on the other side.
image
image

Additional context

Now the numbers are in the limits in this case 0 and 100. Maybe, a good improvement it would be to add the option of "minimum" if someone needs negative numbers not to be restricted to 0.

@Aguillares Aguillares added the enhancement New feature or request label Nov 13, 2024
@Aguillares
Copy link
Author

Sorry, I don't use too much Git-hub. If I made a mistake let me know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants