feat: add progress callback mechanism for real-time updates in data extraction

- Add ProgressInfo and ProgressCalculator classes for structured progress tracking
- Implement RealtimeOutput for immediate log display without buffering
- Add progress callback support to DiscreteMaterialPlanExtractor
- Use queue-based thread-safe communication for GUI progress updates
- Fix log output issue where all content appeared at once after completion

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
Misaka_Company
2026-02-05 14:06:30 +08:00
parent 71621dc8a0
commit 885d87dff8
4 changed files with 329 additions and 82 deletions

39
gui/utils.py Normal file
View File

@@ -0,0 +1,39 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
GUI 工具模块
提供 GUI 相关的工具类和函数。
"""
class RealtimeOutput:
"""实时输出流,每次写入立即回调通知"""
def __init__(self, callback):
"""
初始化实时输出流
Args:
callback: 写入时的回调函数,接收文本内容
"""
self.callback = callback
self.buffer = []
def write(self, text):
"""写入文本"""
if text:
# 将文本按行分割,逐行回调
lines = text.split('\n')
for line in lines:
if line: # 忽略空行(由 split 产生)
self.callback(line)
return len(text)
def flush(self):
"""刷新(兼容性方法)"""
pass
def isatty(self):
"""返回 False表示不是终端"""
return False