77 lines
2.8 KiB
Python
77 lines
2.8 KiB
Python
|
|
"""
|
||
|
|
刷新相机设备按钮修复工具
|
||
|
|
|
||
|
|
此文件包含修复相机设备刷新按钮的工具函数
|
||
|
|
"""
|
||
|
|
|
||
|
|
import logging
|
||
|
|
from PySide6.QtWidgets import QPushButton
|
||
|
|
|
||
|
|
def fix_camera_refresh_button(settings_widget):
|
||
|
|
"""
|
||
|
|
修复相机设置中的刷新设备按钮
|
||
|
|
|
||
|
|
Args:
|
||
|
|
settings_widget: 设置窗口实例
|
||
|
|
|
||
|
|
Returns:
|
||
|
|
bool: 是否成功修复
|
||
|
|
"""
|
||
|
|
try:
|
||
|
|
logging.info("尝试修复相机刷新设备按钮...")
|
||
|
|
|
||
|
|
# 检查是否存在相机设置组件
|
||
|
|
if not hasattr(settings_widget, 'camera_settings'):
|
||
|
|
logging.error("设置窗口中没有camera_settings属性")
|
||
|
|
return False
|
||
|
|
|
||
|
|
# 检查是否存在刷新按钮
|
||
|
|
if hasattr(settings_widget, 'refresh_button'):
|
||
|
|
refresh_button = settings_widget.refresh_button
|
||
|
|
logging.info(f"在settings_widget中找到刷新按钮: {refresh_button}")
|
||
|
|
else:
|
||
|
|
# 尝试查找刷新按钮
|
||
|
|
refresh_button = None
|
||
|
|
# 方法1: 直接在camera_tab中查找
|
||
|
|
if hasattr(settings_widget, 'camera_tab'):
|
||
|
|
for child in settings_widget.camera_tab.findChildren(QPushButton):
|
||
|
|
if child.text() == "刷新设备":
|
||
|
|
refresh_button = child
|
||
|
|
logging.info(f"在camera_tab中找到刷新按钮: {refresh_button}")
|
||
|
|
break
|
||
|
|
|
||
|
|
# 方法2: 在camera_settings中查找
|
||
|
|
if refresh_button is None and hasattr(settings_widget.camera_settings, 'refresh_button'):
|
||
|
|
refresh_button = settings_widget.camera_settings.refresh_button
|
||
|
|
logging.info(f"在camera_settings中找到刷新按钮: {refresh_button}")
|
||
|
|
|
||
|
|
# 如果找到了刷新按钮,则绑定事件
|
||
|
|
if refresh_button:
|
||
|
|
# 断开所有现有连接
|
||
|
|
try:
|
||
|
|
refresh_button.clicked.disconnect()
|
||
|
|
except:
|
||
|
|
pass
|
||
|
|
|
||
|
|
# 连接到refresh_devices方法
|
||
|
|
refresh_button.clicked.connect(settings_widget.camera_settings.refresh_devices)
|
||
|
|
logging.info("成功绑定刷新按钮到refresh_devices方法")
|
||
|
|
|
||
|
|
# 测试调用一次
|
||
|
|
try:
|
||
|
|
settings_widget.camera_settings.refresh_devices()
|
||
|
|
logging.info("已手动调用refresh_devices方法初始化设备列表")
|
||
|
|
except Exception as e:
|
||
|
|
logging.error(f"调用refresh_devices失败: {str(e)}")
|
||
|
|
|
||
|
|
return True
|
||
|
|
else:
|
||
|
|
logging.error("未找到刷新设备按钮")
|
||
|
|
return False
|
||
|
|
|
||
|
|
except Exception as e:
|
||
|
|
logging.error(f"修复相机刷新按钮时发生错误: {str(e)}")
|
||
|
|
import traceback
|
||
|
|
logging.error(traceback.format_exc())
|
||
|
|
return False
|