From fd24f17e05832d4154531b0d83befee5dcaa13c0 Mon Sep 17 00:00:00 2001 From: mamingyi <80972090@qq.com> Date: Sat, 11 Oct 2025 18:46:59 +0800 Subject: [PATCH 1/2] 321 --- src/file_parser.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/file_parser.py b/src/file_parser.py index fc44729..4e74c8c 100644 --- a/src/file_parser.py +++ b/src/file_parser.py @@ -5,7 +5,7 @@ class FileParser: @staticmethod def parse_file(file_path: str) -> str: - # 验证文件路径 + # 验证文件路径123 if not FileParser.validate_file_path(file_path): raise ValueError(f"Invalid file path: {file_path}") -- 2.34.1 From 24b9c07e29cbcb5ce8456d46b1e2ac270d74d21b Mon Sep 17 00:00:00 2001 From: mamingyi <80972090@qq.com> Date: Sun, 19 Oct 2025 16:54:19 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BF=9D=E5=AD=98=E8=BE=93=E5=87=BA?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E5=9B=BE=E6=A0=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- USAGE.md | 35 ------------------------------ src/word_main_window.py | 48 +++++++++++++++++++++++++++++++---------- 2 files changed, 37 insertions(+), 46 deletions(-) delete mode 100644 USAGE.md diff --git a/USAGE.md b/USAGE.md deleted file mode 100644 index 7047814..0000000 --- a/USAGE.md +++ /dev/null @@ -1,35 +0,0 @@ -# 使用说明 - -## 启动应用程序 - -### 方法一:使用启动脚本(推荐) -```bash -./run_app.sh -``` - -### 方法二:直接运行Python代码 -```bash -/usr/bin/python3 src/main.py -``` - -## 使用步骤 - -1. 启动应用程序后,点击顶部菜单栏的"文件"选项 -2. 选择"打开"或使用快捷键 Ctrl+O -3. 在弹出的文件选择对话框中,选择您要练习的文本文件(支持 .txt 和 .docx 格式) -4. 选择文件后,文件内容将加载到应用程序中,但不会立即显示 -5. 在底部的输入区域开始打字练习 -6. 随着您的输入,文本内容会逐步显示在主显示区域 -7. 应用程序会实时显示打字进度和准确率统计 - -## 功能说明 - -- **文本显示**:随着您的输入逐步显示文件内容 -- **进度统计**:显示WPM(每分钟单词数)和准确率 -- **状态栏**:显示当前操作状态和文件信息 - -## 注意事项 - -- 请确保使用系统Python运行应用程序以避免Qt平台插件问题 -- 应用程序设计为只有在用户输入时才显示文本内容,这是正常行为 -- 支持的文件格式:.txt 和 .docx \ No newline at end of file diff --git a/src/word_main_window.py b/src/word_main_window.py index 60074b9..d89f661 100644 --- a/src/word_main_window.py +++ b/src/word_main_window.py @@ -74,12 +74,18 @@ class WordStyleMainWindow(QMainWindow): def set_window_icon(self): """设置窗口图标""" - # 创建简单的Word风格图标 - icon = QIcon() - pixmap = QPixmap(32, 32) - pixmap.fill(QColor("#2B579A")) - icon.addPixmap(pixmap) - self.setWindowIcon(icon) + # 使用我们创建的Word风格图标 + project_root = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + icon_path = os.path.join(project_root, 'resources', 'icons', 'app_icon.png') + if os.path.exists(icon_path): + self.setWindowIcon(QIcon(icon_path)) + else: + # 如果图标文件不存在,创建简单的Word风格图标 + icon = QIcon() + pixmap = QPixmap(32, 32) + pixmap.fill(QColor("#2B579A")) + icon.addPixmap(pixmap) + self.setWindowIcon(icon) def setup_ui(self): """设置Word风格的UI界面""" @@ -513,8 +519,16 @@ class WordStyleMainWindow(QMainWindow): """保存文件""" if self.current_file_path: try: - with open(self.current_file_path, 'w', encoding='utf-8') as f: - f.write(self.text_edit.toPlainText()) + # 如果是.docx文件,创建一个基本的Word文档 + if self.current_file_path.endswith('.docx'): + from docx import Document + doc = Document() + doc.add_paragraph(self.text_edit.toPlainText()) + doc.save(self.current_file_path) + else: + # 对于其他格式,保持原有逻辑 + with open(self.current_file_path, 'w', encoding='utf-8') as f: + f.write(self.text_edit.toPlainText()) self.is_modified = False self.update_window_title() @@ -528,13 +542,25 @@ class WordStyleMainWindow(QMainWindow): def save_as_file(self): """另存为""" file_path, _ = QFileDialog.getSaveFileName( - self, "另存为", "", "文本文档 (*.txt);;所有文件 (*.*)" + self, "另存为", "", "Word文档 (*.docx);;文本文档 (*.txt);;所有文件 (*.*)" ) if file_path: + # 如果用户没有指定扩展名,自动添加.docx扩展名 + if not os.path.splitext(file_path)[1]: + file_path += ".docx" + try: - with open(file_path, 'w', encoding='utf-8') as f: - f.write(self.text_edit.toPlainText()) + # 如果是.docx文件,创建一个基本的Word文档 + if file_path.endswith('.docx'): + from docx import Document + doc = Document() + doc.add_paragraph(self.text_edit.toPlainText()) + doc.save(file_path) + else: + # 对于其他格式,保持原有逻辑 + with open(file_path, 'w', encoding='utf-8') as f: + f.write(self.text_edit.toPlainText()) self.current_file_path = file_path self.is_modified = False -- 2.34.1