Просмотр исходного кода

allow switching screens with input buttons

Thomas Buck 1 год назад
Родитель
Сommit
e3d133a29f
7 измененных файлов: 185 добавлений и 353 удалений
  1. 5
    3
      camp_small.py
  2. 2
    2
      gamepad.py
  3. 49
    25
      image.py
  4. 29
    301
      img_tmp.py
  5. 58
    9
      manager.py
  6. 20
    0
      net.py
  7. 22
    13
      qr.py

+ 5
- 3
camp_small.py Просмотреть файл

@@ -22,7 +22,8 @@ from gamepad import InputWrapper
22 22
 from manager import Manager
23 23
 import util
24 24
 
25
-url = "http://ubabot.frubar.net"
25
+#url = "http://ubabot.frubar.net"
26
+url = "http://www.xythobuz.de"
26 27
 
27 28
 # Need to import InputWrapper before initializing RGB Matrix on Pi
28 29
 i = InputWrapper()
@@ -38,7 +39,7 @@ t.loop_end()
38 39
 
39 40
 # UbaBot is online
40 41
 success = Manager(t)
41
-success.add(ImageScreen(t, "drinka.gif", 0.2, 2, 20.0))
42
+success.add(ImageScreen(t, "drinka.gif", 0.2, 2, 20.0, (0, 0, 0)))
42 43
 success.add(Solid(t, 1.0))
43 44
 success.add(QRScreen(t, url, 30.0, "Drinks:", "tom-thumb", (255, 255, 255), (0, 0, 0)))
44 45
 success.add(Solid(t, 1.0))
@@ -46,6 +47,7 @@ success.add(Solid(t, 1.0))
46 47
 # UbaBot is offline
47 48
 fail = Manager(t)
48 49
 fail.add(ImageScreen(t, "attention.gif", 0.2, 2, 20.0, (0, 0, 0)))
50
+fail.add(Solid(t, 1.0))
49 51
 fail.add(ScrollText(t, "The UbaBot Cocktail machine is currently closed. Please come back later for more drinks!", "lemon", 2, 75, camp_pink))
50 52
 fail.add(Solid(t, 1.0))
51 53
 fail.add(GameOfLife(t, 20, (0, 255, 0), (0, 0, 0), None, 2.0))
@@ -57,7 +59,7 @@ d.success(success)
57 59
 d.fail(fail)
58 60
 
59 61
 # Main "Menu"
60
-m = Manager(t)
62
+m = Manager(t, i)
61 63
 m.add(ScrollText(t, "#CCCAMP23", "lemon", 1, 75, camp_green))
62 64
 m.add(Solid(t, 1.0))
63 65
 m.add(ImageScreen(t, "Favicon.png", 0, 1, 10.0))

+ 2
- 2
gamepad.py Просмотреть файл

@@ -83,9 +83,9 @@ class InputWrapper:
83 83
                         self.keys["x"] = v
84 84
                     elif (event.code == ecodes.KEY_ENTER) or (event.code == ecodes.BTN_Y) or (event.code == ecodes.BTN_TOP):
85 85
                         self.keys["y"] = v
86
-                    elif event.code == ecodes.BTN_PINKIE:
86
+                    elif (event.code == ecodes.BTN_PINKIE) or (event.code == ecodes.KEY_D):
87 87
                         self.keys["r"] = v
88
-                    elif event.code == ecodes.BTN_TOP2:
88
+                    elif (event.code == ecodes.BTN_TOP2) or (event.code == ecodes.KEY_A):
89 89
                         self.keys["l"] = v
90 90
                     elif event.code == ecodes.BTN_BASE4:
91 91
                         self.keys["start"] = v

+ 49
- 25
image.py Просмотреть файл

@@ -13,10 +13,19 @@
13 13
 from PIL import Image
14 14
 import time
15 15
 import os
16
-import util
16
+
17
+# GIF images contain Palletes for each frame.
18
+# These can be different between frames.
19
+# So the library is converting them to RGB.
20
+# This means we can not replace the background easily
21
+# for all but the first frame in animations.
22
+# This setting changes that to keep the same palette, as long as possible.
23
+# This works with some GIFs, but not all of them.
24
+from PIL import GifImagePlugin
25
+GifImagePlugin.LOADING_STRATEGY = GifImagePlugin.LoadingStrategy.RGB_AFTER_DIFFERENT_PALETTE_ONLY
17 26
 
18 27
 class ImageScreen:
19
-    def __init__(self, g, p, t = 0.2, i = 1, to = 10.0, bg = None):
28
+    def __init__(self, g, p, t = 0.2, i = 1, to = 5.0, bg = None):
20 29
         self.gui = g
21 30
         self.time = t
22 31
         self.iterations = i
@@ -39,14 +48,14 @@ class ImageScreen:
39 48
 
40 49
             # keep the aspect ratio and fit within visible area
41 50
             ratio = self.image.width / self.image.height
42
-            width = self.gui.width
43
-            height = self.gui.height
44
-            if width < height:
45
-                width = self.gui.width
46
-                height = int(width / ratio)
47
-            else:
51
+            max_width = int(ratio * self.gui.height)
52
+            max_height = int(self.gui.width / ratio)
53
+            if (max_height >= self.gui.height) or (((self.gui.width - max_width) < (self.gui.height - max_height)) and ((self.gui.width - max_width) >= 0)):
54
+                width = max_width
48 55
                 height = self.gui.height
49
-                width = int(ratio * height)
56
+            else:
57
+                width = self.gui.width
58
+                height = max_height
50 59
 
51 60
             # resize
52 61
             self.image = self.image.resize((width, height),
@@ -73,7 +82,12 @@ class ImageScreen:
73 82
     def finished(self):
74 83
         if self.done >= self.iterations:
75 84
             return True
76
-        return (time.time() - self.start) >= self.timeout
85
+
86
+        # only apply timeout for static images
87
+        if self.image.is_animated:
88
+            return False
89
+        else:
90
+            return (time.time() - self.start) >= self.timeout
77 91
 
78 92
     def draw(self):
79 93
         if self.image.is_animated:
@@ -106,6 +120,8 @@ class ImageScreen:
106 120
                     self.gui.set_pixel(x + self.xOff, y + self.yOff, v)
107 121
 
108 122
 if __name__ == "__main__":
123
+    import sys
124
+
109 125
     import util
110 126
     t = util.getTarget()
111 127
 
@@ -123,21 +139,29 @@ if __name__ == "__main__":
123 139
         if filename != "Favicon.png":
124 140
             continue
125 141
 
126
-        # dump generated image to console, for embedding in Pico script
127
-        print()
128
-        print("Dumping image to img_tmp.py")
129
-        with open("img_tmp.py", "w") as f:
130
-            f.write("# Image \"" + filename + "\"" + os.linesep)
131
-            f.write("# size:" + str(d.image.width) + "x" + str(d.image.height) + os.linesep)
132
-            f.write("img_data = [" + os.linesep)
133
-            for y in range(0, d.image.height):
134
-                f.write("    [" + os.linesep)
135
-                for x in range(0, d.image.width):
136
-                    s = str(d.image.getpixel((x, y)))
137
-                    f.write("        " + s + "," + os.linesep)
138
-                f.write("    ]," + os.linesep)
139
-            f.write("]" + os.linesep)
140
-        print()
142
+        try:
143
+            # dump generated image to console, for embedding in Pico script
144
+            print()
145
+            print("Dumping image to img_tmp.py")
146
+            with open("img_tmp.py", "w") as f:
147
+                f.write("# Image \"" + filename + "\"" + os.linesep)
148
+                f.write("# size:" + str(d.image.width) + "x" + str(d.image.height) + os.linesep)
149
+                f.write("img_data = [" + os.linesep)
150
+                for y in range(0, d.image.height):
151
+                    f.write("    [" + os.linesep)
152
+                    for x in range(0, d.image.width):
153
+                        s = str(d.image.getpixel((x, y)))
154
+                        f.write("        " + s + "," + os.linesep)
155
+                    f.write("    ]," + os.linesep)
156
+                f.write("]" + os.linesep)
157
+            print()
158
+        except Exception as e:
159
+            print()
160
+            if hasattr(sys, "print_exception"):
161
+                sys.print_exception(e)
162
+            else:
163
+                print(e)
164
+                print()
141 165
 
142 166
     m.restart()
143 167
     t.loop(m.draw)

+ 29
- 301
img_tmp.py Просмотреть файл

@@ -1,5 +1,5 @@
1 1
 # Image "Favicon.png"
2
-# size:32x32
2
+# size:32x24
3 3
 img_data = [
4 4
     [
5 5
         (0, 0, 0),
@@ -39,41 +39,6 @@ img_data = [
39 39
         (0, 0, 0),
40 40
         (0, 0, 0),
41 41
         (0, 0, 0),
42
-        (73, 21, 57),
43
-        (251, 72, 196),
44
-        (251, 72, 196),
45
-        (251, 72, 196),
46
-        (251, 72, 196),
47
-        (251, 72, 196),
48
-        (251, 72, 196),
49
-        (251, 72, 196),
50
-        (0, 0, 0),
51
-        (0, 0, 0),
52
-        (0, 0, 0),
53
-        (0, 0, 0),
54
-        (0, 0, 0),
55
-        (0, 0, 0),
56
-        (63, 18, 49),
57
-        (251, 72, 196),
58
-        (251, 72, 196),
59
-        (251, 72, 196),
60
-        (251, 72, 196),
61
-        (251, 72, 196),
62
-        (251, 72, 196),
63
-        (251, 72, 196),
64
-        (251, 72, 196),
65
-        (251, 72, 196),
66
-        (251, 72, 196),
67
-        (251, 72, 196),
68
-        (251, 72, 196),
69
-        (238, 68, 186),
70
-        (0, 0, 0),
71
-    ],
72
-    [
73
-        (0, 0, 0),
74
-        (0, 0, 0),
75
-        (44, 13, 35),
76
-        (251, 72, 196),
77 42
         (251, 72, 196),
78 43
         (251, 72, 196),
79 44
         (251, 72, 196),
@@ -82,6 +47,7 @@ img_data = [
82 47
         (251, 72, 196),
83 48
         (251, 72, 196),
84 49
         (251, 72, 196),
50
+        (3, 1, 2),
85 51
         (0, 0, 0),
86 52
         (0, 0, 0),
87 53
         (0, 0, 0),
@@ -116,7 +82,7 @@ img_data = [
116 82
         (251, 72, 196),
117 83
         (251, 72, 196),
118 84
         (251, 72, 196),
119
-        (66, 19, 51),
85
+        (0, 0, 0),
120 86
         (0, 0, 0),
121 87
         (0, 0, 0),
122 88
         (0, 0, 0),
@@ -132,22 +98,22 @@ img_data = [
132 98
         (251, 72, 196),
133 99
         (251, 72, 196),
134 100
         (251, 72, 196),
135
-        (213, 61, 166),
101
+        (251, 72, 196),
136 102
         (0, 0, 0),
137 103
         (0, 0, 0),
138 104
         (0, 0, 0),
139 105
     ],
140 106
     [
141 107
         (0, 0, 0),
142
-        (245, 70, 191),
143 108
         (251, 72, 196),
144 109
         (251, 72, 196),
145 110
         (251, 72, 196),
111
+        (249, 71, 194),
146 112
         (0, 0, 0),
147 113
         (0, 0, 0),
148 114
         (0, 0, 0),
149 115
         (0, 0, 0),
150
-        (234, 67, 183),
116
+        (21, 6, 16),
151 117
         (251, 72, 196),
152 118
         (251, 72, 196),
153 119
         (251, 72, 196),
@@ -161,11 +127,11 @@ img_data = [
161 127
         (0, 0, 0),
162 128
         (0, 0, 0),
163 129
         (0, 0, 0),
164
-        (0, 0, 0),
165
-        (251, 72, 196),
130
+        (53, 15, 42),
166 131
         (251, 72, 196),
167 132
         (251, 72, 196),
168 133
         (251, 72, 196),
134
+        (177, 51, 138),
169 135
         (0, 0, 0),
170 136
         (0, 0, 0),
171 137
         (0, 0, 0),
@@ -182,44 +148,10 @@ img_data = [
182 148
         (0, 0, 0),
183 149
         (0, 0, 0),
184 150
         (0, 0, 0),
185
-        (249, 71, 194),
186
-        (251, 72, 196),
187
-        (251, 72, 196),
188
-        (4, 1, 3),
189
-        (0, 0, 0),
190
-        (0, 0, 0),
191
-        (0, 0, 0),
192
-        (0, 0, 0),
193
-        (0, 0, 0),
194
-        (0, 0, 0),
195
-        (0, 0, 0),
196
-        (0, 0, 0),
197
-        (0, 0, 0),
198
-        (251, 72, 196),
199
-        (251, 72, 196),
200
-        (251, 72, 196),
201
-        (251, 72, 196),
202 151
         (0, 0, 0),
203
-        (0, 0, 0),
204
-        (0, 0, 0),
205
-        (0, 0, 0),
206
-        (0, 0, 0),
207
-    ],
208
-    [
209
-        (0, 0, 0),
210
-        (251, 72, 196),
211
-        (251, 72, 196),
212
-        (126, 36, 98),
213
-        (0, 0, 0),
214
-        (0, 0, 0),
215
-        (0, 0, 0),
216
-        (0, 0, 0),
217
-        (0, 0, 0),
218
-        (0, 0, 0),
219
-        (0, 0, 0),
220
-        (251, 72, 196),
221 152
         (251, 72, 196),
222 153
         (251, 72, 196),
154
+        (183, 53, 143),
223 155
         (0, 0, 0),
224 156
         (0, 0, 0),
225 157
         (0, 0, 0),
@@ -228,11 +160,11 @@ img_data = [
228 160
         (0, 0, 0),
229 161
         (0, 0, 0),
230 162
         (0, 0, 0),
163
+        (71, 20, 55),
231 164
         (251, 72, 196),
232 165
         (251, 72, 196),
233 166
         (251, 72, 196),
234
-        (251, 72, 196),
235
-        (0, 0, 0),
167
+        (129, 37, 101),
236 168
         (0, 0, 0),
237 169
         (0, 0, 0),
238 170
         (0, 0, 0),
@@ -274,7 +206,7 @@ img_data = [
274 206
         (0, 0, 0),
275 207
     ],
276 208
     [
277
-        (84, 24, 65),
209
+        (97, 28, 76),
278 210
         (251, 72, 196),
279 211
         (251, 72, 196),
280 212
         (0, 0, 0),
@@ -285,7 +217,7 @@ img_data = [
285 217
         (0, 0, 0),
286 218
         (0, 0, 0),
287 219
         (0, 0, 0),
288
-        (251, 72, 196),
220
+        (237, 68, 185),
289 221
         (251, 72, 196),
290 222
         (251, 72, 196),
291 223
         (0, 0, 0),
@@ -308,7 +240,7 @@ img_data = [
308 240
         (0, 0, 0),
309 241
     ],
310 242
     [
311
-        (110, 32, 86),
243
+        (86, 25, 67),
312 244
         (251, 72, 196),
313 245
         (251, 72, 196),
314 246
         (0, 0, 0),
@@ -319,20 +251,9 @@ img_data = [
319 251
         (0, 0, 0),
320 252
         (0, 0, 0),
321 253
         (0, 0, 0),
322
-        (189, 54, 148),
323
-        (251, 72, 196),
324
-        (251, 72, 196),
325
-        (0, 0, 0),
326
-        (0, 0, 0),
327
-        (0, 0, 0),
328
-        (0, 0, 0),
329
-        (0, 0, 0),
330
-        (0, 0, 0),
331
-        (199, 57, 155),
332
-        (251, 72, 196),
254
+        (230, 66, 180),
333 255
         (251, 72, 196),
334 256
         (251, 72, 196),
335
-        (4, 1, 3),
336 257
         (0, 0, 0),
337 258
         (0, 0, 0),
338 259
         (0, 0, 0),
@@ -340,20 +261,8 @@ img_data = [
340 261
         (0, 0, 0),
341 262
         (0, 0, 0),
342 263
         (0, 0, 0),
343
-    ],
344
-    [
345
-        (40, 12, 32),
346 264
         (251, 72, 196),
347 265
         (251, 72, 196),
348
-        (0, 0, 0),
349
-        (0, 0, 0),
350
-        (0, 0, 0),
351
-        (0, 0, 0),
352
-        (0, 0, 0),
353
-        (0, 0, 0),
354
-        (0, 0, 0),
355
-        (0, 0, 0),
356
-        (251, 72, 196),
357 266
         (251, 72, 196),
358 267
         (251, 72, 196),
359 268
         (0, 0, 0),
@@ -363,17 +272,6 @@ img_data = [
363 272
         (0, 0, 0),
364 273
         (0, 0, 0),
365 274
         (0, 0, 0),
366
-        (181, 52, 141),
367
-        (251, 72, 196),
368
-        (251, 72, 196),
369
-        (251, 72, 196),
370
-        (21, 6, 16),
371
-        (0, 0, 0),
372
-        (0, 0, 0),
373
-        (0, 0, 0),
374
-        (0, 0, 0),
375
-        (0, 0, 0),
376
-        (0, 0, 0),
377 275
     ],
378 276
     [
379 277
         (0, 0, 0),
@@ -398,11 +296,11 @@ img_data = [
398 296
         (0, 0, 0),
399 297
         (0, 0, 0),
400 298
         (0, 0, 0),
401
-        (198, 57, 154),
402 299
         (251, 72, 196),
403 300
         (251, 72, 196),
404 301
         (251, 72, 196),
405
-        (21, 6, 16),
302
+        (251, 72, 196),
303
+        (0, 0, 0),
406 304
         (0, 0, 0),
407 305
         (0, 0, 0),
408 306
         (0, 0, 0),
@@ -413,7 +311,7 @@ img_data = [
413 311
         (0, 0, 0),
414 312
         (251, 72, 196),
415 313
         (251, 72, 196),
416
-        (249, 71, 194),
314
+        (251, 72, 196),
417 315
         (0, 0, 0),
418 316
         (0, 0, 0),
419 317
         (0, 0, 0),
@@ -433,11 +331,11 @@ img_data = [
433 331
         (0, 0, 0),
434 332
         (0, 0, 0),
435 333
         (0, 0, 0),
334
+        (179, 51, 140),
436 335
         (251, 72, 196),
437 336
         (251, 72, 196),
438 337
         (251, 72, 196),
439
-        (251, 72, 196),
440
-        (0, 0, 0),
338
+        (50, 14, 39),
441 339
         (0, 0, 0),
442 340
         (0, 0, 0),
443 341
         (0, 0, 0),
@@ -448,46 +346,12 @@ img_data = [
448 346
         (251, 72, 196),
449 347
         (251, 72, 196),
450 348
         (251, 72, 196),
451
-        (0, 0, 0),
452
-        (0, 0, 0),
453
-        (0, 0, 0),
454
-        (0, 0, 0),
455
-        (0, 0, 0),
456
-        (0, 0, 0),
457
-        (248, 71, 194),
458
-        (251, 72, 196),
459 349
         (251, 72, 196),
460 350
         (0, 0, 0),
461 351
         (0, 0, 0),
462 352
         (0, 0, 0),
463 353
         (0, 0, 0),
464 354
         (0, 0, 0),
465
-        (0, 0, 0),
466
-        (0, 0, 0),
467
-        (0, 0, 0),
468
-        (0, 0, 0),
469
-        (0, 0, 0),
470
-        (0, 0, 0),
471
-        (251, 72, 196),
472
-        (251, 72, 196),
473
-        (251, 72, 196),
474
-        (251, 72, 196),
475
-        (0, 0, 0),
476
-        (0, 0, 0),
477
-        (0, 0, 0),
478
-        (0, 0, 0),
479
-    ],
480
-    [
481
-        (0, 0, 0),
482
-        (63, 18, 49),
483
-        (251, 72, 196),
484
-        (251, 72, 196),
485
-        (251, 72, 196),
486
-        (0, 0, 0),
487
-        (0, 0, 0),
488
-        (0, 0, 0),
489
-        (0, 0, 0),
490
-        (10, 3, 8),
491 355
         (251, 72, 196),
492 356
         (251, 72, 196),
493 357
         (251, 72, 196),
@@ -587,44 +451,10 @@ img_data = [
587 451
         (0, 0, 0),
588 452
         (0, 0, 0),
589 453
         (0, 0, 0),
590
-        (35, 10, 28),
591
-        (251, 72, 196),
592
-        (251, 72, 196),
593
-        (251, 72, 196),
594
-        (0, 0, 0),
595
-        (0, 0, 0),
596
-        (0, 0, 0),
597
-        (0, 0, 0),
598
-        (0, 0, 0),
599
-        (0, 0, 0),
600
-        (0, 0, 0),
601
-        (0, 0, 0),
602
-        (0, 0, 0),
603
-        (0, 0, 0),
604
-        (0, 0, 0),
605
-        (189, 54, 148),
606 454
         (251, 72, 196),
607 455
         (251, 72, 196),
608
-        (189, 54, 148),
609
-        (189, 54, 148),
610
-        (211, 60, 164),
611 456
         (251, 72, 196),
612 457
         (251, 72, 196),
613
-        (251, 72, 196),
614
-        (71, 20, 55),
615
-    ],
616
-    [
617
-        (0, 0, 0),
618
-        (0, 0, 0),
619
-        (0, 0, 0),
620
-        (0, 0, 0),
621
-        (0, 0, 0),
622
-        (0, 0, 0),
623
-        (0, 0, 0),
624
-        (251, 72, 196),
625
-        (251, 72, 196),
626
-        (251, 72, 196),
627
-        (35, 10, 28),
628 458
         (0, 0, 0),
629 459
         (0, 0, 0),
630 460
         (0, 0, 0),
@@ -642,7 +472,7 @@ img_data = [
642 472
         (0, 0, 0),
643 473
         (0, 0, 0),
644 474
         (0, 0, 0),
645
-        (0, 0, 0),
475
+        (240, 69, 188),
646 476
         (251, 72, 196),
647 477
         (251, 72, 196),
648 478
         (251, 72, 196),
@@ -687,7 +517,7 @@ img_data = [
687 517
         (0, 0, 0),
688 518
         (0, 0, 0),
689 519
         (0, 0, 0),
690
-        (246, 71, 192),
520
+        (251, 72, 196),
691 521
         (251, 72, 196),
692 522
         (251, 72, 196),
693 523
         (251, 72, 196),
@@ -720,13 +550,13 @@ img_data = [
720 550
         (0, 0, 0),
721 551
         (0, 0, 0),
722 552
         (0, 0, 0),
723
-        (0, 0, 0),
553
+        (208, 60, 162),
554
+        (251, 72, 196),
724 555
         (251, 72, 196),
725 556
         (251, 72, 196),
726 557
         (251, 72, 196),
727 558
         (251, 72, 196),
728 559
         (251, 72, 196),
729
-        (213, 61, 166),
730 560
         (0, 0, 0),
731 561
         (0, 0, 0),
732 562
         (0, 0, 0),
@@ -744,7 +574,7 @@ img_data = [
744 574
         (0, 0, 0),
745 575
         (0, 0, 0),
746 576
         (0, 0, 0),
747
-        (0, 0, 0),
577
+        (10, 3, 8),
748 578
         (251, 72, 196),
749 579
         (251, 72, 196),
750 580
         (251, 72, 196),
@@ -753,44 +583,10 @@ img_data = [
753 583
         (0, 0, 0),
754 584
         (0, 0, 0),
755 585
         (0, 0, 0),
756
-        (0, 0, 0),
757
-        (251, 72, 196),
758
-        (251, 72, 196),
759
-        (251, 72, 196),
760
-        (15, 4, 12),
761
-        (171, 49, 134),
762
-        (251, 72, 196),
763
-        (251, 72, 196),
764
-        (0, 0, 0),
765
-        (0, 0, 0),
766
-        (0, 0, 0),
767
-        (0, 0, 0),
768
-        (0, 0, 0),
769
-        (0, 0, 0),
770
-        (0, 0, 0),
771
-        (0, 0, 0),
772
-        (0, 0, 0),
773
-        (0, 0, 0),
774
-        (0, 0, 0),
775
-        (189, 54, 148),
776
-        (251, 72, 196),
777
-        (251, 72, 196),
778
-        (126, 36, 98),
779
-        (126, 36, 98),
780 586
         (138, 40, 108),
781 587
         (251, 72, 196),
782 588
         (251, 72, 196),
783 589
         (251, 72, 196),
784
-        (79, 23, 61),
785
-    ],
786
-    [
787
-        (0, 0, 0),
788
-        (0, 0, 0),
789
-        (0, 0, 0),
790
-        (251, 72, 196),
791
-        (251, 72, 196),
792
-        (251, 72, 196),
793
-        (251, 72, 196),
794 590
         (0, 0, 0),
795 591
         (0, 0, 0),
796 592
         (251, 72, 196),
@@ -820,7 +616,7 @@ img_data = [
820 616
     [
821 617
         (0, 0, 0),
822 618
         (0, 0, 0),
823
-        (69, 20, 54),
619
+        (242, 69, 189),
824 620
         (251, 72, 196),
825 621
         (251, 72, 196),
826 622
         (251, 72, 196),
@@ -829,7 +625,7 @@ img_data = [
829 625
         (0, 0, 0),
830 626
         (251, 72, 196),
831 627
         (251, 72, 196),
832
-        (60, 17, 47),
628
+        (164, 47, 128),
833 629
         (0, 0, 0),
834 630
         (0, 0, 0),
835 631
         (0, 0, 0),
@@ -848,46 +644,12 @@ img_data = [
848 644
         (251, 72, 196),
849 645
         (251, 72, 196),
850 646
         (251, 72, 196),
851
-        (14, 4, 11),
852
-        (0, 0, 0),
853
-    ],
854
-    [
855
-        (0, 0, 0),
856
-        (0, 0, 0),
857
-        (251, 72, 196),
858
-        (251, 72, 196),
859
-        (251, 72, 196),
860
-        (0, 0, 0),
861
-        (0, 0, 0),
862
-        (0, 0, 0),
863
-        (0, 0, 0),
864
-        (251, 72, 196),
865
-        (251, 72, 196),
866
-        (251, 72, 196),
867
-        (0, 0, 0),
868
-        (0, 0, 0),
869
-        (0, 0, 0),
870
-        (0, 0, 0),
871
-        (0, 0, 0),
872
-        (0, 0, 0),
873
-        (0, 0, 0),
874
-        (0, 0, 0),
875
-        (0, 0, 0),
876
-        (0, 0, 0),
877
-        (189, 54, 148),
878
-        (251, 72, 196),
879
-        (251, 72, 196),
880
-        (251, 72, 196),
881
-        (251, 72, 196),
882
-        (251, 72, 196),
883
-        (251, 72, 196),
884
-        (0, 0, 0),
885 647
         (0, 0, 0),
886 648
         (0, 0, 0),
887 649
     ],
888 650
     [
889 651
         (0, 0, 0),
890
-        (251, 72, 196),
652
+        (198, 57, 154),
891 653
         (251, 72, 196),
892 654
         (251, 72, 196),
893 655
         (251, 72, 196),
@@ -920,7 +682,7 @@ img_data = [
920 682
         (0, 0, 0),
921 683
     ],
922 684
     [
923
-        (118, 34, 92),
685
+        (0, 0, 0),
924 686
         (251, 72, 196),
925 687
         (251, 72, 196),
926 688
         (251, 72, 196),
@@ -968,16 +730,6 @@ img_data = [
968 730
         (251, 72, 196),
969 731
         (251, 72, 196),
970 732
         (251, 72, 196),
971
-        (190, 54, 148),
972
-        (0, 0, 0),
973
-        (0, 0, 0),
974
-        (0, 0, 0),
975
-        (0, 0, 0),
976
-        (0, 0, 0),
977
-        (0, 0, 0),
978
-        (0, 0, 0),
979
-        (189, 54, 148),
980
-        (251, 72, 196),
981 733
         (251, 72, 196),
982 734
         (0, 0, 0),
983 735
         (0, 0, 0),
@@ -986,30 +738,6 @@ img_data = [
986 738
         (0, 0, 0),
987 739
         (0, 0, 0),
988 740
         (0, 0, 0),
989
-    ],
990
-    [
991
-        (0, 0, 0),
992
-        (0, 0, 0),
993
-        (0, 0, 0),
994
-        (0, 0, 0),
995
-        (0, 0, 0),
996
-        (0, 0, 0),
997
-        (0, 0, 0),
998
-        (0, 0, 0),
999
-        (0, 0, 0),
1000
-        (0, 0, 0),
1001
-        (0, 0, 0),
1002
-        (0, 0, 0),
1003
-        (0, 0, 0),
1004
-        (0, 0, 0),
1005
-        (0, 0, 0),
1006
-        (0, 0, 0),
1007
-        (0, 0, 0),
1008
-        (0, 0, 0),
1009
-        (0, 0, 0),
1010
-        (0, 0, 0),
1011
-        (0, 0, 0),
1012
-        (0, 0, 0),
1013 741
         (189, 54, 148),
1014 742
         (251, 72, 196),
1015 743
         (251, 72, 196),

+ 58
- 9
manager.py Просмотреть файл

@@ -10,8 +10,10 @@
10 10
 import time
11 11
 
12 12
 class Manager:
13
-    def __init__(self, g):
13
+    def __init__(self, g, i = None, ss = 2):
14 14
         self.gui = g
15
+        self.input = i
16
+        self.step_size = ss
15 17
         self.screens = []
16 18
         self.restart()
17 19
 
@@ -19,6 +21,13 @@ class Manager:
19 21
         self.index = 0
20 22
         self.done = False
21 23
         self.lastTime = time.time()
24
+        self.old_keys = {
25
+            "l": False,
26
+            "r": False,
27
+        }
28
+
29
+        #print("Manager ", len(self.screens), " reset to ", self.index)
30
+
22 31
         if len(self.screens) > 0:
23 32
             self.screens[0][0].restart()
24 33
 
@@ -29,24 +38,64 @@ class Manager:
29 38
         v = (s, d)
30 39
         self.screens.append(v)
31 40
 
41
+    def buttons(self):
42
+        keys = self.input.get()
43
+
44
+        if keys["l"] and (not self.old_keys["l"]):
45
+            c = self.screens[self.index][0]
46
+            if hasattr(c, "switch_to") and hasattr(c, "child_count"):
47
+                if c.child_count(-1):
48
+                    self.switch_to(-1, False)
49
+                else:
50
+                    c.switch_to(-1, False)
51
+            else:
52
+                self.switch_to(-1, False)
53
+        elif keys["r"] and (not self.old_keys["r"]):
54
+            c = self.screens[self.index][0]
55
+            if hasattr(c, "switch_to") and hasattr(c, "child_count"):
56
+                if c.child_count(1):
57
+                    self.switch_to(1, False)
58
+                else:
59
+                    c.switch_to(1, False)
60
+            else:
61
+                self.switch_to(1, False)
62
+
63
+        self.old_keys = keys.copy()
64
+
65
+    def child_count(self, i):
66
+        if i > 0:
67
+            index = int(self.index / self.step_size)
68
+            l = int(len(self.screens) / self.step_size)
69
+            return index >= (l - 1)
70
+        else:
71
+            return self.index <= 0
72
+
73
+    def switch_to(self, i, update_flag):
74
+        self.lastTime = time.time()
75
+        self.index = int((int(self.index / self.step_size) + i) * self.step_size) % len(self.screens)
76
+
77
+        #print("Manager ", len(self.screens), " switch to ", self.index, update_flag)
78
+
79
+        if update_flag:
80
+            self.done = (self.index == 0)
81
+
82
+        self.screens[self.index][0].restart()
83
+
32 84
     def draw(self):
85
+        if self.input != None:
86
+            self.buttons()
87
+
33 88
         self.screens[self.index][0].draw()
34 89
 
35 90
         if self.screens[self.index][1] == None:
36 91
             # let screen decide when it is done
37 92
             if self.screens[self.index][0].finished():
38
-                self.lastTime = time.time()
39
-                self.index = (self.index + 1) % len(self.screens)
40
-                self.done = (self.index == 0)
41
-                self.screens[self.index][0].restart()
93
+                self.switch_to(1, True)
42 94
         else:
43 95
             # use given timeout
44 96
             now = time.time()
45 97
             if ((now - self.lastTime) > self.screens[self.index][1]) or (now < self.lastTime):
46
-                self.lastTime = now
47
-                self.index = (self.index + 1) % len(self.screens)
48
-                self.done = (self.index == 0)
49
-                self.screens[self.index][0].restart()
98
+                self.switch_to(1, True)
50 99
 
51 100
 if __name__ == "__main__":
52 101
     from splash import SplashScreen

+ 20
- 0
net.py Просмотреть файл

@@ -28,6 +28,26 @@ class CheckHTTP:
28 28
     def fail(self, f):
29 29
         self.failScreen = f
30 30
 
31
+    # Compatibility to Manager button events
32
+    def child_count(self, i):
33
+        self.request()
34
+        if self.response:
35
+            if hasattr(self.successScreen, "child_count"):
36
+                return self.successScreen.child_count(i)
37
+        else:
38
+            if hasattr(self.failScreen, "child_count"):
39
+                return self.failScreen.child_count(i)
40
+
41
+    # Compatibility to Manager button events
42
+    def switch_to(self, i, update_flag):
43
+        self.request()
44
+        if self.response:
45
+            if hasattr(self.successScreen, "switch_to"):
46
+                self.successScreen.switch_to(i, update_flag)
47
+        else:
48
+            if hasattr(self.failScreen, "switch_to"):
49
+                self.failScreen.switch_to(i, update_flag)
50
+
31 51
     def restart(self):
32 52
         self.start = time.time()
33 53
 

+ 22
- 13
qr.py Просмотреть файл

@@ -107,23 +107,32 @@ class QRScreen:
107 107
 if __name__ == "__main__":
108 108
     import util
109 109
     import os
110
+    import sys
110 111
 
111 112
     t = util.getTarget()
112 113
 
113 114
     d = QRScreen(t, "http://ubabot.frubar.net", 10.0, "Drinks:", "tom-thumb", (255, 255, 255), (0, 0, 0))
114 115
 
115
-    # dump generated QR image to console, for embedding in Pico script
116
-    print("Dumping QR image to qr_tmp.py")
117
-    with open("qr_tmp.py", "w") as f:
118
-        f.write("# QR code image for \"" + d.data + "\"" + os.linesep)
119
-        f.write("# size:" + str(d.image.width) + "x" + str(d.image.height) + os.linesep)
120
-        f.write("qr_data = [" + os.linesep)
121
-        for y in range(0, d.image.height):
122
-            f.write("    [" + os.linesep)
123
-            for x in range(0, d.image.width):
124
-                s = str(d.image.getpixel((x, y)))
125
-                f.write("        " + s + "," + os.linesep)
126
-            f.write("    ]," + os.linesep)
127
-        f.write("]" + os.linesep)
116
+    try:
117
+        # dump generated QR image to console, for embedding in Pico script
118
+        print("Dumping QR image to qr_tmp.py")
119
+        with open("qr_tmp.py", "w") as f:
120
+            f.write("# QR code image for \"" + d.data + "\"" + os.linesep)
121
+            f.write("# size:" + str(d.image.width) + "x" + str(d.image.height) + os.linesep)
122
+            f.write("qr_data = [" + os.linesep)
123
+            for y in range(0, d.image.height):
124
+                f.write("    [" + os.linesep)
125
+                for x in range(0, d.image.width):
126
+                    s = str(d.image.getpixel((x, y)))
127
+                    f.write("        " + s + "," + os.linesep)
128
+                f.write("    ]," + os.linesep)
129
+            f.write("]" + os.linesep)
130
+    except Exception as e:
131
+        print()
132
+        if hasattr(sys, "print_exception"):
133
+            sys.print_exception(e)
134
+        else:
135
+            print(e)
136
+            print()
128 137
 
129 138
     t.loop(d.draw)

Загрузка…
Отмена
Сохранить