Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PR: Add mappings for QMouseEvent methods #408

Merged
merged 17 commits into from
Feb 23, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
0bea1c5
Might close https://github.com/spyder-ide/qtpy/issues/394
StSav012 Feb 13, 2023
f3239aa
Rephrase a comment, as @CAM-Gerlach suggested
StSav012 Feb 17, 2023
8ea86ee
Attempt to test the fix for https://github.com/spyder-ide/qtpy/issues…
StSav012 Feb 17, 2023
8ffd2f0
Attempt no. 2 to test the fix for https://github.com/spyder-ide/qtpy/…
StSav012 Feb 17, 2023
83fbfcb
Attempt no. 3 to test the fix for https://github.com/spyder-ide/qtpy/…
StSav012 Feb 17, 2023
81a9612
Attempt no. 4 to test the fix for https://github.com/spyder-ide/qtpy/…
StSav012 Feb 17, 2023
16f619f
Format the docstring as suggested by @CAM-Gerlach
StSav012 Feb 18, 2023
e532db5
Ensure the created window is of sufficient size to point at
StSav012 Feb 18, 2023
c6a2468
Don't wait before moving and clicking the mouse
StSav012 Feb 18, 2023
6c90643
Test run: don't close the window at the end
StSav012 Feb 18, 2023
e90bb1a
Test run: create an instance of `QApplication` before `pytestqt` crashes
StSav012 Feb 18, 2023
966be08
Test run: make `pytestqt` use the Qt API detected by `QtPy`
StSav012 Feb 18, 2023
a1b3059
Revert "Test run: make `pytestqt` use the Qt API detected by `QtPy`"
StSav012 Feb 18, 2023
7562a57
Revert "Test run: create an instance of `QApplication` before `pytest…
StSav012 Feb 18, 2023
24fc073
Don't close the window at the end
StSav012 Feb 18, 2023
0df0983
Merge remote-tracking branch 'origin/issue-394' into issue-394
StSav012 Feb 21, 2023
e0ef0b1
Remove patch that “may be limited to PySide-5.11a1 only”
StSav012 Feb 11, 2023
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
13 changes: 13 additions & 0 deletions qtpy/QtGui.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,16 @@ def movePositionPatched(
) -> bool:
return movePosition(self, operation, mode, n)
QTextCursor.movePosition = movePositionPatched

# Fix https://github.com/spyder-ide/qtpy/issues/394
if PYQT5 or PYSIDE2:
from qtpy.QtCore import QPointF as __QPointF
QMouseEvent.position = lambda self: __QPointF(float(self.x()), float(self.y()))
QMouseEvent.globalPosition = lambda self: __QPointF(float(self.globalX()), float(self.globalY()))
if PYQT6 or PYSIDE6:
QMouseEvent.pos = lambda self: self.position().toPoint()
QMouseEvent.x = lambda self: self.position().toPoint().x()
QMouseEvent.y = lambda self: self.position().toPoint().y()
QMouseEvent.globalPos = lambda self: self.globalPosition().toPoint()
QMouseEvent.globalX = lambda self: self.globalPosition().toPoint().x()
QMouseEvent.globalY = lambda self: self.globalPosition().toPoint().y()
35 changes: 34 additions & 1 deletion qtpy/tests/test_qtgui.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import pytest

from qtpy import PYQT5, PYQT_VERSION, PYSIDE2, PYSIDE6, QtGui
from qtpy import PYQT5, PYQT_VERSION, PYSIDE2, PYSIDE6, QtCore, QtGui, QtWidgets
from qtpy.tests.utils import not_using_conda


Expand Down Expand Up @@ -61,6 +61,39 @@ def test_enum_access():
assert QtGui.QIcon.Normal == QtGui.QIcon.Mode.Normal
assert QtGui.QImage.Format_Invalid == QtGui.QImage.Format.Format_Invalid


@pytest.mark.skipif(
sys.platform.startswith('linux') and not_using_conda(),
reason="Fatal Python error: Aborted on Linux CI when not using conda")
@pytest.mark.skipif(
sys.platform == 'darwin' and sys.version_info[:2] == (3, 7),
reason="Stalls on macOS CI with Python 3.7")
def test_QMouseEvent_pos_functions(qtbot):
"""Test `QMouseEvent.pos` and related functions obsolete in Qt6,
test `QMouseEvent.position` and related functions missing from Qt5"""
StSav012 marked this conversation as resolved.
Show resolved Hide resolved

class Window(QtWidgets.QMainWindow):
def mouseDoubleClickEvent(self, event: QtGui.QMouseEvent) -> None:
assert event.globalPos() - event.pos() == self.mapToParent(QtCore.QPoint(0, 0))
assert event.pos().x() == event.x()
assert event.pos().y() == event.y()
assert event.globalPos().x() == event.globalX()
assert event.globalPos().y() == event.globalY()
assert event.position().x() == event.pos().x()
assert event.position().y() == event.pos().y()
assert event.globalPosition().x() == event.globalPos().x()
assert event.globalPosition().y() == event.globalPos().y()

event.accept()

window = Window()
window.show()

QtCore.QTimer.singleShot(100, lambda: qtbot.mouseMove(window, QtCore.QPoint(42, 6 * 9)))
CAM-Gerlach marked this conversation as resolved.
Show resolved Hide resolved
QtCore.QTimer.singleShot(200, lambda: qtbot.mouseDClick(window, QtCore.Qt.LeftButton))
QtCore.QTimer.singleShot(300, lambda: window.close())


@pytest.mark.skipif(not (PYSIDE2 or PYSIDE6), reason="PySide{2,6} specific test")
def test_qtextcursor_moveposition():
"""Test monkeypatched QTextCursor.movePosition"""
Expand Down