modbus_test/gui/command.py

42 lines
1.2 KiB
Python

from PyQt5.QtWidgets import QWidget, QLabel, QVBoxLayout, QPushButton
from PyQt5.QtCore import QTimer, Qt
import time
from logger import logger
class Command(QWidget):
def __init__(self, startCommand, command_data):
super().__init__()
self.command_data = command_data
self.startCommand = startCommand
self.initUI()
self.timer = QTimer()
self.timer.timeout.connect(self.updateState)
self.timer.start(int(100))
def initUI(self):
self.layout = QVBoxLayout()
self.setLayout(self.layout)
self.stepLabel = QLabel()
for l in [self.stepLabel]:
l.setWordWrap(True)
self.layout.addWidget(l)
self.updButton = QPushButton("Запустить single cycle")
self.updButton.clicked.connect(self.startCommand)
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.stepLabel.setText(f"{self.command_data()}")