Add a simple clock

This commit is contained in:
PapaTutuWawa 2025-01-11 22:25:38 +00:00
parent 9eaa40f809
commit 2cc997797c
3 changed files with 31 additions and 3 deletions

View File

@ -78,6 +78,10 @@ if __name__ == "__main__":
"wallpapers", "wallpapers",
config.wallpapers, config.wallpapers,
) )
engine.rootContext().setContextProperty(
"initialTime",
bridge.currentTime(),
)
engine.loadFromModule("qml", "Main") engine.loadFromModule("qml", "Main")
if not engine.rootObjects(): if not engine.rootObjects():
sys.exit(-1) sys.exit(-1)

View File

@ -12,6 +12,7 @@ Window {
property var wallpaperIndex: 0 property var wallpaperIndex: 0
property var isLoading: false property var isLoading: false
property var bridge property var bridge
property var currentTime: initialTime
Connections { Connections {
target: bridge target: bridge
@ -22,6 +23,7 @@ Window {
} }
Image { Image {
id: wallpaperImage
height: window.height height: window.height
width: window.width width: window.width
visible: true visible: true
@ -44,9 +46,25 @@ Window {
} }
Timer { Timer {
interval: 5 * 60 * 1000 interval: 30 * 1000
running: true running: !isLoading
repeat: true repeat: true
onTriggered: wallpaperIndex = (wallpaperIndex + 1) % wallpapers.length 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
}
} }

View File

@ -1,4 +1,6 @@
from PySide6.QtCore import QObject, Signal from datetime import datetime
from PySide6.QtCore import QObject, Signal, Slot
class DataBridge(QObject): class DataBridge(QObject):
"""Bridge between the QML app and the Python "host".""" """Bridge between the QML app and the Python "host"."""
@ -12,3 +14,7 @@ class DataBridge(QObject):
def set_loading(self, state: bool): def set_loading(self, state: bool):
"""Set the loading state in the UI.""" """Set the loading state in the UI."""
self.isLoading.emit(state) self.isLoading.emit(state)
@Slot(result=str)
def currentTime(self) -> str:
return datetime.now().strftime("%H:%M")