-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathLEDpanel.py
More file actions
360 lines (336 loc) · 10.1 KB
/
Copy pathLEDpanel.py
File metadata and controls
360 lines (336 loc) · 10.1 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
# LEDpanel.py - Shared CRT-styled control panel for LED Commander
import LEDupdate
from WeatherClock import DEFAULT_LOCATION
from StockReport import LoadStockSymbols
PANEL_VERSION = "1.3"
PANEL_TITLE = f"LED Commander Control Panel {PANEL_VERSION}"
DEFAULT_GAME_DURATION = 10
GAME_LAUNCHERS = [
("launch_dotinvaders", "Dot Invaders"),
("launch_defender", "Defender"),
("launch_defender2", "Defender 2"),
("launch_tron", "Tron"),
("launch_outbreak", "Outbreak"),
("launch_spacedot", "Space Dot"),
("launch_blasteroids", "Blasteroids"),
("launch_fallingsand", "Falling Sand"),
("launch_particles", "Particles"),
("launch_gravitysim", "Gravity Sim"),
("launch_mazecar", "Maze Car"),
("launch_spaceexplorer", "Space Explorer"),
]
ACTION_LABELS = {
"showclock": "Digital Clock",
"stopclock": "Stop Clock",
"showtitlescreen": "Title Screen",
"analogclock": "Analog Clock",
"retrodigital": "Retro Digital",
"starrynightdisplaytext": "Starry Night Text",
"launch_stockticker": "Stock Ticker",
"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;
}
.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="F" checked> F</label>
<label><input type="radio" name="Units" value="C"> C</label>
</div>
<input type="submit" value="Weather Report">
</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:
fields = valid_actions[action]
field_html = ""
for field in fields:
value = DEFAULT_GAME_DURATION if field == "duration" else ""
field_html += (
f'<label>{field}'
f'<input type="text" name="{field}" value="{value}"></label>'
)
cards.append(f"""
<div class="command-section game-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>
""")
return f"""
<div class="command-section games-section">
<h2>Games & Simulations</h2>
<p>Duration is in minutes. 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_weather_section()
html += render_stock_section()
html += render_games_section(valid_actions)
game_actions = {action for action, _ in GAME_LAUNCHERS}
for action, fields in valid_actions.items():
if action in ("weatherterminal", "stockterminal") or action in game_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