-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmonitor_demo.py
56 lines (41 loc) · 1.96 KB
/
monitor_demo.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# -*- coding: utf-8 -*-
import sys
import random
from PySide2.QtWidgets import QApplication, QHBoxLayout
from ..dashboard.monitor import *
from ..gui.widget import BasicWidget
from ..gui.container import ComponentManager
class DemoWidget(BasicWidget):
def __init__(self, parent=None):
super(DemoWidget, self).__init__(parent)
def _initUi(self):
layout = QHBoxLayout()
self.ui_temp1 = TemperatureMonitor("温度1", 100, parent=self)
self.ui_temp2 = TemperatureMonitor("温度2", 100, unit_id=1, parent=self)
self.ui_pressure1 = PressureMonitor("压力1", parent=self)
self.ui_pressure2 = PressureMonitor("压力2", unit_id=0, parent=self)
self.ui_pressure3 = PressureMonitor("压力3", unit_id=1, parent=self)
for element in (self.ui_temp1, self.ui_temp2, self.ui_pressure1, self.ui_pressure2, self.ui_pressure3):
layout.addWidget(element)
self.ui_manager = ComponentManager(layout)
# for pressure in self.ui_manager.getByType(PressureMonitor):
# pressure.setSV(1000)
self.setLayout(layout)
self.setWindowTitle("温度/压力监控")
# def _initStyle(self):
# self.setMinimumSize(QSize(900, 300))
def _initSignalAndSlots(self):
self.startTimer(500)
def timerEvent(self, ev):
temperature = random.randint(0, self.ui_temp1.getSV())
temperature += random.choice(range(0, 11)) / 10.0 + random.choice(range(0, 11)) / 100.0
pressure = random.randint(0, 600) + random.choice(range(0, 11)) / 10.0 + random.choice(range(0, 11)) / 100.0
for pressure_monitor in self.ui_manager.getByType(PressureMonitor):
pressure_monitor.setRV(pressure)
for temperature_monitor in self.ui_manager.getByType(TemperatureMonitor):
temperature_monitor.setRV(temperature)
if __name__ == '__main__':
app = QApplication(sys.argv)
widget = DemoWidget()
widget.show()
sys.exit(app.exec_())