From 83b3790e8b688e61b5ecc2668385fc0a8792b3d4 Mon Sep 17 00:00:00 2001 From: Jeffrey Hsu Date: Sun, 18 May 2025 12:02:35 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9A=E7=AC=AC=E4=B8=80?= =?UTF-8?q?=E6=AC=A1=E8=BF=90=E8=A1=8C=E6=97=B6=EF=BC=8C=E6=97=A0=E6=B3=95?= =?UTF-8?q?=E6=89=BE=E5=88=B0=20questions.csv?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 3 ++- ui/main.py | 10 +--------- utils/function.py | 10 ++++++++++ 3 files changed, 13 insertions(+), 10 deletions(-) create mode 100644 utils/function.py diff --git a/main.py b/main.py index 00be303..8fbabdb 100644 --- a/main.py +++ b/main.py @@ -6,6 +6,7 @@ from pathlib import Path from PySide6.QtWidgets import QApplication from ui.main import MainWindow +from utils.function import resource_path appdata_dir = Path(os.environ["APPDATA"]) dtg_dir = appdata_dir / "dtg" @@ -13,7 +14,7 @@ target_csv = dtg_dir / "questions.csv" if not target_csv.exists(): dtg_dir.mkdir(parents=True, exist_ok=True) - source_csv = Path("template/questions.csv") + source_csv = Path(resource_path("template/questions.csv")) if not source_csv.exists(): raise FileNotFoundError(f"源文件不存在:{source_csv.resolve()}") shutil.copy(source_csv, target_csv) diff --git a/ui/main.py b/ui/main.py index 54dba71..af260ba 100644 --- a/ui/main.py +++ b/ui/main.py @@ -1,7 +1,6 @@ import os import platform import subprocess -import sys from pathlib import Path from PySide6.QtCore import QObject, QThread, Signal @@ -10,14 +9,7 @@ from PySide6.QtWidgets import QMainWindow, QFileDialog from module.doc import DocPaper from module.schema import Course, Student, Question from ui.pyui.main import Ui_MainWindow - - -def resource_path(relative_path: str) -> str: - if hasattr(sys, '_MEIPASS'): - base_path = sys._MEIPASS - else: - base_path = os.path.abspath(".") - return os.path.join(base_path, relative_path) +from utils.function import resource_path class Worker(QObject): diff --git a/utils/function.py b/utils/function.py new file mode 100644 index 0000000..e151f4c --- /dev/null +++ b/utils/function.py @@ -0,0 +1,10 @@ +import os +import sys + + +def resource_path(relative_path: str) -> str: + if hasattr(sys, '_MEIPASS'): + base_path = sys._MEIPASS + else: + base_path = os.path.abspath(".") + return os.path.join(base_path, relative_path)