-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathLEDpanel.py
More file actions
509 lines (477 loc) · 15.2 KB
/
Copy pathLEDpanel.py
File metadata and controls
509 lines (477 loc) · 15.2 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
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
# LEDpanel.py - Shared CRT-styled control panel for LED Commander
import LEDupdate
from WeatherClock import DEFAULT_LOCATION
from StockReport import LoadStockSymbols
PANEL_VERSION = "1.6"
PANEL_TITLE = f"LED Commander Control Panel {PANEL_VERSION}"
DEFAULT_GAME_DURATION = 10
DEFAULT_CLOCK_DURATION = 10
# Clock modes shown in a dedicated top-of-page section (easy to find)
CLOCK_LAUNCHERS = [
("showclock", "Digital Clock", []),
("retrodigital", "Retro Digital", []),
("analogclock", "Analog Clock", ["duration"]),
("flipclock", "Flip Clock (70s)", ["duration"]),
("sevensegclock", "7-Seg LED Clock", ["duration"]),
("waterclock", "Water Clock", ["duration"]),
("stopclock", "Stop Clock", []),
]
# Games that default to play-until-game-over (duration 0)
UNTIL_GAME_OVER_LAUNCHERS = {
"launch_rallydot",
}
GAME_LAUNCHERS = [
("launch_dotinvaders", "Dot Invaders"),
("launch_defender2", "Defender"),
("launch_tron", "Tron"),
("launch_outbreak", "Outbreak"),
("launch_ledtv", "LED TV"),
("launch_spacedot", "Space Dot"),
("launch_pacdot", "PacDot"),
("launch_dotzerk", "DotZerk"),
("launch_blasteroids", "Blasteroids"),
("launch_fallingsand", "Falling Sand"),
("launch_particles", "Particles"),
("launch_fractal", "Fractal Blaster"),
("launch_pinball_random", "Pinball (random table)"),
("launch_pinball", "Pinball"),
("launch_pinball2", "Central Park (1966)"),
("launch_gravitysim", "Gravity Sim"),
("launch_mazecar", "Maze Car"),
("launch_spaceexplorer", "Space Explorer"),
("launch_skyfall", "Skyfall"),
("launch_rallydot", "Rally Dot"), # last — also last in idle rotation
]
ACTION_LABELS = {
"showclock": "Digital Clock",
"stopclock": "Stop Clock",
"stop": "Stop Display",
"next": "Next Program",
"showtitlescreen": "Title Screen",
"analogclock": "Analog Clock",
"retrodigital": "Retro Digital",
"flipclock": "Flip Clock (70s)",
"sevensegclock": "7-Seg LED Clock",
"waterclock": "Water Clock",
"ledarcade_intro": "LED Arcade Intro",
"starrynightdisplaytext": "Starry Night Text",
"launch_stockticker": "Stock Ticker",
"launch_ledtv": "LED TV",
"launch_defender": "Defender",
"launch_defender2": "Defender",
"launch_pacdot": "PacDot",
"launch_dotzerk": "DotZerk",
"launch_particles": "Particles",
"launch_fractal": "Fractal Blaster",
"launch_pinball_random": "Pinball (random table)",
"launch_pinball": "Pinball",
"launch_pinball2": "Central Park (1966)",
"launch_rallydot": "Rally Dot",
"twitchtimer_on": "Twitch Timer On",
"twitchtimer_off": "Twitch Timer Off",
"terminalmode_on": "Terminal Mode On",
"terminalmessage": "Terminal Message",
"terminalmode_off": "Terminal Mode Off",
"showheart": "Show Heart",
"showintro": "Show Intro",
"showonair": "On Air",
"showonair_off": "On Air Off",
"showdemotivate": "Demotivator",
"showgif": "Show GIF",
"showviewers": "Show Viewers",
"showimagezoom": "Image Zoom",
"quit": "Quit",
}
PANEL_STYLES = """
body {
font-family: 'Courier New', monospace;
padding: 20px;
background-color: #000;
color: #0f0;
text-shadow: 0 0 5px rgba(0, 255, 0, 0.5);
position: relative;
}
body::before {
content: '';
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: repeating-linear-gradient(
to bottom,
transparent 0px,
transparent 1px,
rgba(0, 0, 0, 0.3) 1px,
rgba(0, 0, 0, 0.3) 2px
);
pointer-events: none;
z-index: 1;
opacity: 0.5;
}
.panel-header {
position: relative;
z-index: 2;
margin-bottom: 20px;
}
.panel-header h1 {
margin: 0 0 16px 0;
color: #0f0;
}
.commands-container {
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: 20px;
position: relative;
z-index: 2;
}
.command-section {
padding: 15px;
border: 1px solid #0f0;
border-radius: 5px;
background-color: #111;
box-shadow: 0 0 10px rgba(0, 255, 0, 0.2);
}
.command-section h2 {
margin-top: 0;
color: #0f0;
font-size: 1rem;
word-break: break-word;
}
label {
color: #0f0;
display: block;
margin-bottom: 8px;
}
p {
color: #0a0;
font-size: 0.85rem;
margin: 0 0 8px 0;
}
input[type="text"] {
width: 100%;
box-sizing: border-box;
background-color: #222;
color: #0f0;
border: 1px solid #0f0;
padding: 5px;
font-family: 'Courier New', monospace;
margin-top: 4px;
}
input[type="submit"] {
background-color: #0f0;
color: #000;
border: none;
padding: 8px 12px;
cursor: pointer;
font-family: 'Courier New', monospace;
margin-top: 8px;
}
input[type="submit"]:hover {
background-color: #00ff00;
}
.unit-choice {
display: flex;
gap: 16px;
margin: 8px 0 12px 0;
}
.unit-choice label {
display: inline-flex;
align-items: center;
gap: 6px;
margin-bottom: 0;
cursor: pointer;
}
.unit-choice input[type="radio"] {
accent-color: #0f0;
}
#status-message {
position: fixed;
top: 10px;
left: 50%;
transform: translateX(-50%);
padding: 10px 16px;
border-radius: 5px;
z-index: 1000;
display: none;
}
.success {
background-color: #004400;
color: #0f0;
border: 1px solid #0f0;
}
.error {
background-color: #440000;
color: #ff0000;
border: 1px solid #ff0000;
}
.games-section {
grid-column: 1 / -1;
}
.games-grid {
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: 20px;
margin-top: 12px;
}
.clocks-section {
grid-column: 1 / -1;
}
.clock-grid {
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: 20px;
margin-top: 12px;
}
.clock-card h3 {
margin-top: 0;
color: #0f0;
font-size: 0.95rem;
}
.game-note {
font-size: 0.85em;
color: #0a0;
margin: 0.25em 0 0.5em 0;
opacity: 0.9;
}
.game-card h3 {
margin: 0 0 10px 0;
color: #0f0;
font-size: 1rem;
}
""" + LEDupdate.UPDATE_STYLES
FORM_SUBMIT_SCRIPT = """
document.addEventListener('DOMContentLoaded', function() {
const forms = document.querySelectorAll('form.command-form');
forms.forEach(form => {
form.addEventListener('submit', function(event) {
event.preventDefault();
const formData = new FormData(form);
const data = Object.fromEntries(formData.entries());
fetch('/command', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(data)
})
.then(response => response.json())
.then(result => {
const statusMsg = document.getElementById('status-message');
statusMsg.innerText = result.message;
statusMsg.className = result.status === 'ok' ? 'success' : 'error';
statusMsg.style.display = 'block';
setTimeout(() => { statusMsg.style.display = 'none'; }, 3000);
})
.catch(error => {
const statusMsg = document.getElementById('status-message');
statusMsg.innerText = 'Error: ' + error;
statusMsg.className = 'error';
statusMsg.style.display = 'block';
setTimeout(() => { statusMsg.style.display = 'none'; }, 3000);
});
});
});
});
"""
def render_stock_section(default_symbols=None):
"""Dedicated stock report control."""
if default_symbols is None:
default_symbols = ", ".join(LoadStockSymbols())
return f"""
<div class="command-section stock-section">
<h2>Stock Report</h2>
<form class="command-form" action="/command" method="post">
<input type="hidden" name="Action" value="stockterminal">
<label>Symbols
<input type="text" name="symbols" value="{default_symbols}" placeholder="TSLA MSFT AAPL">
</label>
<p>Comma or space separated. Leave blank to use KeyConfig.ini.</p>
<input type="submit" value="Stock Report">
</form>
</div>
"""
def render_weather_section(default_location=DEFAULT_LOCATION):
"""Dedicated weather report control with location input."""
return f"""
<div class="command-section weather-section">
<h2>Weather Report</h2>
<form class="command-form" action="/command" method="post">
<input type="hidden" name="Action" value="weatherterminal">
<label>Location
<input type="text" name="Location" value="{default_location}" placeholder="{default_location}">
</label>
<div class="unit-choice">
<span>Units:</span>
<label><input type="radio" name="Units" value="C" checked> C</label>
<label><input type="radio" name="Units" value="F"> F</label>
</div>
<input type="submit" value="Weather Report">
</form>
</div>
"""
def render_clocks_section(valid_actions):
"""Dedicated clock controls near the top of the panel (includes Flip Clock)."""
cards = []
for action, title, default_fields in CLOCK_LAUNCHERS:
if action not in valid_actions:
continue
# Prefer field list from VALID_WEB_ACTIONS; fall back to defaults above
fields = list(valid_actions.get(action) or default_fields)
field_html = ""
for field in fields:
if field == "duration":
field_html += (
f'<label>duration (min)'
f'<input type="text" name="duration" value="{DEFAULT_CLOCK_DURATION}"></label>'
)
else:
field_html += (
f'<label>{field}'
f'<input type="text" name="{field}" value=""></label>'
)
cards.append(f"""
<div class="command-section clock-card">
<h3>{title}</h3>
<form class="command-form" action="/command" method="post">
<input type="hidden" name="Action" value="{action}">
{field_html}
<input type="submit" value="Launch {title}">
</form>
</div>
""")
if not cards:
return ""
return f"""
<div class="command-section clocks-section">
<h2>Clocks</h2>
<p>Wall-clock modes for the panel. Flip Clock is the 1970s white-on-black split-flap style.</p>
<div class="clock-grid">
{"".join(cards)}
</div>
</div>
"""
def render_ledtv_section():
"""Dedicated LED TV launch control (same action as Twitch ?tv)."""
return f"""
<div class="command-section ledtv-section">
<h2>LED TV</h2>
<form class="command-form" action="/command" method="post">
<input type="hidden" name="Action" value="launch_ledtv">
<input type="hidden" name="effect" value="channels">
<label>Duration (minutes)
<input type="text" name="duration" value="5" placeholder="5">
</label>
<p>Channel surf: static, CHn flashes, videos & specialty channels. Same as Twitch <code>?tv</code>.</p>
<input type="submit" value="Launch LED TV">
</form>
</div>
"""
def _action_label(action):
return ACTION_LABELS.get(action, action)
def _game_launcher_actions(valid_actions):
return [
(action, title)
for action, title in GAME_LAUNCHERS
if action in valid_actions
]
def render_games_section(valid_actions):
"""Grouped launch controls for arcade games and sims."""
games = _game_launcher_actions(valid_actions)
if not games:
return ""
cards = []
for action, title in games:
# LED TV has its own top-level section; skip duplicate card
if action == "launch_ledtv":
continue
fields = valid_actions[action]
field_html = ""
until_go = action in UNTIL_GAME_OVER_LAUNCHERS
for field in fields:
if field == "duration":
# 0 = until game over (Rally Dot default)
value = 0 if until_go else DEFAULT_GAME_DURATION
else:
value = ""
field_html += (
f'<label>{field}'
f'<input type="text" name="{field}" value="{value}"></label>'
)
note = ""
if until_go:
note = (
'<p class="game-note">Default duration 0 = play until game over '
'(3 lives). Set minutes to cap the run.</p>'
)
cards.append(f"""
<div class="command-section game-card">
<h3>{title}</h3>
{note}
<form class="command-form" action="/command" method="post">
<input type="hidden" name="Action" value="{action}">
{field_html}
<input type="submit" value="Launch {title}">
</form>
</div>
""")
return f"""
<div class="command-section games-section">
<h2>Games & Simulations</h2>
<p>Duration is in minutes (0 = until game over where supported).
Games here are part of the idle rotation.</p>
<div class="games-grid">
{"".join(cards)}
</div>
</div>
"""
def render_homepage(valid_actions):
"""Render the CRT-themed LED Commander control panel."""
html = f"""
<html>
<head>
<title>LED Commander {PANEL_VERSION}</title>
<style>
{PANEL_STYLES}
</style>
<script>
{LEDupdate.UPDATE_SCRIPT}
{FORM_SUBMIT_SCRIPT}
</script>
</head>
<body>
<div id="status-message"></div>
<div class="panel-header">
<h1>{PANEL_TITLE}</h1>
{LEDupdate.UPDATE_BAR_HTML}
</div>
<div class="commands-container">
"""
html += render_clocks_section(valid_actions)
html += render_weather_section()
html += render_stock_section()
if "launch_ledtv" in valid_actions:
html += render_ledtv_section()
html += render_games_section(valid_actions)
game_actions = {action for action, _ in GAME_LAUNCHERS}
clock_actions = {action for action, _, _ in CLOCK_LAUNCHERS}
for action, fields in valid_actions.items():
if (
action in ("weatherterminal", "stockterminal", "launch_ledtv")
or action in game_actions
or action in clock_actions
):
continue
label = _action_label(action)
html += f'<div class="command-section"><h2>{label}</h2>'
html += '<form class="command-form" action="/command" method="post">'
html += f'<input type="hidden" name="Action" value="{action}">'
for field in fields:
html += f'<label>{field}<input type="text" name="{field}"></label>'
html += f'<input type="submit" value="{label}"></form></div>'
html += """
</div>
</body>
</html>
"""
return html