Exemplo n.º 1
0
    def view(self):
        with self.__view_creation_lock:
            if self._view is None:
                component = QQmlComponent(self.dice.qml_engine, self.qml_file,
                                          self)
                if component.status() == QQmlComponent.Error:
                    qDebug("errors loading component: " +
                           str(component.errors()))
                    qDebug(self.qml_file)
                    for error in component.errors():
                        qDebug(error.description())
                    return QQuickItem(self)

                # don't create the view immediately so the properties are available as soon as the view is created
                view = component.beginCreate(self.dice.qml_context)

                if view:
                    view.setParentItem(self.dice.main_window)
                    view.setProperty("appWindow", self.dice.app_window)
                    view.setProperty("app", self)
                    view.setProperty("mainWindow", self.dice.main_window)
                    self._view = view
                    component.completeCreate()
                    self.view_changed.emit()
                else:
                    component.completeCreate()
                    qDebug("no view")
                    view = QQuickItem(self)
                    view.setParentItem(self.dice.main_window)
                    # TODO: send an alert
                    return view
            return self._view
Exemplo n.º 2
0
    def view(self):
        with self.__view_creation_lock:
            if self._view is None:
                component = QQmlComponent(self.dice.qml_engine, self.qml_file, self)
                if component.status() == QQmlComponent.Error:
                    qDebug("errors loading component: "+str(component.errors()))
                    qDebug(self.qml_file)
                    for error in component.errors():
                        qDebug(error.description())
                    return QQuickItem(self)

                # don't create the view immediately so the properties are available as soon as the view is created
                view = component.beginCreate(self.dice.qml_context)

                if view:
                    view.setParentItem(self.dice.main_window)
                    view.setProperty("appWindow", self.dice.app_window)
                    view.setProperty("app", self)
                    view.setProperty("mainWindow", self.dice.main_window)
                    self._view = view
                    component.completeCreate()
                    self.view_changed.emit()
                else:
                    component.completeCreate()
                    qDebug("no view")
                    view = QQuickItem(self)
                    view.setParentItem(self.dice.main_window)
                    # TODO: send an alert
                    return view
            return self._view
Exemplo n.º 3
0
    # check for component creation errors
    for error in component.errors():
        print(error.toString())
    # check for component creation errors
    for error in line_component.errors():
        print(error.toString())

    classes = []
    for index, class_name in enumerate(["Person", "Home"]):
        # create a new instance of the component
        cclass = component.create()
        # set the class name property of the component
        cclass.setProperty("className", class_name)
        cclass.setX((cclass.width() + 50) * index)
        cclass.setParentItem(engine.rootObjects()[0].findChild(QQuickItem))
        classes.append(cclass)

    line = line_component.beginCreate(engine.rootContext())
    line.setProperty("anchor1", classes[0])
    line.setProperty("anchor2", classes[1])
    line_component.completeCreate()

    # check for object creation errors
    for error in line_component.errors():
        print(error.toString())
    for error in component.errors():
        print(error.toString())

    engine.quit.connect(app.quit)
    sys.exit(app.exec_())