-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.pyw
More file actions
267 lines (218 loc) · 9.03 KB
/
main.pyw
File metadata and controls
267 lines (218 loc) · 9.03 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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
"""
PyDSPMeters: Entry Point
Modular real-time audio visualization utility.
"""
from PySide6.QtWidgets import QApplication, QSplashScreen, QLabel
from PySide6.QtCore import Qt, QTimer, QRectF, QPoint
from PySide6.QtGui import QPainter, QColor, QLinearGradient, QFont, QPen, QIcon
import sys
import os
import ctypes
import glob
from app.theme import build_stylesheet, Colors, Fonts, apply_theme
from app.utils.logging_utils import setup_logging, setup_global_exception_handler
# --- Application Configuration ---
# Set this to the name of your icon file. It will survive Nuitka packaging.
# If left empty, the app will automatically try to find a .ico in its directory.
APP_ICON_NAME = "icon.ico"
# ---------------------------------
class CustomSplashScreen(QSplashScreen):
"""Splash screen with branding and progress."""
def __init__(self):
super().__init__()
self.setWindowFlags(Qt.WindowStaysOnTopHint | Qt.FramelessWindowHint)
self.setFixedSize(450, 280)
self._progress = 0
self._display_progress = 0.0
self._status = "Initializing core components..."
self._pulse = 0.0
self._pulse_dir = 1
# Smoothed colors for theme transitions
self._current_colors = {
"ACCENT": QColor(Colors.ACCENT),
"ACCENT_DIM": QColor(Colors.ACCENT_DIM),
"BG_DARKEST": QColor(Colors.BG_DARKEST),
"BORDER": QColor(Colors.BORDER)
}
# Center on screen
screen = QApplication.primaryScreen().geometry()
self.move(screen.center() - self.rect().center())
# Animation timer
self._timer = QTimer(self)
self._timer.setInterval(16) # ~60fps
self._timer.timeout.connect(self._animate)
self._timer.start()
def set_progress(self, val, status=None):
self._progress = val
if status:
self._status = status
self.update()
QApplication.processEvents()
def _animate(self):
# Lerp progress
diff = self._progress - self._display_progress
if abs(diff) > 0.1:
self._display_progress += diff * 0.1
else:
self._display_progress = float(self._progress)
# Idle pulse
self._pulse += 0.02 * self._pulse_dir
if self._pulse > 1.0 or self._pulse < 0.0:
self._pulse_dir *= -1
self._pulse = max(0.0, min(1.0, self._pulse))
# Lerp colors towards current global theme
changed = False
lerp_speed = 0.05
for key in self._current_colors:
target = QColor(getattr(Colors, key))
current = self._current_colors[key]
if current != target:
r = current.red() + (target.red() - current.red()) * lerp_speed
g = current.green() + (target.green() - current.green()) * lerp_speed
b = current.blue() + (target.blue() - current.blue()) * lerp_speed
a = current.alpha() + (target.alpha() - current.alpha()) * lerp_speed
self._current_colors[key] = QColor(int(r), int(g), int(b), int(a))
changed = True
if changed or abs(diff) > 0.01:
self.update()
def paintEvent(self, event):
with QPainter(self) as p:
p.setRenderHint(QPainter.Antialiasing)
c = self._current_colors
# Draw background gradient
rect = self.rect()
bg_grad = QLinearGradient(rect.topLeft(), rect.bottomRight())
bg_grad.setColorAt(0, c["BG_DARKEST"])
bg_grad.setColorAt(1, c["BG_DARKEST"].lighter(110))
p.fillRect(rect, bg_grad)
# Subtle accent glow / border
p.setPen(QPen(c["BORDER"], 1))
p.drawRect(rect.adjusted(0, 0, -1, -1))
# Glow behind logo
glow = QLinearGradient(rect.center() - QPoint(180, 0), rect.center() + QPoint(180, 0))
glow_col = QColor(c["ACCENT"])
glow_col.setAlpha(35)
glow.setColorAt(0, Qt.transparent)
glow.setColorAt(0.5, glow_col)
glow.setColorAt(1, Qt.transparent)
p.fillRect(rect.adjusted(0, 105, 0, -115), glow)
# Logo Text
p.setPen(c["ACCENT"])
f = Fonts.header()
f.setPointSize(32)
f.setLetterSpacing(QFont.AbsoluteSpacing, 4)
f.setWeight(QFont.Black)
p.setFont(f)
# Pulse the logo opacity
col = c["ACCENT"]
col.setAlpha(int(200 + 55 * self._pulse))
p.setPen(col)
p.drawText(rect.adjusted(0, -25, 0, 0), Qt.AlignCenter, "PYDSPMETERS")
# Subtitle
p.setPen(QColor(Colors.TEXT_DIM))
f.setPointSize(10)
f.setLetterSpacing(QFont.AbsoluteSpacing, 1)
f.setBold(False)
f.setWeight(QFont.Normal)
p.setFont(f)
p.drawText(rect.adjusted(0, 30, 0, 0), Qt.AlignCenter, "MODULAR AUDIO ANALYZER")
# Version
f.setPointSize(8)
p.setFont(f)
p.setPen(QColor(Colors.BORDER_ACCENT))
p.drawText(rect.adjusted(0, 0, -15, -15), Qt.AlignBottom | Qt.AlignRight, "v1.2.0")
# Status (placed ABOVE progress bar)
p.setPen(QColor(Colors.TEXT_DIM))
f.setPointSize(9)
p.setFont(f)
p.drawText(rect.adjusted(50, 0, -50, -65), Qt.AlignBottom | Qt.AlignLeft, self._status)
# Progress bar container
bar_rect = QRectF(50, 230, 350, 6)
p.setBrush(QColor(Colors.BG_DARK))
p.setPen(Qt.NoPen)
p.drawRoundedRect(bar_rect, 3, 3)
# Progress bar fill
if self._display_progress > 0:
progress_rect = QRectF(50, 230, 350 * (self._display_progress / 100), 6)
grad = QLinearGradient(progress_rect.topLeft(), progress_rect.topRight())
grad.setColorAt(0, c["ACCENT_DIM"])
grad.setColorAt(1, c["ACCENT"])
p.setBrush(grad)
p.drawRoundedRect(progress_rect, 3, 3)
def main():
# Initialize Logging and Global Exception Handling as early as possible
setup_logging()
setup_global_exception_handler()
# Handle Ctrl+C (SIGINT)
import signal, sys
signal.signal(signal.SIGINT, signal.SIG_DFL)
# High-DPI support
QApplication.setHighDpiScaleFactorRoundingPolicy(
Qt.HighDpiScaleFactorRoundingPolicy.PassThrough
)
app = QApplication(sys.argv)
app.setApplicationName("PyDSPMeters")
# Override default Python taskbar icon if a .ico is found or in settings
if sys.platform == "win32":
try:
myappid = 'pydspmeters.app.1.0'
ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID(myappid)
except Exception:
pass
# Try to load icon robustly (survives Nuitka packaging)
base_dir = os.path.dirname(os.path.abspath(__file__))
icon_path = ""
if APP_ICON_NAME:
target_path = os.path.join(base_dir, APP_ICON_NAME)
if os.path.exists(target_path):
icon_path = target_path
if not icon_path:
icos = glob.glob(os.path.join(base_dir, "*.ico"))
if icos:
icon_path = icos[0]
if icon_path and os.path.exists(icon_path):
app.setWindowIcon(QIcon(icon_path))
# Initialize theme
apply_theme("Midnight")
# Show Splash immediately
splash = CustomSplashScreen()
splash.show()
app.processEvents()
# Now do heavier imports
splash.set_progress(20, "Loading UI modules...")
app.processEvents()
from app.window_manager import MainWindow
splash.set_progress(40, "Initializing Audio Engine...")
app.processEvents()
from app.audio_engine import AudioEngine
engine = AudioEngine(sample_rate=44100, block_size=1024)
splash.set_progress(60, "Restoring workspace...")
app.processEvents()
app.processEvents()
app.setStyleSheet(build_stylesheet())
app.processEvents()
window = MainWindow(engine, splash=splash)
app.processEvents()
splash.set_progress(90, "Starting real-time streams...")
app.processEvents()
# Wait for window to be ready
def finalize():
# Prepare layout and dock if needed BEFORE showing
window.finish_loading()
app.processEvents()
# First ensure window is shown and rendered
window.show()
app.processEvents()
# Then fade out or finish splash
splash.set_progress(100, "Ready")
app.processEvents()
# Give it one more beat to ensure MainWindow is fully painted
QTimer.singleShot(200, lambda: splash.finish(window))
QTimer.singleShot(100, finalize)
sys.exit(app.exec())
if __name__ == "__main__":
try:
main()
except KeyboardInterrupt:
import os
os._exit(0)