modbus_test/gui/informer.py

52 lines
1.9 KiB
Python

from PyQt6.QtWidgets import QWidget, QLabel, QVBoxLayout, QPushButton
from PyQt6.QtCore import QTimer, Qt
import time
from logger import logger
class Informer(QWidget):
def __init__(self, updateData, world_coord, axis_coord, command_count):
super().__init__()
self.world_coord = world_coord
self.axis_coord = axis_coord
self.command_count = command_count
self.updateData = updateData
self.timer = QTimer()
self.timer.timeout.connect(self.updateState)
self.timer.start(int(100))
# Инициализация пользовательского интерфейса
self.initUI()
def initUI(self):
self.layout = QVBoxLayout()
self.setLayout(self.layout)
self.wLabel = QLabel(f'Мировые координаты {self.world_coord()}')
self.aLabel = QLabel(f'Поворот осей {self.axis_coord()}')
self.cLabel = QLabel(f'Количество команд в стеке {self.command_count()}')
for l in [self.wLabel, self.aLabel, self.cLabel]:
l.setWordWrap(True)
self.layout.addWidget(l)
self.updButton = QPushButton('Обновить данные')
self.updButton.clicked.connect(self.updateData)
self.layout.addWidget(self.updButton)
def paintEvent(self, event):
# Установка цвета фона
self.setAutoFillBackground(True)
p = self.palette()
p.setColor(self.backgroundRole(), Qt.GlobalColor.lightGray)
self.setPalette(p)
def updateState(self):
self.wLabel.setText(f'Мировые координаты {self.world_coord()}')
self.aLabel.setText(f'Поворот осей {self.axis_coord()}')
self.cLabel.setText(f'Количество команд в стеке {self.command_count()}')