| 6 | |
| 7 | |
| 8 | def main(): |
| 9 | import traceback |
| 10 | |
| 11 | from PyQt5.QtCore import Qt, QTranslator |
| 12 | from PyQt5.QtWidgets import QApplication |
| 13 | |
| 14 | from videocaptioner.config import TRANSLATIONS_PATH |
| 15 | from videocaptioner.core.utils.cache import disable_cache, enable_cache |
| 16 | from videocaptioner.core.utils.logger import setup_logger |
| 17 | |
| 18 | # Suppress qfluentwidgets ad |
| 19 | with open(os.devnull, "w") as _devnull: |
| 20 | sys.stdout, _stdout = _devnull, sys.stdout |
| 21 | from qfluentwidgets import FluentTranslator |
| 22 | sys.stdout = _stdout |
| 23 | |
| 24 | from videocaptioner.ui.common.config import cfg |
| 25 | from videocaptioner.ui.view.main_window import MainWindow |
| 26 | |
| 27 | # Qt platform plugin path |
| 28 | lib_folder = "Lib" if platform.system() == "Windows" else "lib" |
| 29 | plugin_path = os.path.join( |
| 30 | sys.prefix, lib_folder, "site-packages", "PyQt5", "Qt5", "plugins" |
| 31 | ) |
| 32 | os.environ["QT_QPA_PLATFORM_PLUGIN_PATH"] = plugin_path |
| 33 | |
| 34 | # Logger + global exception hook |
| 35 | logger = setup_logger("VideoCaptioner") |
| 36 | |
| 37 | def exception_hook(exctype, value, tb): |
| 38 | logger.error("".join(traceback.format_exception(exctype, value, tb))) |
| 39 | sys.__excepthook__(exctype, value, tb) |
| 40 | |
| 41 | sys.excepthook = exception_hook |
| 42 | |
| 43 | # Cache |
| 44 | if cfg.get(cfg.cache_enabled): |
| 45 | enable_cache() |
| 46 | else: |
| 47 | disable_cache() |
| 48 | |
| 49 | # DPI scaling |
| 50 | if cfg.get(cfg.dpiScale) == "Auto": |
| 51 | QApplication.setHighDpiScaleFactorRoundingPolicy( |
| 52 | Qt.HighDpiScaleFactorRoundingPolicy.PassThrough # type: ignore |
| 53 | ) |
| 54 | QApplication.setAttribute(Qt.AA_EnableHighDpiScaling, True) # type: ignore |
| 55 | else: |
| 56 | os.environ["QT_ENABLE_HIGHDPI_SCALING"] = "0" |
| 57 | os.environ["QT_SCALE_FACTOR"] = str(cfg.get(cfg.dpiScale)) |
| 58 | QApplication.setAttribute(Qt.AA_UseHighDpiPixmaps, True) # type: ignore |
| 59 | |
| 60 | app = QApplication(sys.argv) |
| 61 | app.setAttribute(Qt.AA_DontCreateNativeWidgetSiblings, True) # type: ignore |
| 62 | |
| 63 | # i18n |
| 64 | locale = cfg.get(cfg.language).value |
| 65 | app.installTranslator(FluentTranslator(locale)) |