فهرست منبع

Merge pull request #76 from Siecje/qml

Adding PyQt5 QML example
Thomas Kluyver 8 سال پیش
والد
کامیت
f3073a92af

+ 9 - 0
examples/pyqt5_qml/basicqml/JSManager.qml

@@ -0,0 +1,9 @@
+import QtQuick 2.7
+import QtQuick.Controls 1.4
+import QtQuick.Dialogs 1.2
+import QtQuick.Layouts 1.1
+
+Item {
+    id: jsManager
+    signal text(string text)
+}

+ 0 - 0
examples/pyqt5_qml/basicqml/__init__.py


+ 17 - 0
examples/pyqt5_qml/basicqml/main.js

@@ -0,0 +1,17 @@
+"use strict";
+
+function JSManager() {
+    return Qt.createQmlObject("import JSManager 1.0; JSManager {}",
+                              appWindow, "JSManager");
+}
+
+function onLoad(){
+    var jsManager = new JSManager();
+
+    // Populate text
+    jsManager.text.connect(function(text){
+      jsText.text = text;
+    });
+
+    jsManager.get_text();
+}

+ 25 - 0
examples/pyqt5_qml/basicqml/main.py

@@ -0,0 +1,25 @@
+import os
+import sys
+import time
+import threading
+from PyQt5 import QtCore, QtGui, QtQml
+
+
+THIS_DIR = os.path.dirname(os.path.abspath(__file__))
+
+
+class JSManager(QtCore.QObject):
+    text = QtCore.pyqtSignal(QtCore.QVariant)
+
+    @QtCore.pyqtSlot()
+    def get_text(self):
+        def go():
+            _text = "Hello from JavaScript"
+            self.text.emit(_text)
+        threading.Thread(target=go).start()
+
+
+app = QtGui.QGuiApplication(sys.argv)
+QtQml.qmlRegisterType(JSManager, 'JSManager', 1, 0, 'JSManager')
+engine = QtQml.QQmlApplicationEngine(os.path.join(THIS_DIR, "main.qml"))
+app.exec_()

+ 36 - 0
examples/pyqt5_qml/basicqml/main.qml

@@ -0,0 +1,36 @@
+import QtQuick 2.7
+import QtQuick.Controls 1.4
+import QtQuick.Layouts 1.0
+
+import "main.js" as App
+
+ApplicationWindow {
+    id: appWindow
+    objectName: "appWindow"
+    visible: true
+    width: 800;
+    height: 600;
+
+    ColumnLayout {
+        anchors.horizontalCenter: parent.horizontalCenter
+        anchors.verticalCenter: parent.verticalCenter
+        anchors.margins: 3
+        spacing: 3
+        Column {
+            Text {
+                id: mainText
+                objectName: "mainText"
+                text: "Hello from QML"
+            }
+        }
+        Column {
+            Text {
+                id: jsText
+                objectName: "jsText"
+            }
+        }
+    }
+    Component.onCompleted: {
+        App.onLoad();
+    }
+}

+ 14 - 0
examples/pyqt5_qml/installer.cfg

@@ -0,0 +1,14 @@
+[Application]
+name=QML App (PyQt5)
+version=1.0
+entry_point=basicqml:main
+
+[Python]
+version=3.5.2
+bitness=64
+format=bundled
+
+[Include]
+packages=basicqml
+pypi_wheels= PyQt5==5.7
+    sip==4.18.1