-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
86 lines (60 loc) · 2.53 KB
/
Copy pathmain.py
File metadata and controls
86 lines (60 loc) · 2.53 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
#!/usr/bin/env python3
import sys
from pathlib import Path
from multiprocessing import freeze_support
from PySide6.QtCore import QLockFile, QTimer
from PySide6.QtWidgets import QApplication, QMessageBox
from strikechess import __version__
from strikechess.services import SettingsService
from strikechess.ui import MainWindow, SplashScreen
from strikechess.utils import create_svg_icon, install_translators, root_path
SplashScreenDurationMilliseconds: Final[int] = 3000
def _create_app() -> QApplication:
"""Create QApplication object initialized with basic settings."""
app: QApplication = QApplication()
app.setStyle("fusion")
app.setApplicationName("StrikeChess")
app.setDesktopFileName("StrikeChess")
app.setApplicationVersion(__version__)
app.setWindowIcon(create_svg_icon("logo"))
app.setApplicationDisplayName("StrikeChess")
return app
def _show_duplicate_launch_warning() -> None:
"""Show warning that StrikeChess has already been launched."""
settings: SettingsService = SettingsService()
install_translators(settings.value("ui", "language"))
theme_name: str = settings.value("ui", "theme")
file_path: Path = root_path() / "assets" / "themes" / f"{theme_name}.qss"
message_box: QMessageBox = QMessageBox(
QMessageBox.Icon.Warning,
QApplication.translate("StrikeChess", "App Error"),
QApplication.translate("StrikeChess", "StrikeChess has already been launched!"),
)
with open(file_path, encoding="utf-8") as qss_file:
message_box.setStyleSheet(qss_file.read())
message_box.exec()
def _switch(splash_screen: SplashScreen, main_window: MainWindow) -> None:
"""Switch from splash screen to main window."""
splash_screen.finish(main_window)
main_window.showMaximized()
main_window.update_clock_timers()
main_window.request_engine_move()
def main() -> None:
"""Launch app with splash screen, abort duplicate launch attempt."""
app: QApplication = _create_app()
lock_directory: Path = Path.home() / ".StrikeChess"
lock_directory.mkdir(exist_ok=True)
lock_file: QLockFile = QLockFile(str(lock_directory / "StrikeChess.lock"))
if not lock_file.tryLock(1):
_show_duplicate_launch_warning()
sys.exit()
splash_screen: SplashScreen = SplashScreen().show_raised()
main_window: MainWindow = MainWindow()
QTimer.singleShot(
SplashScreenDurationMilliseconds,
lambda: _switch(splash_screen, main_window),
)
app.exec()
if __name__ == "__main__":
freeze_support()
main()