mirror of
https://github.com/YaoFANGUK/video-subtitle-remover.git
synced 2026-05-03 23:37:32 +08:00
添加PyInstaller macOS打包支持:资源路径处理、multiprocessing兼容、配置文件外置
Some checks failed
Docker Build and Push / check-secrets (push) Successful in 2s
Docker Build and Push / build-and-push (cpu, latest) (push) Has been skipped
Docker Build and Push / build-and-push (cuda, 11.8) (push) Has been skipped
Docker Build and Push / build-and-push (cuda, 12.6) (push) Has been skipped
Docker Build and Push / build-and-push (cuda, 12.8) (push) Has been skipped
Docker Build and Push / build-and-push (directml, latest) (push) Has been skipped
Build Windows CPU / build (push) Has been cancelled
Build Windows CUDA 11.8 / build (push) Has been cancelled
Build Windows CUDA 12.6 / build (push) Has been cancelled
Build Windows CUDA 12.8 / build (push) Has been cancelled
Build Windows DirectML / build (push) Has been cancelled
Some checks failed
Docker Build and Push / check-secrets (push) Successful in 2s
Docker Build and Push / build-and-push (cpu, latest) (push) Has been skipped
Docker Build and Push / build-and-push (cuda, 11.8) (push) Has been skipped
Docker Build and Push / build-and-push (cuda, 12.6) (push) Has been skipped
Docker Build and Push / build-and-push (cuda, 12.8) (push) Has been skipped
Docker Build and Push / build-and-push (directml, latest) (push) Has been skipped
Build Windows CPU / build (push) Has been cancelled
Build Windows CUDA 11.8 / build (push) Has been cancelled
Build Windows CUDA 12.6 / build (push) Has been cancelled
Build Windows CUDA 12.8 / build (push) Has been cancelled
Build Windows DirectML / build (push) Has been cancelled
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
|
||||
import os
|
||||
import sys
|
||||
from pathlib import Path
|
||||
from qfluentwidgets import (qconfig, ConfigItem, QConfig, OptionsValidator, BoolValidator, OptionsConfigItem,
|
||||
EnumSerializer, RangeValidator, RangeConfigItem, ConfigValidator)
|
||||
@@ -101,7 +102,13 @@ class Config(QConfig):
|
||||
# 视频保存目录
|
||||
saveDirectory = ConfigItem("Main", "SaveDirectory", "", ConfigValidator())
|
||||
|
||||
CONFIG_FILE = 'config/config.json'
|
||||
# PyInstaller 打包后配置文件写入 .app bundle 同级目录(避免修改签名)
|
||||
if getattr(sys, 'frozen', False):
|
||||
# sys.executable -> Contents/MacOS/VideoSubtitleRemover, 向上3级到 .app 所在目录
|
||||
_app_dir = os.path.dirname(os.path.dirname(os.path.dirname(sys.executable)))
|
||||
CONFIG_FILE = os.path.join(_app_dir, 'config', 'config.json')
|
||||
else:
|
||||
CONFIG_FILE = 'config/config.json'
|
||||
config = Config()
|
||||
qconfig.load(CONFIG_FILE, config)
|
||||
|
||||
|
||||
@@ -379,6 +379,7 @@ class SubtitleRemover:
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
multiprocessing.freeze_support()
|
||||
multiprocessing.set_start_method("spawn")
|
||||
from backend.tools.args_handler import parse_args
|
||||
args = parse_args()
|
||||
|
||||
11
gui.py
11
gui.py
@@ -8,6 +8,14 @@
|
||||
|
||||
import sys
|
||||
import os
|
||||
|
||||
# PyInstaller 打包后资源路径处理
|
||||
def resource_path(relative_path):
|
||||
"""获取资源文件的绝对路径(兼容 PyInstaller 打包)"""
|
||||
if getattr(sys, 'frozen', False):
|
||||
return os.path.join(sys._MEIPASS, relative_path)
|
||||
return os.path.join(os.path.abspath(os.path.dirname(__file__)), relative_path)
|
||||
|
||||
import configparser
|
||||
import cv2
|
||||
import multiprocessing
|
||||
@@ -42,7 +50,7 @@ class SubtitleExtractorGUI(FluentWindow):
|
||||
# self.themeListener.start()
|
||||
|
||||
# 设置窗口图标
|
||||
self.setWindowIcon(QtGui.QIcon("design/vsr.ico"))
|
||||
self.setWindowIcon(QtGui.QIcon(resource_path("design/vsr.ico")))
|
||||
self.setWindowTitle(tr['SubtitleExtractorGUI']['Title'] + " v" + VERSION)
|
||||
# 创建界面布局
|
||||
self._create_layout()
|
||||
@@ -162,6 +170,7 @@ class SubtitleExtractorGUI(FluentWindow):
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
multiprocessing.freeze_support()
|
||||
multiprocessing.set_start_method("spawn")
|
||||
QApplication.setHighDpiScaleFactorRoundingPolicy(
|
||||
Qt.HighDpiScaleFactorRoundingPolicy.PassThrough)
|
||||
|
||||
Reference in New Issue
Block a user