From 2cc997797c97627227b9060052b68ba02f69d7a4 Mon Sep 17 00:00:00 2001 From: "Alexander \"PapaTutuWawa" Date: Sat, 11 Jan 2025 22:25:38 +0000 Subject: [PATCH] Add a simple clock --- microkodi/main.py | 4 ++++ microkodi/qml/Main.qml | 22 ++++++++++++++++++++-- microkodi/ui/bridge.py | 8 +++++++- 3 files changed, 31 insertions(+), 3 deletions(-) diff --git a/microkodi/main.py b/microkodi/main.py index 550ee31..ee724d0 100644 --- a/microkodi/main.py +++ b/microkodi/main.py @@ -78,6 +78,10 @@ if __name__ == "__main__": "wallpapers", config.wallpapers, ) + engine.rootContext().setContextProperty( + "initialTime", + bridge.currentTime(), + ) engine.loadFromModule("qml", "Main") if not engine.rootObjects(): sys.exit(-1) diff --git a/microkodi/qml/Main.qml b/microkodi/qml/Main.qml index 529944e..87876c1 100644 --- a/microkodi/qml/Main.qml +++ b/microkodi/qml/Main.qml @@ -12,6 +12,7 @@ Window { property var wallpaperIndex: 0 property var isLoading: false property var bridge + property var currentTime: initialTime Connections { target: bridge @@ -22,6 +23,7 @@ Window { } Image { + id: wallpaperImage height: window.height width: window.width visible: true @@ -44,9 +46,25 @@ Window { } Timer { - interval: 5 * 60 * 1000 - running: true + interval: 30 * 1000 + running: !isLoading repeat: true onTriggered: wallpaperIndex = (wallpaperIndex + 1) % wallpapers.length } + + Timer { + interval: 5 * 1000 + running: true + repeat: true + onTriggered: currentTime = bridge.currentTime() + } + + Label { + text: currentTime + anchors.right: wallpaperImage.right + anchors.top: wallpaperImage.top + anchors.topMargin: 20 + anchors.rightMargin: 20 + font.pixelSize: 50 + } } \ No newline at end of file diff --git a/microkodi/ui/bridge.py b/microkodi/ui/bridge.py index f260ee7..3930bee 100644 --- a/microkodi/ui/bridge.py +++ b/microkodi/ui/bridge.py @@ -1,4 +1,6 @@ -from PySide6.QtCore import QObject, Signal +from datetime import datetime + +from PySide6.QtCore import QObject, Signal, Slot class DataBridge(QObject): """Bridge between the QML app and the Python "host".""" @@ -12,3 +14,7 @@ class DataBridge(QObject): def set_loading(self, state: bool): """Set the loading state in the UI.""" self.isLoading.emit(state) + + @Slot(result=str) + def currentTime(self) -> str: + return datetime.now().strftime("%H:%M") \ No newline at end of file