|
43 | 43 | import shutil |
44 | 44 |
|
45 | 45 |
|
46 | | -__version__ = "1.1.0.b8" |
| 46 | +__version__ = "1.1.0.b9" |
47 | 47 |
|
48 | 48 | # Enable support for `from Qt import *` |
49 | 49 | __all__ = [] |
|
706 | 706 | "QtCore.Signal": "QtCore.Signal", |
707 | 707 | "QtCore.Slot": "QtCore.Slot", |
708 | 708 | "QtGui.QItemSelectionRange": "QtCore.QItemSelectionRange", |
709 | | - |
710 | 709 | }, |
711 | 710 | "PyQt4": { |
712 | 711 | "QtGui.QAbstractProxyModel": "QtCore.QAbstractProxyModel", |
@@ -1028,6 +1027,7 @@ def _pyside2(): |
1028 | 1027 |
|
1029 | 1028 | if hasattr(Qt, "_QtCore"): |
1030 | 1029 | Qt.__qt_version__ = Qt._QtCore.qVersion() |
| 1030 | + Qt.QtCompat.qInstallMessageHandler = _qInstallMessageHandler |
1031 | 1031 | Qt.QtCompat.translate = Qt._QtCore.QCoreApplication.translate |
1032 | 1032 |
|
1033 | 1033 | if hasattr(Qt, "_QtWidgets"): |
@@ -1079,6 +1079,7 @@ def _pyside(): |
1079 | 1079 | if hasattr(Qt, "_QtCore"): |
1080 | 1080 | Qt.__qt_version__ = Qt._QtCore.qVersion() |
1081 | 1081 | QCoreApplication = Qt._QtCore.QCoreApplication |
| 1082 | + Qt.QtCompat.qInstallMessageHandler = _qInstallMessageHandler |
1082 | 1083 | Qt.QtCompat.translate = ( |
1083 | 1084 | lambda context, sourceText, disambiguation, n: |
1084 | 1085 | QCoreApplication.translate( |
@@ -1118,6 +1119,7 @@ def _pyqt5(): |
1118 | 1119 | if hasattr(Qt, "_QtCore"): |
1119 | 1120 | Qt.__binding_version__ = Qt._QtCore.PYQT_VERSION_STR |
1120 | 1121 | Qt.__qt_version__ = Qt._QtCore.QT_VERSION_STR |
| 1122 | + Qt.QtCompat.qInstallMessageHandler = _qInstallMessageHandler |
1121 | 1123 | Qt.QtCompat.translate = Qt._QtCore.QCoreApplication.translate |
1122 | 1124 |
|
1123 | 1125 | if hasattr(Qt, "_QtWidgets"): |
@@ -1196,8 +1198,8 @@ def _pyqt4(): |
1196 | 1198 | if hasattr(Qt, "_QtCore"): |
1197 | 1199 | Qt.__binding_version__ = Qt._QtCore.PYQT_VERSION_STR |
1198 | 1200 | Qt.__qt_version__ = Qt._QtCore.QT_VERSION_STR |
1199 | | - |
1200 | 1201 | QCoreApplication = Qt._QtCore.QCoreApplication |
| 1202 | + Qt.QtCompat.qInstallMessageHandler = _qInstallMessageHandler |
1201 | 1203 | Qt.QtCompat.translate = ( |
1202 | 1204 | lambda context, sourceText, disambiguation, n: |
1203 | 1205 | QCoreApplication.translate( |
@@ -1275,10 +1277,6 @@ def _loadUi(uifile, baseinstance=None): |
1275 | 1277 | return the newly created instance of the user interface. |
1276 | 1278 |
|
1277 | 1279 | """ |
1278 | | - if hasattr(baseinstance, "layout") and baseinstance.layout(): |
1279 | | - message = ("QLayout: Attempting to add Layout to %s which " |
1280 | | - "already has a layout") |
1281 | | - raise RuntimeError(message % (baseinstance)) |
1282 | 1280 |
|
1283 | 1281 | if hasattr(Qt, "_uic"): |
1284 | 1282 | return Qt._uic.loadUi(uifile, baseinstance) |
@@ -1359,6 +1357,43 @@ def createWidget(self, class_name, parent=None, name=""): |
1359 | 1357 | raise NotImplementedError("No implementation available for loadUi") |
1360 | 1358 |
|
1361 | 1359 |
|
| 1360 | +def _qInstallMessageHandler(handler): |
| 1361 | + """Install a message handler that works in all bindings |
| 1362 | +
|
| 1363 | + Args: |
| 1364 | + handler: A function that takes 3 arguments, or None |
| 1365 | + """ |
| 1366 | + def messageOutputHandler(*args): |
| 1367 | + # In Qt4 bindings, message handlers are passed 2 arguments |
| 1368 | + # In Qt5 bindings, message handlers are passed 3 arguments |
| 1369 | + # The first argument is a QtMsgType |
| 1370 | + # The last argument is the message to be printed |
| 1371 | + # The Middle argument (if passed) is a QMessageLogContext |
| 1372 | + if len(args) == 3: |
| 1373 | + msgType, logContext, msg = args |
| 1374 | + elif len(args) == 2: |
| 1375 | + msgType, msg = args |
| 1376 | + logContext = None |
| 1377 | + else: |
| 1378 | + raise TypeError( |
| 1379 | + "handler expected 2 or 3 arguments, got {0}".format(len(args))) |
| 1380 | + |
| 1381 | + if isinstance(msg, bytes): |
| 1382 | + # In python 3, some bindings pass a bytestring, which cannot be |
| 1383 | + # used elsewhere. Decoding a python 2 or 3 bytestring object will |
| 1384 | + # consistently return a unicode object. |
| 1385 | + msg = msg.decode() |
| 1386 | + |
| 1387 | + handler(msgType, logContext, msg) |
| 1388 | + |
| 1389 | + passObject = messageOutputHandler if handler else handler |
| 1390 | + if Qt.IsPySide or Qt.IsPyQt4: |
| 1391 | + return Qt._QtCore.qInstallMsgHandler(passObject) |
| 1392 | + elif Qt.IsPySide2 or Qt.IsPyQt5: |
| 1393 | + return Qt._QtCore.qInstallMessageHandler(passObject) |
| 1394 | + |
| 1395 | + |
| 1396 | + |
1362 | 1397 | def _convert(lines): |
1363 | 1398 | """Convert compiled .ui file from PySide2 to Qt.py |
1364 | 1399 |
|
|
0 commit comments