display_controls.py 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. """
  2. 显示设置控件
  3. """
  4. import streamlit as st
  5. from typing import Dict, Tuple
  6. def create_display_settings_section(display_config: Dict) -> Tuple[int, str, float, bool]:
  7. """
  8. 显示设置(由配置驱动)
  9. Args:
  10. display_config: 显示配置字典
  11. Returns:
  12. tuple: (line_width, display_mode, zoom_level, show_line_numbers)
  13. """
  14. st.sidebar.divider()
  15. st.sidebar.subheader("🖼️ 显示设置")
  16. line_width = st.sidebar.slider(
  17. "线条宽度",
  18. int(display_config.get("line_width_min", 1)),
  19. int(display_config.get("line_width_max", 5)),
  20. int(display_config.get("default_line_width", 2)),
  21. )
  22. display_mode = st.sidebar.radio(
  23. "显示模式",
  24. ["对比显示", "仅显示划线图", "仅显示原图"],
  25. index=1,
  26. )
  27. zoom_level = st.sidebar.slider(
  28. "图片缩放",
  29. float(display_config.get("zoom_min", 0.25)),
  30. float(display_config.get("zoom_max", 2.0)),
  31. float(display_config.get("default_zoom", 1.0)),
  32. float(display_config.get("zoom_step", 0.25)),
  33. )
  34. show_line_numbers = st.sidebar.checkbox(
  35. "显示线条编号",
  36. value=bool(display_config.get("show_line_numbers", True)),
  37. )
  38. return line_width, display_mode, zoom_level, show_line_numbers
  39. def create_undo_redo_section():
  40. """创建撤销/重做区域"""
  41. from .state_manager import undo_last_action, redo_last_action
  42. from .drawing import clear_table_image_cache
  43. st.sidebar.divider()
  44. st.sidebar.subheader("↩️ 撤销/重做")
  45. col1, col2 = st.sidebar.columns(2)
  46. with col1:
  47. if st.button("↩️ 撤销", disabled=len(st.session_state.undo_stack) == 0):
  48. if undo_last_action():
  49. clear_table_image_cache()
  50. st.success("✅ 已撤销")
  51. st.rerun()
  52. with col2:
  53. if st.button("↪️ 重做", disabled=len(st.session_state.redo_stack) == 0):
  54. if redo_last_action():
  55. clear_table_image_cache()
  56. st.success("✅ 已重做")
  57. st.rerun()
  58. st.sidebar.info(f"📚 历史记录: {len(st.session_state.undo_stack)} 条")