|
|
|
|
@ -15,6 +15,7 @@ from services.network_service import NetworkService
|
|
|
|
|
from typing_logic import TypingLogic
|
|
|
|
|
from ui.word_style_ui import WeatherAPI
|
|
|
|
|
from file_parser import FileParser
|
|
|
|
|
from input_handler.input_processor import InputProcessor
|
|
|
|
|
|
|
|
|
|
class WeatherFetchThread(QThread):
|
|
|
|
|
weather_fetched = pyqtSignal(dict)
|
|
|
|
|
@ -86,6 +87,9 @@ class WordStyleMainWindow(QMainWindow):
|
|
|
|
|
# 临时文件管理
|
|
|
|
|
self.temp_files = [] # 跟踪创建的临时文件
|
|
|
|
|
|
|
|
|
|
# 初始化输入处理器
|
|
|
|
|
self.input_processor = InputProcessor()
|
|
|
|
|
|
|
|
|
|
# 初始化网络服务和WeatherAPI
|
|
|
|
|
self.network_service = NetworkService()
|
|
|
|
|
self.weather_api = WeatherAPI()
|
|
|
|
|
@ -455,6 +459,13 @@ class WordStyleMainWindow(QMainWindow):
|
|
|
|
|
# 设置默认文档内容
|
|
|
|
|
self.text_edit.setPlainText("在此输入您的内容...")
|
|
|
|
|
|
|
|
|
|
# 连接输入处理器到文本编辑器
|
|
|
|
|
self.text_edit.set_input_processor(self.input_processor)
|
|
|
|
|
|
|
|
|
|
# 连接输入处理器的信号
|
|
|
|
|
self.input_processor.text_changed.connect(self.on_input_text_changed)
|
|
|
|
|
self.input_processor.key_pressed.connect(self.on_key_pressed)
|
|
|
|
|
|
|
|
|
|
document_layout.addWidget(self.text_edit)
|
|
|
|
|
|
|
|
|
|
# 创建图片显示区域
|
|
|
|
|
@ -563,6 +574,29 @@ class WordStyleMainWindow(QMainWindow):
|
|
|
|
|
self.is_modified = True
|
|
|
|
|
self.update_window_title()
|
|
|
|
|
|
|
|
|
|
def on_input_text_changed(self, text):
|
|
|
|
|
"""输入处理器文本变化处理"""
|
|
|
|
|
if self.view_mode == "learning" and self.imported_content:
|
|
|
|
|
# 在学习模式下,根据输入处理器的状态更新显示
|
|
|
|
|
current_text = self.text_edit.toPlainText()
|
|
|
|
|
expected_text = self.imported_content[:len(text)]
|
|
|
|
|
|
|
|
|
|
# 如果文本不匹配,更新显示
|
|
|
|
|
if current_text != expected_text:
|
|
|
|
|
cursor = self.text_edit.textCursor()
|
|
|
|
|
self.text_edit.setPlainText(expected_text)
|
|
|
|
|
# 保持光标在末尾
|
|
|
|
|
cursor.movePosition(QTextCursor.End)
|
|
|
|
|
self.text_edit.setTextCursor(cursor)
|
|
|
|
|
|
|
|
|
|
def on_key_pressed(self, key):
|
|
|
|
|
"""按键按下处理"""
|
|
|
|
|
# 更新状态栏显示当前按键
|
|
|
|
|
if key in ['\b', '\x7f']:
|
|
|
|
|
self.status_bar.showMessage("退格键已处理", 1000)
|
|
|
|
|
else:
|
|
|
|
|
self.status_bar.showMessage(f"按键: {key}", 1000)
|
|
|
|
|
|
|
|
|
|
def handle_learning_mode_typing(self):
|
|
|
|
|
"""学习模式下的打字处理 - 从上次中断处继续显示学习文档C内容到文档A"""
|
|
|
|
|
if self.imported_content and self.typing_logic:
|
|
|
|
|
@ -574,8 +608,9 @@ class WordStyleMainWindow(QMainWindow):
|
|
|
|
|
|
|
|
|
|
# 只有在光标位于文本末尾时才显示新内容
|
|
|
|
|
if cursor_position == len(current_text):
|
|
|
|
|
# 计算应该显示的字符数(基于当前已显示的字符数)
|
|
|
|
|
chars_to_show = min(self.displayed_chars + 1, len(self.imported_content))
|
|
|
|
|
# 使用输入处理器的状态来显示文本
|
|
|
|
|
input_text = self.input_processor.input_buffer
|
|
|
|
|
chars_to_show = len(input_text)
|
|
|
|
|
|
|
|
|
|
# 更新已显示字符数
|
|
|
|
|
self.displayed_chars = chars_to_show
|
|
|
|
|
@ -588,7 +623,7 @@ class WordStyleMainWindow(QMainWindow):
|
|
|
|
|
self.typing_logic.typed_chars = self.displayed_chars
|
|
|
|
|
self.typing_logic.current_index = self.displayed_chars
|
|
|
|
|
|
|
|
|
|
# 获取应该显示的文本部分(从上次中断处继续)
|
|
|
|
|
# 获取应该显示的文本部分(基于输入处理器的状态)
|
|
|
|
|
display_text = self.imported_content[:self.displayed_chars]
|
|
|
|
|
|
|
|
|
|
# 临时禁用文本变化信号,避免递归
|
|
|
|
|
|