forked from SawyerTheNerd/AniWatchDownloader
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.pyw
More file actions
73 lines (61 loc) · 2.9 KB
/
main.pyw
File metadata and controls
73 lines (61 loc) · 2.9 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
import os
os.environ['PYTHONIOENCODING'] = 'utf-8'
import sys
# Handle Unicode encoding for Windows console
if hasattr(sys.stdout, 'reconfigure'):
sys.stdout.reconfigure(encoding='utf-8', errors='replace')
if hasattr(sys.stderr, 'reconfigure'):
sys.stderr.reconfigure(encoding='utf-8', errors='replace')
PROJECT_ROOT = os.path.abspath(os.path.dirname(__file__))
if PROJECT_ROOT not in sys.path:
sys.path.insert(0, PROJECT_ROOT)
try:
from gui.main_window import AnimeDownloaderWindow
except ImportError as e:
print(f"Error importing AnimeDownloaderWindow: {e}")
sys.exit(1)
from PyQt6.QtWidgets import QApplication
from PyQt6.QtWidgets import QApplication, QStyleFactory
from PyQt6.QtCore import QSettings, QFile, QTextStream, QIODevice # For reading QSS
KEY_APP_STYLE = "interface/appStyle"
KEY_CUSTOM_QSS_THEME = "interface/customQssTheme"
def apply_app_appearance_settings(app: QApplication):
settings = QSettings()
app_style_name = settings.value(KEY_APP_STYLE, "Default (OS)", type=str)
if app_style_name != "Default (OS)" and app_style_name in QStyleFactory.keys():
try:
style = QStyleFactory.create(app_style_name)
if style:
app.setStyle(style)
print(f"[Appearance] Applied Qt Style: {app_style_name}")
except Exception as e:
print(f"[Appearance] Error applying Qt Style '{app_style_name}': {e}")
else:
print(f"[Appearance] Using default OS Qt Style (Requested: {app_style_name}).")
qss_file_path = settings.value(KEY_CUSTOM_QSS_THEME, "", type=str)
if qss_file_path and os.path.exists(qss_file_path):
try:
file = QFile(qss_file_path)
if file.open(QIODevice.OpenModeFlag.ReadOnly | QIODevice.OpenModeFlag.Text):
stream = QTextStream(file)
app.setStyleSheet(stream.readAll())
file.close()
print(f"[Appearance] Applied custom QSS theme: {qss_file_path}")
else:
print(f"[Appearance] Error: Could not open QSS file: {qss_file_path} - {file.errorString()}")
except Exception as e:
print(f"[Appearance] Error applying QSS theme from '{qss_file_path}': {e}")
elif qss_file_path: # Path saved but file not found
print(f"[Appearance] Warning: QSS theme file not found at '{qss_file_path}'.")
else: # No custom QSS theme selected
app.setStyleSheet("") # Clear any previous global stylesheet
print(f"[Appearance] No custom QSS theme selected. Using style's default appearance.")
if __name__ == "__main__":
app = QApplication(sys.argv)
app.setOrganizationName("AniWatch")
app.setApplicationName("AniWatch Downloader")
apply_app_appearance_settings(app) # Apply before creating main window
from gui.main_window import AnimeDownloaderWindow
main_window = AnimeDownloaderWindow()
main_window.show()
sys.exit(app.exec())