From 67d40503f1ec4f0579cc0ddf85e1a554092b52bf Mon Sep 17 00:00:00 2001 From: kumattau Date: Wed, 19 Jan 2022 00:27:03 +0900 Subject: [PATCH] Fix mappings of instance method and slot alias (PyQt6 and PySide6) --- qtpy/QtCore.py | 16 ++++++++-------- qtpy/QtGui.py | 10 +++++----- qtpy/QtPrintSupport.py | 10 +++++----- qtpy/QtSql.py | 12 ++++++------ qtpy/QtWidgets.py | 28 ++++++++++++++-------------- 5 files changed, 38 insertions(+), 38 deletions(-) diff --git a/qtpy/QtCore.py b/qtpy/QtCore.py index b6f2c906..9267d5a3 100644 --- a/qtpy/QtCore.py +++ b/qtpy/QtCore.py @@ -22,7 +22,7 @@ # For issue #153 from PyQt6.QtCore import QDateTime - QDateTime.toPython = QDateTime.toPyDateTime + QDateTime.toPython = lambda self, *args, **kwargs: self.toPyDateTime(*args, **kwargs) # For issue #311 # Seems like there is an error with sip. Without first @@ -35,10 +35,10 @@ # Map missing methods QCoreApplication.exec_ = QCoreApplication.exec - QEventLoop.exec_ = QEventLoop.exec - QThread.exec_ = QThread.exec - - QLibraryInfo.location = QLibraryInfo.path + QEventLoop.exec_ = lambda self, *args, **kwargs: self.exec(*args, **kwargs) + QThread.exec_ = lambda self, *args, **kwargs: self.exec(*args, **kwargs) + + QLibraryInfo.location = QLibraryInfo.path # Those are imported from `import *` del pyqtSignal, pyqtBoundSignal, pyqtSlot, pyqtProperty, QT_VERSION_STR @@ -80,9 +80,9 @@ # Map DeprecationWarning methods QCoreApplication.exec_ = QCoreApplication.exec - QEventLoop.exec_ = QEventLoop.exec - QThread.exec_ = QThread.exec - QTextStreamManipulator.exec_ = QTextStreamManipulator.exec + QEventLoop.exec_ = lambda self, *args, **kwargs: self.exec(*args, **kwargs) + QThread.exec_ = lambda self, *args, **kwargs: self.exec(*args, **kwargs) + QTextStreamManipulator.exec_ = lambda self, *args, **kwargs: self.exec(*args, **kwargs) elif PYSIDE2: from PySide2.QtCore import * diff --git a/qtpy/QtGui.py b/qtpy/QtGui.py index f949fe45..1bb9a743 100644 --- a/qtpy/QtGui.py +++ b/qtpy/QtGui.py @@ -15,12 +15,12 @@ from PyQt6 import QtGui from PyQt6.QtGui import * from PyQt6.QtOpenGL import * - QFontMetrics.width = QFontMetrics.horizontalAdvance + QFontMetrics.width = lambda self, *args, **kwargs: self.horizontalAdvance(*args, **kwargs) # Map missing/renamed methods - QDrag.exec_ = QDrag.exec + QDrag.exec_ = lambda self, *args, **kwargs: self.exec(*args, **kwargs) QGuiApplication.exec_ = QGuiApplication.exec - QTextDocument.print_ = QTextDocument.print + QTextDocument.print_ = lambda self, *args, **kwargs: self.print(*args, **kwargs) # Allow unscoped access for enums inside the QtGui module from .enums_compat import promote_enums @@ -33,10 +33,10 @@ elif PYSIDE6: from PySide6.QtGui import * from PySide6.QtOpenGL import * - QFontMetrics.width = QFontMetrics.horizontalAdvance + QFontMetrics.width = lambda self, *args, **kwargs: self.horizontalAdvance(*args, **kwargs) # Map DeprecationWarning methods - QDrag.exec_ = QDrag.exec + QDrag.exec_ = lambda self, *args, **kwargs: self.exec(*args, **kwargs) QGuiApplication.exec_ = QGuiApplication.exec else: raise PythonQtError('No Qt bindings could be found') diff --git a/qtpy/QtPrintSupport.py b/qtpy/QtPrintSupport.py index 85cbb981..4fcec32b 100644 --- a/qtpy/QtPrintSupport.py +++ b/qtpy/QtPrintSupport.py @@ -15,14 +15,14 @@ from PyQt5.QtPrintSupport import * elif PYQT6: from PyQt6.QtPrintSupport import * - QPageSetupDialog.exec_ = QPageSetupDialog.exec - QPrintDialog.exec_ = QPrintDialog.exec - QPrintPreviewWidget.print_ = QPrintPreviewWidget.print + QPageSetupDialog.exec_ = lambda self, *args, **kwargs: self.exec(*args, **kwargs) + QPrintDialog.exec_ = lambda self, *args, **kwargs: self.exec(*args, **kwargs) + QPrintPreviewWidget.print_ = lambda self, *args, **kwargs: self.print(*args, **kwargs) elif PYSIDE6: from PySide6.QtPrintSupport import * # Map DeprecationWarning methods - QPageSetupDialog.exec_ = QPageSetupDialog.exec - QPrintDialog.exec_ = QPrintDialog.exec + QPageSetupDialog.exec_ = lambda self, *args, **kwargs: self.exec(*args, **kwargs) + QPrintDialog.exec_ = lambda self, *args, **kwargs: self.exec(*args, **kwargs) elif PYSIDE2: from PySide2.QtPrintSupport import * else: diff --git a/qtpy/QtSql.py b/qtpy/QtSql.py index 3cdaaf33..038c34db 100644 --- a/qtpy/QtSql.py +++ b/qtpy/QtSql.py @@ -13,15 +13,15 @@ from PyQt5.QtSql import * elif PYQT6: from PyQt6.QtSql import * - QSqlDatabase.exec_ = QSqlDatabase.exec - QSqlQuery.exec_ = QSqlQuery.exec - QSqlResult.exec_ = QSqlResult.exec + QSqlDatabase.exec_ = lambda self, *args, **kwargs: self.exec(*args, **kwargs) + QSqlQuery.exec_ = lambda self, *args, **kwargs: self.exec(*args, **kwargs) + QSqlResult.exec_ = lambda self, *args, **kwargs: self.exec(*args, **kwargs) elif PYSIDE6: from PySide6.QtSql import * # Map DeprecationWarning methods - QSqlDatabase.exec_ = QSqlDatabase.exec - QSqlQuery.exec_ = QSqlQuery.exec - QSqlResult.exec_ = QSqlResult.exec + QSqlDatabase.exec_ = lambda self, *args, **kwargs: self.exec(*args, **kwargs) + QSqlQuery.exec_ = lambda self, *args, **kwargs: self.exec(*args, **kwargs) + QSqlResult.exec_ = lambda self, *args, **kwargs: self.exec(*args, **kwargs) elif PYSIDE2: from PySide2.QtSql import * else: diff --git a/qtpy/QtWidgets.py b/qtpy/QtWidgets.py index 84639330..70996ae7 100644 --- a/qtpy/QtWidgets.py +++ b/qtpy/QtWidgets.py @@ -18,15 +18,15 @@ from PyQt6.QtOpenGLWidgets import QOpenGLWidget # Map missing/renamed methods - QTextEdit.setTabStopWidth = QTextEdit.setTabStopDistance - QTextEdit.tabStopWidth = QTextEdit.tabStopDistance - QTextEdit.print_ = QTextEdit.print - QPlainTextEdit.setTabStopWidth = QPlainTextEdit.setTabStopDistance - QPlainTextEdit.tabStopWidth = QPlainTextEdit.tabStopDistance - QPlainTextEdit.print_ = QPlainTextEdit.print + QTextEdit.setTabStopWidth = lambda self, *args, **kwargs: self.setTabStopDistance(*args, **kwargs) + QTextEdit.tabStopWidth = lambda self, *args, **kwargs: self.tabStopDistance(*args, **kwargs) + QTextEdit.print_ = lambda self, *args, **kwargs: self.print(*args, **kwargs) + QPlainTextEdit.setTabStopWidth = lambda self, *args, **kwargs: self.setTabStopDistance(*args, **kwargs) + QPlainTextEdit.tabStopWidth = lambda self, *args, **kwargs: self.tabStopDistance(*args, **kwargs) + QPlainTextEdit.print_ = lambda self, *args, **kwargs: self.print(*args, **kwargs) QApplication.exec_ = QApplication.exec - QDialog.exec_ = QDialog.exec - QMenu.exec_ = QMenu.exec + QDialog.exec_ = lambda self, *args, **kwargs: self.exec(*args, **kwargs) + QMenu.exec_ = lambda self, *args, **kwargs: self.exec(*args, **kwargs) # Allow unscoped access for enums inside the QtWidgets module from .enums_compat import promote_enums @@ -40,15 +40,15 @@ from PySide6.QtOpenGLWidgets import QOpenGLWidget # Map missing/renamed methods - QTextEdit.setTabStopWidth = QTextEdit.setTabStopDistance - QTextEdit.tabStopWidth = QTextEdit.tabStopDistance - QPlainTextEdit.setTabStopWidth = QPlainTextEdit.setTabStopDistance - QPlainTextEdit.tabStopWidth = QPlainTextEdit.tabStopDistance + QTextEdit.setTabStopWidth = lambda self, *args, **kwargs: self.setTabStopDistance(*args, **kwargs) + QTextEdit.tabStopWidth = lambda self, *args, **kwargs: self.tabStopDistance(*args, **kwargs) + QPlainTextEdit.setTabStopWidth = lambda self, *args, **kwargs: self.setTabStopDistance(*args, **kwargs) + QPlainTextEdit.tabStopWidth = lambda self, *args, **kwargs: self.tabStopDistance(*args, **kwargs) # Map DeprecationWarning methods QApplication.exec_ = QApplication.exec - QDialog.exec_ = QDialog.exec - QMenu.exec_ = QMenu.exec + QDialog.exec_ = lambda self, *args, **kwargs: self.exec(*args, **kwargs) + QMenu.exec_ = lambda self, *args, **kwargs: self.exec(*args, **kwargs) elif PYSIDE2: from PySide2.QtWidgets import * else: