forked from WEIFENG2333/VideoCaptioner
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
90 lines (68 loc) · 2.56 KB
/
main.py
File metadata and controls
90 lines (68 loc) · 2.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
"""
Copyright (c) 2024 [VideoCaptioner]
All rights reserved.
Author: Weifeng
"""
import os
import platform
import sys
import traceback
from app.config import TRANSLATIONS_PATH
# Add project root directory to Python path
project_root = os.path.dirname(os.path.abspath(__file__))
sys.path.append(project_root)
# Use appropriate library folder name based on OS
lib_folder = "Lib" if platform.system() == "Windows" else "lib"
plugin_path = os.path.join(
sys.prefix, lib_folder, "site-packages", "PyQt5", "Qt5", "plugins"
)
os.environ["QT_QPA_PLATFORM_PLUGIN_PATH"] = plugin_path
# Delete pyd files app*.pyd
for file in os.listdir():
if file.startswith("app") and file.endswith(".pyd"):
os.remove(file)
# Now import the modules that depend on the setup above
from PyQt5.QtCore import Qt, QTranslator # noqa: E402
from PyQt5.QtWidgets import QApplication # noqa: E402
from qfluentwidgets import FluentTranslator # noqa: E402
from app.common.config import cfg # noqa: E402
from app.config import RESOURCE_PATH # noqa: E402
from app.core.utils.cache import disable_cache, enable_cache # noqa: E402
from app.core.utils.logger import setup_logger # noqa: E402
from app.view.main_window import MainWindow # noqa: E402
logger_instance = setup_logger("VideoCaptioner")
def exception_hook(exctype, value, tb):
logger_instance.error("".join(traceback.format_exception(exctype, value, tb)))
sys.__excepthook__(exctype, value, tb) # 调用默认的异常处理
sys.excepthook = exception_hook
# 应用缓存配置
if cfg.get(cfg.cache_enabled):
enable_cache()
else:
disable_cache()
# Enable DPI Scale
if cfg.get(cfg.dpiScale) == "Auto":
QApplication.setHighDpiScaleFactorRoundingPolicy(
Qt.HighDpiScaleFactorRoundingPolicy.PassThrough # type: ignore
)
QApplication.setAttribute(Qt.AA_EnableHighDpiScaling, True) # type: ignore
else:
os.environ["QT_ENABLE_HIGHDPI_SCALING"] = "0"
os.environ["QT_SCALE_FACTOR"] = str(cfg.get(cfg.dpiScale))
QApplication.setAttribute(Qt.AA_UseHighDpiPixmaps, True) # type: ignore
app = QApplication(sys.argv)
app.setAttribute(Qt.AA_DontCreateNativeWidgetSiblings, True) # type: ignore
# Internationalization
locale = cfg.get(cfg.language).value
translator = FluentTranslator(locale)
myTranslator = QTranslator()
translations_path = TRANSLATIONS_PATH / f"VideoCaptioner_{locale.name()}.qm"
myTranslator.load(str(translations_path))
app.installTranslator(translator)
app.installTranslator(myTranslator)
def main():
w = MainWindow()
w.show()
sys.exit(app.exec_())
if __name__ == "__main__":
main()