Merge pull request 'feature/weight_show' (#2) from feature/weight_show into bugfix/ui_sensor_reset

Reviewed-on: #2
This commit is contained in:
2025-09-30 15:52:17 +08:00
5 changed files with 4505 additions and 61 deletions

314
.gitignore vendored
View File

@ -1,64 +1,276 @@
# Python
**/__pycache__/
# ---> Qt
# C++ objects and libs
*.slo
*.lo
*.o
*.a
*.la
*.lai
*.so
*.so.*
*.dll
*.dylib
# Qt-es
object_script.*.Release
object_script.*.Debug
*_plugin_import.cpp
/.qmake.cache
/.qmake.stash
*.pro.user
*.pro.user.*
*.qbs.user
*.qbs.user.*
*.moc
moc_*.cpp
moc_*.h
qrc_*.cpp
ui_*.h
*.qmlc
*.jsc
Makefile*
*build-*
*.qm
*.prl
# Qt unit tests
target_wrapper.*
# QtCreator
*.autosave
# QtCreator Qml
*.qmlproject.user
*.qmlproject.user.*
# QtCreator CMake
CMakeLists.txt.user*
# QtCreator 4.8< compilation database
compile_commands.json
# QtCreator local machine specific files for imported projects
*creator.user*
*_qmlcache.qrc
# ---> Python
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
# C extensions
*.so
# IDEs and editors
.idea/
# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST
# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/
# Translations
*.mo
*.pot
# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal
# Flask stuff:
instance/
.webassets-cache
# Scrapy stuff:
.scrapy
# Sphinx documentation
docs/_build/
# PyBuilder
.pybuilder/
target/
# Jupyter Notebook
.ipynb_checkpoints
# IPython
profile_default/
ipython_config.py
# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version
# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock
# UV
# Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
#uv.lock
# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock
# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
#pdm.lock
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
# in version control.
# https://pdm.fming.dev/latest/usage/project/#working-with-version-control
.pdm.toml
.pdm-python
.pdm-build/
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/
# Celery stuff
celerybeat-schedule
celerybeat.pid
# SageMath parsed files
*.sage.py
# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/
# Spyder project settings
.spyderproject
.spyproject
# Rope project settings
.ropeproject
# mkdocs documentation
/site
# mypy
.mypy_cache/
.dmypy.json
dmypy.json
# Pyre type checker
.pyre/
# pytype static type analyzer
.pytype/
# Cython debug symbols
cython_debug/
# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
# Ruff stuff:
.ruff_cache/
# PyPI configuration file
.pypirc
# 忽略.vscode文件夹
.vscode/
*.suo
# *.ntvs*
# *.njsproj
# # *.sln
# *.sw?
.VSCodeCounter
# OS generated files
# .DS_Store
# .DS_Store?
# ._*
# .Spotlight-V100
# .Trashes
# ehthumbs.db
# Thumbs.db
# 忽略工作区文件
*.code-workspace
.DS_Store
# Logs
# 忽略 .idea
.idea/
# 忽略python缓存文件
*/__pycache__
*.py[cod]
# 忽略日志文件
log/
*.log
*.log.*
# 忽略测试文件
test.py
# Temporary files
# *.tmp
# *.temp
# .cache/
# 忽略配置文件
config.json
# Test coverage
# .coverage
# .coverage.*
# coverage.xml
# 忽略下载文件夹
download/
# Debug
# *.pyc
# *.pyd
# *.so
# *.dll
# *.exe
# Runtime data
# pids
# *.pid
# *.seed
# *.pid.lock
# Project specific
# test.py
# test2.py
# test3.py
# test6.py
# TEST3.py
# workflow_test.py
# MvFGSdkLog/
# MvSDKLog/
# Trace/com_pose.txt
# Trace/com_pose2.txt
# 忽略构建文件夹
build/
dist/
PyQt_Fluent_Widgets.egg-info/
PySide6_Fluent_Widgets.egg-info/
PyQt6_Fluent_Widgets.egg-info/
PySide2_Fluent_Widgets.egg-info/
/COM/__pycache__
/__pycache__
/CU/__pycache__
/EMV/__pycache__
/Model/__pycache__
/Trace/__pycache__
/Util/__pycache__
/view/__pycache__
/log/log.log

View File

@ -47,6 +47,7 @@ photo_v5 = 0.0
photo_w5 = 1.0
linecount = 2
remain_linename = 1
remain_dropweight_kg = 50
remain_count = 18
maduo_count = 30
io_take_addr = 8

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):
@ -764,6 +765,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))
@ -803,8 +805,10 @@ class MainWindow(QMainWindow, Ui_MainWindow):
if line_model:
self.feedLine_dict[f'{Constant.dropLine_set_section}-35'] = 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'))
@ -1491,6 +1495,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()
@ -1945,7 +2033,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()
@ -2009,16 +2099,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):

4064
ui_MainWin - 副本 (3).py Normal file

File diff suppressed because it is too large Load Diff

View File

@ -628,7 +628,36 @@ class Ui_MainWindow(object):
"border-image: None;")
self.frame_sign_2.setFrameShape(QFrame.Shape.StyledPanel)
self.frame_sign_2.setFrameShadow(QFrame.Shadow.Raised)
self.gridLayout_4 = QGridLayout(self.frame_sign_2)
# 9/30 新增显示 投料的重量的信息
self.verticalLayout_sign = QVBoxLayout(self.frame_sign_2)
self.verticalLayout_sign.setObjectName(u"verticalLayout_sign")
self.verticalLayout_sign.setContentsMargins(0, 0, 0, 0) # 清除边距
self.verticalLayout_sign.setSpacing(5) # 新标签与下方网格布局的间距
# 1. 添加新的信息标签(放在上方)
self.weight_label_info = QLabel(self.frame_sign_2)
self.weight_label_info.setObjectName(u"label_info")
# 设置标签样式 background-color: #2c2c2c;
self.weight_label_info.setStyleSheet(u"""
QLabel {
background-color: rgba(255, 255, 255, 0);
color: red;
font: 11pt "Microsoft YaHei UI";
padding: 5px;
border-radius: 3px;
}
""")
self.weight_label_info.setText("显示当前的重量") # 初始信息
# self.weight_label_info.setAlignment(Qt.AlignmentFlag.AlignLeft | Qt.AlignmentFlag.AlignVCenter)
self.weight_label_info.setAlignment(Qt.AlignmentFlag.AlignCenter) # 居中
self.verticalLayout_sign.addWidget(self.weight_label_info)
# 9/10
# self.gridLayout_4 = QGridLayout(self.frame_sign_2)
self.gridLayout_4 = QGridLayout()
self.gridLayout_4.setObjectName(u"gridLayout_4")
self.pushButton_sign_go = QPushButton(self.frame_sign_2)
self.pushButton_sign_go.setObjectName(u"pushButton_sign_go")
@ -786,6 +815,9 @@ class Ui_MainWindow(object):
self.gridLayout_4.addWidget(self.label_sign_feed, 0, 7, 1, 1)
# 9/10 添加 取料中、拍照中等布局
self.verticalLayout_sign.addLayout(self.gridLayout_4)
self.verticalLayout_14.addWidget(self.frame_sign_2)
@ -3310,6 +3342,47 @@ class Ui_MainWindow(object):
self.verticalLayout_11.addWidget(self.comboBox_lineIndex)
# 9/29 新增重量选择框 和 选择投料重量提示
weight_h_layout = QHBoxLayout()
# weight_h_layout.setSpacing(10)
self.weight_label = QLabel(self.frame_20)
self.weight_label.setText("选择码垛重量:")
self.weight_label.setStyleSheet("color: white;")
weight_h_layout.addWidget(self.weight_label)
self.comboBox_dropWeight = QComboBox(self.frame_20)
self.comboBox_dropWeight.setObjectName(u"comboBox_dropWeight")
self.comboBox_dropWeight.setStyleSheet(u"QComboBox {\n"
" border-radius: 10px;\n"
" padding: 5px 5px 5px 5px;\n"
" background-color: #2c2c2c;\n"
" color: white;\n"
" border: 1px solid #474747;\n"
" min-width: 80px;\n"
"}\n"
"\n"
"\n"
"QComboBox::drop-down {\n"
" width: 0px;\n"
" border: none;\n"
"\n"
"}\n"
"\n"
"QComboBox::down-arrow {\n"
" image: none;\n"
"}\n"
"\n"
"QComboBox QAbstractItemView {\n"
" border-bottom-right-radius: 10px;\n"
" border-bottom-left-radius: 10px;\n"
" background-color: #D3D3D3;\n"
" border: 1px solid gray;\n"
" padding: 4px 4px 4px 4px;\n"
" outline: none;\n"
"}")
weight_h_layout.addWidget(self.comboBox_dropWeight)
self.verticalLayout_11.addLayout(weight_h_layout)
self.stackedWidget_num = QStackedWidget(self.frame_20)
self.stackedWidget_num.setObjectName(u"stackedWidget_num")
self.stackedWidget_num.setStyleSheet(u"border:none;")