refactor(gui): 抽日志搜索工具栏到 components/log_search_toolbar (1813 → 1739)
This commit is contained in:
1 parent
dc1744a93f
commit
5e3015f59b
2 files changed
+142
-83
No files matched your search
+8
-83
@@ -95,6 +95,7 @@ from gui.components.run_tab import setup_run_tab
|
||||
from gui.components.filter_tab import setup_filter_tab
|
||||
from gui.components.realtime_tab import setup_realtime_tab
|
||||
from gui.components.log_text_colors import configure_log_text_colors
|
||||
from gui.components.log_search_toolbar import setup_log_search_toolbar
|
||||
|
||||
# 导入日志颜色配置模块
|
||||
try:
|
||||
@@ -1193,90 +1194,14 @@ def main():
|
||||
log_text.pack(fill=BOTH, expand=True, padx=10, pady=(0, 10))
|
||||
|
||||
# 搜索工具栏
|
||||
log_search_frame = ttk.Frame(log_box)
|
||||
log_search_frame.pack(fill=X, padx=10, pady=(10, 5))
|
||||
|
||||
# 关键字筛选(与行为日志一致)
|
||||
log_filter_var = tk.StringVar(value="")
|
||||
ttk.Label(log_search_frame, text="筛选:").pack(side=LEFT)
|
||||
ttk.Entry(log_search_frame, textvariable=log_filter_var, width=16).pack(
|
||||
side=LEFT, padx=(0, 8)
|
||||
)
|
||||
|
||||
log_search_var = tk.StringVar(value="")
|
||||
log_search_entry = ttk.Entry(
|
||||
log_search_frame, textvariable=log_search_var, width=20
|
||||
)
|
||||
|
||||
def refresh_run_log():
|
||||
_refresh_run_log_impl(
|
||||
runner,
|
||||
text_widget=log_text,
|
||||
filter_getter=lambda: log_filter_var.get().strip(),
|
||||
theme_getter=lambda: str(gui_theme_var.get() or "litera"),
|
||||
)
|
||||
|
||||
log_search_matches = [] # 存储所有匹配的位置
|
||||
log_current_match_index = -1 # 当前匹配的索引
|
||||
|
||||
|
||||
def search_in_log_text(direction=1):
|
||||
"""在运行日志中搜索文本(调用通用搜索实现)"""
|
||||
nonlocal log_search_matches, log_current_match_index
|
||||
log_current_match_index = _generic_search_widget_impl(
|
||||
log_text,
|
||||
log_search_var,
|
||||
log_search_matches,
|
||||
log_current_match_index,
|
||||
direction,
|
||||
)
|
||||
|
||||
def search_next_in_log():
|
||||
"""搜索下一个"""
|
||||
search_in_log_text(1)
|
||||
|
||||
def search_prev_in_log():
|
||||
"""搜索上一个"""
|
||||
search_in_log_text(-1)
|
||||
|
||||
def clear_search_in_log():
|
||||
"""清除搜索高亮"""
|
||||
nonlocal log_search_matches, log_current_match_index
|
||||
log_search_var.set("")
|
||||
log_text.tag_remove("search_highlight", "1.0", "end")
|
||||
log_text.tag_remove("search_current", "1.0", "end")
|
||||
log_search_matches = []
|
||||
log_current_match_index = -1
|
||||
|
||||
# 绑定回车键搜索
|
||||
def on_log_search_entry_key(event):
|
||||
if event.keysym == "Return":
|
||||
search_next_in_log()
|
||||
|
||||
log_search_entry.bind("<KeyPress>", on_log_search_entry_key)
|
||||
|
||||
# 将 刷新 放在筛选后面,搜索区域与行为日志一致(带分隔条)
|
||||
ttk.Button(log_search_frame, text="刷新", command=refresh_run_log).pack(
|
||||
side=LEFT, padx=(0, 8)
|
||||
)
|
||||
ttk.Separator(log_search_frame, orient="vertical").pack(
|
||||
side=LEFT, fill=Y, padx=5, pady=3
|
||||
)
|
||||
ttk.Label(log_search_frame, text="搜索:").pack(side=LEFT)
|
||||
# 把搜索输入框放在分隔符后
|
||||
log_search_entry.pack(side=LEFT, padx=(0, 5))
|
||||
ttk.Button(log_search_frame, text="搜索", command=search_next_in_log).pack(
|
||||
side=LEFT, padx=(0, 2)
|
||||
)
|
||||
ttk.Button(log_search_frame, text="上一个", command=search_prev_in_log).pack(
|
||||
side=LEFT, padx=(0, 2)
|
||||
)
|
||||
ttk.Button(log_search_frame, text="下一个", command=search_next_in_log).pack(
|
||||
side=LEFT, padx=(0, 2)
|
||||
)
|
||||
ttk.Button(log_search_frame, text="清除", command=clear_search_in_log).pack(
|
||||
side=LEFT, padx=(0, 5)
|
||||
_log_search_handles = setup_log_search_toolbar(
|
||||
log_box,
|
||||
log_text=log_text,
|
||||
runner=runner,
|
||||
theme_getter=lambda: str(gui_theme_var.get() or "litera"),
|
||||
)
|
||||
log_filter_var = _log_search_handles.log_filter_var
|
||||
refresh_run_log = _log_search_handles.refresh_run_log
|
||||
|
||||
|
||||
configure_log_text_colors(
|
||||
|
||||
Reference in new issue
Block a user