| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- """
- 模式设置(新建/编辑)
- """
- import streamlit as st
- from PIL import Image
- from typing import Dict, Tuple
- try:
- from ..table_line_generator import TableLineGenerator
- except ImportError:
- from table_line_generator import TableLineGenerator
- from .display_controls import create_display_settings_section, create_undo_redo_section
- from .analysis_controls import create_analysis_section
- def setup_new_annotation_mode(ocr_data, image, config: Dict) -> Tuple:
- """
- 设置新建标注模式的通用逻辑
-
- Args:
- ocr_data: OCR 数据
- image: 图片对象
- config: 显示配置
-
- Returns:
- tuple: (y_tolerance, x_tolerance, min_row_height, line_width,
- display_mode, zoom_level, show_line_numbers)
- """
- # 参数调整
- st.sidebar.header("🔧 参数调整")
- y_tolerance = st.sidebar.slider(
- "Y轴聚类容差(像素)",
- 1, 20, 5,
- key="new_y_tol"
- )
- x_tolerance = st.sidebar.slider(
- "X轴聚类容差(像素)",
- 5, 50, 10,
- key="new_x_tol"
- )
- min_row_height = st.sidebar.slider(
- "最小行高(像素)",
- 10, 100, 20,
- key="new_min_h"
- )
-
- # 显示设置
- line_width, display_mode, zoom_level, show_line_numbers = \
- create_display_settings_section(config)
- create_undo_redo_section()
-
- # 初始化生成器
- if 'generator' not in st.session_state or st.session_state.generator is None:
- try:
- generator = TableLineGenerator(image, ocr_data)
- st.session_state.generator = generator
- except Exception as e:
- st.error(f"❌ 初始化生成器失败: {e}")
- st.stop()
-
- # 分析按钮
- create_analysis_section(y_tolerance, x_tolerance, min_row_height)
-
- return (y_tolerance, x_tolerance, min_row_height,
- line_width, display_mode, zoom_level, show_line_numbers)
- def setup_edit_annotation_mode(structure: Dict, image, config: Dict) -> Tuple:
- """
- 设置编辑标注模式的通用逻辑
-
- Args:
- structure: 表格结构
- image: 图片对象(可为 None)
- config: 显示配置
-
- Returns:
- tuple: (image, line_width, display_mode, zoom_level, show_line_numbers)
- """
- # 如果没有图片,创建虚拟画布
- if image is None:
- if 'table_bbox' in structure:
- bbox = structure['table_bbox']
- dummy_width = bbox[2] + 100
- dummy_height = bbox[3] + 100
- else:
- dummy_width = 2000
- dummy_height = 2000
- image = Image.new('RGB', (dummy_width, dummy_height), color='white')
- st.info(f"💡 使用虚拟画布 ({dummy_width}x{dummy_height})")
-
- # 显示设置
- line_width, display_mode, zoom_level, show_line_numbers = \
- create_display_settings_section(config)
- create_undo_redo_section()
-
- return image, line_width, display_mode, zoom_level, show_line_numbers
|