Exemplo n.º 1
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.º 2
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.º 3
0
    def testQQuickNetworkFactory(self):
        view = QQuickView()

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

        view.setSource(url)
        view.show()

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

        self.app.exec_()
Exemplo n.º 4
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.º 5
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.º 6
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.º 7
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.º 8
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)
def viewload():
    app = QGuiApplication(sys.argv)
    view = QQuickView()
    view_model = URControlViewModel()
    ur_singal = view_model.gui
    view.rootContext().setContextProperty("urSingal", ur_singal)
    # qmlRegisterType(UIsignal, 'PySignal', 1, 0, 'PySignal') # implicit error when using slot and singal
    qmlRegisterType(ur_visual.FboItem, "QmlVTK", 1, 0, "VtkFboItem")

    view.setSource(QUrl.fromLocalFile(abs_path("qmlRobotGui\main.qml")))
    view.setResizeMode(QQuickView.SizeRootObjectToView)
    view.setTitle("UR Controller")
    if view.status() == QQuickView.Error:
        sys.exit(-1)
    view.show()

    root_obj = view.rootObject()
    view_model.init_connect(root_obj)
    root_obj.destroyed.connect(view_model.disconnectRobot)

    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.
    del view
Exemplo n.º 10
0
from __future__ import print_function

import os
import sys
from PySide2.QtCore import QTimer, QUrl
from PySide2.QtGui import QGuiApplication
import PySide2.QtQml
from PySide2.QtQuick import QQuickView

if __name__ == '__main__':
    app = QGuiApplication(sys.argv)

    timer = QTimer()
    timer.start(2000)

    view = QQuickView()
    qmlFile = os.path.join(os.path.dirname(__file__), 'view.qml')
    view.setSource(QUrl.fromLocalFile(os.path.abspath(qmlFile)))
    if view.status() == QQuickView.Error:
        sys.exit(-1)
    root = view.rootObject()

    timer.timeout.connect(root.updateRotater)

    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.
    del view
    sys.exit(res)
Exemplo n.º 11
0
        self._name = value

    colorChanged = Signal()
    color = Property(QColor, getColor, setColor, notify=colorChanged)
    name = Property(text_type, getName, setName)
    chartCleared = Signal()

    @Slot() # This should be something like @Invokable
    def clearChart(self):
        self.setColor(Qt.transparent)
        self.update()
        self.chartCleared.emit()

if __name__ == '__main__':
    app = QGuiApplication(sys.argv)

    qmlRegisterType(PieChart, 'Charts', 1, 0, 'PieChart');

    view = QQuickView()
    view.setResizeMode(QQuickView.SizeRootObjectToView)
    qmlFile = os.path.join(os.path.dirname(__file__), 'app.qml')
    view.setSource(QUrl.fromLocalFile(os.path.abspath(qmlFile)))
    if view.status() == QQuickView.Error:
        sys.exit(-1)
    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.
    del view
    sys.exit(res)
Exemplo n.º 12
0
class QTUI(UIBase):
    def xyToIndex(self, x, y):
        return y * 8 + x

    def indexToXY(self, index):
        return (index % 8, index // 8)

    def ioThread(self, inputQueue, emitter):
        while True:
            io = inputQueue.get()

            if (io["type"] == UIMessageType.SETUP):
                player = io["data"]["player_name"]
                emitter.sendName(player[WHITE], player[BLACK])
            elif (io["type"] == UIMessageType.BOARD):
                for index in range(0, 64):
                    col, row = self.indexToXY(index)
                    item = io["data"][row][col]
                    if (item == BLACK):
                        emitter.send(index, True)
                    elif (item == WHITE):
                        emitter.send(index, False)
                time.sleep(0.2)

            elif (io["type"] == UIMessageType.SCORE):
                emitter.sendScore(io["data"]["o"], io["data"]["x"])
            elif (io["type"] == UIMessageType.TURN):
                turn = io["data"]
                if turn == "x":
                    emitter.sendMark(True)
                else:
                    emitter.sendMark(False)
            elif (io["type"] == UIMessageType.FORFEIT):
                print("Tidak ada langkah mungkin, skip")
            elif (io["type"] == UIMessageType.DOTURN):
                pass
            elif (io["type"] == UIMessageType.QUIT):
                break

            self.inputQueue.task_done()

    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})