Hating main event loop
This commit is contained in:
parent
111c4ce870
commit
ce060cac1a
|
@ -1,7 +1,9 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
import sys
|
import sys
|
||||||
|
import random
|
||||||
|
|
||||||
from PySide2.QtCore import (
|
from PySide2.QtCore import (
|
||||||
QDateTime, Qt
|
Qt, QTimer
|
||||||
)
|
)
|
||||||
from PySide2.QtWidgets import (
|
from PySide2.QtWidgets import (
|
||||||
QApplication, QMainWindow
|
QApplication, QMainWindow
|
||||||
|
@ -9,8 +11,8 @@ from PySide2.QtWidgets import (
|
||||||
from PySide2.QtCharts import (
|
from PySide2.QtCharts import (
|
||||||
QtCharts
|
QtCharts
|
||||||
)
|
)
|
||||||
|
|
||||||
from UM24CUI import Ui_MainWindow
|
from UM24CUI import Ui_MainWindow
|
||||||
import random
|
|
||||||
|
|
||||||
|
|
||||||
class UM24Lab(QMainWindow):
|
class UM24Lab(QMainWindow):
|
||||||
|
@ -27,48 +29,55 @@ class UM24Lab(QMainWindow):
|
||||||
self.ui.widgetCurrent.setChart(self.ui.plotCurrent)
|
self.ui.widgetCurrent.setChart(self.ui.plotCurrent)
|
||||||
|
|
||||||
# --- Voltage ---
|
# --- Voltage ---
|
||||||
voltage = self.ui.plotVoltage
|
self.voltage = self.ui.plotVoltage
|
||||||
series = QtCharts.QLineSeries()
|
self.voltage_series = QtCharts.QLineSeries()
|
||||||
series.setName('Voltage over time')
|
self.voltage_series.setName('Voltage over time')
|
||||||
# Add random demo data
|
self.voltage.addSeries(self.voltage_series)
|
||||||
for x in range(100):
|
|
||||||
y = random.randint(0, 10)
|
|
||||||
series.append(x, y)
|
|
||||||
voltage.addSeries(series)
|
|
||||||
|
|
||||||
axis_x = QtCharts.QValueAxis()
|
axis_x = QtCharts.QValueAxis()
|
||||||
axis_x.setTickCount(60)
|
axis_x.setTickCount(60)
|
||||||
axis_x.setTitleText('Seconds')
|
axis_x.setTitleText('Seconds')
|
||||||
voltage.addAxis(axis_x, Qt.AlignBottom)
|
self.voltage.addAxis(axis_x, Qt.AlignBottom)
|
||||||
series.attachAxis(axis_x)
|
self.voltage_series.attachAxis(axis_x)
|
||||||
|
|
||||||
axis_y = QtCharts.QValueAxis()
|
axis_y = QtCharts.QValueAxis()
|
||||||
axis_y.setTickCount(10)
|
axis_y.setTickCount(10)
|
||||||
axis_y.setTitleText('Voltage (V)')
|
axis_y.setTitleText('Voltage (V)')
|
||||||
voltage.addAxis(axis_y, Qt.AlignLeft)
|
self.voltage.addAxis(axis_y, Qt.AlignLeft)
|
||||||
series.attachAxis(axis_y)
|
self.voltage_series.attachAxis(axis_y)
|
||||||
|
|
||||||
# --- Current ---
|
# --- Current ---
|
||||||
current = self.ui.plotCurrent
|
self.current = self.ui.plotCurrent
|
||||||
series = QtCharts.QLineSeries()
|
self.current_series = QtCharts.QLineSeries()
|
||||||
series.setName('Current over time')
|
self.current_series.setName('Current over time')
|
||||||
# Add random demo data
|
self.current.addSeries(self.current_series)
|
||||||
for x in range(100):
|
|
||||||
y = random.randint(0, 10)
|
|
||||||
series.append(x, y)
|
|
||||||
current.addSeries(series)
|
|
||||||
|
|
||||||
axis_x = QtCharts.QValueAxis()
|
axis_x = QtCharts.QValueAxis()
|
||||||
axis_x.setTickCount(60)
|
axis_x.setTickCount(60)
|
||||||
axis_x.setTitleText('Seconds')
|
axis_x.setTitleText('Seconds')
|
||||||
current.addAxis(axis_x, Qt.AlignBottom)
|
self.current.addAxis(axis_x, Qt.AlignBottom)
|
||||||
series.attachAxis(axis_x)
|
self.current_series.attachAxis(axis_x)
|
||||||
|
|
||||||
axis_y = QtCharts.QValueAxis()
|
axis_y = QtCharts.QValueAxis()
|
||||||
axis_y.setTickCount(10)
|
axis_y.setTickCount(10)
|
||||||
axis_y.setTitleText('Current (A)')
|
axis_y.setTitleText('Current (A)')
|
||||||
current.addAxis(axis_y, Qt.AlignLeft)
|
self.current.addAxis(axis_y, Qt.AlignLeft)
|
||||||
series.attachAxis(axis_y)
|
self.current_series.attachAxis(axis_y)
|
||||||
|
|
||||||
|
self.timer_step = 0
|
||||||
|
self.voltage_series.append(self.timer_step, 0)
|
||||||
|
self.current_series.append(self.timer_step, 0)
|
||||||
|
|
||||||
|
timer = QTimer()
|
||||||
|
timer.timeout.connect(self.update_graphs)
|
||||||
|
timer.start(0)
|
||||||
|
|
||||||
|
def update_graphs(self):
|
||||||
|
self.voltage_series.append(self.timer_step, random.randint(0, 10))
|
||||||
|
self.current_series.append(self.timer_step, random.randint(0, 10))
|
||||||
|
self.ui.progressTempC.setValue(random.randint(0, 100))
|
||||||
|
self.timer_step += 1
|
||||||
|
self.update()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
@ -77,4 +86,13 @@ if __name__ == '__main__':
|
||||||
labview = UM24Lab()
|
labview = UM24Lab()
|
||||||
labview.show()
|
labview.show()
|
||||||
|
|
||||||
|
def idle_processor():
|
||||||
|
labview.update_graphs()
|
||||||
|
app.processEvents()
|
||||||
|
# print(labview.timer_step)
|
||||||
|
|
||||||
|
# mainTimer = QTimer()
|
||||||
|
# mainTimer.timeout.connect(idle_processor)
|
||||||
|
# mainTimer.start(50)
|
||||||
|
|
||||||
sys.exit(app.exec_())
|
sys.exit(app.exec_())
|
||||||
|
|
Loading…
Reference in New Issue