Update Python example with new API

This commit is contained in:
2020-11-18 16:20:28 +01:00
parent d756ef2c1e
commit 389e6a108a
3 changed files with 433 additions and 55 deletions

View File

@@ -29,7 +29,7 @@ import time
from threading import Thread
from signal import signal, SIGINT
import sys
from genericmonitor import GenericMonitor, GenericMonitorGroup, GenericMonitorItem
from genericmonitor import *
class TimerThread(Thread,GenericMonitor):
@@ -38,20 +38,24 @@ class TimerThread(Thread,GenericMonitor):
self.stopMainLoop()
def _displayTimerValue(self):
item = GenericMonitorItem('timer', onClick='signal', box='right')
group = GenericMonitorGroup('Timer', item)
curValue = self.timers[self.curTimer]
item.text = '%02d:%02d' % (int(curValue/60)%60, curValue%60)
text = '%02d:%02d' % (int(curValue/60)%60, curValue%60)
if curValue >= (60*60):
item.text = '%02d:%s' % (int(curValue/(60*60)), item.text)
text = '%02d:%s' % (int(curValue/(60*60)), text)
if self.curTimer == 0:
style = 'color:white'
if curValue > (60*60):
style += ';background-color:red'
if self.timerPaused and curValue:
style = 'color:black;background-color:white'
else:
style = 'color:white'
if curValue >= (60*60):
style += ';background-color:red'
else:
style = 'color:#215D9C'
item.style = style
self.notify(group)
self.textWidget.setText(text)
self.textWidget.setStyle(style)
self.notify(self.monitorGroup)
def run(self):
self.setupMonitor()
@@ -59,6 +63,12 @@ class TimerThread(Thread,GenericMonitor):
self.curTimer = 0
self.timerPaused = False
self._stopLoop = False
self.textWidget = GenericMonitorTextWidget('')
signals = {'on-click':'signal'}
self.monitorItem = GenericMonitorItem('timer', [self.textWidget], signals, box='right')
self.monitorGroup = GenericMonitorGroup('Timer', self.monitorItem)
while not self._stopLoop:
time.sleep(1)
if not self.timerPaused:
@@ -66,7 +76,7 @@ class TimerThread(Thread,GenericMonitor):
self._displayTimerValue()
def _forMe(self, sender):
return sender == 'timer@Timer'
return sender == self.monitorItem.getFullName()
def onClick(self, sender):
if not self._forMe(sender): return