Files
Feeding_control_system/view/widgets/plan_widget.py
2025-11-01 16:13:30 +08:00

169 lines
6.0 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

from PySide6.QtWidgets import (QWidget, QVBoxLayout, QHBoxLayout, QLabel,
QApplication)
from PySide6.QtCore import Qt
from PySide6.QtGui import QPainter, QPixmap
from .value_adjuster import ValueAdjuster
from .switch_button import SwitchButton
import sys
import resources.resources_rc
from utils.image_paths import ImagePaths
class PlanWidget(QWidget):
def __init__(self, parent=None):
super().__init__(parent)
# 加载背景图
self.bg_pixmap = QPixmap(ImagePaths.TASK_PLAN_BACKGROUND)
self.setFixedSize(self.bg_pixmap.size())
# 存储可修改控件的字典
self.controls = {
"plan_no": None, # 计划单号
"volume": None, # 计划方量ValueAdjuster
"ratio": None, # 计划配比
"status": None, # 下发状态
"auto_dispatch": None # 自动派单SwitchButton
}
# 主垂直布局
main_layout = QVBoxLayout(self)
main_layout.setContentsMargins(13, 5, 6, 15)
main_layout.setSpacing(0)
# 第一行:计划单号
row1_layout = QHBoxLayout()
row1_layout.setSpacing(0)
status_icon1 = QLabel()
status_icon1.setPixmap(QPixmap(ImagePaths.TASK_RECT4))
status_icon1.setFixedSize(6, 6)
row1_layout.addWidget(status_icon1)
row1_layout.addSpacing(4)
label1 = QLabel("计划单号")
label1.setStyleSheet("font-size: 18px; color: #03f5ff;")
label1.setFixedSize(73, 20)
row1_layout.addWidget(label1, alignment=Qt.AlignLeft)
value1 = QLabel("PD0001")
value1.setStyleSheet("font-size: 18px; color: white;")
row1_layout.addWidget(value1)
main_layout.addLayout(row1_layout)
self.controls["plan_no"] = value1
# 第二行:计划方量
row2_layout = QHBoxLayout()
status_icon2 = QLabel()
status_icon2.setPixmap(QPixmap(ImagePaths.TASK_RECT1))
status_icon2.setFixedSize(6, 6)
row2_layout.addWidget(status_icon2)
row2_layout.addSpacing(4)
label2 = QLabel("计划方量")
label2.setStyleSheet("font-size: 18px; color: #03f5ff;")
row2_layout.addWidget(label2)
self.fangliang_adjuster = ValueAdjuster() # 导入的方量调整控件
row2_layout.addWidget(self.fangliang_adjuster)
main_layout.addLayout(row2_layout)
self.controls["volume"] = self.fangliang_adjuster
# 第三行:计划配比
row3_layout = QHBoxLayout()
status_icon3 = QLabel()
status_icon3.setFixedSize(6, 6)
status_icon3.setPixmap(QPixmap(ImagePaths.TASK_RECT2))
row3_layout.addWidget(status_icon3)
row3_layout.addSpacing(4)
label3 = QLabel("计划配比")
label3.setStyleSheet("font-size: 18px; color: #03f5ff;")
row3_layout.addWidget(label3)
value3 = QLabel("C55P12")
value3.setStyleSheet("font-size: 18px; color: white;")
row3_layout.addWidget(value3)
main_layout.addLayout(row3_layout)
# 存入字典
self.controls["ratio"] = value3
# 第四行:下发状态
row4_layout = QHBoxLayout()
status_icon4 = QLabel()
status_icon4.setFixedSize(6, 6)
status_icon4.setPixmap(QPixmap(ImagePaths.TASK_RECT3))
row4_layout.addWidget(status_icon4)
row4_layout.addSpacing(4)
label4 = QLabel("下发状态")
label4.setStyleSheet("font-size: 18px; color: #03f5ff;")
row4_layout.addWidget(label4)
value4 = QLabel("计划中")
value4.setStyleSheet("font-size: 18px; color: white;")
row4_layout.addWidget(value4)
main_layout.addLayout(row4_layout)
self.controls["status"] = value4
# 第五行:自动派单
row5_layout = QHBoxLayout()
status_icon5 = QLabel()
status_icon5.setPixmap(QPixmap(ImagePaths.TASK_RECT5))
status_icon5.setFixedSize(6, 6)
row5_layout.addWidget(status_icon5)
row5_layout.addSpacing(4)
label5 = QLabel("自动派单")
label5.setStyleSheet("font-size: 18px; color: #03f5ff;")
row5_layout.addWidget(label5)
self.switch = SwitchButton()
self.switch.setChecked(True)
row5_layout.addWidget(self.switch, alignment=Qt.AlignLeft)
main_layout.addLayout(row5_layout)
self.controls["auto_dispatch"] = self.switch
def paintEvent(self, event):
"""绘制背景图片"""
painter = QPainter(self)
painter.drawPixmap(self.rect(), self.bg_pixmap)
super().paintEvent(event)
# ------------------- 对外修改接口 -------------------
def set_plan_no(self, new_no:str):
"""修改计划单号"""
if self.controls["plan_no"]:
self.controls["plan_no"].setText(new_no)
def set_plan_volume(self, new_volume:float):
"""修改计划方量"""
if self.controls["volume"]:
self.controls["volume"].set_value(new_volume)
def set_plan_ratio(self, new_ratio:str):
"""修改计划配比"""
if self.controls["ratio"]:
self.controls["ratio"].setText(new_ratio)
def set_status(self, new_status:str):
"""修改下发状态"""
if self.controls["status"]:
self.controls["status"].setText(new_status)
def set_auto_dispatch(self, is_checked:bool):
"""修改自动派单开关状态, true: 开启自动派单, False: 关闭自动派单"""
if self.controls["auto_dispatch"]:
self.controls["auto_dispatch"].setChecked(is_checked)
if __name__ == "__main__":
app = QApplication(sys.argv)
widget = PlanWidget()
widget.show()
# 测试接口
widget.set_plan_no("PD0002") # 计划单号
widget.set_plan_ratio("C60P15") # 计划配比
widget.set_plan_volume(5) # 计划方量
widget.set_status("已下发") # 下发状态
widget.set_auto_dispatch(False) # 自动派单
sys.exit(app.exec())