#!/usr/bin/env python3 """ 简化测试脚本 - 验证学习模式内容同步功能 """ import sys import os sys.path.append(os.path.join(os.path.dirname(__file__), 'src')) from PyQt5.QtWidgets import QApplication, QTextEdit, QVBoxLayout, QWidget from learning_mode_window import LearningModeWindow class TestWindow(QWidget): def __init__(self): super().__init__() self.setWindowTitle("测试主窗口") self.setGeometry(100, 100, 600, 400) # 创建布局 layout = QVBoxLayout() # 创建文本编辑器 self.text_edit = QTextEdit() self.text_edit.setPlainText("初始内容\n") layout.addWidget(self.text_edit) self.setLayout(layout) # 创建学习模式窗口 self.learning_window = LearningModeWindow(parent=self) self.learning_window.imported_content = "这是一段测试内容。" self.learning_window.current_position = 0 self.learning_window.show() # 连接内容同步信号 self.learning_window.content_changed.connect(self.on_content_changed) print("测试开始...") print(f"主窗口内容: {repr(self.text_edit.toPlainText())}") print(f"学习窗口内容: {repr(self.learning_window.imported_content)}") print(f"学习窗口当前位置: {self.learning_window.current_position}") # 模拟用户输入正确内容 print("\n模拟用户输入正确内容...") self.learning_window.current_position = 3 # 用户输入了3个字符 self.learning_window.on_text_changed() # 调用文本变化处理 def on_content_changed(self, new_content, position): """内容同步回调""" print(f"收到内容同步信号: new_content={repr(new_content)}, position={position}") # 在文本编辑器末尾添加新内容 current_text = self.text_edit.toPlainText() self.text_edit.setPlainText(current_text + new_content) print(f"主窗口更新后内容: {repr(self.text_edit.toPlainText())}") def test_content_sync(): """测试内容同步功能""" app = QApplication(sys.argv) test_window = TestWindow() test_window.show() print("\n测试完成!") # 运行应用 sys.exit(app.exec_()) if __name__ == "__main__": test_content_sync()