def test_implicit_wrapInstance(): """.wrapInstance doesn't need the `base` argument""" from Qt import QtCompat, QtWidgets app = QtWidgets.QApplication(sys.argv) try: button = QtWidgets.QPushButton("Hello world") button.setObjectName("MySpecialButton") pointer = QtCompat.getCppPointer(button) widget = QtCompat.wrapInstance(long(pointer)) assert isinstance(widget, QtWidgets.QWidget), widget assert widget.objectName() == button.objectName() if binding("PySide"): assert widget != button elif binding("PySide2") and _pyside2_commit_date() is None: assert widget != button elif binding("PySide2") and \ _pyside2_commit_date() <= datetime.datetime( 2017, 8, 25): assert widget == button else: assert widget == button finally: app.exit()
def test_implicit_wrapInstance(): """.wrapInstance doesn't need the `base` argument""" from Qt import QtCompat, QtWidgets app = QtWidgets.QApplication(sys.argv) try: button = QtWidgets.QPushButton("Hello world") button.setObjectName("MySpecialButton") pointer = QtCompat.getCppPointer(button) widget = QtCompat.wrapInstance(long(pointer)) assert isinstance(widget, QtWidgets.QWidget), widget assert widget.objectName() == button.objectName() if binding("PySide"): assert widget != button elif binding("PySide2") and _pyside2_commit_date() is None: assert widget != button elif binding("PySide2") and \ _pyside2_commit_date() <= datetime.datetime( 2017, 8, 25): assert widget == button else: assert widget == button finally: app.exit()
def test_implicit_wrapInstance_for_base_types(): """Tests .wrapInstance implicit cast of `Foo` pointer to `Foo` object Testing is based upon the following parameters: 1. The `base` argument has a default value. 2. `Foo` is a standard Qt class. """ from Qt import QtCompat, QtWidgets app = QtWidgets.QApplication(sys.argv) try: button = QtWidgets.QPushButton("Hello world") button.setObjectName("MySpecialButton") pointer = QtCompat.getCppPointer(button) widget = QtCompat.wrapInstance(long(pointer)) assert widget.objectName() == button.objectName() assert type(widget) is QtWidgets.QPushButton, widget if binding("PySide"): assert widget != button elif binding("PySide2") and _pyside2_commit_date() is None: assert widget != button elif binding("PySide2") and \ _pyside2_commit_date() <= datetime.datetime( 2017, 8, 25): assert widget == button else: assert widget == button finally: app.exit()
def test_wrapInstance(): """Tests .wrapInstance cast of pointer to explicit class Note: sip.wrapInstance will ignore the explicit class if there is a more suitable type available. """ from Qt import QtCompat, QtWidgets app = QtWidgets.QApplication(sys.argv) try: button = QtWidgets.QPushButton("Hello world") button.setObjectName("MySpecialButton") pointer = QtCompat.getCppPointer(button) widget = QtCompat.wrapInstance(long(pointer), QtWidgets.QWidget) assert widget.objectName() == button.objectName() if binding("PyQt4") or binding("PyQt5"): # Even when we explicitly pass QWidget we will get QPushButton assert type(widget) is QtWidgets.QPushButton, widget else: assert type(widget) is QtWidgets.QWidget, widget # IMPORTANT: this differs across sip and shiboken. if binding("PySide") or binding("PySide2"): assert widget != button else: assert widget == button finally: app.exit()
def test_implicit_wrapInstance_for_derived_types(): """Tests .wrapInstance implicit cast of `Foo` pointer to `Bar` object Testing is based upon the following parameters: 1. The `base` argument has a default value. 2. `Bar` is a standard Qt class. 3. `Foo` is a strict subclass of `Bar`, separated by one or more levels of inheritance. 4. `Foo` is not a standard Qt class. Note: For sip usage, implicit cast of `Foo` pointer always results in a `Foo` object. """ from Qt import QtCompat, QtWidgets app = QtWidgets.QApplication(sys.argv) try: class A(QtWidgets.QPushButton): pass class B(A): pass button = B("Hello world") button.setObjectName("MySpecialButton") pointer = QtCompat.getCppPointer(button) widget = QtCompat.wrapInstance(long(pointer)) assert widget.objectName() == button.objectName() if binding("PyQt4") or binding("PyQt5"): assert type(widget) is B, widget else: assert type(widget) is QtWidgets.QPushButton, widget if binding("PySide") or binding("PySide2"): assert widget != button else: assert widget == button finally: app.exit()
def test_wrapInstance(): """.wrapInstance and .getCppPointer is identical across all bindings""" from Qt import QtCompat, QtWidgets app = QtWidgets.QApplication(sys.argv) try: button = QtWidgets.QPushButton("Hello world") button.setObjectName("MySpecialButton") pointer = QtCompat.getCppPointer(button) widget = QtCompat.wrapInstance(long(pointer), QtWidgets.QWidget) assert isinstance(widget, QtWidgets.QWidget), widget assert widget.objectName() == button.objectName() # IMPORTANT: this differs across sip and shiboken. if binding("PySide") or binding("PySide2"): assert widget != button else: assert widget == button finally: app.exit()
def test_wrapInstance(): """.wrapInstance and .getCppPointer is identical across all bindings""" from Qt import QtCompat, QtWidgets app = QtWidgets.QApplication(sys.argv) try: button = QtWidgets.QPushButton("Hello world") button.setObjectName("MySpecialButton") pointer = QtCompat.getCppPointer(button) widget = QtCompat.wrapInstance(long(pointer), QtWidgets.QWidget) assert isinstance(widget, QtWidgets.QWidget), widget assert widget.objectName() == button.objectName() # IMPORTANT: this differs across sip and shiboken. if binding("PySide") or binding("PySide2"): assert widget != button else: assert widget == button finally: app.exit()