update 更新界面显示_3

This commit is contained in:
FrankCV2048
2024-09-13 23:45:15 +08:00
parent cf4f114609
commit 96da34f983
59 changed files with 648 additions and 27743 deletions

93
app.py
View File

@ -7,7 +7,7 @@ from multiprocessing import Process
from PyQt5.uic.properties import QtWidgets
from PySide6.QtCore import QThread, Signal, Slot, QObject, QEvent
from PySide6.QtGui import QIntValidator, QStandardItemModel, QStandardItem, Qt
from PySide6.QtGui import QIntValidator, QStandardItemModel, QStandardItem, Qt, QMovie
from PySide6.QtWidgets import QApplication, QMainWindow, QPushButton, QLabel, QHeaderView, QTableWidget, \
QTableWidgetItem, QWidget, QHBoxLayout, QAbstractItemView, QMessageBox
from datetime import datetime
@ -29,7 +29,7 @@ from queue import Queue
from Model.Position import Real_Position, Detection_Position
from threading import Thread
from CU.Command import Status
from Util.util_log import log
class MainWindow(QMainWindow, Ui_MainWindow):
def __init__(self):
@ -98,14 +98,8 @@ class MainWindow(QMainWindow, Ui_MainWindow):
"""
def init_log(self):
log.init_log(self.textEdit_log_info, self.textEdit_log_error, Constant.log_file_path)
self.logger_textEdit = logging.getLogger("QTextEditLogger")
self.logger_textEdit.setLevel(logging.DEBUG)
text_edit_handler = QTextEditLogger(self.textEdit_log_info)
formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s', datefmt='%Y-%m-%d %H:%M:%S')
text_edit_handler.setFormatter(formatter)
self.logger_textEdit.addHandler(text_edit_handler)
def init_UI(self):
self.pushButton_num1.clicked.connect(self.send_num_button_click)
@ -142,12 +136,15 @@ class MainWindow(QMainWindow, Ui_MainWindow):
self.pushButton_pauseFeed.clicked.connect(self.send_pauseFeed_button_click)
self.pushButton_clearAlarm.clicked.connect(self.send_clear_alarm_command)
self.pushButton_reset.clicked.connect(self.send_reset_button_click)
self.pushButton_speed.setText(str(Constant.speed))
self.pushButton_speed.clicked.connect(self.send_setSpeed_label_doubelClick)
self.lineEdit_speed.returnPressed.connect(self.send_setSpeed_lineEdit_returePressed)
self.lineEdit_num.returnPressed.connect(self.send_custom_num_returnPressed)
self.tabWidget_control.currentChanged.connect(self.send_tabWidget_control_change)
int_validator = QIntValidator(0, 100, self.lineEdit_num)
self.lineEdit_num.setValidator(int_validator)
@ -160,6 +157,7 @@ class MainWindow(QMainWindow, Ui_MainWindow):
self.horizontalSlider_feedingNum.blockSignals(True)
self.horizontalSlider_feedingNum.setMinimum(0)
self.lineEdit_speed.hide()
self.pushButton_stopFeed.hide()
self.pushButton_pauseFeed.hide()
@ -365,12 +363,18 @@ class MainWindow(QMainWindow, Ui_MainWindow):
pass
def send_startFeed_button_click(self):
# 触发自动运行
if self.robotClient.status_model.curMode != 7:
self.send_switch_tool_command()
log.log_message(logging.INFO, Constant.str_sys_switch_tool)
self.send_start_tool_command()
log.log_message(logging.INFO, Constant.str_sys_start_tool)
num = self.horizontalSlider_feedingNum.maximum()
line_index = str(self.comboBox_lineIndex.currentIndex() + 1)
line_head = self.comboBox_lineIndex.currentData()
self.command_quene.put(FeedCommand(FeedingConfig(num, self.feedLine_dict[line_head])))
self.stackedWidget_num.setCurrentIndex(1)
self.set_run_status_button(True)
log.log_message(logging.INFO, f'{self.feedLine_dict[line_head].name}:{Constant.str_feed_start}')
def send_num_button_click(self):
button = self.sender()
@ -440,8 +444,23 @@ class MainWindow(QMainWindow, Ui_MainWindow):
def send_addNum_button_click(self):
self.feeding.feedConfig.num += 1
log.log_message(logging.INFO, Constant.str_sys_feedNum_add)
max_num = int(self.label_maxNum.text()) + 1
self.horizontalSlider_feedingNum.setMaximum(max_num)
self.label_maxNum.setText(str(max_num))
def send_subNum_button_click(self):
if self.feeding.feedConfig.num <= 1:
#self.send_stopFeed_button_click()
self.feeding.feedStatus = FeedStatus.FNone
# 清空运行命令
self.send_clear_auto_command()
log.log_message(logging.INFO, Constant.str_feed_stop)
return
self.feeding.feedConfig.num -= 1
log.log_message(logging.INFO, Constant.str_sys_feedNum_sub)
max_num = int(self.label_maxNum.text())-1
self.horizontalSlider_feedingNum.setMaximum(max_num)
self.label_maxNum.setText(str(max_num))
def send_custom_num_returnPressed(self):
self.pushButton_num_free.show()
@ -449,6 +468,7 @@ class MainWindow(QMainWindow, Ui_MainWindow):
self.horizontalSlider_feedingNum.setMaximum(int(self.lineEdit_num.text()))
self.horizontalSlider_feedingNum.setValue(0)
self.label_maxNum.setText(self.lineEdit_num.text())
log.log_message(logging.INFO, f'{Constant.str_sys_setFeedNum}:{self.label_maxNum.text()} ')
def send_stack_feedSet_button_click(self, index):
# self.logger.info("This is an info message")
@ -468,7 +488,7 @@ class MainWindow(QMainWindow, Ui_MainWindow):
return
def send_position_returnPressed(self):
log.log_message(logging.INFO, Constant.str_sys_manualPosition)
self.send_position_command(float(self.lineEdit_j1.text()),
float(self.lineEdit_j2.text()),
float(self.lineEdit_j3.text()),
@ -486,6 +506,7 @@ class MainWindow(QMainWindow, Ui_MainWindow):
self.lineEdit_speed.hide()
self.pushButton_speed.setText(str(Constant.speed))
self.pushButton_speed.show()
log.log_message(logging.INFO, Constant.str_sys_setSpeed + str(Constant.speed))
pass
def send_get_safe_position_button_click(self):
@ -550,23 +571,37 @@ class MainWindow(QMainWindow, Ui_MainWindow):
pass
def send_stopFeed_button_click(self):
pass
# 清空状态
self.feeding.feedStatus = FeedStatus.FNone
# 清空运行命令
self.send_clear_auto_command()
#
log.log_message(logging.INFO, Constant.str_feed_stop)
def send_pauseFeed_button_click(self):
if self.pushButton_pauseFeed.text() == '暂停':
self.pushButton_pauseFeed.setText('继续')
log.log_message(logging.INFO, Constant.str_feed_pause)
self.send_pause_command(True)
self.feeding.pause = True
else:
self.pushButton_pauseFeed.setText('暂停')
self.send_pause_command(False)
log.log_message(logging.INFO, Constant.str_feed_continue)
self.send_start_tool_command()
log.log_message(logging.INFO, Constant.str_sys_start_tool)
self.feeding.pause = False
pass
def send_tabWidget_control_change(self):
if self.robotClient.status_model.curMode != 7:
self.send_switch_tool_command()
log.log_message(logging.INFO, Constant.str_sys_switch_tool)
self.send_start_tool_command()
def send_reset_button_click(self):
line_head = self.comboBox_lineIndex.currentData()
safe_position = self.feedLine_dict[line_head].safe_position
self.send_position_command(safe_position.X, safe_position.Y, safe_position.Z, safe_position.U, safe_position.V, safe_position.W,move_type=MoveType.WORLD)
def send_tabelFeedSet_itemChanged(self, item):
row = item.row()
@ -653,7 +688,7 @@ class MainWindow(QMainWindow, Ui_MainWindow):
self.updateUI_Position()
self.updateUI_label_detection()
self.updateUI_label_status()
self.updateUI_frame_sign(self.feeding.feedStatus)
def updateUI_label_detection(self):
@ -664,6 +699,22 @@ class MainWindow(QMainWindow, Ui_MainWindow):
self.comboBox_lineIndex.clear()
for key, value in self.feedLine_dict.items():
self.comboBox_lineIndex.addItem(value.name, key)
def updateUI_label_status(self):
if self.robotClient.status_model.isMoving==1:
self.label_move_sign.show()
if self.label_move_sign.text() == '正在移动.':
self.label_move_sign.setText('正在移动..')
else:
self.label_move_sign.setText('正在移动.')
else:
self.label_move_sign.hide()
if self.robotClient.status_model.curMode >= 0:
try:
self.label_status_model.setText(Constant.mode_array[self.robotClient.status_model.curMode])
except:
self.label_status_model.setText('未知模式')
self.label_status_remoteCmdLen.setText(str(self.robotClient.status_model.RemoteCmdLen))
def updateUI_Position(self):
self.horizontalSlider_J1.setValue(self.status_address.axis_0)
@ -739,7 +790,7 @@ class MainWindow(QMainWindow, Ui_MainWindow):
if self.label_connect_status.styleSheet().strip() != self.noActive_status_Qss:
self.label_connect_status.setStyleSheet(self.noActive_status_Qss)
self.noActive_status_Qss = self.label_connect_status.styleSheet().strip()
def set_sign_status(self,label,btn,signed:bool):
def set_sign_status(self,label,btn,signed:bool):
try :
if signed:
@ -776,8 +827,7 @@ class MainWindow(QMainWindow, Ui_MainWindow):
def send_clear_auto_command(self):
clear_command = CMDInstructRequest()
request_command = clear_command.toString()
print(request_command)
log_str = f'清除自动指令'
log.log_message(logging.INFO, Constant.str_sys_clearAlarm)
self.command_quene.put(request_command)
def send_position_command(self, x1, x2, x3, x4, x5, x6, move_type: MoveType = MoveType.WORLD):
@ -800,7 +850,7 @@ class MainWindow(QMainWindow, Ui_MainWindow):
f'm4:{position_instruction.m3}-' \
f'm5:{position_instruction.m4}-' \
f'm6:{position_instruction.m5}'
self.logger_textEdit.info(log_str)
log.log_message(logging.INFO,log_str)
self.robotClient.add_sendQuene(request_command)
def send_pause_command(self, pause: bool):
@ -812,7 +862,6 @@ class MainWindow(QMainWindow, Ui_MainWindow):
pause_command.cmdData.append("0")
request_command = pause_command.toString()
print(request_command)
log_str = f'暂停:{pause}'
self.robotClient.add_sendQuene(request_command)
def send_clear_alarm_command(self, pause: bool):
@ -830,7 +879,7 @@ class MainWindow(QMainWindow, Ui_MainWindow):
switch_command.cmdData.append("2")
request_command = switch_command.toString()
print(request_command)
log_str = f'切换工具'
self.robotClient.add_sendQuene(request_command)
def send_start_tool_command(self):
@ -839,7 +888,7 @@ class MainWindow(QMainWindow, Ui_MainWindow):
switch_command.cmdData.append("1")
request_command = switch_command.toString()
print(request_command)
log_str = f'切换工具'
self.robotClient.add_sendQuene(request_command)