pyvista / pyvista-gui

A Graphical User Interface built atop PyVista
MIT License
14 stars 1 forks source link

Click/drag off screen crashes app #6

Open banesullivan opened 4 years ago

banesullivan commented 4 years ago

2020-02-11 21 02 20

Click the camera and drag off screen then a crash happens:

(dev) ➜  pyvista_gui git:(feat/expand) python -m pyvista_gui
DEBUG:pyvista_gui.gui:GUI initialized
DEBUG:matplotlib.pyplot:Loaded backend macosx version unknown.
DEBUG:matplotlib.pyplot:Loaded backend qt5agg version unknown.
DEBUG:matplotlib.pyplot:Loaded backend Qt5Agg version unknown.
DEBUG:asyncio:Using selector: KqueueSelector
Traceback (most recent call last):
  File "/Users/bane/anaconda3/envs/dev/lib/python3.7/site-packages/vtkmodules/qt/QVTKRenderWindowInteractor.py", line 474, in mouseMoveEvent
    ctrl, shift, chr(0), 0, None)
  File "/Users/bane/anaconda3/envs/dev/lib/python3.7/site-packages/vtkmodules/qt/QVTKRenderWindowInteractor.py", line 420, in _setEventInformation
    scale = self._getPixelRatio()
  File "/Users/bane/anaconda3/envs/dev/lib/python3.7/site-packages/vtkmodules/qt/QVTKRenderWindowInteractor.py", line 412, in _getPixelRatio
    return QApplication.devicePixelRatio()
TypeError: devicePixelRatio(self): first argument of unbound method must have type 'QGuiApplication'
[1]    37123 abort      python -m pyvista_gui
akaszynski commented 4 years ago

This seems to be an internal, vtk error. We can override it or protect it with a super and catch the error.

ali-zakaria commented 4 years ago

I faced the same issue when using QVTKRenderWindowInteractor on a remote desktop, I opened an issue on VTK gitlab repo: https://gitlab.kitware.com/vtk/vtk/-/issues/17854

If anyone needs an urgent fix for this issue, this dirty workaround can do the job:

_getPixelRatio_BUG = QVTKRenderWindowInteractor._getPixelRatio
def _getPixelRatio_WORKAROUND(self):
    try:
        return _getPixelRatio_BUG()
    except Exception as err:
        print("Exception QVTKRenderWindowInteractor._getPixelRatio: {0}".format(err))
        return Qt.QApplication.instance().devicePixelRatio()
setattr(QVTKRenderWindowInteractor, '_getPixelRatio_WORKAROUND', _getPixelRatio_WORKAROUND)
QVTKRenderWindowInteractor._getPixelRatio = _getPixelRatio_WORKAROUND

I added these lines to my main function, right before calling app = Qt.QApplication(sys.argv)

akaszynski commented 4 years ago

Nice fix @zakaria220

@banesullivan, should we consider incorporating this into pyvista? Perhaps in qt_plotting? We can then conditionally add it for unpatched versions of vtk.

banesullivan commented 4 years ago

Ah, that's a nifty little hack of a solution! Thanks, @zakaria220!

@akaszynski: I'm all for adding it directly into pyvista and just overriding the method on our class rather than monkey-patching

ali-zakaria commented 4 years ago

VTK 9.0.0 has been released with a fix https://github.com/Kitware/VTK/releases/tag/v9.0.0