Exemplo n.º 1
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()
Exemplo n.º 2
0
 def testAbstractItemModelTransferToQML(self):
     view = QQuickView()
     view.setSource(QUrl.fromLocalFile(adjust_filename('bug_814.qml', __file__)))
     root = view.rootObject()
     model = ListModel()
     root.setProperty('model', model)
     view.show()
    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.º 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)
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.º 6
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.º 7
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.º 8
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))
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
#!/bin/python

import sys
import options
from PySide2.QtWidgets import QApplication, QPushButton
from PySide2.QtCore import Slot, QUrl
from PySide2.QtQuick import QQuickView

app = QApplication([])
view = QQuickView()
url = QUrl("components/quote_view.qml")
options = options.extract_options(" ".join(sys.argv))

view.setResizeMode(QQuickView.SizeRootObjectToView)
view.setSource(url)

rootElement = view.rootObject()

for (optName, optValue) in options.items():
    rootElement.setProperty(optName, optValue)

view.show()

app.exec_()
Exemplo n.º 12
0
from __future__ import print_function

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

def sayThis(s):
    print(s)

if __name__ == '__main__':
    app = QGuiApplication(sys.argv)
    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()
    root.textRotationChanged.connect(sayThis)
    root.buttonClicked.connect(lambda: sayThis("clicked button (QML top-level signal)"))

    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.º 13
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})
Exemplo n.º 14
0
from PySide2.QtWidgets import QApplication, QPushButton
from PySide2.QtCore import Slot, QUrl
from PySide2.QtQuick import QQuickView

profile = QUrl.fromLocalFile("img/profile.jpg")
username = "******"
pseudo = "@NoBrainSkull"


@Slot()
def say_hello():
    print("Button clicked, Hello!")


app = QApplication([])
view = QQuickView()
url = QUrl("components/view.qml")
button = QPushButton("click me")
button.clicked.connect(say_hello)

view.setResizeMode(QQuickView.SizeRootObjectToView)
view.setSource(url)

user = view.rootObject()
user.setProperty('username', username)
user.setProperty('pseudo', pseudo)
user.setProperty('picture', profile)
view.show()

app.exec_()