jarvisteach / appJar

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

scrollPane crashes on macbook pro trackpad scroll #501

Open quasarbright opened 6 years ago

quasarbright commented 6 years ago

I'm running on appJar 0.93.0 and python 3.5.2. My hardware is a 2018 Macbook Pro 15". I'm running on MacOS High Sierra 10.13.6. When I run the app, it works fine. I can scroll by clicking and dragging the scroll bar. However, when I try to scroll with the trackpad, the app crashes. Here is the code and error message:
code:

from appJar import gui
app = gui('main menu', '400x400')
app.startScrollPane('songPane', row=0, rowspan=3, colspan=3)
for x in range(4, 100):
    app.addLabel(str(x))
app.stopScrollPane()
with app.frame('left', row=3, column=0):
    app.addLabel('1')
with app.frame('mid', row=3, column=1):
    app.addLabel('2')
with app.frame('right', row=3, column=2):
    app.addLabel('3')
def stopFunction():
    print('k bye')
    return True
app.go()

error message:

2018-07-31 10:43:35.589 Python[68203:2740615] ApplePersistenceIgnoreState: Existing state will not be touched. New state will be written to (null)
2018-07-31 10:43:40,264 appJar:ERROR [Line 18->1813/go]: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/appJar/appjar.py", line 1808, in go
    self.topLevel.mainloop()
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/tkinter/__init__.py", line 1131, in mainloop
    self.tk.mainloop(n)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte

Trying to scroll up while already at the top of the page doesn't crash it, but scrolling down to view the rest does crash it.

quasarbright commented 6 years ago

Something else I noticed: using app.button('Accessibility', app.showAccess, icon='ACCESS') and scrolling through fonts with trackpad works fine.

jarvisteach commented 6 years ago

I've seen this issue (with the scroll pane) raised before - issue #337 It's not an issue with appJar, but instead a problem with your python/tcl installation on your Mac.

It's discussed here: https://stackoverflow.com/questions/16995969/inertial-scrolling-in-mac-os-x-with-tkinter-and-python

With some suggestions on how to resolve it. I can't reproduce it on my Mac, so can't suggest anything more...

quasarbright commented 6 years ago

one suggestion involved a try catch with root.mainloop() in tkinter (https://stackoverflow.com/a/36667213/5651606). How would this be done in appJar?

jarvisteach commented 6 years ago

I would look to upgrade your version of tcl/python first.

If that doesn't work, you can go in and edit the appJar file. Search for the go function (def go), and scroll to the end of it, where you'll find:

        # start the main loop
        try:  
            self.topLevel.mainloop()
        except(KeyboardInterrupt, SystemExit) as e: 
            gui.trace("appJar stopped through ^c or exit()")
            self.stop()
        except Exception as e: 
            self.exception(e)
            self.stop()

You'll want to try to merge this with the code given on the slashdot article:

while True:
    try:
        root.mainloop()
        break
    except UnicodeDecodeError:
        pass

Maybe something like this:

while True:
    try:
        self.topLevel.mainloop()
    except(KeyboardInterrupt, SystemExit) as e: 
        gui.trace("appJar stopped through ^c or exit()")
        self.stop()
        break
    except UnicodeDecodeError:
        gui.trace("appJar caught UnicodeDecodeError - possible scrolling issue?")
        pass    
    except Exception as e: 
        self.exception(e)
        self.stop()
        break
jarvisteach commented 6 years ago

One slight edit to the above, add a break after calling mainloop():

while True:
    try:
        self.topLevel.mainloop()
        break
    except(KeyboardInterrupt, SystemExit) as e: 
        gui.trace("appJar stopped through ^c or exit()")
        self.stop()
        break
    except UnicodeDecodeError:
        gui.trace("appJar caught UnicodeDecodeError - possible scrolling issue?")
        pass    
    except Exception as e: 
        self.exception(e)
        self.stop()
        break
jarvisteach commented 6 years ago

Oh, and if it works, do let me know....

quasarbright commented 6 years ago

This stops the crashing, but produces some strange behavior:
In the code I provided, which used a scrollPane, scrolling with the trackpad either does nothing or scrolls an unpredictable distance with a delay of a second or two. Scrolling by dragging the scroll bar works normally. Also, usually, when you hover over the scroll bar or drag it, it turns a darker gray and goes back to light gray after the mouse leaves it or is released. Now, it stays dark until you focus another window. The same happens in a table widget which is long enough to require scrolling. It's good that it fixes the crashing, but it isn't usable with trackpad.
Scrolling through the fonts after using app.button('Accessibility', app.showAccess, icon='ACCESS') works as it did before (properly scrolling with trackpad)

jarvisteach commented 6 years ago

I'm not too surprised that you get strange behaviour - catching the exception and restarting the mainloop is a proper cludge!

The table widget is inside a scrollPane, so I'd expect to see the same behaviour from both.

The fonts are displayed in a listbox widget, which uses a really simple scrollable widget implementation, missing most of the features of the scrollpane.

I can't reproduce the error, so I can't try to troubleshoot it. I do all of my development on a mac (although it's pretty old) and don't have any issues, and haven't had problems on my Pi or the Windows machines at school.

Could you run your code with the -v flag, and let me know exactly what versions you're on?

quasarbright commented 6 years ago
appJar: 0.93.0 Python: 3.5.2 TCL: 8.5, TK: 8.5 Platform: Darwin pid: 73349
locale: en_US
tpulatha commented 6 years ago

I get the exact same crash when I try to use a tree on mac. Code coudn't be simpler:

with gui("Version 1.0") as app:
    app.setSize(300,1000)
    app.addTree('t1',someXML)
appJar: 0.93.0 Python: 3.7.0 TCL: 8.5, TK: 8.5 Platform: Darwin pid: XXXXX
locale: en_US

Didn't try to update my installations (don't want to mess with my system), outside of an update/upgrade brew.

jarvisteach commented 5 years ago

OK, I'm now seeing this same issue on my current installation (slightly newer mac).

As mentioned earlier - it is an issue with TCL and not appJar, but I will look to see what can be done about it...