Skip to content

Commit

Permalink
Remove QAction wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
dalthviz committed Dec 13, 2024
1 parent 6ce8edb commit 6643eac
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 31 deletions.
28 changes: 2 additions & 26 deletions qtpy/QtGui.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ def movePositionPatched(

# Follow similar approach for `QDropEvent` and child classes
QDropEvent.position = lambda self: self.posF()

if PYQT6 or PYSIDE6:
# Part of the fix for https://github.com/spyder-ide/qtpy/issues/394
for _class in (
Expand Down Expand Up @@ -264,27 +265,8 @@ def movePositionPatched(
QDropEvent.posF = lambda self: self.position()


# Make `QAction.setShortcut` and `QAction.setShortcuts` compatible with Qt>=6.4
if PYQT5 or PYSIDE2 or parse(_qt_version) < parse("6.4"):

class _QAction(QAction):
old_set_shortcut = QAction.setShortcut
old_set_shortcuts = QAction.setShortcuts

def setShortcut(self, shortcut):
return set_shortcut(
self,
shortcut,
old_set_shortcut=_QAction.old_set_shortcut,
)

def setShortcuts(self, shortcuts):
return set_shortcuts(
self,
shortcuts,
old_set_shortcuts=_QAction.old_set_shortcuts,
)

# Make `QAction.setShortcut` and `QAction.setShortcuts` compatible with Qt>=6.4
_action_set_shortcut = partialmethod(
set_shortcut,
old_set_shortcut=QAction.setShortcut,
Expand All @@ -295,9 +277,3 @@ def setShortcuts(self, shortcuts):
)
QAction.setShortcut = _action_set_shortcut
QAction.setShortcuts = _action_set_shortcuts
# Despite the two previous lines!
if (
QAction.setShortcut is not _action_set_shortcut
or QAction.setShortcuts is not _action_set_shortcuts
):
QAction = _QAction
4 changes: 1 addition & 3 deletions qtpy/QtWidgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ def __getattr__(name):
)
from PyQt6.QtWidgets import *

from qtpy.QtGui import QAction # See spyder-ide/qtpy#461

# Attempt to import QOpenGLWidget, but if that fails,
# don't raise an exception until the name is explicitly accessed.
# See https://github.com/spyder-ide/qtpy/pull/387/
Expand Down Expand Up @@ -211,8 +209,8 @@ def __getattr__(name):
"directory",
)

# Make `addAction` compatible with Qt6 >= 6.4
if PYQT5 or PYSIDE2 or parse(_qt_version) < parse("6.4"):
# Make `addAction` compatible with Qt6 >= 6.4
_menu_add_action = partialmethod(
add_action,
old_add_action=QMenu.addAction,
Expand Down
4 changes: 2 additions & 2 deletions qtpy/tests/test_qtwidgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def test_QMenu_functions(qtbot):
QtWidgets.QMenu.exec_(menu.actions(), QtCore.QPoint(1, 1))


def test_QMenu_submenu_instance(qtbot):
def test_QMenu_instance(qtbot):
"""Test `QtWidgets.QMenu` submenus are `QtWidgets.QMenu` instances."""
menu = QtWidgets.QMenu()
menu.addMenu("test")
Expand All @@ -164,7 +164,7 @@ def test_QToolBar_functions(qtbot):
)


def test_QToolBar_submenu_instance(qtbot):
def test_QToolBar_instance(qtbot):
"""Test `QtWidgets.QToolBar` passes `isinstance` checks."""
window = QtWidgets.QMainWindow()
new_toolbar = window.addToolBar("Toolbar title")
Expand Down

0 comments on commit 6643eac

Please sign in to comment.