-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.py
More file actions
119 lines (92 loc) · 4.24 KB
/
Copy pathmain.py
File metadata and controls
119 lines (92 loc) · 4.24 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
import sys
import os
import time
from PySide6.QtWidgets import QApplication, QWidget, QVBoxLayout, QLabel
from PySide6.QtCore import Qt, QTimer, QPropertyAnimation, QEasingCurve, Property
from PySide6.QtGui import QPixmap, QPainter
def get_resource_path(relative_path):
if hasattr(sys, '_MEIPASS'):
return os.path.join(sys._MEIPASS, relative_path)
return os.path.join(os.path.abspath("."), relative_path)
class RotatingLogo(QWidget):
def __init__(self, pix_path, parent=None):
super().__init__(parent)
self.setFixedHeight(80)
self.pixmap = QPixmap(pix_path).scaled(64, 64, Qt.KeepAspectRatio, Qt.SmoothTransformation)
self._rotation = 0
self.anim = QPropertyAnimation(self, b"rotation")
self.anim.setDuration(1500)
self.anim.setStartValue(0)
self.anim.setEndValue(360)
self.anim.setLoopCount(-1) # Continuous
self.anim.setEasingCurve(QEasingCurve.Linear)
self.anim.start()
@Property(float)
def rotation(self): return self._rotation
@rotation.setter
def rotation(self, val):
self._rotation = val
self.update()
def paintEvent(self, e):
painter = QPainter(self)
painter.setRenderHint(QPainter.Antialiasing)
painter.setRenderHint(QPainter.SmoothPixmapTransform)
center = self.rect().center()
painter.translate(center)
painter.rotate(self._rotation)
painter.translate(-center)
# Draw pixmap centered
x = (self.width() - self.pixmap.width()) // 2
y = (self.height() - self.pixmap.height()) // 2
painter.drawPixmap(x, y, self.pixmap)
painter.end()
class SplashScreen(QWidget):
def __init__(self):
super().__init__()
self.setWindowFlags(Qt.SplashScreen | Qt.FramelessWindowHint | Qt.WindowStaysOnTopHint)
self.setAttribute(Qt.WA_TranslucentBackground)
self.setFixedSize(460, 280)
from ui.theme import COLORS
from core.i18n import tr
container = QWidget(self)
container.setFixedSize(self.size())
container.setObjectName("SplashContainer")
container.setStyleSheet(f"#SplashContainer {{ background-color: {COLORS['surface']}; border-radius: 16px; border: 1px solid {COLORS['border']}; }}")
layout = QVBoxLayout(container)
layout.setContentsMargins(32, 32, 32, 32)
layout.setSpacing(12)
layout.setAlignment(Qt.AlignCenter)
self.logo = RotatingLogo(get_resource_path("logo.png"))
layout.addWidget(self.logo)
title = QLabel("SyncTree")
title.setStyleSheet(f"font-size: 26px; font-weight: bold; color: {COLORS['text']};")
title.setAlignment(Qt.AlignCenter)
layout.addWidget(title)
subtitle = QLabel(tr("app_subtitle"))
subtitle.setStyleSheet(f"font-size: 15px; color: {COLORS['text_disabled']};")
subtitle.setAlignment(Qt.AlignCenter)
layout.addWidget(subtitle)
layout.addSpacing(16)
author_lbl = QLabel(f'<span style="color: {COLORS["text"]}; font-size: 15px; font-weight: bold;">{tr("author")} </span><span style="color: {COLORS["primary"]}; font-size: 15px; font-weight: bold;">Andrew Wang Dev</span>')
author_lbl.setAlignment(Qt.AlignCenter)
layout.addWidget(author_lbl)
def main():
# Make sure we run from the script directory for config.json to behave well
os.chdir(os.path.dirname(os.path.abspath(__file__)))
# Optional styling or High DPI scaling - MUST be before QApplication
if hasattr(Qt, 'HighDpiScaleFactorRoundingPolicy'):
QApplication.setHighDpiScaleFactorRoundingPolicy(Qt.HighDpiScaleFactorRoundingPolicy.PassThrough)
app = QApplication(sys.argv)
splash = SplashScreen()
splash.show()
app.processEvents()
start_time = time.time()
from ui.window import MainWindow
window = MainWindow()
elapsed = time.time() - start_time
delay = max(0, 1200 - int(elapsed * 1000))
QTimer.singleShot(delay, lambda: [splash.close(), window.show()])
sys.exit(app.exec())
if __name__ == "__main__":
# Qt is needed for the high-dpi check, but we import it lazily or globally
main()