修复:第一次运行时,无法找到 questions.csv
This commit is contained in:
3
main.py
3
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)
|
||||
|
||||
10
ui/main.py
10
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):
|
||||
|
||||
10
utils/function.py
Normal file
10
utils/function.py
Normal file
@@ -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)
|
||||
Reference in New Issue
Block a user