Add a simple clock
This commit is contained in:
parent
9eaa40f809
commit
2cc997797c
@ -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)
|
||||
|
@ -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
|
||||
}
|
||||
}
|
@ -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")
|
Loading…
Reference in New Issue
Block a user