kklmn / xrt

Package xrt (XRayTracer) is a python software library for ray tracing and wave propagation in x-ray regime. It is primarily meant for modeling synchrotron sources, beamlines and beamline elements.
MIT License
80 stars 29 forks source link

Anaconda macOS pyQt wheelEvent error #106

Open glebdovzhenko opened 2 years ago

glebdovzhenko commented 2 years ago

Hello,

I'm running xrtQook on Anaconda on macOS Monterey 12.3, and there are some issues with the UI:

1) after launching xrtGlow with the glasses button the parameter lists in xrtQook freeze and don't accept text anymore 2) there are some none-crashing errors like these: [6485:49923:0326/151935.664605:ERROR:gl_context_cgl.cc(136)] Error creating context. [6485:49923:0326/151935.665435:ERROR:gl_context_cgl.cc(136)] Error creating context. [6485:49923:0326/151935.665758:ERROR:gl_context_cgl.cc(136)] Error creating context. [6485:49923:0326/151935.666041:ERROR:gl_context_cgl.cc(136)] Error creating context. 2022-03-26 15:20:35.164 python[6485:68991] GLUT Warning: glutInit being called a second time. QOpenGLContext::swapBuffers() called with non-exposed window, behavior is undefined QOpenGLContext::swapBuffers() called with non-exposed window, behavior is undefined QOpenGLContext::swapBuffers() called with non-exposed window, behavior is undefined QOpenGLContext::swapBuffers() called with non-exposed window, behavior is undefined 3) the UI randomly crashes with this error: Traceback (most recent call last): File "/Users/glebdovzhenko/.conda/envs/XRTcalc/lib/python3.9/site-packages/xrt/gui/commons/qt.py", line 148, in wheelEvent return self.parent().wheelEvent(*args, **kwargs) RuntimeError: no access to protected functions or signals for objects not created from Python /Users/glebdovzhenko/.conda/envs/XRTcalc/bin/pythonw: line 3: 6485 Abort trap: 6 /Users/glebdovzhenko/.conda/envs/XRTcalc/python.app/Contents/MacOS/python "$@"

Same behaviour with python and pythonw. I've installed all packages following the instructions through conda, except for xrt itself which I installed through pip because I wanted 1.4 version. Conda list and pip freeze are in attachment.

Thanks!

condalist.txt pipfreeze.txt

glebdovzhenko commented 2 years ago

BTW same thing is happening for me on Python 3.8. Perhaps I need to downgrade Qt/pyQt?

condalist.txt pipfreeze.txt

kklmn commented 2 years ago

Hi,

What do you see in the Qook's welcome page under "Your system"?

glebdovzhenko commented 2 years ago

Thanks for the quick response!

Your system macOS-10.16, Python 3.8.13 Qt 5.9.7, PyQt5 5.9.2 OpenGL 3.1.6 pyopencl 2022.1 xrt 1.4.0 in /Users/glebdovzhenko/.conda/envs/XRTcalc.3.8/lib/python3.8/site-packages, this is the latest version at PyPI

yxrmz commented 2 years ago

Hi, wheelEvent and freezes are known issues on MacOS/Qt, there's no quick solution other than disabling some functions in the code for mac users. I'm working on a big update for Glow at the moment that should solve the context-related warnings, might be available in couple months.

kklmn commented 2 years ago

@glebdovzhenko, if you're ok with experimenting with your env, remove PyQt and install PySide2 instead. I have no idea how it would behave on macos. Note, PySide6 does not work with xrt (yet).

glebdovzhenko commented 2 years ago

@kklmn I have tried PySide2 (with python 3.8) like you suggested. I think (?) the freezes have stopped, but the wheelEvent crashes have not. Thanks! Now I can work with it if I remember not to use the mouse wheel. Does it simplify the issue if it's just the wheelEvents, or is there still no quick solution?

kklmn commented 2 years ago

Because the exception doesn't happen in my system, I cannot look into it. Roman is not a mac guy too. But you can try to catch the exception yourself as you know where it happens. Simply put pass in the except RuntimeError: clause and see what you get.

glebdovzhenko commented 2 years ago

So the exception happens in xrt/gui/commons/qt.py, line 183. If I understand everything correctly, the purpose of the QComboBox.wheelEvent() override is that when the user is not focused on the ComboBox, the values of the ComboBox are not being changed by the mouse wheel. And I would guess that the purpose of the else clause (where the error happens) is to generate a QTableView.wheelEvent instead, so that even when the user is scrolling over a ComboBox, the TableView is still being scrolled. Anyway, I just commented the else clause out entirely and did not find any annoyances with the scrolling: no exceptions, no ComboBox issues. I guess that's a solution, if it does not break things for Windows/Linux.

kklmn commented 2 years ago

Yes, the whole derived class was created for this purpose: with the default QComboBox, a mouse scroll affects the first combobox in the main tree view but doesn't scroll the tree view itself. This was pretty annoying. Ok, since the solution doesn't work on macOS, we will need to look at it again.

kklmn commented 2 years ago

And thank you for testing!