-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
76 lines (61 loc) · 2.12 KB
/
main.py
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
import os
import sys
import logging
from logging.handlers import RotatingFileHandler
from PySide6.QtWidgets import QApplication
from PySide6.QtCore import Qt
from PySide6.QtGui import QColor, QPalette
from core.main_window import MainWindow
name = "DEEF-Lite-Image-Viewer"
version = "v3.1.0"
author = "deeffest"
website = "deeffest.pythonanywhere.com"
def setup_logging():
log_dir = os.path.join(os.path.expanduser("~"), name, "logs")
if not os.path.exists(log_dir):
os.makedirs(log_dir)
log_file = os.path.join(log_dir, "app.log")
rotating_handler = RotatingFileHandler(
log_file, maxBytes=5 * 1024 * 1024, backupCount=5
)
rotating_handler.setLevel(logging.INFO)
rotating_handler.setFormatter(logging.Formatter(
'[%(asctime)s] %(message)s', datefmt='%Y.%m.%d %H:%M:%S'
))
logging.basicConfig(
level=logging.INFO,
handlers=[
rotating_handler,
logging.StreamHandler(sys.stdout)
]
)
def is_dark_theme(app):
color_scheme = app.styleHints().colorScheme()
return color_scheme == Qt.ColorScheme.Dark
def customize_palette(app, is_dark):
palette = app.palette()
if is_dark:
highlight_color = QColor(0, 128, 0)
highlighted_text_color = QColor(255, 255, 255)
else:
highlight_color = QColor(144, 238, 144)
highlighted_text_color = QColor(0, 0, 0)
palette.setColor(QPalette.Highlight, highlight_color)
palette.setColor(QPalette.HighlightedText, highlighted_text_color)
app.setPalette(palette)
if __name__ == "__main__":
setup_logging()
app = QApplication(sys.argv)
app.setApplicationName(name)
app.setApplicationVersion(version)
app.setOrganizationName(author)
app.setOrganizationDomain(website)
app.setStyle("Fusion")
is_dark = is_dark_theme(app)
customize_palette(app, is_dark)
image_path = None
if len(sys.argv) > 1:
image_path = sys.argv[1]
window = MainWindow(app, "dark" if is_dark else "light", image_path)
window.show()
sys.exit(app.exec())