添加下载模板功能
This commit is contained in:
@@ -1,10 +1,16 @@
|
||||
import io
|
||||
import os
|
||||
import re
|
||||
import shutil
|
||||
import sys
|
||||
import tempfile
|
||||
from typing import Optional
|
||||
|
||||
import matplotlib
|
||||
from PySide6.QtCore import Qt
|
||||
from PySide6.QtWidgets import QWidget
|
||||
from matplotlib import pyplot as plt
|
||||
from qfluentwidgets import InfoBar, InfoBarPosition
|
||||
|
||||
|
||||
def format_ranges(nums):
|
||||
@@ -185,4 +191,35 @@ def resource_path(relative_path: str) -> str:
|
||||
return os.path.join(base_path, relative_path)
|
||||
|
||||
|
||||
def open_template(file_name: str, widget: QWidget) -> None:
|
||||
"""将模板文件复制到临时目录并打开"""
|
||||
file_path = resource_path("template/" + file_name)
|
||||
|
||||
if not os.path.exists(file_path):
|
||||
raise FileNotFoundError(f"Template file '{file_name}' not found.")
|
||||
|
||||
# 复制到临时目录
|
||||
tmp_dir = tempfile.gettempdir()
|
||||
tmp_file_path = os.path.join(tmp_dir, file_name)
|
||||
shutil.copy(file_path, tmp_file_path)
|
||||
|
||||
# 打开文件
|
||||
if sys.platform.startswith('win'):
|
||||
os.startfile(tmp_file_path)
|
||||
elif sys.platform.startswith('darwin'):
|
||||
os.system(f'open "{tmp_file_path}"')
|
||||
else:
|
||||
os.system(f'xdg-open "{tmp_file_path}"')
|
||||
|
||||
InfoBar.info(
|
||||
title='已打开文件',
|
||||
content="编辑后请将文件另存为,保存至其他目录",
|
||||
orient=Qt.Horizontal,
|
||||
isClosable=True,
|
||||
position=InfoBarPosition.TOP_RIGHT,
|
||||
duration=2000,
|
||||
parent=widget
|
||||
)
|
||||
|
||||
|
||||
DEVELOPMENT_ENV = getattr(sys, 'frozen', False)
|
||||
|
||||
Reference in New Issue
Block a user