Exemple #1
0
 def testIt(self):
     app = QGuiApplication([])
     qmlRegisterType(MyClass,'Example',1,0,'MyClass')
     view = QQuickView()
     view.setSource(QUrl.fromLocalFile(adjust_filename('bug_926.qml', __file__)))
     self.assertEqual(len(view.errors()), 0)
     view.show()
     QTimer.singleShot(0, app.quit)
     app.exec_()
Exemple #2
0
 def testIt(self):
     app = QGuiApplication([])
     qmlRegisterType(MyClass, 'Example', 1, 0, 'MyClass')
     view = QQuickView()
     view.setSource(
         QUrl.fromLocalFile(adjust_filename('bug_926.qml', __file__)))
     self.assertEqual(len(view.errors()), 0)
     view.show()
     QTimer.singleShot(0, app.quit)
     app.exec_()
Exemple #3
0
class QuickWindow(MayaQWidgetBaseMixin, QMainWindow):
    """A window that can be used to display a QML UI in Maya."""
    def __init__(self, url=None, *args, **kwargs):
        super(QuickWindow, self).__init__(*args, **kwargs)
        self.view = QQuickView()
        self.view.statusChanged.connect(self.onStatusChanged)
        self.widget = None
        if url:
            self.setSource(url)
        self.setFocusPolicy(Qt.NoFocus)

    def setContextProperty(self, name, value):
        """Set a context property on the window.

        Context properties are used to handle the interop between QML and Python

        :param name: Name of the property
        :param value: Instance of the property object
        """
        self.view.engine().rootContext().setContextProperty(name, value)

    def addImportPath(self, path):
        """Add a new module import path to the window engine."""
        self.view.engine().addImportPath(path)

    def setSource(self, url):
        if isinstance(url, string_types):
            url = QUrl.fromLocalFile(os.path.abspath(url))
        self.view.setSource(url)
        size = self.view.size()
        self.widget = QWidget.createWindowContainer(self.view, self)
        self.setCentralWidget(self.widget)
        self.setFocusProxy(self.widget)
        self.resize(size)

    def onStatusChanged(self, status):
        if status == QQuickView.Error:
            errors = self.view.errors()
            for error in errors:
                logging.critical(error)
Exemple #4
0
    font = QFont("Helvetica", 16)
    app.setFont(font)
    view = QQuickView()
    view.width = 800
    view.height = 460
    view.setResizeMode(QQuickView.SizeRootObjectToView)

    # Expose the data to the Qml code
    ctx = view.rootContext()
    ctx.setContextProperty("drinks", drinks)
    ctx.setContextProperty("cart", cart)
    ctx.setContextProperty("logbook", cart.log)
    ctx.setContextProperty("uidmap", uidmap)
    ctx.setContextProperty("dayFee", DAY_FEE)

    qml_file = os.path.join(os.path.dirname(__file__), "view.qml")
    view.setSource(QUrl.fromLocalFile(os.path.abspath(qml_file)))

    # Show the window
    if view.status() == QQuickView.Error:
        print("QtQuick error")
        print("caused by:")
        print(view.errors())
        sys.exit(-1)
    if fullscreen:
        view.showFullScreen()
    else:
        view.show()

    app.exec_()
Exemple #5
0
    view = QQuickView()
    view.width = 800
    view.height = 460
    view.setResizeMode(QQuickView.SizeRootObjectToView)

    # Expose the data to the Qml code
    ctx = view.rootContext()
    ctx.setContextProperty("drinks", drinks)
    ctx.setContextProperty("cart", cart)
    ctx.setContextProperty("logbook", cart.log)
    ctx.setContextProperty("uidmap", uidmap)
    ctx.setContextProperty("dayFee", DAY_FEE)

    qml_file = os.path.join(os.path.dirname(__file__), "view.qml")
    view.setSource(QUrl.fromLocalFile(os.path.abspath(qml_file)))

    # show errors/ warnings
    if view.errors():
        print("QtQuick errors:")
        print(view.errors())

    # Show the window
    if view.status() == QQuickView.Error:
        sys.exit(-1)
    if fullscreen:
        view.showFullScreen()
    else:
        view.show()

    app.exec_()
Exemple #6
0
    model = TreeModel(str(all))
    f.close()
    app = QApplication(sys.argv)
    if True:
        current_path = os.path.dirname(
            sys.argv[0])  #os.path.abspath(os.path.dirname(__file__))
        ui_path = os.path.join(current_path, '')
        qml_file = os.path.join(ui_path, 'main.qml')
        url = QUrl.fromLocalFile(qml_file)

        view = QQuickView()
        view.rootContext().setContextProperty("theModel", model)
        view.setSource(url)
        view.setResizeMode(QQuickView.SizeRootObjectToView)
        if view.status() == QQuickView.Error:
            oops = view.errors()
            print(oops)
            import sys
            sys.exit(-1)
        else:
            #view.rootContext().setContextProperty("theModel", model)
            view.show()
            view.rootContext().setContextProperty("theModel", model)
        app.exec_()
    else:
        view = QTreeView()
        view.setWindowTitle("Simple Tree Model")
        view.setModel(model)
        view.show()
        sys.exit(app.exec_())