Exemplo n.º 1
0
def main(argv):
    data = [
        [4, 9, 2],
        [1, 0, 0],
        [3, 5, 0],
        [3, 3, 2],
        [7, 8, 9],
    ]

    myModel = BasicModel(data)


    app = QtWidgets.QApplication(argv)
    view = QQuickView()
    view.rootContext().setContextProperty("myModel", myModel)
    view.setResizeMode(QQuickView.SizeRootObjectToView)
    view.resize(640, 480)

    url = QtCore.QUrl("table.qml")

    result = view.setSource(url)

    # TODO somehow connect myModel python to QML Table view.

    view.show()
    sys.exit(app.exec_())
Exemplo n.º 2
0
    def threadWorker(self):
        self.app = QGuiApplication()
        self.view = QQuickView()
        self.view.setResizeMode(QQuickView.SizeRootObjectToView)

        #Load the QML file
        qml_file = os.path.join(os.path.dirname(__file__), "view.qml")
        self.view.setSource(QUrl.fromLocalFile(os.path.abspath(qml_file)))

        root = self.view.rootObject()

        ioHandler = Handler(self.moveQueue)
        context = self.view.rootContext()
        context.setContextProperty("handler", ioHandler)

        #Show the window
        if self.view.status() == QQuickView.Error:
            sys.exit(-1)

        ioSignaler = ioObject(root)

        input_thread = threading.Thread(target=self.ioThread,
                                        args=(self.inputQueue, ioSignaler))
        input_thread.start()

        self.view.show()
        self.app.exec_()

        self.inputQueue.put({"type": UIMessageType.QUIT})
        input_thread.join()
        self.outputQueue.put({"type": UICommandType.QUIT})
        self.moveQueue.put({"x": -1, "y": -1})
Exemplo n.º 3
0
def main():
    app = QApplication([])
    view = QQuickView()
    view.setResizeMode(QQuickView.SizeRootObjectToView)

    # QML経由でアクセスするPythonTextクラスのインスタンスを生成する
    python_text = PythonText()
    # QMLのrootアイテムのコンテキストを取得する
    context = view.rootContext()
    """ QMLの rootアイテムにQML側からアクセスするPythonのクラスを登録する
            PySide2.QtQml.QQmlContext.setContextProperty(arg__1, arg__2)
            arg__1 – QML側からアクセスするためのQMLオブジェクト名
            arg__2 - QML側からアクセスさせるPythonクラス
    """
    context.setContextProperty("pythonText", python_text)

    url = QUrl("HelloWorld.qml")
    view.setSource(url)
    if view.status() == QQuickView.Error:
        sys.exit(-1)

    view.show()
    ret = app.exec_()
    del view
    sys.exit(ret)
Exemplo n.º 4
0
def main():
    argv = sys.argv

    app = QGuiApplication(argv)

    qmlRegisterType(FigureCanvasQTAggToolbar, "Backend", 1, 0,
                    "FigureToolbarByPython")

    # this should work in the future
    # qmlRegisterType(
    #     QUrl.fromLocalFile( str(pathlib.Path(backend_qquick5agg.__file__)/'SubplotTool.qml')),
    #     "Backend", 1, 0, "SubplotTool")

    imgProvider = MatplotlibIconProvider()
    view = QQuickView()

    view.engine().addImageProvider("mplIcons", imgProvider)
    view.setResizeMode(QQuickView.SizeRootObjectToView)
    view.setSource(
        QUrl(str(pathlib.Path(__file__).parent / 'FigureToolbar.qml')))

    win = view.rootObject()
    fig = win.findChild(QObject, "figure").getFigure()
    ax = fig.add_subplot(111)
    x = np.linspace(-5, 5)
    ax.plot(x, np.sin(x))

    view.show()

    rc = app.exec_()
    # There is some trouble arising when deleting all the objects here
    # but I have not figure out how to solve the error message.
    # It looks like 'app' is destroyed before some QObject
    sys.exit(rc)
Exemplo n.º 5
0
 def testAbstractItemModelTransferToQML(self):
     view = QQuickView()
     model = ListModel()
     view.rootContext().setContextProperty("pythonModel", model)
     view.setSource(QUrl.fromLocalFile(adjust_filename('bug_814.qml', __file__)))
     root = view.rootObject()
     view.show()
def main():
    qInstallMessageHandler(lambda x, y, msg: print(msg))

    argv = sys.argv

    # Trick to set the style / not found how to do it in pythonic way
    #argv.extend(["-style", "universal"])
    app = QGuiApplication(argv)

    qmlRegisterType(FigureCanvasQTAgg, "Backend", 1, 0, "FigureCanvasByPython")

    view = QQuickView()
    view.setResizeMode(QQuickView.SizeRootObjectToView)
    view.setSource(QUrl(str(pathlib.Path(__file__).parent / 'Figure.qml')))
    view.show()

    win = view.rootObject()
    qml_figure_canvas = win.findChild(QObject, "figure")
    fig = qml_figure_canvas.getFigure()
    print(fig)
    ax = fig.add_subplot(111)
    x = np.linspace(-5, 5)
    ax.plot(x, np.sin(x))

    rc = app.exec_()
    # There is some trouble arising when deleting all the objects here
    # but I have not figure out how to solve the error message.
    # It looks like 'app' is destroyed before some QObject
    sys.exit(rc)
Exemplo n.º 7
0
def brunchmark():
    app = QApplication([])
    view = QQuickView()
    url = QUrl("./brunchmark/brunchmark.qml")

    view.setSource(url)
    view.show()
    app.exec_()

    # app = QApplication([])
    # engine = QQmlApplicationEngine()
    # engine.load("./brunchmark/brunchmark.qml")
    # win = engine.rootObjects()[0]
    # win.show()
    # sys.exit(app.exec_())


# if __name__ == "__main__":
#     app = QApplication(sys.argv)

#     widget = MyWidget()
#     widget.resize(800, 600)
#     widget.show()

#     sys.exit(app.exec_())
    def testIncubateWhileCall(self):
        app = QGuiApplication(sys.argv)
        view = QQuickView()
        controller = CustomIncubationController(self)
        view.engine().setIncubationController(controller)
        view.setResizeMode(QQuickView.SizeRootObjectToView)
        view.setSource(
            QUrl.fromLocalFile(
                adjust_filename('qqmlincubator_incubateWhile.qml', __file__)))
        view.show()

        root = view.rootObject()
        # The QML code will issue an interrupt signal after half of its items are loaded.
        root.shouldInterrupt.connect(controller.interrupter)
        res = app.exec_()

        itemsToCreate = root.property("itemsToCreate")
        loadedItems = root.property("loadedItems")
        self.assertEqual(loadedItems, itemsToCreate / 2)

        # Finish incubating the remaining items.
        controller.incubateFor(1000)
        loadedItems = root.property("loadedItems")
        self.assertEqual(loadedItems, itemsToCreate)

        # Deleting the view before it goes out of scope is required to make sure all child QML
        # instances are destroyed in the correct order.
        del view
        del app
Exemplo n.º 9
0
def main():
    app = QApplication([])
    """ 指定したクラスを、QMLモジュールのQMLタイプとしてバインディングする
            qmlRegisterType(class, uri, versionMajor, versionMinor, qmlName)
            class        - QML側でQML Type定義するPythonクラス
            uri          - 定義するQMLモジュール名
            versionMajor - QMLモジュールのメジャーバージョン 
            versionMinor - QMLモジュールのマイナーバージョン
            qmlName      - 定義するQMLタイプ名
    """
    qmlRegisterType(PythonText, "FromPythonTextLibrary", 1, 0,
                    "FromPythonText")

    view = QQuickView()
    view.setResizeMode(QQuickView.SizeRootObjectToView)

    url = QUrl("HelloWorld.qml")
    view.setSource(url)
    if view.status() == QQuickView.Error:
        sys.exit(-1)
    view.show()

    ret = app.exec_()
    del view
    sys.exit(ret)
Exemplo n.º 10
0
def main(argv):
    app = QtWidgets.QApplication(argv)
    view = QQuickView()
    url = QtCore.QUrl("basic.qml")

    view.setSource(url)
    view.show()
    sys.exit(app.exec_())
Exemplo n.º 11
0
def main():
    '''main entry point'''
    app = QApplication([])

    view = QQuickView()
    view.setSource(QUrl("view.qml"))
    view.show()
    app.exec_()
Exemplo n.º 12
0
def hello_QML():
    app = QApplication([])
    view = QQuickView()
    url = QUrl("view.qml")

    view.setSource(url)
    view.show()
    app.exec_()
Exemplo n.º 13
0
 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)
Exemplo n.º 14
0
    def testSignalEmission(self):
        qmlRegisterType(MyItem, "my.item", 1, 0, "MyItem")

        view = QQuickView()
        view.setSource(QUrl.fromLocalFile(adjust_filename('bug_951.qml', __file__)))

        self.app.exec_()
        self.assertTrue(MyItem.COMPONENT_COMPLETE_CALLED)
Exemplo n.º 15
0
def run():
    app = QApplication(sys.argv)
    view = QQuickView()
    url = QUrl(os.path.join(os.path.dirname(__file__), 'view.qml'))

    view.setSource(url)
    view.setResizeMode(QQuickView.SizeRootObjectToView)
    view.show()
    app.exec_()
Exemplo n.º 16
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_()
Exemplo n.º 17
0
    def testModelExport(self):
        view = QQuickView()
        dataList = [MyObject("Item 1"), MyObject("Item 2"), MyObject("Item 3"), MyObject("Item 4")]

        ctxt = view.rootContext()
        ctxt.setContextProperty("myModel", dataList)

        url = QUrl.fromLocalFile(adjust_filename('viewmodel.qml', __file__))
        view.setSource(url)
        view.show()

        self.assertEqual(view.status(), QQuickView.Ready)
Exemplo n.º 18
0
    def testIt(self):
        global paintCalled
        app = QGuiApplication([])
        qmlRegisterType(Bug825, 'bugs', 1, 0, 'Bug825')
        self.assertRaises(TypeError, qmlRegisterType, A, 'bugs', 1, 0, 'A')

        view = QQuickView()
        view.setSource(QUrl.fromLocalFile(adjust_filename('bug_825.qml', __file__)))
        view.show()
        QTimer.singleShot(250, view.close)
        app.exec_()
        self.assertTrue(paintCalled)
Exemplo n.º 19
0
def main():
    app = QGuiApplication([])

    # reg qml types here
    register_qml_types()

    # force gc to run
    gc.collect()

    view = QQuickView()
    url = QUrl(__file__.replace(".py", ".qml"))
    view.setSource(url)
Exemplo n.º 20
0
    def test_qml_type(self):
        qmlRegisterType(TestClass, 'JavaScriptExceptions', 1, 0,
                        'JavaScriptExceptions')

        view = QQuickView()
        qml_url = QUrl.fromLocalFile(
            adjust_filename('javascript_exceptions.qml', __file__))

        view.setSource(qml_url)

        self.assertTrue(test_1)
        self.assertTrue(test_2)
Exemplo n.º 21
0
    def testQQuickNetworkFactory(self):
        view = QQuickView()
        self.factory = CustomFactory()
        view.engine().setNetworkAccessManagerFactory(self.factory)

        url = QUrl.fromLocalFile(adjust_filename('hw.qml', __file__))

        view.setSource(url)
        view.show()

        self.assertEqual(view.status(), QQuickView.Ready)

        self.app.exec_()
Exemplo n.º 22
0
def main(argv):
    app = QApplication(argv)
    view = QQuickView(
        QUrl.fromLocalFile(str(entry_path.joinpath("./view.qml").resolve())))

    # engine = QQmlApplicationEngine()
    # engine.load()
    # login.setModality(Qt.WindowModality.ApplicationModal)
    # window.setMinimumSize(QSize(400, 250))
    print(view.children())
    print(view.rootObject().findChild(QQmlComponent, "test"))
    view.show()

    return app.exec_()
Exemplo n.º 23
0
    def testSignalArguments(self):
        view = QQuickView()
        obj = Obj()

        context = view.rootContext()
        context.setContextProperty("o", obj)
        view.setSource(QUrl.fromLocalFile(adjust_filename('signal_arguments.qml', __file__)))
        root = view.rootObject()
        self.assertTrue(root)
        button = root.findChild(QObject, "button")
        self.assertTrue(button)
        view.show()
        button.clicked.emit()
        self.assertEqual(obj.value, 42)
Exemplo n.º 24
0
    def testIt(self):
        app = QGuiApplication([])

        qmlRegisterType(PieChart, 'Charts', 1, 0, 'PieChart')
        qmlRegisterType(PieSlice, "Charts", 1, 0, "PieSlice")

        view = QQuickView()
        view.setSource(
            QUrl.fromLocalFile(adjust_filename('registertype.qml', __file__)))
        view.show()
        QTimer.singleShot(250, view.close)
        app.exec_()
        self.assertTrue(appendCalled)
        self.assertTrue(paintCalled)
Exemplo n.º 25
0
    def testReturnPolicy(self):
        view = QQuickView()

        item1 = QQuickItem()
        item1.setObjectName("Item1")
        item1.setParentItem(view.contentItem())
        self.assertEqual(item1.objectName(), "Item1") # check if the item still valid

        item2 = QQuickItem()
        item2.setObjectName("Item2")
        item2.setParentItem(view.contentItem())
        item1 = None
        self.assertEqual(item2.objectName(), "Item2") # check if the item still valid

        view = None
Exemplo n.º 26
0
def main():
    app = QApplication([])
    view = QQuickView()

    view.setResizeMode(QQuickView.SizeRootObjectToView)

    url = QUrl("HelloWorld.qml")
    view.setSource(url)
    if view.status() == QQuickView.Error:
        sys.exit(-1)

    view.show()

    ret = app.exec_()

    del view
    sys.exit(ret)
Exemplo n.º 27
0
    def testQQuickViewList(self):
        view = QQuickView()

        dataList = ["Item 1", "Item 2", "Item 3", "Item 4"]

        ctxt = view.rootContext()
        ctxt.setContextProperty("myModel", dataList)

        url = QUrl.fromLocalFile(adjust_filename('view.qml', __file__))
        view.setSource(url)
        view.show()

        self.assertEqual(view.status(), QQuickView.Ready)
        rootObject = view.rootObject()
        self.assertTrue(rootObject)
        self.assertTrue(QtQml.qmlEngine(rootObject))
        self.assertTrue(QtQml.qmlContext(rootObject))
Exemplo n.º 28
0
    def testReturnPolicy(self):
        view = QQuickView()

        item1 = QQuickItem()
        item1.setObjectName("Item1")
        # TODO: This existed in QDeclarativeView but not in QQuickView.
        # Have to rewrite this to the QQuickView equivalent
        view.scene().addItem(item1)
        self.assertEqual(item1.objectName(),
                         "Item1")  # check if the item still valid

        item2 = QQuickItem()
        item2.setObjectName("Item2")
        item1.scene().addItem(item2)
        item1 = None
        self.assertEqual(item2.objectName(),
                         "Item2")  # check if the item still valid

        view = None
Exemplo n.º 29
0
def main():
    """
    Entry point into program
    """
    app = QGuiApplication(sys.argv)

    # Register the Backend which can be used in the qml view
    qmlRegisterType(Backend, 'Interface', 1, 0, 'Backend')

    # Create a quickview widget and load the view
    view = QQuickView()
    view.setResizeMode(QQuickView.SizeRootObjectToView)
    view.setSource(QUrl.fromLocalFile('view.qml'))
    view.show()
    res = app.exec_()

    # Deleting the view before it goes out of scope is required to make
    # sure all child QML instances are destroyed in the correct order.
    # Sept 2019 * Not sure if we still need to do this *
    del view
    sys.exit(res)
Exemplo n.º 30
0
def main():
    """ .qml ファイルのロードする準備
    QGuiApplication と QQuickView のインスタンスを生成する
    """
    app = QApplication([])
    view = QQuickView()
    """ Qt Quickの表示方法の設定
    PySide2.QtQuick.QQuickView.ResizeMode の enum 定義
    
    表示サイズはQMLのrootのQML rootアイテム(topの QMLオブジェクト)で
    サイズ変更されます。
    QQuickView.SizeViewToRootObject	: 表示はQMLの rootアイテム
                                      (topのQMLオブジェクト)でサイズ変更する
    QQuickView.SizeRootObjectToView	 : 表示は、rootアイテムサイズに
                                       QMLのオブジェクトが自動的に調整する
    """
    view.setResizeMode(QQuickView.SizeRootObjectToView)
    """ 画面表示するQMLコンポーネントの読み出し
    URL形式で画面表示するQMLファイルを設定する。
    """
    url = QUrl("HelloWorld.qml")
    view.setSource(url)
    if view.status() == QQuickView.Error:
        sys.exit(-1)

    # QMLコンポーネントの表示
    view.show()

    # QApplicationのイベントループ
    ret = app.exec_()
    """ アプリケーションの終了処理
    注意:
      アプリケーション終了前にQQuickViewのオブジェクトを
       delしてから終了させる。
    """
    del view
    sys.exit(ret)