|
|
@@ -50,6 +50,19 @@ class OCRLayoutManager:
|
|
|
self.show_all_boxes = False
|
|
|
self.fit_to_container = False
|
|
|
self.zoom_level = 1.0
|
|
|
+
|
|
|
+ def _clear_selection_callback(self, layout_type: str):
|
|
|
+ """在按钮回调中清理选择/搜索状态(避免 widget 实例化后修改报错)"""
|
|
|
+ # 业务态
|
|
|
+ st.session_state.selected_text = ""
|
|
|
+ # 紧凑布局的搜索态
|
|
|
+ st.session_state.compact_search_query = ""
|
|
|
+
|
|
|
+ # widget key 对应的状态(必须在 on_click 回调里改)
|
|
|
+ search_key = f"{layout_type}_search_input"
|
|
|
+ quick_select_key = f"{layout_type}_quick_text_selector"
|
|
|
+ st.session_state[search_key] = ""
|
|
|
+ st.session_state[quick_select_key] = 0
|
|
|
|
|
|
def clear_image_cache(self):
|
|
|
"""清理所有图像缓存"""
|
|
|
@@ -595,12 +608,12 @@ class OCRLayoutManager:
|
|
|
st.rerun()
|
|
|
|
|
|
with col5:
|
|
|
- if st.button("🧹 清除选择", key=f"{layout_type}_clear_selection"):
|
|
|
- # 清除选中的文本
|
|
|
- st.session_state.selected_text = None
|
|
|
- # 清除搜索框内容
|
|
|
- st.session_state.compact_search_query = None
|
|
|
- st.rerun()
|
|
|
+ st.button(
|
|
|
+ "🧹 清除选择",
|
|
|
+ key=f"{layout_type}_clear_selection",
|
|
|
+ on_click=self._clear_selection_callback,
|
|
|
+ kwargs={"layout_type": layout_type},
|
|
|
+ )
|
|
|
|
|
|
# 使用增强的图像加载方法
|
|
|
image = self.load_and_rotate_image(self.validator.image_path)
|