Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 35 additions & 20 deletions pyvistaqt/rwi.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@

Changes by Chen Jintao, Aug. 2021
Support for PySide6

Changes by Eric Larson and Guillaume Favelier, Apr. 2022
Support for PyQt6
"""

# Check whether a specific PyQt implementation was chosen
Expand Down Expand Up @@ -200,15 +203,27 @@
else:
raise ImportError("Unknown base class for QVTKRenderWindowInteractor " + QVTKRWIBase)

CursorShape = Qt.CursorShape if PyQtImpl == "PyQt6" else Qt
MouseButton = Qt.MouseButton if PyQtImpl == "PyQt6" else Qt
WindowType = Qt.WindowType if PyQtImpl == "PyQt6" else Qt
WidgetAttribute = Qt.WidgetAttribute if PyQtImpl == "PyQt6" else Qt
KeyboardModifier = Qt.KeyboardModifier if PyQtImpl == "PyQt6" else Qt
FocusPolicy = Qt.FocusPolicy if PyQtImpl == "PyQt6" else Qt
SizePolicy = QSizePolicy.Policy if PyQtImpl == "PyQt6" else QSizePolicy
ConnectionType = Qt.ConnectionType if PyQtImpl == "PyQt6" else Qt
Key = Qt.Key if PyQtImpl == "PyQt6" else Qt
if PyQtImpl == 'PyQt6':
CursorShape = Qt.CursorShape
MouseButton = Qt.MouseButton
WindowType = Qt.WindowType
WidgetAttribute = Qt.WidgetAttribute
KeyboardModifier = Qt.KeyboardModifier
FocusPolicy = Qt.FocusPolicy
ConnectionType = Qt.ConnectionType
Key = Qt.Key
SizePolicy = QSizePolicy.Policy
EventType = QEvent.Type
else:
CursorShape = MouseButton = WindowType = WidgetAttribute = \
KeyboardModifier = FocusPolicy = ConnectionType = Key = Qt
SizePolicy = QSizePolicy
EventType = QEvent

if PyQtImpl in ('PyQt4', 'PySide'):
MiddleButton = MouseButton.MidButton
else:
MiddleButton = MouseButton.MiddleButton


def _get_event_pos(ev):
Expand Down Expand Up @@ -497,14 +512,14 @@ def _GetCtrlShift(self, ev):
ctrl = shift = False

if hasattr(ev, 'modifiers'):
if ev.modifiers() & Qt.ShiftModifier:
if ev.modifiers() & KeyboardModifier.ShiftModifier:
shift = True
if ev.modifiers() & Qt.ControlModifier:
if ev.modifiers() & KeyboardModifier.ControlModifier:
ctrl = True
else:
if self.__saveModifiers & Qt.ShiftModifier:
if self.__saveModifiers & KeyboardModifier.ShiftModifier:
shift = True
if self.__saveModifiers & Qt.ControlModifier:
if self.__saveModifiers & KeyboardModifier.ControlModifier:
ctrl = True

return ctrl, shift
Expand Down Expand Up @@ -548,18 +563,18 @@ def mousePressEvent(self, ev):
pos_x, pos_y = _get_event_pos(ev)
ctrl, shift = self._GetCtrlShift(ev)
repeat = 0
if ev.type() == QEvent.MouseButtonDblClick:
if ev.type() == EventType.MouseButtonDblClick:
repeat = 1
self._setEventInformation(pos_x, pos_y,
ctrl, shift, chr(0), repeat, None)

self._ActiveButton = ev.button()

if self._ActiveButton == Qt.LeftButton:
if self._ActiveButton == MouseButton.LeftButton:
self._Iren.LeftButtonPressEvent()
elif self._ActiveButton == Qt.RightButton:
elif self._ActiveButton == MouseButton.RightButton:
self._Iren.RightButtonPressEvent()
elif self._ActiveButton == Qt.MidButton:
elif self._ActiveButton == MiddleButton:
self._Iren.MiddleButtonPressEvent()

def mouseReleaseEvent(self, ev):
Expand All @@ -568,11 +583,11 @@ def mouseReleaseEvent(self, ev):
self._setEventInformation(pos_x, pos_y,
ctrl, shift, chr(0), 0, None)

if self._ActiveButton == Qt.LeftButton:
if self._ActiveButton == MouseButton.LeftButton:
self._Iren.LeftButtonReleaseEvent()
elif self._ActiveButton == Qt.RightButton:
elif self._ActiveButton == MouseButton.RightButton:
self._Iren.RightButtonReleaseEvent()
elif self._ActiveButton == Qt.MidButton:
elif self._ActiveButton == MiddleButton:
self._Iren.MiddleButtonReleaseEvent()

def mouseMoveEvent(self, ev):
Expand Down