Skip to content
New issue

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

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

Already on GitHub? # to your account

Fix case where percent = 0 causes error in display_progress_bar #17

Merged
merged 1 commit into from
Feb 22, 2024

Conversation

paul-1
Copy link
Contributor

@paul-1 paul-1 commented Feb 22, 2024

Occasionally the first draw of the progress bar is actually at 0% complete. This causes a problem in the math to calculate how full the progress bar is. The error is that x2 is not >= x1

@AndreaFavero71
Copy link
Owner

AndreaFavero71 commented Feb 22, 2024

Hi Paul, your proposal is correct: Accoring to the PIL documentation, indeed X2 must be >= X1

The strange thing is that it has worked for so long the way it is.
I just wanted to check what happens when x2<x1:

if __name__ == "__main__":
    """the main function can be used to test the display. """
    
    import time
    display.set_backlight(1)                                    # display backlight is set on
    print("barLength:", "\tpercent:", "\tfilledPixels:", "\tfilledPixels-(x+gap):")
    for i in range(-10,101):
        display.display_progress_bar(i, scrambling=False)
        if i in (-1,0,1,100):
            time.sleep(10)
        else:
            time.sleep(0.05)

The initial printout is:

barLength: 	percent: 	filledPixels: 	filledPixels-(x+gap):
126 	 -10 	 6 	 -12
126 	 -9 	 7 	 -11
126 	 -8 	 8 	 -10
126 	 -7 	 9 	 -9
126 	 -6 	 10 	 -8
126 	 -5 	 12 	 -6
126 	 -4 	 13 	 -5
126 	 -3 	 14 	 -4
126 	 -2 	 15 	 -3
126 	 -1 	 16 	 -2
126 	 0 	 18 	 0
126 	 1 	 19 	 1
126 	 2 	 20 	 2
126 	 3 	 21 	 3

In my case, when x2<x1, the rectangles fills to the left of the (x1) origin yet not error.
Could you kindly elaborate on the error you're experiencing?

@paul-1
Copy link
Contributor Author

paul-1 commented Feb 22, 2024

My guess is that its the newer version of the pillow library. I just installed mine last weekend. The exception was added in pillow version 9.5.0

Here is the pull request that changed to an exception
python-pillow/Pillow#6978

@AndreaFavero71
Copy link
Owner

You're right.
By updating from the 8.12 I had to the latest 10.2.0 I got the error "ValueError: x1 must be greater than or equal to x0".
Thank you for spotting the error and the fix.

@AndreaFavero71 AndreaFavero71 merged commit bf333ac into AndreaFavero71:main Feb 22, 2024
@paul-1 paul-1 deleted the Progressbar branch February 23, 2024 00:14
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants