Merge branch 'feature/main_ui' of http://www.xj-robot.com:3000/xiongyi/Feeding_control_system into feature/main_ui
This commit is contained in:
@ -63,6 +63,33 @@ class MainController:
|
||||
"""更新UI状态"""
|
||||
# print(f"更新UI状态: {prop} = {value}")
|
||||
|
||||
if prop == "feed_status" and value == 4:
|
||||
# 盖板到位的情况, 更新 管片任务 (目前)
|
||||
self.main_window.update_segment_tasks()
|
||||
return
|
||||
|
||||
if prop == "mould_finish_weight":
|
||||
# 模具车中料的重量
|
||||
current_mould_weight = value
|
||||
if self.system.state._mould_need_weight != 0:
|
||||
# 计算 模具车 和 生产进度
|
||||
progress = int((current_mould_weight / self.system.state._mould_need_weight) * 100) # 去掉百分号之后的整数
|
||||
progress = min(progress, 100) # 限制为100
|
||||
self.main_window.arc_progress.setProgress(progress)
|
||||
self.main_window.production_progress.setProgress(progress)
|
||||
return
|
||||
|
||||
if prop == "upper_volume":
|
||||
# 上料斗方量
|
||||
self.hopper_controller.onUpdateUpperHopperVolume(value)
|
||||
return
|
||||
|
||||
if prop == "lower_weight":
|
||||
# 低位料斗重量
|
||||
self.hopper_controller.onUpdateLowerHopperWeight(value)
|
||||
return
|
||||
|
||||
|
||||
def __connectSignals(self):
|
||||
self.main_window.about_to_close.connect(self.handleMainWindowClose) # 处理主界面关闭
|
||||
|
||||
|
||||
@ -112,39 +112,73 @@ class MainWindow(QWidget):
|
||||
self.bottom_control_widget = BottomControlWidget() # 最下方: 控制的按钮 (系统诊断、系统中心等)
|
||||
|
||||
def initSubWidgets(self):
|
||||
# 初始化派单任务的 任务id
|
||||
self.dispatch_task_widget.set_task_id("task1", "PD0001")
|
||||
self.dispatch_task_widget.set_task_id("task2", "PD0002")
|
||||
self.dispatch_task_widget.set_task_id("task3", "PD0003")
|
||||
|
||||
# 读取数据库,初始化 管片任务的数据
|
||||
from busisness.blls import ArtifactBll, PDRecordBll
|
||||
artifact_dal = ArtifactBll()
|
||||
artifacts = artifact_dal.get_artifact_task()
|
||||
# print("\n打印artifacts数据:")
|
||||
for i, artifact in enumerate(artifacts):
|
||||
# 如果是数据类对象,转换为字典输出
|
||||
# print(artifact.MouldCode)
|
||||
# if hasattr(artifact, "__dataclass_fields__"):
|
||||
# print(f"第{i+1}条: {artifact.__dict__}")
|
||||
# else:
|
||||
# print(f"第{i+1}条: {artifact}")
|
||||
self.segment_task_widget.set_task_id(f"task{i + 1}", artifact.MouldCode)
|
||||
self.segment_task_widget.set_task_volume(f"task{i + 1}", artifact.BetonVolume)
|
||||
pass
|
||||
# 初始化 管片任务 和 派单任务显示的数据
|
||||
self.update_segment_tasks()
|
||||
self.update_dispatch_tasks()
|
||||
|
||||
pdrecord_dal = PDRecordBll()
|
||||
pdrecords = pdrecord_dal.get_PD_record()
|
||||
# print(pdrecords[0].MouldCode)
|
||||
# print("\n打印pdrecords数据:")
|
||||
for i, record in enumerate(pdrecords):
|
||||
# 如果是数据类对象,转换为字典输出
|
||||
# print(record.__dict__["MouldCode"])
|
||||
# if hasattr(record, "__dataclass_fields__"):
|
||||
# print(f"第{i+1}条: {record.__dict__}")
|
||||
# else:
|
||||
# print(f"第{i+1}条: {record}")
|
||||
self.dispatch_task_widget.set_task_volume(f"task{i + 1}", record.BetonVolume)
|
||||
pass
|
||||
def update_segment_tasks(self):
|
||||
"""从数据库中读取管片任务数据并更新到UI"""
|
||||
def convert_to_ampm(time_str: str) -> str:
|
||||
"""
|
||||
将时间转换为"hh:mmAM/PM"形式(如03:22PM)
|
||||
Args:
|
||||
time_str: 原始时间字符串"
|
||||
Returns:
|
||||
转换后的时间字符串(如"03:22PM")
|
||||
"""
|
||||
from datetime import datetime
|
||||
# 可能的时间格式(优先尝试带微秒的格式)
|
||||
time_formats = [
|
||||
"%Y-%m-%d %H:%M:%S", # 不带微秒
|
||||
"%Y-%m-%d %H:%M:%S.%f" # 带微秒(如.528453)
|
||||
]
|
||||
|
||||
for fmt in time_formats:
|
||||
try:
|
||||
dt = datetime.strptime(time_str, fmt)
|
||||
return dt.strftime("%I:%M%p") # 转换为12小时制时分+AM/PM
|
||||
except ValueError:
|
||||
continue # 格式不匹配,尝试下一种格式
|
||||
|
||||
# 所有格式都不匹配时,返回占位符
|
||||
return "--:--"
|
||||
|
||||
try:
|
||||
from busisness.blls import ArtifactBll
|
||||
artifact_dal = ArtifactBll()
|
||||
artifacts = artifact_dal.get_artifact_task() # 获取管片任务数据
|
||||
|
||||
# 遍历数据并更新UI
|
||||
for i, artifact in enumerate(artifacts):
|
||||
# 更新任务ID和方量到管片任务
|
||||
self.segment_task_widget.set_task_id(f"task{i + 1}", artifact.MouldCode)
|
||||
self.segment_task_widget.set_task_volume(f"task{i + 1}", artifact.BetonVolume)
|
||||
if artifact.BeginTime: # 更新时间
|
||||
# print("artifact.BeginTime: ", artifact.BeginTime)
|
||||
self.segment_task_widget.set_task_time(f"task{i + 1}", convert_to_ampm(artifact.BeginTime))
|
||||
|
||||
except Exception as e:
|
||||
print(f"更新管片任务数据失败: {e}")
|
||||
|
||||
def update_dispatch_tasks(self):
|
||||
"""从数据库中读取派单任务数据并更新到UI"""
|
||||
try:
|
||||
from busisness.blls import PDRecordBll
|
||||
pdrecord_dal = PDRecordBll()
|
||||
pdrecords = pdrecord_dal.get_PD_record() # 获取派单任务数据
|
||||
|
||||
# 遍历数据并更新UI
|
||||
for i, record in enumerate(pdrecords):
|
||||
# 更新方量到派单任务widget
|
||||
self.dispatch_task_widget.set_task_volume(f"task{i + 1}", record.BetonVolume)
|
||||
|
||||
except Exception as e:
|
||||
print(f"更新派单任务数据失败: {e}")
|
||||
|
||||
def setupLayout(self):
|
||||
"""设置垂直布局,从上到下排列部件"""
|
||||
|
||||
Reference in New Issue
Block a user