|
14 | 14 | import numpy as np |
15 | 15 | from phylib.utils import Bunch, connect, emit |
16 | 16 |
|
17 | | -from phy.gui.qt import QEvent, QOpenGLWindow, Qt |
| 17 | +from phy.gui.qt import QOpenGLWindow, Qt |
18 | 18 |
|
19 | 19 | from . import gloo |
20 | 20 | from .gloo import gl |
@@ -824,41 +824,19 @@ def keyReleaseEvent(self, e): |
824 | 824 | self._key_event('key_release', e) |
825 | 825 | self._current_key_event = None |
826 | 826 |
|
827 | | - def event(self, e): # pragma: no cover |
828 | | - """Touch event.""" |
829 | | - out = super().event(e) |
830 | | - t = e.type() |
831 | | - # Two-finger pinch. |
832 | | - if t == QEvent.TouchBegin: |
833 | | - self.emit('pinch_begin') |
834 | | - elif t == QEvent.TouchEnd: |
835 | | - self.emit('pinch_end') |
836 | | - elif t == QEvent.Gesture: |
837 | | - gesture = e.gesture(Qt.PinchGesture) |
838 | | - if gesture: |
839 | | - (x, y) = gesture.centerPoint().x(), gesture.centerPoint().y() |
840 | | - scale = gesture.scaleFactor() |
841 | | - last_scale = gesture.lastScaleFactor() |
842 | | - rotation = gesture.rotationAngle() |
843 | | - self.emit( |
844 | | - 'pinch', |
845 | | - pos=(x, y), |
846 | | - scale=scale, |
847 | | - last_scale=last_scale, |
848 | | - rotation=rotation, |
849 | | - ) |
850 | | - # General touch event. |
851 | | - elif t == QEvent.TouchUpdate: |
852 | | - points = e.touchPoints() |
853 | | - # These variables are lists of (x, y) coordinates. |
854 | | - pos, last_pos = zip( |
855 | | - *[ |
856 | | - ((p.pos().x(), p.pos.y()), (p.lastPos().x(), p.lastPos.y())) |
857 | | - for p in points |
858 | | - ] |
859 | | - ) |
860 | | - self.emit('touch', pos=pos, last_pos=last_pos) |
861 | | - return out |
| 827 | + def close(self): |
| 828 | + """Close the OpenGL canvas. |
| 829 | +
|
| 830 | + The Qt offscreen platform plugin crashes when closing a shown QOpenGLWindow after |
| 831 | + rendering. Hiding the window avoids the native crash and is sufficient for headless |
| 832 | + test cleanup. |
| 833 | + """ |
| 834 | + from os import environ |
| 835 | + |
| 836 | + if environ.get('QT_QPA_PLATFORM') == 'offscreen': |
| 837 | + self.hide() |
| 838 | + return |
| 839 | + super().close() |
862 | 840 |
|
863 | 841 | def update(self): |
864 | 842 | """Update the OpenGL canvas.""" |
|
0 commit comments