diff --git a/src/qml-client/main.py b/src/qml-client/main.py new file mode 100644 index 0000000..2db33f0 --- /dev/null +++ b/src/qml-client/main.py @@ -0,0 +1,47 @@ +import sys +import os +import platform +from PySide6.QtCore import QUrl + +from PySide6.QtGui import QGuiApplication, QIcon +from PySide6.QtQml import QQmlApplicationEngine + + +if __name__ == "__main__": + organizationName = "Bamatics" + organizationDomain = "bamatics.de" + applicationName = "SSE Client" + versionMajor = 1 + versionMinor = 0 + versionMicro = 0 + + + app = QGuiApplication([]) + app.setOrganizationDomain(organizationDomain) + app.setOrganizationName(organizationName) + app.setApplicationName(applicationName) + app.setApplicationDisplayName(applicationName) + path = os.path.dirname( os.path.realpath(__file__) ) + + myappid = u''+ organizationName + '.' + applicationName + '.' +str(versionMajor) # arbitrary string + # if platform.system() == "Darwin": + # app.setWindowIcon( QIcon( "src/images/svg/app_icon.svg" ) ) + # if platform.system() == "Windows": + # #https://stackoverflow.com/questions/1551605/how-to-set-applications-taskbar-icon-in-windows-7/1552105#1552105 + # icon = QIcon(path + "/images/svg/app_icon.svg") + # app.setWindowIcon( icon ) + # import ctypes + # ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID(myappid) + + engine = QQmlApplicationEngine() + + #Register models + + engine.rootContext().setContextProperty("applicationDirPath", path ) + engine.load( QUrl().fromLocalFile( os.path.join(path, "qml/main.qml")) ) + + if not engine.rootObjects(): + sys.exit(-1) + + + sys.exit( app.exec() ) \ No newline at end of file diff --git a/src/qml-client/qml/main.qml b/src/qml-client/qml/main.qml new file mode 100644 index 0000000..653da11 --- /dev/null +++ b/src/qml-client/qml/main.qml @@ -0,0 +1,127 @@ +import QtQuick +import QtQuick.Window +import QtQuick.Controls +import QtQuick.Layouts +import QtQuick.Controls.Material + +import Qt.labs.settings + +ApplicationWindow { + id: window + width: 800 + height: 600 + + visible: true + title: Qt.application.name + + Settings { + category: "ApplicationWindow" + property alias x: window.x + property alias y: window.y + property alias width: window.width + property alias height: window.height + } + Settings { + category: "settings" + property alias nrOfElements: nrOfElements.value + } + Settings{ + id: settings + } + + property int counter: 0 + property bool online: false + + function add(entry){ + var diff = data.count - nrOfElements.value+1 + if( diff > 0 ) + data.remove(0, diff) + data.append( entry ) + } + + function update(event){ + console.log(event) + } + + function fetch(){ + console.log("Try to fetch...") + var last_response_len = 0; + var xhr = new XMLHttpRequest(); + xhr.open('GET', 'http://127.0.0.1/stream', true); // method, adress, async + xhr.setRequestHeader('Accept', 'text/event-stream'); + xhr.onreadystatechange = console.log( xhr.readyState ) + xhr.onprogress = () => { + var responseText = xhttxhrp.response.substr(last_response_len); + last_response_len = xhr.response.length; + update( responseText ) + } + xhr.send() + } + + ListModel{ + id: data + } + + Timer{ + id: reconnect + interval: 3000 + repeat: true + running: false + onTriggered: fetch() + } + Component.onCompleted: { + fetch() + } + + header: RowLayout{ + Label{ + Layout.alignment: Qt.AlignLeft + text: 'Nr of Elements: ' + nrOfElements.value + } + Slider{ + Layout.alignment: Qt.AlignLeft + id: nrOfElements + from: 5 + to: 25 + stepSize: 1 + onValueChanged: { + while( data.count > value ) + { + data.remove(0, 1); + } + } + } + Rectangle{ + Layout.alignment: Qt.AlignLeft + id: status + property bool online: window.online + width: 100 + height: 30 + color: online ? 'green' : 'red' + radius: 5 + Label{ + anchors.centerIn: parent + text: parent.online ? 'Online' : 'Offline' + } + } + Button{ + text: "Test" + onClicked: { + counter++; + var txt = "Counter " + counter + window.add( {type: "Message", txt: txt} ) + } + + } + Item{ + Layout.fillWidth: true + } + } + ListView{ + anchors.fill: parent + model: data + delegate: Label{ + text: type + ' : ' + txt + } + } +} \ No newline at end of file