add(增加了重量选择框和提示栏、以及优化了线路选择功能)

This commit is contained in:
2025-09-30 10:46:40 +08:00
parent a571d91fd5
commit adea31758d
4 changed files with 4242 additions and 10 deletions

112
main.py
View File

@ -48,6 +48,7 @@ from ui_MainWin import Ui_MainWindow
from view.ResetView import StopDialog
from EMV.EMV import RelayController
from CU.drop import DropPositionManager
import re
class MainWindow(QMainWindow, Ui_MainWindow):
@ -756,6 +757,7 @@ class MainWindow(QMainWindow, Ui_MainWindow):
self.last_time = time.time()
self.remain_lineName = self.configReader.get('Robot_Feed', 'remain_lineName')
self.remain_drop_weight = self.configReader.get("Robot_Feed", "remain_dropweight_kg") # 9/29 投料重量, 单位kg
self.remain_Count = int(self.configReader.get('Robot_Feed', 'remain_Count'))
self.maduo_Count = int(self.configReader.get('Robot_Feed', 'maduo_Count'))
self.label_remain_num.setText(str(self.remain_Count))
@ -898,8 +900,10 @@ class MainWindow(QMainWindow, Ui_MainWindow):
if line_model:
self.feedLine_dict[f'{Constant.dropLine_set_section}{i}'] = line_model
self.updateUI_Select_Line()
pass
# self.updateUI_Select_Line()
# 9/29 初始化线名选择框 和 重量选择框
self.updateui_select_line_by_feedLine_ini()
self.updateui_select_dropweight_by_drop_ini()
def init_robot_info(self):
j1_min = int(self.configReader.get('Robot_Feed', 'j1_min'))
@ -1729,6 +1733,90 @@ class MainWindow(QMainWindow, Ui_MainWindow):
self.comboBox_lineIndex.clear()
for key, value in self.feedLine_dict.items():
self.comboBox_lineIndex.addItem(value.name, key)
# 9/29: 只需要加载FeedLine.ini中的name 作为comboBox_lineIndex的选项
def updateui_select_line_by_feedLine_ini(self):
self.comboBox_lineIndex.clear()
configReader = configparser.ConfigParser()
configReader.read(Constant.feedLine_set_file, encoding="utf-8")
for index in range(1, Constant.MAX_Line_num):
section = f"{Constant.feedLine_set_section}{index}"
if configReader.has_section(section):
line_name = configReader.get(section, "name")
self.comboBox_lineIndex.addItem(line_name, section)
# 设置初始化选中,初始选中 f'{Constant.feedLine_set_section}{self.remain_linename}'
if self.remain_lineName:
selected_value = f"{Constant.feedLine_set_section}{self.remain_lineName}"
selected_index = self.comboBox_lineIndex.findData(selected_value)
if selected_index >= 0:
self.comboBox_lineIndex.setCurrentIndex(selected_index)
# 9/29 初始化加载 drop.ini 中的name获取预先设置的重量
def updateui_select_dropweight_by_drop_ini(self):
self.comboBox_dropWeight.clear()
configReader = configparser.ConfigParser()
# 读取重量路径配置文件 drop.ini
configReader.read(Constant.dropLine_set_file, encoding="utf-8")
# drop_name匹配xxxkg获取重量
weight_pattern = re.compile(r'(\d+kg)')
for index in range(1, Constant.MAX_Line_num):
section = f"{Constant.dropLine_set_section}{index}"
if configReader.has_section(section):
drop_name = configReader.get(section, "name")
match = weight_pattern.search(drop_name)
if match:
# 提取匹配到的内容(如"50kg"
weight_text = match.group(1)
else:
# 无法匹配xxxkg 则使用"未知重量"
weight_text = "未知重量"
# userData: 如 DropLine50kg
userData = f"{Constant.dropLine_set_section}{weight_text}"
self.comboBox_dropWeight.addItem(weight_text, userData)
# 连接槽函数
self.comboBox_dropWeight.currentIndexChanged.connect(self.on_drop_weight_changed)
# 设置初始化选中的重量
if self.remain_drop_weight:
# selected_value: 如 DropLine50kg
selected_value = f"{Constant.dropLine_set_section}{self.remain_drop_weight}kg"
selected_index = self.comboBox_dropWeight.findData(selected_value)
if selected_index >= 0:
self.comboBox_dropWeight.setCurrentIndex(selected_index)
# 初始化重量提示标签
self.weight_label_info.setText(f"Tips: 当前选择的码垛重量为 {self.remain_drop_weight}kg")
"""9/29 重量下拉框选中项变化时, 更新self.remain_drop_weight"""
def on_drop_weight_changed(self, index):
# 默认的重量为 50 kg
default_weight = 50
if index < 0: # 没有选中项时(如下拉框为空)
self.remain_drop_weight = default_weight
return
# 获取当前选中项的显示文本(如"50kg"
selected_text = self.comboBox_dropWeight.currentText()
# 提取重量数值(从"50kg"中提取"50"
weight_pattern = re.compile(r'(\d+)kg')
match = weight_pattern.search(selected_text)
if match:
# 提取数字部分(如"50"
self.remain_drop_weight = match.group(1)
else:
# 若为"未知重量"remain_drop_weight 也为 default_weight
self.remain_drop_weight = default_weight
# 更新上方的码垛重量提示Tips
self.weight_label_info.setText(f"Tips: 当前选择的码垛重量为 {selected_text}")
def updateUI_label_status(self):
if self.robotClient.status_model.isMoving==1:
self.label_move_sign.show()
@ -2201,7 +2289,9 @@ class MainWindow(QMainWindow, Ui_MainWindow):
def send_click_change_stackView(self,index):
self.stackedWidget_view.setCurrentIndex(index)
if index == 0:
self.updateUI_Select_Line()
# 9/29 切换界面,不刷新 线名选择框 comboBox_lineIndex
# self.updateUI_Select_Line()
pass
if index == 2:
self.updateRobotSeting()
self.updateUI_Photo_Set()
@ -2265,16 +2355,20 @@ class MainWindow(QMainWindow, Ui_MainWindow):
#记录投料袋数
def record_remain_num(self):
try:
self.configReader = configparser.ConfigParser()
self.configReader.read(Constant.set_ini)
if self.feeding.feedConfig:
self.configReader = configparser.ConfigParser()
self.configReader.read(Constant.set_ini)
if self.feeding.feedConfig:
self.configReader.set('Robot_Feed', 'remain_linename', str(self.feeding.feedConfig.feedLine.id))
self.configReader.set('Robot_Feed', 'remain_count', str(self.feeding.feedConfig.remain_count))
if self.cur_pushbutton_num:
if self.cur_pushbutton_num:
self.configReader.set('Robot_Feed', 'maduo_count', self.cur_pushbutton_num.text())
self.configReader.write(open(Constant.set_ini, 'w', encoding='utf-8'))
# 9/29 保存 remain_dropweight_kg 投料的重量35、50 (单位kg)
self.configReader.set("Robot_Feed", "remain_dropweight_kg", str(self.remain_drop_weight))
self.configReader.write(open(Constant.set_ini, 'w', encoding='utf-8'))
except:
log.log_message(logging.ERROR, Constant.str_sys_log_feedNum)
log.log_message(logging.ERROR, Constant.str_sys_log_feedNum)
class MyApplication(QApplication):