Commit c7524571 by Yuhaibo

1

parent a179dd7d
# 调试语句清理报告
**清理时间**: 2025-11-26 20:31:38
**备份目录**: backups\cleanup_20251126_203137
## 清理统计
- 扫描文件总数: 108
- 修改文件数量: 58
- 删除语句总数: 540
## 详细清理记录
| 文件 | 删除数量 |
|------|----------|
| handlers\modelpage\model_test_handler.py | 85 |
| handlers\videopage\missionpanel_handler.py | 46 |
| handlers\modelpage\model_training_handler.py | 37 |
| handlers\videopage\general_set_handler.py | 33 |
| widgets\datasetpage\datapreprocess_panel.py | 30 |
| handlers\videopage\amplify_window_handler.py | 20 |
| widgets\videopage\general_set.py | 20 |
| widgets\modelpage\training_page.py | 17 |
| handlers\modelpage\test_integration.py | 14 |
| handlers\modelpage\tools\test_dat_conversion.py | 13 |
| handlers\modelpage\tools\test_bat_model.py | 12 |
| handlers\modelpage\tools\test_pt_detection.py | 12 |
| handlers\cleanup_debug_statements.py | 11 |
| widgets\videopage\channelpanel.py | 11 |
| widgets\videopage\missionpanel.py | 11 |
| handlers\datasetpage\crop_preview_handler.py | 10 |
| handlers\app.py | 9 |
| handlers\datasetpage\test_realtime_monitoring.py | 9 |
| widgets\datasetpage\datacollection_panel.py | 9 |
| widgets\datasetpage\test_labelme_integration.py | 9 |
| widgets\datasetpage\crop_preview_panel.py | 8 |
| handlers\modelpage\tools\test_bat_image_detection.py | 7 |
| handlers\modelpage\tools\test_dat_image_detection.py | 7 |
| handlers\videopage\thread_manager\result_distributor.py | 6 |
| widgets\locate_debug_statements.py | 6 |
| widgets\style_manager.py | 6 |
| widgets\videopage\curvepanel.py | 6 |
| handlers\datasetpage\datacollection_channel_handler.py | 5 |
| handlers\videopage\mock_physical_zoom_controller.py | 5 |
| handlers\videopage\detection.py | 4 |
| handlers\videopage\thread_manager\threads\display_thread.py | 4 |
| widgets\videopage\historyvideopanel.py | 4 |
| handlers\modelpage\cleanup_test_code.py | 3 |
| handlers\modelpage\model_trainingworker_handler.py | 3 |
| handlers\videopage\channelpanel_handler.py | 3 |
| handlers\videopage\curvepanel_handler.py | 3 |
| handlers\videopage\test_handler.py | 3 |
| handlers\videopage\HK_SDK\test_hikcapture.py | 3 |
| handlers\videopage\thread_manager\threads\storage_thread.py | 3 |
| handlers\videopage\thread_manager\threads\test_model_loading.py | 3 |
| widgets\datasetpage\annotationtool.py | 3 |
| widgets\datasetpage\crop_config_dialog.py | 3 |
| widgets\datasetpage\videobrowser.py | 3 |
| widgets\datasetpage\videoclipper.py | 3 |
| handlers\view_handler.py | 2 |
| handlers\modelpage\model_page_handler.py | 2 |
| handlers\modelpage\model_set_handler.py | 2 |
| widgets\modelpage\modelset_page.py | 2 |
| handlers\datasetpage\datapreprocess_handler.py | 1 |
| handlers\videopage\HK_SDK\FocusControl.py | 1 |
| handlers\videopage\HK_SDK\HCNetSDK.py | 1 |
| handlers\videopage\HK_SDK\HKcapture.py | 1 |
| handlers\videopage\thread_manager\thread_manager.py | 1 |
| widgets\menubar.py | 1 |
| widgets\datasetpage\test_crop_preview_integration.py | 1 |
| widgets\datasetpage\training_panel.py | 1 |
| widgets\videopage\logicsetting_dialogue.py | 1 |
| widgets\videopage\modelsetting_dialogue.py | 1 |
# 调试语句清理工具使用说明
## 工具简介
`cleanup_debug_statements.py` 是一个智能化的调试语句清理脚本,可以自动删除项目中的调试代码,同时保留功能性代码。
## 功能特性
### ✅ 会删除的内容
1. **调试print语句**
- 包含调试关键词: `🔍``调试``DEBUG``debug``测试``test`
- 包含调试标记: `[调试]``[DEBUG]``[测试]`
- 空print语句或只打印分隔线的语句
2. **调试日志语句**
- `logging.debug(...)`
- `logger.debug(...)`
3. **调试注释**
- 包含调试关键词的注释
- 不包含重要标记的调试注释
### ❌ 不会删除的内容
1. **功能性输出**
- 包含: `错误``警告``成功``失败``完成`
- 包含: `ERROR``WARNING``INFO`
2. **重要注释**
- `TODO``FIXME``XXX``HACK``NOTE`
3. **普通代码**
- 所有非调试的正常代码
## 使用方法
### 1. 运行脚本
```bash
# 在项目根目录下运行
python handlers/cleanup_debug_statements.py
```
### 2. 确认操作
脚本会显示清理规则并要求确认:
```
是否继续清理? (y/n):
```
输入 `y` 继续,输入 `n` 取消。
### 3. 查看结果
清理完成后会显示:
- 扫描文件总数
- 修改文件数量
- 删除语句总数
- 备份目录位置
## 安全保障
### 自动备份
- 每次运行都会创建完整备份
- 备份位置: `backups/cleanup_YYYYMMDD_HHMMSS/`
- 保留原始文件的完整目录结构
### 恢复方法
如果需要恢复,只需从备份目录复制文件回来:
```bash
# 示例: 恢复单个文件
cp backups/cleanup_20251126_203000/handlers/app.py handlers/app.py
# 示例: 恢复整个目录
cp -r backups/cleanup_20251126_203000/handlers/* handlers/
```
## 清理报告
脚本会生成详细的清理报告: `handlers/CLEANUP_REPORT.md`
报告内容包括:
- 清理时间
- 备份目录
- 清理统计
- 每个文件的详细清理记录(按删除数量排序)
## 示例
### 会被删除的代码
```python
# 调试print
print(f"🔍 [调试] 变量值: {value}")
print(f"[DEBUG] 进入函数")
print("="*60) # 分隔线
# 调试日志
logging.debug("调试信息")
logger.debug(f"变量: {var}")
# 调试注释
# 🔍 调试: 这里需要检查
# DEBUG: 临时代码
```
### 会被保留的代码
```python
# 功能性输出
print(f"❌ 错误: {error_msg}")
print(f"✅ 操作成功")
logging.info("程序启动")
# 重要注释
# TODO: 需要优化性能
# FIXME: 修复边界情况
# NOTE: 这是重要说明
# 普通代码
result = process_data(input_data)
```
## 注意事项
1. **首次使用建议**
- 先在测试分支运行
- 检查清理结果
- 确认无误后再应用到主分支
2. **排除目录**
- 自动排除: `__pycache__`, `.git`, `venv`, `env`, `backups`, `database`
- 只处理 `.py` 文件
3. **保守策略**
- 默认采用保守策略
- 不确定的语句不会删除
- 优先保留而非删除
## 自定义配置
如需修改清理规则,可以编辑脚本中的以下部分:
```python
# 调试关键词(会被删除)
self.debug_keywords = [
r'🔍', r'调试', r'DEBUG', r'debug', r'测试', r'test',
# 添加更多关键词...
]
# 保留关键词(不会被删除)
self.keep_keywords = [
r'TODO', r'FIXME', r'XXX', r'HACK', r'NOTE',
r'错误', r'警告', r'成功', r'失败', r'完成',
# 添加更多关键词...
]
```
## 技术支持
如遇到问题:
1. 检查备份目录是否正常创建
2. 查看清理报告了解详细信息
3. 从备份恢复文件
4. 调整清理规则后重新运行
---
**最后更新**: 2025-11-26
......@@ -2048,188 +2048,3 @@ class AnnotationWidget(QtWidgets.QWidget):
def showAnnotationError(self, message):
"""显示标注错误(由handler调用)"""
pass
if __name__ == "__main__":
"""独立调试入口"""
import sys
app = QtWidgets.QApplication(sys.argv)
# 测试1: 面板嵌入式使用
print("=" * 50)
print("测试模式1: 面板嵌入到主窗口")
print("=" * 50)
main_window = QtWidgets.QMainWindow()
main_window.setWindowTitle("GeneralSetPanel 组件测试 - 嵌入式")
main_window.resize(1000, 800)
# 创建组件
panel = GeneralSetPanel(main_window)
panel.setChannelInfo("通道1", "channel1", {'task_id': 'TASK001', 'task_name': '制冷任务'})
# 连接信号用于测试
def on_task_info_changed(info):
print(f"[测试] 任务信息变化: {info}")
def on_area_count_changed(count):
print(f"[测试] 区域个数变化: {count}")
def on_annotation_requested():
"""测试标注功能 - 直接弹出标注界面"""
print(f"[测试] 请求开始标注")
# 创建测试图像
import cv2
import numpy as np
test_frame = np.zeros((720, 1280, 3), dtype=np.uint8)
test_frame[:] = (100, 120, 140) # 灰色背景
# 添加一些文字说明(使用英文,因为cv2.putText不支持中文)
cv2.putText(test_frame, "Test Annotation Frame", (50, 50),
cv2.FONT_HERSHEY_SIMPLEX, 1.5, (255, 255, 255), 2)
cv2.putText(test_frame, "Draw detection areas and mark liquid levels", (50, 100),
cv2.FONT_HERSHEY_SIMPLEX, 0.8, (200, 200, 200), 1)
# 添加一些测试区域
cv2.rectangle(test_frame, (200, 200), (400, 400), (0, 255, 0), 2)
cv2.rectangle(test_frame, (500, 300), (700, 500), (0, 0, 255), 2)
print(" 测试图像创建完成,包含中文说明文字")
# 创建标注界面组件
annotation_widget = AnnotationWidget(main_window, None)
# 连接信号
def on_annotation_completed(boxes, bottoms, tops):
pass
# 更新面板的标注状态
panel.updateAnnotationStatus(True, len(boxes))
QtWidgets.QMessageBox.information(
main_window,
"标注完成",
f"成功标注 {len(boxes)} 个检测区域\n\n"
f"标注结果已保存到面板中"
)
def on_annotation_cancelled():
pass
annotation_widget.annotationCompleted.connect(on_annotation_completed)
annotation_widget.annotationCancelled.connect(on_annotation_cancelled)
# 加载测试图像并显示
if annotation_widget.loadFrame(test_frame):
annotation_widget.show()
print("[测试] 标注界面已显示")
else:
QtWidgets.QMessageBox.warning(
main_window,
"测试失败",
"无法加载测试图像到标注界面"
)
def on_detection_start_requested():
"""测试检测开始功能"""
QtWidgets.QMessageBox.information(
main_window,
"开始检测",
"检测功能已启动!\n\n正在加载标注区域并开始液位检测..."
)
# 添加信号连接处理(独立调试时需要)
def on_load_channel_model_config(channel_id):
print(f"[测试] 请求加载通道模型配置: {channel_id}")
# 独立调试时不加载实际配置,只打印日志
def on_auto_save_model_path(model_path):
print(f"[测试] 请求自动保存模型路径: {model_path}")
# 独立调试时不保存实际配置,只打印日志
panel.taskInfoChanged.connect(on_task_info_changed)
panel.areaCountChanged.connect(on_area_count_changed)
panel.annotationRequested.connect(on_annotation_requested)
panel.detectionStartRequested.connect(on_detection_start_requested)
panel.loadChannelModelConfigRequested.connect(on_load_channel_model_config)
panel.autoSaveModelPathRequested.connect(on_auto_save_model_path)
main_window.setCentralWidget(panel)
main_window.show()
# 添加一个简单的测试按钮来直接测试标注界面
test_button = QtWidgets.QPushButton("测试标注界面")
test_button.clicked.connect(on_annotation_requested)
panel.layout().addWidget(test_button)
# 可选:添加一个按钮来测试对话框模式
def test_dialog():
dialog = GeneralSetDialog(
main_window,
channel_name="通道2",
task_info={'task_id': 'TASK002', 'task_name': '测试任务'}
)
if dialog.exec_() == QtWidgets.QDialog.Accepted:
settings = dialog.getSettings()
pass
else:
pass
# 添加测试按钮到状态栏
test_dialog_btn = QtWidgets.QPushButton("测试对话框模式")
test_dialog_btn.clicked.connect(test_dialog)
main_window.statusBar().addPermanentWidget(test_dialog_btn)
def test_annotation_widget():
"""测试标注界面组件"""
# 创建测试图像
import cv2
import numpy as np
test_frame = np.zeros((720, 1280, 3), dtype=np.uint8)
test_frame[:] = (100, 120, 140) # 灰色背景
# 添加一些文字说明
cv2.putText(test_frame, "Test Annotation Frame", (50, 50),
cv2.FONT_HERSHEY_SIMPLEX, 1.5, (255, 255, 255), 2)
cv2.putText(test_frame, "Draw detection areas and mark liquid levels", (50, 100),
cv2.FONT_HERSHEY_SIMPLEX, 0.8, (200, 200, 200), 1)
# 创建标注界面组件
annotation_widget = AnnotationWidget(main_window, None)
# 连接信号
def on_annotation_completed(boxes, bottoms, tops):
pass
QtWidgets.QMessageBox.information(
main_window,
"标注完成",
f"成功标注 {len(boxes)} 个检测区域"
)
def on_annotation_cancelled():
pass
annotation_widget.annotationCompleted.connect(on_annotation_completed)
annotation_widget.annotationCancelled.connect(on_annotation_cancelled)
# 加载测试图像并显示
if annotation_widget.loadFrame(test_frame):
annotation_widget.show()
print("[测试] 标注界面已显示")
else:
QtWidgets.QMessageBox.warning(
main_window,
"测试失败",
"无法加载测试图像到标注界面"
)
test_annotation_btn = QtWidgets.QPushButton("测试标注界面")
test_annotation_btn.clicked.connect(test_annotation_widget)
main_window.statusBar().addPermanentWidget(test_annotation_btn)
sys.exit(app.exec_())
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment