update 修改qss带来的异常退出
This commit is contained in:
158
main.py
158
main.py
@ -4,10 +4,10 @@ import logging
|
||||
import queue
|
||||
import sys
|
||||
from multiprocessing import Process
|
||||
|
||||
import traceback
|
||||
from PyQt5.uic.properties import QtWidgets
|
||||
from PySide6 import QtCore
|
||||
from PySide6.QtCore import QThread, Signal, Slot, QObject, QEvent
|
||||
from PySide6.QtCore import QThread, Signal, Slot, QObject, QEvent, QTimer
|
||||
from PySide6.QtGui import QIntValidator, QStandardItemModel, QStandardItem, Qt, QMovie, QIcon
|
||||
from PySide6.QtWidgets import QApplication, QMainWindow, QPushButton, QLabel, QHeaderView, QTableWidget, \
|
||||
QTableWidgetItem, QWidget, QHBoxLayout, QAbstractItemView, QMessageBox, QSizePolicy
|
||||
@ -21,6 +21,7 @@ import Constant
|
||||
from CU.Command import FeedCommand
|
||||
from CU.Feeding import FeedLine, FeedingConfig, Feeding, FeedStatus
|
||||
from Util.util_log import QTextEditLogger
|
||||
from Util.util_time import CRisOrFall
|
||||
from Vision.camera_coordinate_dete import Detection
|
||||
from COM.COM_Robot import RobotClient
|
||||
from Expection import Error_Code
|
||||
@ -158,58 +159,7 @@ class MainWindow(QMainWindow, Ui_MainWindow):
|
||||
|
||||
|
||||
def init_qss(self):
|
||||
self.active_status_Qss = """
|
||||
|
||||
background-color: #A2EF4D;
|
||||
color: #ffffff;
|
||||
border-radius: 8px;
|
||||
border: 1px solid #A2EF4D;
|
||||
qproperty-alignment: 'AlignCenter';
|
||||
|
||||
"""
|
||||
self.noActive_status_Qss = """
|
||||
|
||||
background-color: #FD3251;
|
||||
color: #ffffff;
|
||||
border-radius: 8px;
|
||||
border: 1px solid #FD3251;
|
||||
qproperty-alignment: 'AlignCenter';
|
||||
|
||||
"""
|
||||
|
||||
self.active_label_sign_Qss = """
|
||||
|
||||
background-color: rgba(255, 255, 255, 0);
|
||||
font: 700 12pt "Microsoft YaHei UI";
|
||||
color: red;
|
||||
|
||||
|
||||
"""
|
||||
self.active_btn_sign_Qss = """
|
||||
|
||||
background-color: rgb(255, 0, 0);
|
||||
font: 9pt "楷体";
|
||||
border: 1px solid #dcdfe6;
|
||||
border-radius: 5px;
|
||||
|
||||
|
||||
|
||||
"""
|
||||
self.noactive_label_sign_Qss = """
|
||||
|
||||
background-color: rgba(255, 255, 255, 0);
|
||||
font: 700 12pt "Microsoft YaHei UI";
|
||||
color: #7A7A7A;
|
||||
"""
|
||||
self.noactive_btn_sign_Qss = """
|
||||
|
||||
background-color: #7A7A7A;
|
||||
font: 9pt "楷体";
|
||||
border: 1px solid #dcdfe6;
|
||||
border-radius: 5px;
|
||||
|
||||
|
||||
"""
|
||||
pass
|
||||
|
||||
def init_log(self):
|
||||
log.init_log(self.textEdit_log_info, self.textEdit_log_error, Constant.log_file_path)
|
||||
@ -334,9 +284,9 @@ class MainWindow(QMainWindow, Ui_MainWindow):
|
||||
solenoid_valve1_addr = int(self.configReader.get('Robot_Feed', 'solenoid_valve1_addr'))
|
||||
solenoid_valve2_addr = int(self.configReader.get('Robot_Feed', 'solenoid_valve2_addr'))
|
||||
solenoid_valve3_addr = int(self.configReader.get('Robot_Feed', 'solenoid_valve3_addr'))
|
||||
time_delay_take = int(self.configReader.get('Robot_Feed', 'takeDelay'))
|
||||
time_delay_put = int(self.configReader.get('Robot_Feed', 'putDelay'))
|
||||
time_delay_shake = int(self.configReader.get('Robot_Feed', 'shakeDelay'))
|
||||
time_delay_take = float(self.configReader.get('Robot_Feed', 'takeDelay'))
|
||||
time_delay_put = float(self.configReader.get('Robot_Feed', 'putDelay'))
|
||||
time_delay_shake = float(self.configReader.get('Robot_Feed', 'shakeDelay'))
|
||||
#TODO
|
||||
#dropDelay_time = int(self.configReader.get('Robot_Feed', 'dropDelay_time'))
|
||||
self.robotClient = RobotClient(ip, port, photo_locs, self.command_position_quene, self.status_address,[solenoid_valve1_addr, solenoid_valve2_addr, solenoid_valve3_addr],time_delay_take,time_delay_put,time_delay_shake)
|
||||
@ -562,7 +512,7 @@ class MainWindow(QMainWindow, Ui_MainWindow):
|
||||
self.main_UI_threading = Thread(target=self.updateUI)
|
||||
self.main_UI_threading.start()
|
||||
|
||||
self.check_continue()
|
||||
|
||||
pass
|
||||
def check_continue(self):
|
||||
if self.remain_Count!=0:
|
||||
@ -576,6 +526,7 @@ class MainWindow(QMainWindow, Ui_MainWindow):
|
||||
remain_messageBox.setStandardButtons(QMessageBox.StandardButton.Ok | QMessageBox.StandardButton.Cancel)
|
||||
result = remain_messageBox.exec()
|
||||
if result == QMessageBox.StandardButton.Cancel:
|
||||
self.remain_Count = 0
|
||||
return
|
||||
self.configReader.read(Constant.feedLine_set_file, encoding='utf-8')
|
||||
line_name = self.configReader.get(key, 'name')
|
||||
@ -636,6 +587,7 @@ class MainWindow(QMainWindow, Ui_MainWindow):
|
||||
self.command_quene.put(FeedCommand(FeedingConfig(num, self.feedLine_dict[line_head], self.feeding.robotClient.photo_locs[:])))
|
||||
self.stackedWidget_num.setCurrentIndex(1)
|
||||
self.set_run_status_button(True)
|
||||
self.feeding.pause = False
|
||||
log.log_message(logging.INFO, f'{self.feedLine_dict[line_head].name}:{Constant.str_feed_start}')
|
||||
|
||||
def send_num_button_click(self):
|
||||
@ -724,6 +676,8 @@ class MainWindow(QMainWindow, Ui_MainWindow):
|
||||
self.label_maxNum.setText(str(max_num))
|
||||
|
||||
def send_custom_num_returnPressed(self):
|
||||
if self.lineEdit_num.text()== '' or not self.lineEdit_num.text().isdigit():
|
||||
return
|
||||
self.horizontalSlider_feedingNum.setMaximum(int(self.lineEdit_num.text()))
|
||||
self.horizontalSlider_feedingNum.setValue(0)
|
||||
self.label_maxNum.setText(self.lineEdit_num.text())
|
||||
@ -761,9 +715,9 @@ class MainWindow(QMainWindow, Ui_MainWindow):
|
||||
solenoid1_addr = int(self.lineEdit_solenoid1_addr.text())
|
||||
solenoid2_addr = int(self.lineEdit_solenoid2_addr.text())
|
||||
solenoid3_addr = int(self.lineEdit_solenoid3_addr.text())
|
||||
time_delay_take = int(self.lineEdit_timedelay_take.text())
|
||||
time_delay_put = int(self.lineEdit_timedelay_put.text())
|
||||
time_delay_shake = int(self.lineEdit_timedelay_shake.text())
|
||||
time_delay_take = float(self.lineEdit_timedelay_take.text())
|
||||
time_delay_put = float(self.lineEdit_timedelay_put.text())
|
||||
time_delay_shake = float(self.lineEdit_timedelay_shake.text())
|
||||
self.robotClient.con_ios[0] = solenoid1_addr
|
||||
self.robotClient.con_ios[1] = solenoid2_addr
|
||||
self.robotClient.con_ios[2] = solenoid3_addr
|
||||
@ -882,6 +836,7 @@ class MainWindow(QMainWindow, Ui_MainWindow):
|
||||
self.feeding.feedStatus = FeedStatus.FNone
|
||||
# 清空运行命令
|
||||
self.send_clear_auto_command()
|
||||
self.feeding.feedConfig.num = 0
|
||||
log.log_message(logging.INFO, Constant.str_feed_stop)
|
||||
|
||||
def send_pauseFeed_button_click(self):
|
||||
@ -1077,6 +1032,7 @@ class MainWindow(QMainWindow, Ui_MainWindow):
|
||||
self.label_status_remoteCmdLen.setText(str(self.robotClient.status_model.RemoteCmdLen))
|
||||
if self.robotClient.status_model.curAlarm != 0:
|
||||
log.log_message(logging.ERROR, Constant.str_sys_log_alarm_error+str(self.robotClient.status_model.curAlarm))
|
||||
self.feeding.pause = True
|
||||
self.label_status_alarmcode.setText(str(self.robotClient.status_model.curAlarm))
|
||||
self.label_status_toolIndex.setText(str(self.robotClient.status_model.toolCoord))
|
||||
self.label_status_speed.setText(str(self.robotClient.status_model.curSpeed_n))
|
||||
@ -1153,34 +1109,33 @@ class MainWindow(QMainWindow, Ui_MainWindow):
|
||||
|
||||
|
||||
def set_label_status_style(self, connected: bool):
|
||||
|
||||
if connected:
|
||||
if self.label_connect_status.styleSheet().strip() != self.active_status_Qss:
|
||||
self.label_connect_status.setStyleSheet(self.active_status_Qss)
|
||||
self.active_status_Qss = self.label_connect_status.styleSheet().strip()
|
||||
|
||||
else:
|
||||
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()
|
||||
#return
|
||||
if connected and not self.label_connect_status.isEnabled():
|
||||
self.label_connect_status.setEnabled(True)
|
||||
if not connected and self.label_connect_status.isEnabled():
|
||||
self.label_connect_status.setDisabled(True)
|
||||
def set_sign_status(self,label,btn,signed:bool):
|
||||
|
||||
#return
|
||||
try :
|
||||
if signed:
|
||||
if label.styleSheet().strip() != self.active_label_sign_Qss:
|
||||
label.setStyleSheet(self.active_label_sign_Qss)
|
||||
self.active_label_sign_Qss = label.styleSheet().strip()
|
||||
|
||||
if btn.styleSheet().strip() != self.active_btn_sign_Qss:
|
||||
btn.setStyleSheet(self.active_btn_sign_Qss)
|
||||
self.active_btn_sign_Qss = btn.styleSheet().strip()
|
||||
else:
|
||||
if label.styleSheet().strip() != self.noactive_label_sign_Qss:
|
||||
label.setStyleSheet(self.noactive_label_sign_Qss)
|
||||
self.noactive_label_sign_Qss = label.styleSheet().strip()
|
||||
if btn.styleSheet().strip() != self.noactive_btn_sign_Qss:
|
||||
btn.setStyleSheet(self.noactive_btn_sign_Qss)
|
||||
self.noactive_btn_sign_Qss = btn.styleSheet().strip()
|
||||
if signed and label.isEnabled():
|
||||
label.setDisabled(True)
|
||||
btn.setDisabled(True)
|
||||
# if label.styleSheet().strip() != self.active_label_sign_Qss:
|
||||
# label.setStyleSheet(self.active_label_sign_Qss)
|
||||
# self.active_label_sign_Qss = label.styleSheet().strip()
|
||||
#
|
||||
# if btn.styleSheet().strip() != self.active_btn_sign_Qss:
|
||||
# btn.setStyleSheet(self.active_btn_sign_Qss)
|
||||
# self.active_btn_sign_Qss = btn.styleSheet().strip()
|
||||
if not signed and not label.isEnabled():
|
||||
label.setEnabled(True)
|
||||
btn.setEnabled(True)
|
||||
# if label.styleSheet().strip() != self.noactive_label_sign_Qss:
|
||||
# label.setStyleSheet(self.noactive_label_sign_Qss)
|
||||
# self.noactive_label_sign_Qss = label.styleSheet().strip()
|
||||
# if btn.styleSheet().strip() != self.noactive_btn_sign_Qss:
|
||||
# btn.setStyleSheet(self.noactive_btn_sign_Qss)
|
||||
# self.noactive_btn_sign_Qss = btn.styleSheet().strip()
|
||||
except Exception as e:
|
||||
print(e)
|
||||
|
||||
@ -1530,6 +1485,11 @@ class MainWindow(QMainWindow, Ui_MainWindow):
|
||||
self.feeding.sendIOControl(index-1, 0)
|
||||
log.log_message(logging.INFO, f'关闭IO{index}')
|
||||
|
||||
def showEvent(self, event):
|
||||
super().showEvent(event)
|
||||
QTimer.singleShot(2000, self.check_continue)
|
||||
|
||||
|
||||
def closeEvent(self, event):
|
||||
self.record_remain_num()
|
||||
self.detection.release()
|
||||
@ -1548,10 +1508,32 @@ class MainWindow(QMainWindow, Ui_MainWindow):
|
||||
except:
|
||||
log.log_message(logging.ERROR, Constant.str_sys_log_feedNum)
|
||||
|
||||
|
||||
class MyApplication(QApplication):
|
||||
def __init__(self, argv):
|
||||
super().__init__(argv)
|
||||
|
||||
def notify(self, receiver, event):
|
||||
try:
|
||||
return super().notify(receiver, event)
|
||||
except Exception as e:
|
||||
log.log_message(logging.ERROR, e)
|
||||
# 可以在这里记录日志或者执行其他操作
|
||||
return False
|
||||
|
||||
def handle_exception(exc_type, exc_value, exc_tb):
|
||||
if issubclass(exc_type, KeyboardInterrupt):
|
||||
log.log_message(logging.INFO, "用户主动退出程序")
|
||||
return
|
||||
log.log_message(logging.ERROR, exc_value)
|
||||
print("未处理的异常:", exc_type, exc_value)
|
||||
traceback.print_exception(exc_type, exc_value, exc_tb)
|
||||
|
||||
if __name__ == "__main__":
|
||||
app = QApplication(sys.argv)
|
||||
app = MyApplication(sys.argv)
|
||||
window = MainWindow()
|
||||
window.show()
|
||||
sys.excepthook = handle_exception # 你的 PySide 应用程序代码 pass
|
||||
sys.exit(app.exec())
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user