Skip to content

Commit

Permalink
Merge pull request #403 from mottosso/mottosso-patch-1
Browse files Browse the repository at this point in the history
Update Qt.py
  • Loading branch information
mottosso authored May 7, 2024
2 parents 5a88175 + bee5c0f commit 33b83f2
Show file tree
Hide file tree
Showing 3 changed files with 246 additions and 35 deletions.
70 changes: 53 additions & 17 deletions Qt.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
DOCUMENTATION
Qt.py was born in the film and visual effects industry to address
the growing need for the development of software capable of running
with more than one flavour of the Qt bindings for Python.
with more than one flavour of the Qt bindings for Python.
Supported Binding: PySide, PySide2, PySide6, PyQt4, PyQt5
1. Build for one, run with all
Expand Down Expand Up @@ -47,7 +47,7 @@
import json


__version__ = "1.3.10"
__version__ = "1.4.0"

# Enable support for `from Qt import *`
__all__ = []
Expand Down Expand Up @@ -112,7 +112,6 @@
"QGenericArgument",
"QGenericReturnArgument",
"QItemSelection",
"QItemSelectionModel",
"QItemSelectionRange",
"QIODevice",
"QLibraryInfo",
Expand Down Expand Up @@ -152,7 +151,6 @@
"QSize",
"QSizeF",
"QSocketNotifier",
"QStringListModel",
"QSysInfo",
"QSystemSemaphore",
"QT_TRANSLATE_NOOP",
Expand Down Expand Up @@ -197,8 +195,6 @@
"qUnregisterResourceData",
"qVersion",
"qWarning",
"Signal",
"Slot"
],
"QtGui": [
"QAbstractTextDocumentLayout",
Expand Down Expand Up @@ -271,7 +267,6 @@
"QQuaternion",
"QRadialGradient",
"QRegion",
"QRegExpValidator",
"QResizeEvent",
"QSessionManager",
"QShortcutEvent",
Expand Down Expand Up @@ -930,6 +925,9 @@ def createWidget(self, class_name, parent=None, name=""):
These members from the original submodule are misplaced relative PySide2
NOTE: For bindings where a member is not replaced, they still
need to be added such that they are added to Qt.py
"""
_misplaced_members = {
"PySide6": {
Expand All @@ -943,6 +941,9 @@ def createWidget(self, class_name, parent=None, name=""):
"QtCore.QItemSelection": "QtCore.QItemSelection",
"QtCore.QItemSelectionModel": "QtCore.QItemSelectionModel",
"QtCore.QItemSelectionRange": "QtCore.QItemSelectionRange",
"QtCore.QRegularExpression": "QtCore.QRegExp",
"QtStateMachine.QStateMachine": "QtCore.QStateMachine",
"QtStateMachine.QState": "QtCore.QState",
"QtGui.QRegularExpressionValidator": "QtGui.QRegExpValidator",
"QtGui.QShortcut": "QtWidgets.QShortcut",
"QtGui.QAction": "QtWidgets.QAction",
Expand All @@ -961,14 +962,16 @@ def createWidget(self, class_name, parent=None, name=""):
"QtCompat.qInstallMessageHandler", _qInstallMessageHandler
],
"QtWidgets.QStyleOptionViewItem": "QtCompat.QStyleOptionViewItemV4",
"QtMultimedia.QSound": "QtMultimedia.QSound",
"QtWidgets.QActionGroup": "QtGui.QActionGroup",
},
"PySide2": {
"QtGui.QStringListModel": "QtCore.QStringListModel",
"QtGui.QStringListModel": "QtCore.QStringListModel",
"QtCore.Property": "QtCore.Property",
"QtCore.Signal": "QtCore.Signal",
"QtCore.Slot": "QtCore.Slot",
"QtCore.QRegExp": "QtCore.QRegExp",
"QtWidgets.QShortcut": "QtWidgets.QShortcut",
"QtGui.QRegExpValidator": "QtGui.QRegExpValidator",
"QtCore.QAbstractProxyModel": "QtCore.QAbstractProxyModel",
"QtCore.QSortFilterProxyModel": "QtCore.QSortFilterProxyModel",
"QtCore.QItemSelection": "QtCore.QItemSelection",
Expand All @@ -989,7 +992,6 @@ def createWidget(self, class_name, parent=None, name=""):
"QtCompat.qInstallMessageHandler", _qInstallMessageHandler
],
"QtWidgets.QStyleOptionViewItem": "QtCompat.QStyleOptionViewItemV4",
"QtMultimedia.QSound": "QtMultimedia.QSound",
},
"PyQt5": {
"QtCore.pyqtProperty": "QtCore.Property",
Expand All @@ -1000,6 +1002,8 @@ def createWidget(self, class_name, parent=None, name=""):
"sip.unwrapinstance": ["QtCompat.getCppPointer", _getcpppointer],
"sip.isdeleted": ["QtCompat.isValid", _isvalid],
"QtWidgets.qApp": "QtWidgets.QApplication.instance()",
"QtGui.QRegExpValidator": "QtGui.QRegExpValidator",
"QtCore.QRegExp": "QtCore.QRegExp",
"QtCore.QCoreApplication.translate": [
"QtCompat.translate", _translate
],
Expand All @@ -1009,29 +1013,35 @@ def createWidget(self, class_name, parent=None, name=""):
"QtCore.qInstallMessageHandler": [
"QtCompat.qInstallMessageHandler", _qInstallMessageHandler
],
"QtWidgets.QShortcut": "QtWidgets.QShortcut",
"QtWidgets.QStyleOptionViewItem": "QtCompat.QStyleOptionViewItemV4",
"QtMultimedia.QSound": "QtMultimedia.QSound",
},
"PySide": {
"QtCore.Property": "QtCore.Property",
"QtCore.Signal": "QtCore.Signal",
"QtCore.Slot": "QtCore.Slot",
"QtGui.QAbstractProxyModel": "QtCore.QAbstractProxyModel",
"QtGui.QSortFilterProxyModel": "QtCore.QSortFilterProxyModel",
"QtGui.QStringListModel": "QtCore.QStringListModel",
"QtGui.QItemSelection": "QtCore.QItemSelection",
"QtGui.QItemSelectionModel": "QtCore.QItemSelectionModel",
"QtGui.QItemSelectionRange": "QtCore.QItemSelectionRange",
"QtGui.QAbstractPrintDialog": "QtPrintSupport.QAbstractPrintDialog",
"QtGui.QRegExpValidator": "QtGui.QRegExpValidator",
"QtGui.QPageSetupDialog": "QtPrintSupport.QPageSetupDialog",
"QtGui.QPrintDialog": "QtPrintSupport.QPrintDialog",
"QtGui.QPrintEngine": "QtPrintSupport.QPrintEngine",
"QtGui.QPrintPreviewDialog": "QtPrintSupport.QPrintPreviewDialog",
"QtGui.QPrintPreviewWidget": "QtPrintSupport.QPrintPreviewWidget",
"QtGui.QPrinter": "QtPrintSupport.QPrinter",
"QtWidgets.QShortcut": "QtWidgets.QShortcut",
"QtGui.QPrinterInfo": "QtPrintSupport.QPrinterInfo",
"QtUiTools.QUiLoader": ["QtCompat.loadUi", _loadUi],
"shiboken.wrapInstance": ["QtCompat.wrapInstance", _wrapinstance],
"shiboken.unwrapInstance": ["QtCompat.getCppPointer", _getcpppointer],
"shiboken.isValid": ["QtCompat.isValid", _isvalid],
"QtGui.qApp": "QtWidgets.QApplication.instance()",
"QtCore.QRegExp": "QtCore.QRegExp",
"QtCore.QCoreApplication.translate": [
"QtCompat.translate", _translate
],
Expand All @@ -1042,7 +1052,6 @@ def createWidget(self, class_name, parent=None, name=""):
"QtCompat.qInstallMessageHandler", _qInstallMessageHandler
],
"QtGui.QStyleOptionViewItemV4": "QtCompat.QStyleOptionViewItemV4",
"QtGui.QSound": "QtMultimedia.QSound",
},
"PyQt4": {
"QtGui.QAbstractProxyModel": "QtCore.QAbstractProxyModel",
Expand All @@ -1055,9 +1064,11 @@ def createWidget(self, class_name, parent=None, name=""):
"QtCore.pyqtSlot": "QtCore.Slot",
"QtGui.QItemSelectionRange": "QtCore.QItemSelectionRange",
"QtGui.QAbstractPrintDialog": "QtPrintSupport.QAbstractPrintDialog",
"QtGui.QRegExpValidator": "QtGui.QRegExpValidator",
"QtGui.QPageSetupDialog": "QtPrintSupport.QPageSetupDialog",
"QtGui.QPrintDialog": "QtPrintSupport.QPrintDialog",
"QtGui.QPrintEngine": "QtPrintSupport.QPrintEngine",
"QtWidgets.QShortcut": "QtWidgets.QShortcut",
"QtGui.QPrintPreviewDialog": "QtPrintSupport.QPrintPreviewDialog",
"QtGui.QPrintPreviewWidget": "QtPrintSupport.QPrintPreviewWidget",
"QtGui.QPrinter": "QtPrintSupport.QPrinter",
Expand All @@ -1068,6 +1079,7 @@ def createWidget(self, class_name, parent=None, name=""):
"sip.isdeleted": ["QtCompat.isValid", _isvalid],
"QtCore.QString": "str",
"QtGui.qApp": "QtWidgets.QApplication.instance()",
"QtCore.QRegExp": "QtCore.QRegExp",
"QtCore.QCoreApplication.translate": [
"QtCompat.translate", _translate
],
Expand All @@ -1078,7 +1090,6 @@ def createWidget(self, class_name, parent=None, name=""):
"QtCompat.qInstallMessageHandler", _qInstallMessageHandler
],
"QtGui.QStyleOptionViewItemV4": "QtCompat.QStyleOptionViewItemV4",
"QtGui.QSound": "QtMultimedia.QSound",
}
}

Expand Down Expand Up @@ -1141,6 +1152,12 @@ def createWidget(self, class_name, parent=None, name=""):
"getOpenFileNames": "QtWidgets.QFileDialog.getOpenFileNames",
"getSaveFileName": "QtWidgets.QFileDialog.getSaveFileName",
},
"QFont":{
"setWeight": "QtGui.QFont.setWeight",
},
"Qt": {
"MidButton": "QtCore.Qt.MiddleButton",
},
},
"PyQt5": {
"QWidget": {
Expand All @@ -1161,6 +1178,12 @@ def createWidget(self, class_name, parent=None, name=""):
"getOpenFileNames": "QtWidgets.QFileDialog.getOpenFileNames",
"getSaveFileName": "QtWidgets.QFileDialog.getSaveFileName",
},
"QFont":{
"setWeight": "QtGui.QFont.setWeight",
},
"Qt": {
"MidButton": "QtCore.Qt.MiddleButton",
},
},
"PySide": {
"QWidget": {
Expand All @@ -1179,6 +1202,12 @@ def createWidget(self, class_name, parent=None, name=""):
"getOpenFileNames": "QtWidgets.QFileDialog.getOpenFileNames",
"getSaveFileName": "QtWidgets.QFileDialog.getSaveFileName",
},
"QFont":{
"setWeight": "QtGui.QFont.setWeight",
},
"Qt": {
"MidButton": "QtCore.Qt.MiddleButton",
},
},
"PyQt4": {
"QWidget": {
Expand All @@ -1197,6 +1226,12 @@ def createWidget(self, class_name, parent=None, name=""):
"getOpenFileNames": "QtWidgets.QFileDialog.getOpenFileNames",
"getSaveFileName": "QtWidgets.QFileDialog.getSaveFileName",
},
"QFont":{
"setWeight": "QtGui.QFont.setWeight",
},
"Qt": {
"MidButton": "QtCore.Qt.MiddleButton",
},
},
}

Expand Down Expand Up @@ -1275,6 +1310,7 @@ def _reassign_misplaced_members(binding):
"""


for src, dst in _misplaced_members[binding].items():
dst_value = None

Expand All @@ -1293,6 +1329,7 @@ def _reassign_misplaced_members(binding):
if len(dst_parts) > 1:
dst_member = dst_parts[1]


# Get the member we want to store in the namesapce.
if not dst_value:
try:
Expand Down Expand Up @@ -1439,7 +1476,7 @@ def _pyside6():
if hasattr(Qt, "_QtWidgets"):
Qt.QtCompat.setSectionResizeMode = \
Qt._QtWidgets.QHeaderView.setSectionResizeMode

def setWeight(func):
def wrapper(self, weight):
weight = {
Expand All @@ -1460,7 +1497,7 @@ def wrapper(self, weight):
wrapper.__name__ = func.__name__

return wrapper


decorators = {
"QFont": {
Expand All @@ -1469,7 +1506,6 @@ def wrapper(self, weight):
}

_reassign_misplaced_members("PySide6")
_build_compatibility_members("PySide6")
_build_compatibility_members("PySide6", decorators)


Expand Down
Loading

0 comments on commit 33b83f2

Please sign in to comment.