Skip to content

Commit

Permalink
Fix mappings of instance method and slot alias (PyQt6 and PySide6)
Browse files Browse the repository at this point in the history
  • Loading branch information
kumattau committed Jan 18, 2022
1 parent 3d17033 commit 67d4050
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 38 deletions.
16 changes: 8 additions & 8 deletions qtpy/QtCore.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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 *
Expand Down
10 changes: 5 additions & 5 deletions qtpy/QtGui.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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')
10 changes: 5 additions & 5 deletions qtpy/QtPrintSupport.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
12 changes: 6 additions & 6 deletions qtpy/QtSql.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
28 changes: 14 additions & 14 deletions qtpy/QtWidgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down

0 comments on commit 67d4050

Please sign in to comment.