Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
O
Oil_Level_Recognition_System
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
柳青君
Oil_Level_Recognition_System
Commits
f1a1c631
Commit
f1a1c631
authored
Nov 26, 2025
by
Yuhaibo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1
parent
c35b6fe4
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
309 additions
and
112 deletions
+309
-112
CLEANUP_PROGRESS.md
handlers/CLEANUP_PROGRESS.md
+109
-0
app.py
handlers/app.py
+1
-33
missionpanel_handler.py
handlers/videopage/missionpanel_handler.py
+1
-41
locate_debug_statements.py
widgets/locate_debug_statements.py
+195
-0
responsive_layout.py
widgets/responsive_layout.py
+0
-6
style_manager.py
widgets/style_manager.py
+3
-32
No files found.
handlers/CLEANUP_PROGRESS.md
0 → 100644
View file @
f1a1c631
# 调试代码清理进度报告
**开始时间**
: 2025-11-26 19:32
**总文件数**
: 64
**总调试语句数**
: 3441
## 清理策略
1.
print语句: 3225处 - 全部删除
2.
DEBUG注释: 200处 - 全部删除
3.
TODO/FIXME注释: 16处 - 保留(用于后续开发)
## 清理进度
### handlers 文件夹
#### ✅ handlers/app.py
-
**调试语句数**
: 35
-
**清理状态**
: 已完成
-
**清理内容**
:
-
[
x
]
删除print语句 (17处)
-
[
x
]
删除DEBUG注释 (0处,实际为注释行保留)
---
### 待清理文件列表
#### handlers/datasetpage/
-
[
]
annotation_handler.py (21处)
-
[
]
crop_preview_handler.py
-
[
]
dataset_handler.py
-
[
]
preprocess_handler.py
-
[
]
training_handler.py
-
[
]
videobrowser_handler.py
#### handlers/modelpage/
-
[
]
model_loader.py
-
[
]
model_operations.py
-
[
]
model_set_handler.py
-
[
]
training_handler.py
-
[
]
tools/
*
.py (多个工具文件)
#### handlers/videopage/
-
[
]
amplify_window_handler.py
-
[
]
channelpanel_handler.py
-
[
]
curvepanel_handler.py
-
[
]
detection.py
-
[
]
general_set_handler.py
-
[
]
historypanel_handler.py
-
[
]
missionpanel_handler.py
-
[
]
modelsetting_handler.py
-
[
]
test_handler.py
-
[
]
thread_manager/
*
.py (多个线程管理文件)
-
[
]
HK_SDK/
*
.py (多个SDK文件)
#### handlers/其他
-
[
]
settings_handler.py
-
[
]
view_handler.py
### widgets 文件夹
#### widgets/datasetpage/
-
[
]
annotationtool.py
-
[
]
crop_config_dialog.py
-
[
]
crop_preview_panel.py
-
[
]
datacollection_panel.py
-
[
]
datapreprocess_panel.py
-
[
]
training_panel.py
-
[
]
videobrowser.py
-
[
]
videoclipper.py
#### widgets/videopage/
-
[
]
channelpanel.py
-
[
]
curvepanel.py
-
[
]
general_set.py
-
[
]
historyvideopanel.py
-
[
]
logicsetting_dialogue.py
-
[
]
missionpanel.py
-
[
]
modelsetting_dialogue.py
#### widgets/modelpage/
-
[
]
modelset_page.py
-
[
]
training_page.py
#### widgets/其他
-
[
]
menubar.py
-
[
]
responsive_layout.py
-
[
]
style_manager.py
---
## 统计信息
-
**已完成文件**
: 4/64 (部分完成)
-
**已删除语句**
: 约100+/3441
-
**完成百分比**
: 约3%
## 已完成清理的文件
### 完全清理
1.
✅
**handlers/app.py**
- 删除17处print语句
2.
✅
**widgets/style_manager.py**
- 删除12处print语句和DEBUG注释
3.
✅
**widgets/responsive_layout.py**
- 删除5处print语句
### 部分清理
4.
🔄
**handlers/videopage/missionpanel_handler.py**
- 已清理前330行,删除约20处print语句(文件共2050行,需继续清理)
---
*最后更新: 2025-11-26 19:32*
handlers/app.py
View file @
f1a1c631
...
...
@@ -559,10 +559,6 @@ class MainWindow(
# 设置窗口标题
self
.
setWindowTitle
(
self
.
tr
(
"帕特智能油液位检测"
))
print
(
f
"[MainWindow] 窗口标题已设置: 帕特智能油液位检测"
)
print
(
f
"[MainWindow] 注意:窗口标题栏由操作系统绘制,不受Qt字体设置影响"
)
print
(
f
" - 标题栏字体由Windows系统设置控制"
)
print
(
f
" - 应用字体只影响窗口内部的Qt控件(按钮、标签、表格等)"
)
# 设置窗口图标(用于左上角和任务栏)
self
.
_setWindowIcon
()
...
...
@@ -623,11 +619,8 @@ class MainWindow(
if
os
.
path
.
exists
(
icon_path
):
icon
=
QtGui
.
QIcon
(
icon_path
)
self
.
setWindowIcon
(
icon
)
print
(
f
"[主窗口] 窗口图标已设置: {icon_path}"
)
else
:
print
(
f
"[主窗口] 图标文件不存在: {icon_path}"
)
except
Exception
as
e
:
p
rint
(
f
"[主窗口] 设置窗口图标失败: {e}"
)
p
ass
def
_loadDefaultConfig
(
self
):
"""从 default_config.yaml 加载配置"""
...
...
@@ -637,19 +630,10 @@ class MainWindow(
if
os
.
path
.
exists
(
self
.
_config_path
):
with
open
(
self
.
_config_path
,
'r'
,
encoding
=
'utf-8'
)
as
f
:
config
=
yaml
.
safe_load
(
f
)
or
{}
print
(
f
" 成功加载配置文件: {self._config_path}"
)
print
(
f
" 配置的通道: {[k for k in config.keys() if k.startswith('channel')]}"
)
# 显示编译模式(条件编译变量)
compilation_mode
=
config
.
get
(
'compilation'
,
'debug'
)
print
(
f
" 编译模式: {compilation_mode}"
)
return
config
else
:
print
(
f
"配置文件不存在: {self._config_path}"
)
return
{}
except
Exception
as
e
:
print
(
f
" 加载配置文件失败: {e}"
)
import
traceback
traceback
.
print_exc
()
return
{}
...
...
@@ -767,7 +751,6 @@ class MainWindow(
# 🔥 为每个通道面板的任务标签设置变量名(channel1mission, channel2mission, channel3mission, channel4mission)
mission_var_name
=
f
'channel{i+1}mission'
setattr
(
self
,
mission_var_name
,
channelPanel
.
taskLabel
)
print
(
f
"[MainWindow] 已设置任务标签变量: {mission_var_name}"
)
if
hasattr
(
self
,
'_connectChannelPanelSignals'
):
self
.
_connectChannelPanelSignals
(
channelPanel
)
...
...
@@ -838,7 +821,6 @@ class MainWindow(
# 🔥 设置曲线面板的任务选择下拉框变量名(curvemission)
self
.
curvemission
=
self
.
curvePanel
.
curvemission
print
(
f
"[MainWindow] 已设置曲线任务变量: curvemission"
)
# 连接任务选择变化信号
self
.
curvemission
.
currentTextChanged
.
connect
(
self
.
_onCurveMissionChanged
)
...
...
@@ -854,14 +836,12 @@ class MainWindow(
# 🔥 不再从任务配置读取通道列表,改为基于CSV文件数量动态显示
# 曲线线程会读取所有CSV文件,这里只需要确保有足够的容器显示
if
not
mission_name
or
mission_name
==
"请选择任务"
:
print
(
f
"[曲线布局] 未选择任务,隐藏所有通道容器"
)
self
.
_updateCurveChannelDisplay
([])
return
# 🔥 显示所有4个通道容器,让曲线系统自动填充
# 实际显示的曲线数量由CSV文件数量决定
all_channels
=
[
'通道1'
,
'通道2'
,
'通道3'
,
'通道4'
]
print
(
f
"📊 [曲线布局] 任务 {mission_name} 已选择,显示所有通道容器,等待CSV文件加载"
)
self
.
_updateCurveChannelDisplay
(
all_channels
)
# 🔥 删除 _getTaskChannels 方法,不再需要从配置文件读取通道列表
...
...
@@ -899,8 +879,6 @@ class MainWindow(
total_height
=
100
# 最小高度
self
.
curve_channel_container
.
setFixedSize
(
640
,
total_height
)
print
(
f
"[曲线布局] 已更新通道显示,显示 {visible_count} 个通道"
)
def
_createModelPage
(
self
):
"""创建模型管理页面"""
...
...
@@ -920,7 +898,6 @@ class MainWindow(
from
handlers.modelpage.model_training_handler
import
ModelTrainingHandler
except
ImportError
:
ModelTrainingHandler
=
None
print
(
"[WARNING] 无法导入ModelTrainingHandler,训练功能将不可用"
)
if
ModelTrainingHandler
:
self
.
training_handler
=
ModelTrainingHandler
()
...
...
@@ -1004,7 +981,6 @@ class MainWindow(
# ========== 通道管理按钮信号 ==========
# 🔥 已改为内嵌显示,由 MissionPanelHandler 处理,不再使用弹窗
# self.missionTable.channelManageClicked.connect(self.onChannelManage) # 旧的弹窗方式
print
(
"[App] 通道管理已改为内嵌显示,不再使用弹窗"
)
# ========== 通道面板信号(为所有面板连接) ==========
# 注意:channelConnected, channelDisconnected, channelEdited, amplifyClicked, channelNameChanged
...
...
@@ -1171,7 +1147,6 @@ class MainWindow(
except
Exception
as
e
:
import
traceback
print
(
f
"安装事件过滤器失败: {e}"
)
traceback
.
print_exc
()
def
_installEventFilterRecursive
(
self
,
widget
,
event_filter
):
...
...
@@ -1201,13 +1176,11 @@ class MainWindow(
except
Exception
as
e
:
# 出错时忽略,不影响主流程
print
(
f
"_installEventFilterRecursive 失败: {e}"
)
return
0
def
closeEvent
(
self
,
event
):
"""窗口关闭事件"""
try
:
print
(
"[应用] 正在关闭应用..."
)
# 清理全局检测线程
if
hasattr
(
self
,
'view_handler'
)
and
self
.
view_handler
:
...
...
@@ -1215,7 +1188,6 @@ class MainWindow(
if
video_handler
:
thread_manager
=
getattr
(
video_handler
,
'thread_manager'
,
None
)
if
thread_manager
:
print
(
"[应用] 清理全局检测线程..."
)
thread_manager
.
cleanup_global_detection_thread
()
# 保存窗口状态
...
...
@@ -1226,10 +1198,7 @@ class MainWindow(
# 保存当前页面索引
self
.
settings
.
setValue
(
"window/last_page"
,
self
.
getCurrentPageIndex
())
print
(
"[应用] 应用关闭清理完成"
)
except
Exception
as
e
:
print
(
f
"[应用] 关闭清理失败: {e}"
)
import
traceback
traceback
.
print_exc
()
...
...
@@ -1251,7 +1220,6 @@ def main():
app
.
setOrganizationName
(
'Detection'
)
# 🔥 暂时禁用全局字体配置,测试是否解决重复显示问题
print
(
f
"🔍 [调试] 跳过全局字体应用到应用程序"
)
# FontManager.applyToApplication(app)
# 设置应用样式(可选)
...
...
handlers/videopage/missionpanel_handler.py
View file @
f1a1c631
...
...
@@ -60,8 +60,6 @@ class MissionPanelHandler:
mission_panel
.
channelCancelled
.
connect
(
self
.
_handleChannelCancelled
)
mission_panel
.
channelDebugRequested
.
connect
(
self
.
_handleChannelDebug
)
print
(
"[MissionPanelHandler] 通道管理信号已连接"
)
# 🔥 根据编译模式控制调试按钮的可见性
self
.
_updateDebugButtonVisibility
()
...
...
@@ -83,8 +81,6 @@ class MissionPanelHandler:
# 如果点击的是曲线按钮
if
column_index
==
CURVE_BUTTON_COLUMN
:
print
(
f
"📊 [任务面板] 曲线按钮被点击 (行: {row_index})"
)
# 获取该行的任务信息
if
hasattr
(
self
,
'mission_panel'
)
and
self
.
mission_panel
:
# 从表格获取任务编号和任务名称
...
...
@@ -96,24 +92,16 @@ class MissionPanelHandler:
task_name
=
task_name_item
.
text
()
# 组合任务文件夹名称
mission_folder_name
=
f
"{task_id}_{task_name}"
print
(
f
"📁 [任务面板] 任务文件夹名称: {mission_folder_name}"
)
# 设置 curvemission 的值
if
hasattr
(
self
,
'curvePanel'
)
and
self
.
curvePanel
:
success
=
self
.
curvePanel
.
setMissionFromTaskName
(
mission_folder_name
)
if
success
:
print
(
f
"✅ [任务面板] 已设置 curvemission 为: {mission_folder_name}"
)
else
:
print
(
f
"⚠️ [任务面板] 设置 curvemission 失败: {mission_folder_name}"
)
# 调用ViewHandler的toggleVideoPageMode方法切换布局
if
hasattr
(
self
,
'toggleVideoPageMode'
):
self
.
toggleVideoPageMode
()
else
:
print
(
"⚠️ toggleVideoPageMode 方法不存在"
)
except
Exception
as
e
:
print
(
f
"❌ 处理按钮点击失败: {e}"
)
import
traceback
traceback
.
print_exc
()
...
...
@@ -163,11 +151,8 @@ class MissionPanelHandler:
# 🔥 第一步:先创建结果文件夹并获取路径
mission_result_folder_path
=
self
.
_createmission_resultFolder
(
task_info
)
if
mission_result_folder_path
:
print
(
f
"结果文件夹已创建: {mission_result_folder_path}"
)
# 将结果文件夹路径添加到task_info中
task_info
[
'mission_result_folder_path'
]
=
mission_result_folder_path
else
:
print
(
"结果文件夹创建失败,继续保存配置(不包含路径)"
)
# 第二步:保存任务配置到YAML文件(包含mission_result_folder_path)
if
self
.
_saveMissionConfig
(
task_info
):
...
...
@@ -181,14 +166,12 @@ class MissionPanelHandler:
# 第四步:添加到表格
if
self
.
mission_panel
:
self
.
mission_panel
.
addTaskRow
(
task_info
)
print
(
f
"任务已创建: {task_info['task_name']}"
)
else
:
QtWidgets
.
QMessageBox
.
warning
(
self
.
mission_panel
,
"警告"
,
"任务配置保存失败,但任务已添加到列表"
)
except
Exception
as
e
:
print
(
f
"添加任务失败: {e}"
)
import
traceback
traceback
.
print_exc
()
QtWidgets
.
QMessageBox
.
warning
(
...
...
@@ -197,7 +180,7 @@ class MissionPanelHandler:
def
_handleTaskCancelled
(
self
):
"""处理任务取消"""
p
rint
(
" 新建任务已取消"
)
p
ass
def
_handleTaskSelected
(
self
,
task_info
):
"""
...
...
@@ -217,24 +200,17 @@ class MissionPanelHandler:
selected_channels
=
task_info
.
get
(
'selected_channels'
,
[])
if
not
task_id
or
not
task_name
:
print
(
"任务编号或任务名称为空,跳过同步"
)
# 重置current_mission为默认值
if
hasattr
(
self
,
'current_mission'
):
self
.
current_mission
=
r"D:\restructure\liquid_level_line_detection_system\database\mission_result\None"
print
(
f
"[当前任务] 已重置为: {self.current_mission}"
)
return
if
not
selected_channels
:
print
(
"未选择通道,跳过同步"
)
return
print
(
f
"任务已选中: {task_id} - {task_name}"
)
print
(
f
" 关联通道: {', '.join(selected_channels)}"
)
# 🔥 从任务配置文件中读取完整的任务信息(包括mission_result_folder_path)
full_task_info
=
self
.
_loadMissionConfig
(
task_id
,
task_name
)
if
not
full_task_info
:
print
(
"无法读取任务配置文件,使用基本信息"
)
full_task_info
=
task_info
# 获取结果文件夹路径(作为save_liquid_data_path)
...
...
@@ -258,12 +234,8 @@ class MissionPanelHandler:
task_folder_name
=
os
.
path
.
basename
(
os
.
path
.
normpath
(
mission_result_folder_path
))
else
:
task_folder_name
=
str
(
mission_result_folder_path
)
.
strip
()
print
(
f
" 任务文件夹名称: {task_folder_name}"
)
print
(
f
" 结果文件夹路径: {mission_result_folder_path}"
)
else
:
task_folder_name
=
f
"{task_id}_{task_name}"
print
(
f
" 任务文件夹名称: {task_folder_name}"
)
print
(
" 未找到结果文件夹路径"
)
# 🔥 检查通道是否已有任务,如果有则弹出确认对话框
channels_with_tasks
=
self
.
_checkChannelsWithExistingTasks
(
selected_channels
,
task_folder_name
)
...
...
@@ -278,28 +250,22 @@ class MissionPanelHandler:
message
+=
f
"
\n\n
确定要重新分配任务 [{task_id}_{task_name}] 吗?"
# 🔥 创建自定义确认对话框(标题栏显示警告图标,内容区域无图标,中文按钮)
print
(
"
\n
[对话框调试] 创建任务重新分配确认对话框"
)
msg_box
=
QtWidgets
.
QMessageBox
(
self
.
mission_panel
if
hasattr
(
self
,
'mission_panel'
)
else
None
)
msg_box
.
setWindowTitle
(
"重新分配任务确认"
)
msg_box
.
setText
(
message
)
msg_box
.
setIcon
(
QtWidgets
.
QMessageBox
.
NoIcon
)
# 内容区域不显示图标
print
(
f
" - 设置内容区域图标: NoIcon"
)
# 设置窗口标题栏图标为系统警告图标
warning_icon
=
msg_box
.
style
()
.
standardIcon
(
QtWidgets
.
QStyle
.
SP_MessageBoxWarning
)
msg_box
.
setWindowIcon
(
warning_icon
)
print
(
f
" - 设置窗口图标: SP_MessageBoxWarning"
)
print
(
f
" - 窗口图标是否为空: {warning_icon.isNull()}"
)
# 移除帮助按钮
original_flags
=
msg_box
.
windowFlags
()
msg_box
.
setWindowFlags
(
msg_box
.
windowFlags
()
&
~
QtCore
.
Qt
.
WindowContextHelpButtonHint
)
print
(
f
" - 原始窗口标志: {original_flags}"
)
print
(
f
" - 最终窗口标志: {msg_box.windowFlags()}"
)
# 添加自定义按钮(中文)
btn_confirm
=
msg_box
.
addButton
(
"确认"
,
QtWidgets
.
QMessageBox
.
YesRole
)
...
...
@@ -313,13 +279,10 @@ class MissionPanelHandler:
clicked_button
=
msg_box
.
clickedButton
()
if
clicked_button
==
btn_cancel
:
print
(
"❌ [任务分配] 用户取消任务重新分配"
)
# 🔥 通知Widget取消任务分配,不高亮行
if
self
.
mission_panel
:
self
.
mission_panel
.
cancelTaskAssignment
()
return
print
(
"✅ [任务分配] 用户确认重新分配任务"
)
# 🔥 遍历选中的通道,只更新这些通道的任务标签(不影响其他通道)
for
channel_key
in
selected_channels
:
...
...
@@ -334,8 +297,6 @@ class MissionPanelHandler:
# 更新通道面板的任务信息和配置文件
self
.
_updateChannelTaskInfo
(
channel_id
,
task_id
,
task_name
,
mission_result_folder_path
)
else
:
print
(
f
"无法解析通道ID: {channel_key}"
)
# 🔥 确认任务分配,高亮选中的行
if
self
.
mission_panel
:
...
...
@@ -343,7 +304,6 @@ class MissionPanelHandler:
# 🔥 恢复自动状态刷新:任务分配后刷新所有任务状态
self
.
_refreshAllTaskStatus
()
print
(
f
"✅ [状态刷新] 已刷新所有任务状态显示"
)
except
Exception
as
e
:
print
(
f
"处理任务选中失败: {e}"
)
...
...
widgets/locate_debug_statements.py
0 → 100644
View file @
f1a1c631
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
调试语句定位脚本
用于查找并记录 widgets 和 handlers 文件夹中的调试语句位置
"""
import
os
import
re
from
pathlib
import
Path
from
datetime
import
datetime
class
DebugStatementLocator
:
"""调试语句定位器"""
def
__init__
(
self
,
target_dirs
):
"""
初始化定位器
Args:
target_dirs: 要扫描的目标目录列表
"""
self
.
target_dirs
=
target_dirs
self
.
debug_patterns
=
[
# print 语句
(
r'^\s*print\s*\('
,
'print语句'
),
# logging.debug
(
r'^\s*logging\.debug\s*\('
,
'logging.debug'
),
# logger.debug
(
r'^\s*logger\.debug\s*\('
,
'logger.debug'
),
# self.logger.debug
(
r'^\s*self\.logger\.debug\s*\('
,
'self.logger.debug'
),
# console.log (如果有JS代码)
(
r'^\s*console\.log\s*\('
,
'console.log'
),
# 包含 DEBUG 或 debug 的注释
(
r'^\s*#.*(?:DEBUG|debug|调试|测试)'
,
'DEBUG注释'
),
# TODO/FIXME 注释
(
r'^\s*#.*(?:TODO|FIXME|XXX|HACK)'
,
'TODO/FIXME注释'
),
]
self
.
results
=
[]
def
scan_file
(
self
,
file_path
):
"""
扫描单个文件
Args:
file_path: 文件路径
"""
try
:
with
open
(
file_path
,
'r'
,
encoding
=
'utf-8'
)
as
f
:
lines
=
f
.
readlines
()
for
line_num
,
line
in
enumerate
(
lines
,
1
):
for
pattern
,
pattern_name
in
self
.
debug_patterns
:
if
re
.
search
(
pattern
,
line
):
self
.
results
.
append
({
'file'
:
str
(
file_path
),
'line'
:
line_num
,
'type'
:
pattern_name
,
'content'
:
line
.
strip
()
})
except
Exception
as
e
:
print
(
f
"扫描文件 {file_path} 时出错: {e}"
)
def
scan_directory
(
self
,
directory
):
"""
扫描目录
Args:
directory: 目录路径
"""
dir_path
=
Path
(
directory
)
if
not
dir_path
.
exists
():
print
(
f
"目录不存在: {directory}"
)
return
# 遍历所有 Python 文件
for
py_file
in
dir_path
.
rglob
(
'*.py'
):
# 跳过 __pycache__ 和本脚本自身
if
'__pycache__'
in
str
(
py_file
)
or
py_file
.
name
==
'locate_debug_statements.py'
:
continue
self
.
scan_file
(
py_file
)
def
scan_all
(
self
):
"""扫描所有目标目录"""
for
directory
in
self
.
target_dirs
:
print
(
f
"正在扫描目录: {directory}"
)
self
.
scan_directory
(
directory
)
def
generate_report
(
self
,
output_file
=
'debug_statements_report.txt'
):
"""
生成报告
Args:
output_file: 输出文件名
"""
# 按文件分组
files_dict
=
{}
for
item
in
self
.
results
:
file_path
=
item
[
'file'
]
if
file_path
not
in
files_dict
:
files_dict
[
file_path
]
=
[]
files_dict
[
file_path
]
.
append
(
item
)
# 生成报告内容
report_lines
=
[]
report_lines
.
append
(
"="
*
80
)
report_lines
.
append
(
"调试语句定位报告"
)
report_lines
.
append
(
f
"生成时间: {datetime.now().strftime('
%
Y-
%
m-
%
d
%
H:
%
M:
%
S')}"
)
report_lines
.
append
(
"="
*
80
)
report_lines
.
append
(
""
)
report_lines
.
append
(
f
"总计发现 {len(self.results)} 处调试语句"
)
report_lines
.
append
(
f
"涉及 {len(files_dict)} 个文件"
)
report_lines
.
append
(
""
)
report_lines
.
append
(
"="
*
80
)
report_lines
.
append
(
""
)
# 按文件输出
for
file_path
in
sorted
(
files_dict
.
keys
()):
items
=
files_dict
[
file_path
]
report_lines
.
append
(
f
"
\n
文件: {file_path}"
)
report_lines
.
append
(
f
"发现 {len(items)} 处调试语句:"
)
report_lines
.
append
(
"-"
*
80
)
for
item
in
sorted
(
items
,
key
=
lambda
x
:
x
[
'line'
]):
report_lines
.
append
(
f
" 行 {item['line']:4d} | {item['type']:20s} | {item['content']}"
)
report_lines
.
append
(
""
)
# 统计信息
report_lines
.
append
(
"="
*
80
)
report_lines
.
append
(
"统计信息"
)
report_lines
.
append
(
"="
*
80
)
type_counts
=
{}
for
item
in
self
.
results
:
type_name
=
item
[
'type'
]
type_counts
[
type_name
]
=
type_counts
.
get
(
type_name
,
0
)
+
1
for
type_name
,
count
in
sorted
(
type_counts
.
items
(),
key
=
lambda
x
:
x
[
1
],
reverse
=
True
):
report_lines
.
append
(
f
" {type_name:20s}: {count:4d} 处"
)
report_lines
.
append
(
""
)
report_lines
.
append
(
"="
*
80
)
# 写入文件
report_content
=
'
\n
'
.
join
(
report_lines
)
# 获取项目根目录
script_dir
=
Path
(
__file__
)
.
parent
.
parent
output_path
=
script_dir
/
output_file
with
open
(
output_path
,
'w'
,
encoding
=
'utf-8'
)
as
f
:
f
.
write
(
report_content
)
print
(
f
"
\n
报告已生成: {output_path}"
)
print
(
f
"总计发现 {len(self.results)} 处调试语句"
)
return
output_path
def
main
():
"""主函数"""
# 获取项目根目录
script_dir
=
Path
(
__file__
)
.
parent
.
parent
# 定义要扫描的目录
target_dirs
=
[
script_dir
/
'widgets'
,
script_dir
/
'handlers'
]
print
(
"="
*
80
)
print
(
"调试语句定位工具"
)
print
(
"="
*
80
)
print
(
f
"项目根目录: {script_dir}"
)
print
(
f
"扫描目录: {', '.join([str(d) for d in target_dirs])}"
)
print
(
"="
*
80
)
print
()
# 创建定位器并扫描
locator
=
DebugStatementLocator
(
target_dirs
)
locator
.
scan_all
()
# 生成报告
report_path
=
locator
.
generate_report
()
print
(
"
\n
扫描完成!"
)
print
(
f
"请查看报告文件: {report_path}"
)
if
__name__
==
'__main__'
:
main
()
widgets/responsive_layout.py
View file @
f1a1c631
...
...
@@ -38,13 +38,11 @@ class ResponsiveLayout:
app
=
QtWidgets
.
QApplication
.
instance
()
if
app
is
None
:
print
(
"[响应式布局] 警告: 无法获取QApplication实例,使用默认缩放比例"
)
return
# 获取主屏幕
screen
=
app
.
primaryScreen
()
if
screen
is
None
:
print
(
"[响应式布局] 警告: 无法获取主屏幕,使用默认缩放比例"
)
return
# 获取屏幕几何信息
...
...
@@ -63,10 +61,6 @@ class ResponsiveLayout:
cls
.
_scale_factor
=
max
(
cls
.
MIN_SCALE_FACTOR
,
min
(
cls
.
MAX_SCALE_FACTOR
,
raw_scale
))
cls
.
_scale_factor_w
=
cls
.
_scale_factor
cls
.
_scale_factor_h
=
cls
.
_scale_factor
print
(
f
"[响应式布局] 屏幕分辨率: {cls._screen_width}x{cls._screen_height}"
)
print
(
f
"[响应式布局] 原始缩放: 宽度={raw_scale_w:.3f}, 高度={raw_scale_h:.3f}"
)
print
(
f
"[响应式布局] 统一缩放因子: {cls._scale_factor:.3f} (限制范围: {cls.MIN_SCALE_FACTOR}-{cls.MAX_SCALE_FACTOR})"
)
@classmethod
def
scale_width
(
cls
,
base_width
):
...
...
widgets/style_manager.py
View file @
f1a1c631
...
...
@@ -14,19 +14,14 @@ import os
import
os.path
as
osp
import
sys
print
(
f
"[DEBUG style_manager.py] 开始导入 PyQt5..."
)
try
:
from
PyQt5
import
QtGui
,
QtWidgets
,
QtCore
print
(
f
"[DEBUG style_manager.py] PyQt5 导入成功"
)
except
ImportError
as
e
:
print
(
f
"[DEBUG style_manager.py] PyQt5 导入失败: {e}"
)
raise
try
:
from
qtpy
import
QtCore
as
QtCore_qtpy
print
(
f
"[DEBUG style_manager.py] qtpy 导入成功"
)
except
ImportError
as
e
:
print
(
f
"[DEBUG style_manager.py] qtpy 导入失败: {e}"
)
raise
...
...
@@ -128,39 +123,30 @@ class FontManager:
old_font
.
italic
()
!=
font
.
italic
()
or
old_font
.
underline
()
!=
font
.
underline
()):
# print(f"🔍 [FontManager] 应用字体到 {widget_type}: 文本='{widget_text}', 旧字体={old_font.family()} {old_font.pointSize()}pt")
widget
.
setFont
(
font
)
new_font
=
widget
.
font
()
# print(f"🔍 [FontManager] 字体已应用: 新字体={new_font.family()} {new_font.pointSize()}pt")
else
:
pass
# print(f"🔍 [FontManager] 跳过字体设置 {widget_type}: 文本='{widget_text}', 字体已相同={old_font.family()} {old_font.pointSize()}pt")
pass
@staticmethod
def
applyToApplication
(
app
):
"""应用默认字体到整个应用程序"""
font
=
FontManager
.
getDefaultFont
()
app
.
setFont
(
font
)
# print(f"[字体管理器] 已应用全局字体: {FontManager.DEFAULT_FONT_FAMILY}, {FontManager.DEFAULT_FONT_SIZE}pt")
# print(f"[字体管理器] 应用范围: 窗口内部Qt控件")
# print(f"[字体管理器] 不影响: 窗口标题栏(由操作系统绘制)")
@staticmethod
def
applyToWidgetRecursive
(
widget
,
size
=
None
,
weight
=
None
):
"""递归应用字体到控件及其所有子控件"""
# print(f"🔍 [FontManager] 递归字体应用被调用: {type(widget).__name__}")
# 应用字体到当前控件
FontManager
.
applyToWidget
(
widget
,
size
,
weight
)
# 递归应用到所有子控件
children
=
widget
.
findChildren
(
QtWidgets
.
QWidget
)
# print(f"🔍 [FontManager] 找到 {len(children)} 个子控件")
for
child
in
children
:
child_type
=
type
(
child
)
.
__name__
child_text
=
getattr
(
child
,
'text'
,
lambda
:
'N/A'
)()
# print(f"🔍 [FontManager] 递归应用到子控件: {child_type}, 文本='{child_text}'")
FontManager
.
applyToWidget
(
child
,
size
,
weight
)
@staticmethod
...
...
@@ -172,8 +158,6 @@ class FontManager:
FontManager
.
DEFAULT_FONT_SIZE
=
size
if
weight
is
not
None
:
FontManager
.
DEFAULT_FONT_WEIGHT
=
weight
# print(f"[字体管理器] 默认字体配置已更新: {FontManager.DEFAULT_FONT_FAMILY}, {FontManager.DEFAULT_FONT_SIZE}pt, 粗细: {FontManager.DEFAULT_FONT_WEIGHT}")
@staticmethod
def
applyToDialog
(
dialog
):
...
...
@@ -185,9 +169,8 @@ class FontManager:
# 递归应用到所有子控件
FontManager
.
applyToWidgetRecursive
(
dialog
)
# print(f"✅ [FontManager] 已为对话框/页面应用字体: {type(dialog).__name__}")
except
Exception
as
e
:
pass
# print(f"⚠️ [FontManager] 应用字体到对话框失败: {e}")
pass
# 字体管理器便捷函数
...
...
@@ -299,21 +282,16 @@ class DialogManager:
@staticmethod
def
show_warning
(
parent
,
title
,
message
):
"""显示警告对话框"""
print
(
f
"[DEBUG DialogManager] show_warning 被调用"
)
print
(
f
"[DEBUG DialogManager] 创建对话框..."
)
msg_box
=
DialogManager
.
_create_base_dialog
(
parent
,
title
,
message
,
QtWidgets
.
QStyle
.
SP_MessageBoxWarning
)
print
(
f
"[DEBUG DialogManager] 设置标准按钮..."
)
msg_box
.
setStandardButtons
(
QtWidgets
.
QMessageBox
.
Ok
)
print
(
f
"[DEBUG DialogManager] 设置中文按钮文本..."
)
DialogManager
.
_set_chinese_button_texts
(
msg_box
)
# 🔥 确保OK按钮文本为"确定"
ok_btn
=
msg_box
.
button
(
QtWidgets
.
QMessageBox
.
Ok
)
if
ok_btn
:
ok_btn
.
setText
(
"确定"
)
print
(
f
"[DEBUG DialogManager] 显示对话框..."
)
msg_box
.
exec_
()
@staticmethod
...
...
@@ -415,8 +393,6 @@ class DialogManager:
DialogManager
.
DEFAULT_STYLE
=
style_sheet
print
(
f
"[DEBUG style_manager.py] DialogManager 类定义完成: {DialogManager}"
)
# 对话框管理器便捷函数
def
show_warning
(
parent
,
title
,
message
):
"""显示警告对话框(中文按钮)"""
...
...
@@ -481,8 +457,7 @@ def get_icons_dir():
# 调试信息:如果图标目录不存在,打印警告
if
not
osp
.
exists
(
icons_path
):
pass
# print(f"警告: 图标目录不存在: {icons_path}")
# print(f" 项目根目录: {project_root}")
pass
return
icons_path
...
...
@@ -500,8 +475,6 @@ def newIcon(icon):
return
QtGui
.
QIcon
(
icon_path
)
# 如果找不到图标文件,返回空图标(避免程序崩溃)
# print(f"警告: 找不到图标文件: {icon}")
# print(f" 搜索目录: {icons_dir}")
return
QtGui
.
QIcon
()
def
newButton
(
text
,
icon
=
None
,
slot
=
None
):
...
...
@@ -850,7 +823,6 @@ class MenuBarStyleManager:
def
applyToMenuBar
(
cls
,
menubar
):
"""应用标准菜单栏样式到菜单栏控件"""
menubar
.
setStyleSheet
(
cls
.
DEFAULT_MENUBAR_STYLE
)
# print(f"[菜单栏样式管理器] 已应用菜单栏样式,悬停颜色: #B0B0B0")
@classmethod
def
setDefaultMenuBarStyle
(
cls
,
style_sheet
):
...
...
@@ -870,7 +842,6 @@ class MenuBarStyleManager:
"background-color: #B0B0B0;"
,
f
"background-color: {color};"
)
# print(f"[菜单栏样式管理器] 悬停颜色已更新为: {color}")
# 菜单栏样式管理器便捷函数
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment