50 lines
1.7 KiB
Python
50 lines
1.7 KiB
Python
from PyQt6.QtWidgets import QWidget, QLabel, QVBoxLayout, QPushButton
|
|
from PyQt6.QtCore import QTimer, Qt
|
|
import time
|
|
from logger import logger
|
|
|
|
|
|
class Command(QWidget):
|
|
def __init__(self, startCommand, changeType, command_data, command_type):
|
|
super().__init__()
|
|
|
|
self.command_data = command_data
|
|
self.command_type = command_type
|
|
self.startCommand = startCommand
|
|
self.changeType = changeType
|
|
|
|
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(text="Загрузка данных")
|
|
self.commandLabel = QLabel(text="Тип загрузки")
|
|
|
|
for l in [self.commandLabel, 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)
|
|
|
|
self.chgButton = QPushButton("Изменить тип")
|
|
self.chgButton.clicked.connect(lambda: self.changeType('calc' if self.command_type() == 'base' else 'base'))
|
|
self.layout.addWidget(self.chgButton)
|
|
|
|
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()}")
|
|
self.commandLabel.setText(f"Тип загрузки {self.command_type()}") |