"""애플리케이션 진입점.""" from __future__ import annotations import contextlib import logging import sys from pathlib import Path from .config import AppConfig from .constants import APP_NAME, ORG_NAME, user_data_dir def setup_logging(verbose: bool = False, to_file: bool = True) -> None: """로그 설정. `to_file=False` 는 저장 위치를 아직 고르기 전에 쓴다. 그 시점에 파일 핸들러를 열면 사용자가 고르지도 않은 기본 폴더가 만들어지고 로그가 거기에 남는다. """ handlers: list[logging.Handler] = [logging.StreamHandler(sys.stderr)] if to_file: with contextlib.suppress(OSError): handlers.append( logging.FileHandler(user_data_dir() / "livesub.log", encoding="utf-8") ) logging.basicConfig( level=logging.DEBUG if verbose else logging.INFO, format="%(asctime)s %(levelname)-7s %(name)s: %(message)s", handlers=handlers, force=True, ) # 모델 라이브러리들이 INFO로 너무 시끄럽다. for noisy in ("urllib3", "filelock", "huggingface_hub", "transformers"): logging.getLogger(noisy).setLevel(logging.WARNING) def main(argv: list[str] | None = None) -> int: argv = list(sys.argv if argv is None else argv) verbose = "--verbose" in argv or "-v" in argv setup_logging(verbose, to_file=False) from PySide6.QtCore import Qt from PySide6.QtGui import QIcon from PySide6.QtWidgets import QApplication from .ui import MainWindow QApplication.setAttribute(Qt.ApplicationAttribute.AA_UseHighDpiPixmaps, True) app = QApplication(argv) app.setApplicationName(APP_NAME) app.setOrganizationName(ORG_NAME) app.setQuitOnLastWindowClosed(True) icon_path = Path(__file__).resolve().parent / "resources" / "icon.png" if icon_path.is_file(): app.setWindowIcon(QIcon(str(icon_path))) # 설정을 읽기 전에 어디서 읽을지부터 정해야 한다. 한 번 고르면 다음 실행부터 # 이 화면은 건너뛴다. from .storage import is_configured from .ui.data_location import ask_initial_location if not is_configured() and not ask_initial_location(): return 0 setup_logging(verbose) config = AppConfig.load() window = MainWindow(config) if not config.start_minimized: window.show() return app.exec() if __name__ == "__main__": raise SystemExit(main())