Browse Source

allow switching screens with input buttons

Thomas Buck 1 year ago
parent
commit
e3d133a29f
7 changed files with 185 additions and 353 deletions
  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 View File

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

+ 2
- 2
gamepad.py View File

83
                         self.keys["x"] = v
83
                         self.keys["x"] = v
84
                     elif (event.code == ecodes.KEY_ENTER) or (event.code == ecodes.BTN_Y) or (event.code == ecodes.BTN_TOP):
84
                     elif (event.code == ecodes.KEY_ENTER) or (event.code == ecodes.BTN_Y) or (event.code == ecodes.BTN_TOP):
85
                         self.keys["y"] = v
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
                         self.keys["r"] = v
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
                         self.keys["l"] = v
89
                         self.keys["l"] = v
90
                     elif event.code == ecodes.BTN_BASE4:
90
                     elif event.code == ecodes.BTN_BASE4:
91
                         self.keys["start"] = v
91
                         self.keys["start"] = v

+ 49
- 25
image.py View File

13
 from PIL import Image
13
 from PIL import Image
14
 import time
14
 import time
15
 import os
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
 class ImageScreen:
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
         self.gui = g
29
         self.gui = g
21
         self.time = t
30
         self.time = t
22
         self.iterations = i
31
         self.iterations = i
39
 
48
 
40
             # keep the aspect ratio and fit within visible area
49
             # keep the aspect ratio and fit within visible area
41
             ratio = self.image.width / self.image.height
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
                 height = self.gui.height
55
                 height = self.gui.height
49
-                width = int(ratio * height)
56
+            else:
57
+                width = self.gui.width
58
+                height = max_height
50
 
59
 
51
             # resize
60
             # resize
52
             self.image = self.image.resize((width, height),
61
             self.image = self.image.resize((width, height),
73
     def finished(self):
82
     def finished(self):
74
         if self.done >= self.iterations:
83
         if self.done >= self.iterations:
75
             return True
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
     def draw(self):
92
     def draw(self):
79
         if self.image.is_animated:
93
         if self.image.is_animated:
106
                     self.gui.set_pixel(x + self.xOff, y + self.yOff, v)
120
                     self.gui.set_pixel(x + self.xOff, y + self.yOff, v)
107
 
121
 
108
 if __name__ == "__main__":
122
 if __name__ == "__main__":
123
+    import sys
124
+
109
     import util
125
     import util
110
     t = util.getTarget()
126
     t = util.getTarget()
111
 
127
 
123
         if filename != "Favicon.png":
139
         if filename != "Favicon.png":
124
             continue
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
     m.restart()
166
     m.restart()
143
     t.loop(m.draw)
167
     t.loop(m.draw)

+ 29
- 301
img_tmp.py View File

1
 # Image "Favicon.png"
1
 # Image "Favicon.png"
2
-# size:32x32
2
+# size:32x24
3
 img_data = [
3
 img_data = [
4
     [
4
     [
5
         (0, 0, 0),
5
         (0, 0, 0),
39
         (0, 0, 0),
39
         (0, 0, 0),
40
         (0, 0, 0),
40
         (0, 0, 0),
41
         (0, 0, 0),
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
         (251, 72, 196),
42
         (251, 72, 196),
78
         (251, 72, 196),
43
         (251, 72, 196),
79
         (251, 72, 196),
44
         (251, 72, 196),
82
         (251, 72, 196),
47
         (251, 72, 196),
83
         (251, 72, 196),
48
         (251, 72, 196),
84
         (251, 72, 196),
49
         (251, 72, 196),
50
+        (3, 1, 2),
85
         (0, 0, 0),
51
         (0, 0, 0),
86
         (0, 0, 0),
52
         (0, 0, 0),
87
         (0, 0, 0),
53
         (0, 0, 0),
116
         (251, 72, 196),
82
         (251, 72, 196),
117
         (251, 72, 196),
83
         (251, 72, 196),
118
         (251, 72, 196),
84
         (251, 72, 196),
119
-        (66, 19, 51),
85
+        (0, 0, 0),
120
         (0, 0, 0),
86
         (0, 0, 0),
121
         (0, 0, 0),
87
         (0, 0, 0),
122
         (0, 0, 0),
88
         (0, 0, 0),
132
         (251, 72, 196),
98
         (251, 72, 196),
133
         (251, 72, 196),
99
         (251, 72, 196),
134
         (251, 72, 196),
100
         (251, 72, 196),
135
-        (213, 61, 166),
101
+        (251, 72, 196),
136
         (0, 0, 0),
102
         (0, 0, 0),
137
         (0, 0, 0),
103
         (0, 0, 0),
138
         (0, 0, 0),
104
         (0, 0, 0),
139
     ],
105
     ],
140
     [
106
     [
141
         (0, 0, 0),
107
         (0, 0, 0),
142
-        (245, 70, 191),
143
         (251, 72, 196),
108
         (251, 72, 196),
144
         (251, 72, 196),
109
         (251, 72, 196),
145
         (251, 72, 196),
110
         (251, 72, 196),
111
+        (249, 71, 194),
146
         (0, 0, 0),
112
         (0, 0, 0),
147
         (0, 0, 0),
113
         (0, 0, 0),
148
         (0, 0, 0),
114
         (0, 0, 0),
149
         (0, 0, 0),
115
         (0, 0, 0),
150
-        (234, 67, 183),
116
+        (21, 6, 16),
151
         (251, 72, 196),
117
         (251, 72, 196),
152
         (251, 72, 196),
118
         (251, 72, 196),
153
         (251, 72, 196),
119
         (251, 72, 196),
161
         (0, 0, 0),
127
         (0, 0, 0),
162
         (0, 0, 0),
128
         (0, 0, 0),
163
         (0, 0, 0),
129
         (0, 0, 0),
164
-        (0, 0, 0),
165
-        (251, 72, 196),
130
+        (53, 15, 42),
166
         (251, 72, 196),
131
         (251, 72, 196),
167
         (251, 72, 196),
132
         (251, 72, 196),
168
         (251, 72, 196),
133
         (251, 72, 196),
134
+        (177, 51, 138),
169
         (0, 0, 0),
135
         (0, 0, 0),
170
         (0, 0, 0),
136
         (0, 0, 0),
171
         (0, 0, 0),
137
         (0, 0, 0),
182
         (0, 0, 0),
148
         (0, 0, 0),
183
         (0, 0, 0),
149
         (0, 0, 0),
184
         (0, 0, 0),
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
         (0, 0, 0),
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
         (251, 72, 196),
152
         (251, 72, 196),
222
         (251, 72, 196),
153
         (251, 72, 196),
154
+        (183, 53, 143),
223
         (0, 0, 0),
155
         (0, 0, 0),
224
         (0, 0, 0),
156
         (0, 0, 0),
225
         (0, 0, 0),
157
         (0, 0, 0),
228
         (0, 0, 0),
160
         (0, 0, 0),
229
         (0, 0, 0),
161
         (0, 0, 0),
230
         (0, 0, 0),
162
         (0, 0, 0),
163
+        (71, 20, 55),
231
         (251, 72, 196),
164
         (251, 72, 196),
232
         (251, 72, 196),
165
         (251, 72, 196),
233
         (251, 72, 196),
166
         (251, 72, 196),
234
-        (251, 72, 196),
235
-        (0, 0, 0),
167
+        (129, 37, 101),
236
         (0, 0, 0),
168
         (0, 0, 0),
237
         (0, 0, 0),
169
         (0, 0, 0),
238
         (0, 0, 0),
170
         (0, 0, 0),
274
         (0, 0, 0),
206
         (0, 0, 0),
275
     ],
207
     ],
276
     [
208
     [
277
-        (84, 24, 65),
209
+        (97, 28, 76),
278
         (251, 72, 196),
210
         (251, 72, 196),
279
         (251, 72, 196),
211
         (251, 72, 196),
280
         (0, 0, 0),
212
         (0, 0, 0),
285
         (0, 0, 0),
217
         (0, 0, 0),
286
         (0, 0, 0),
218
         (0, 0, 0),
287
         (0, 0, 0),
219
         (0, 0, 0),
288
-        (251, 72, 196),
220
+        (237, 68, 185),
289
         (251, 72, 196),
221
         (251, 72, 196),
290
         (251, 72, 196),
222
         (251, 72, 196),
291
         (0, 0, 0),
223
         (0, 0, 0),
308
         (0, 0, 0),
240
         (0, 0, 0),
309
     ],
241
     ],
310
     [
242
     [
311
-        (110, 32, 86),
243
+        (86, 25, 67),
312
         (251, 72, 196),
244
         (251, 72, 196),
313
         (251, 72, 196),
245
         (251, 72, 196),
314
         (0, 0, 0),
246
         (0, 0, 0),
319
         (0, 0, 0),
251
         (0, 0, 0),
320
         (0, 0, 0),
252
         (0, 0, 0),
321
         (0, 0, 0),
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
         (251, 72, 196),
255
         (251, 72, 196),
334
         (251, 72, 196),
256
         (251, 72, 196),
335
-        (4, 1, 3),
336
         (0, 0, 0),
257
         (0, 0, 0),
337
         (0, 0, 0),
258
         (0, 0, 0),
338
         (0, 0, 0),
259
         (0, 0, 0),
340
         (0, 0, 0),
261
         (0, 0, 0),
341
         (0, 0, 0),
262
         (0, 0, 0),
342
         (0, 0, 0),
263
         (0, 0, 0),
343
-    ],
344
-    [
345
-        (40, 12, 32),
346
         (251, 72, 196),
264
         (251, 72, 196),
347
         (251, 72, 196),
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
         (251, 72, 196),
266
         (251, 72, 196),
358
         (251, 72, 196),
267
         (251, 72, 196),
359
         (0, 0, 0),
268
         (0, 0, 0),
363
         (0, 0, 0),
272
         (0, 0, 0),
364
         (0, 0, 0),
273
         (0, 0, 0),
365
         (0, 0, 0),
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
         (0, 0, 0),
277
         (0, 0, 0),
398
         (0, 0, 0),
296
         (0, 0, 0),
399
         (0, 0, 0),
297
         (0, 0, 0),
400
         (0, 0, 0),
298
         (0, 0, 0),
401
-        (198, 57, 154),
402
         (251, 72, 196),
299
         (251, 72, 196),
403
         (251, 72, 196),
300
         (251, 72, 196),
404
         (251, 72, 196),
301
         (251, 72, 196),
405
-        (21, 6, 16),
302
+        (251, 72, 196),
303
+        (0, 0, 0),
406
         (0, 0, 0),
304
         (0, 0, 0),
407
         (0, 0, 0),
305
         (0, 0, 0),
408
         (0, 0, 0),
306
         (0, 0, 0),
413
         (0, 0, 0),
311
         (0, 0, 0),
414
         (251, 72, 196),
312
         (251, 72, 196),
415
         (251, 72, 196),
313
         (251, 72, 196),
416
-        (249, 71, 194),
314
+        (251, 72, 196),
417
         (0, 0, 0),
315
         (0, 0, 0),
418
         (0, 0, 0),
316
         (0, 0, 0),
419
         (0, 0, 0),
317
         (0, 0, 0),
433
         (0, 0, 0),
331
         (0, 0, 0),
434
         (0, 0, 0),
332
         (0, 0, 0),
435
         (0, 0, 0),
333
         (0, 0, 0),
334
+        (179, 51, 140),
436
         (251, 72, 196),
335
         (251, 72, 196),
437
         (251, 72, 196),
336
         (251, 72, 196),
438
         (251, 72, 196),
337
         (251, 72, 196),
439
-        (251, 72, 196),
440
-        (0, 0, 0),
338
+        (50, 14, 39),
441
         (0, 0, 0),
339
         (0, 0, 0),
442
         (0, 0, 0),
340
         (0, 0, 0),
443
         (0, 0, 0),
341
         (0, 0, 0),
448
         (251, 72, 196),
346
         (251, 72, 196),
449
         (251, 72, 196),
347
         (251, 72, 196),
450
         (251, 72, 196),
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
         (251, 72, 196),
349
         (251, 72, 196),
460
         (0, 0, 0),
350
         (0, 0, 0),
461
         (0, 0, 0),
351
         (0, 0, 0),
462
         (0, 0, 0),
352
         (0, 0, 0),
463
         (0, 0, 0),
353
         (0, 0, 0),
464
         (0, 0, 0),
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
         (251, 72, 196),
355
         (251, 72, 196),
492
         (251, 72, 196),
356
         (251, 72, 196),
493
         (251, 72, 196),
357
         (251, 72, 196),
587
         (0, 0, 0),
451
         (0, 0, 0),
588
         (0, 0, 0),
452
         (0, 0, 0),
589
         (0, 0, 0),
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
         (251, 72, 196),
454
         (251, 72, 196),
607
         (251, 72, 196),
455
         (251, 72, 196),
608
-        (189, 54, 148),
609
-        (189, 54, 148),
610
-        (211, 60, 164),
611
         (251, 72, 196),
456
         (251, 72, 196),
612
         (251, 72, 196),
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
         (0, 0, 0),
458
         (0, 0, 0),
629
         (0, 0, 0),
459
         (0, 0, 0),
630
         (0, 0, 0),
460
         (0, 0, 0),
642
         (0, 0, 0),
472
         (0, 0, 0),
643
         (0, 0, 0),
473
         (0, 0, 0),
644
         (0, 0, 0),
474
         (0, 0, 0),
645
-        (0, 0, 0),
475
+        (240, 69, 188),
646
         (251, 72, 196),
476
         (251, 72, 196),
647
         (251, 72, 196),
477
         (251, 72, 196),
648
         (251, 72, 196),
478
         (251, 72, 196),
687
         (0, 0, 0),
517
         (0, 0, 0),
688
         (0, 0, 0),
518
         (0, 0, 0),
689
         (0, 0, 0),
519
         (0, 0, 0),
690
-        (246, 71, 192),
520
+        (251, 72, 196),
691
         (251, 72, 196),
521
         (251, 72, 196),
692
         (251, 72, 196),
522
         (251, 72, 196),
693
         (251, 72, 196),
523
         (251, 72, 196),
720
         (0, 0, 0),
550
         (0, 0, 0),
721
         (0, 0, 0),
551
         (0, 0, 0),
722
         (0, 0, 0),
552
         (0, 0, 0),
723
-        (0, 0, 0),
553
+        (208, 60, 162),
554
+        (251, 72, 196),
724
         (251, 72, 196),
555
         (251, 72, 196),
725
         (251, 72, 196),
556
         (251, 72, 196),
726
         (251, 72, 196),
557
         (251, 72, 196),
727
         (251, 72, 196),
558
         (251, 72, 196),
728
         (251, 72, 196),
559
         (251, 72, 196),
729
-        (213, 61, 166),
730
         (0, 0, 0),
560
         (0, 0, 0),
731
         (0, 0, 0),
561
         (0, 0, 0),
732
         (0, 0, 0),
562
         (0, 0, 0),
744
         (0, 0, 0),
574
         (0, 0, 0),
745
         (0, 0, 0),
575
         (0, 0, 0),
746
         (0, 0, 0),
576
         (0, 0, 0),
747
-        (0, 0, 0),
577
+        (10, 3, 8),
748
         (251, 72, 196),
578
         (251, 72, 196),
749
         (251, 72, 196),
579
         (251, 72, 196),
750
         (251, 72, 196),
580
         (251, 72, 196),
753
         (0, 0, 0),
583
         (0, 0, 0),
754
         (0, 0, 0),
584
         (0, 0, 0),
755
         (0, 0, 0),
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
         (138, 40, 108),
586
         (138, 40, 108),
781
         (251, 72, 196),
587
         (251, 72, 196),
782
         (251, 72, 196),
588
         (251, 72, 196),
783
         (251, 72, 196),
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
         (0, 0, 0),
590
         (0, 0, 0),
795
         (0, 0, 0),
591
         (0, 0, 0),
796
         (251, 72, 196),
592
         (251, 72, 196),
820
     [
616
     [
821
         (0, 0, 0),
617
         (0, 0, 0),
822
         (0, 0, 0),
618
         (0, 0, 0),
823
-        (69, 20, 54),
619
+        (242, 69, 189),
824
         (251, 72, 196),
620
         (251, 72, 196),
825
         (251, 72, 196),
621
         (251, 72, 196),
826
         (251, 72, 196),
622
         (251, 72, 196),
829
         (0, 0, 0),
625
         (0, 0, 0),
830
         (251, 72, 196),
626
         (251, 72, 196),
831
         (251, 72, 196),
627
         (251, 72, 196),
832
-        (60, 17, 47),
628
+        (164, 47, 128),
833
         (0, 0, 0),
629
         (0, 0, 0),
834
         (0, 0, 0),
630
         (0, 0, 0),
835
         (0, 0, 0),
631
         (0, 0, 0),
848
         (251, 72, 196),
644
         (251, 72, 196),
849
         (251, 72, 196),
645
         (251, 72, 196),
850
         (251, 72, 196),
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
         (0, 0, 0),
647
         (0, 0, 0),
886
         (0, 0, 0),
648
         (0, 0, 0),
887
     ],
649
     ],
888
     [
650
     [
889
         (0, 0, 0),
651
         (0, 0, 0),
890
-        (251, 72, 196),
652
+        (198, 57, 154),
891
         (251, 72, 196),
653
         (251, 72, 196),
892
         (251, 72, 196),
654
         (251, 72, 196),
893
         (251, 72, 196),
655
         (251, 72, 196),
920
         (0, 0, 0),
682
         (0, 0, 0),
921
     ],
683
     ],
922
     [
684
     [
923
-        (118, 34, 92),
685
+        (0, 0, 0),
924
         (251, 72, 196),
686
         (251, 72, 196),
925
         (251, 72, 196),
687
         (251, 72, 196),
926
         (251, 72, 196),
688
         (251, 72, 196),
968
         (251, 72, 196),
730
         (251, 72, 196),
969
         (251, 72, 196),
731
         (251, 72, 196),
970
         (251, 72, 196),
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
         (251, 72, 196),
733
         (251, 72, 196),
982
         (0, 0, 0),
734
         (0, 0, 0),
983
         (0, 0, 0),
735
         (0, 0, 0),
986
         (0, 0, 0),
738
         (0, 0, 0),
987
         (0, 0, 0),
739
         (0, 0, 0),
988
         (0, 0, 0),
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
         (189, 54, 148),
741
         (189, 54, 148),
1014
         (251, 72, 196),
742
         (251, 72, 196),
1015
         (251, 72, 196),
743
         (251, 72, 196),

+ 58
- 9
manager.py View File

10
 import time
10
 import time
11
 
11
 
12
 class Manager:
12
 class Manager:
13
-    def __init__(self, g):
13
+    def __init__(self, g, i = None, ss = 2):
14
         self.gui = g
14
         self.gui = g
15
+        self.input = i
16
+        self.step_size = ss
15
         self.screens = []
17
         self.screens = []
16
         self.restart()
18
         self.restart()
17
 
19
 
19
         self.index = 0
21
         self.index = 0
20
         self.done = False
22
         self.done = False
21
         self.lastTime = time.time()
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
         if len(self.screens) > 0:
31
         if len(self.screens) > 0:
23
             self.screens[0][0].restart()
32
             self.screens[0][0].restart()
24
 
33
 
29
         v = (s, d)
38
         v = (s, d)
30
         self.screens.append(v)
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
     def draw(self):
84
     def draw(self):
85
+        if self.input != None:
86
+            self.buttons()
87
+
33
         self.screens[self.index][0].draw()
88
         self.screens[self.index][0].draw()
34
 
89
 
35
         if self.screens[self.index][1] == None:
90
         if self.screens[self.index][1] == None:
36
             # let screen decide when it is done
91
             # let screen decide when it is done
37
             if self.screens[self.index][0].finished():
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
         else:
94
         else:
43
             # use given timeout
95
             # use given timeout
44
             now = time.time()
96
             now = time.time()
45
             if ((now - self.lastTime) > self.screens[self.index][1]) or (now < self.lastTime):
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
 if __name__ == "__main__":
100
 if __name__ == "__main__":
52
     from splash import SplashScreen
101
     from splash import SplashScreen

+ 20
- 0
net.py View File

28
     def fail(self, f):
28
     def fail(self, f):
29
         self.failScreen = f
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
     def restart(self):
51
     def restart(self):
32
         self.start = time.time()
52
         self.start = time.time()
33
 
53
 

+ 22
- 13
qr.py View File

107
 if __name__ == "__main__":
107
 if __name__ == "__main__":
108
     import util
108
     import util
109
     import os
109
     import os
110
+    import sys
110
 
111
 
111
     t = util.getTarget()
112
     t = util.getTarget()
112
 
113
 
113
     d = QRScreen(t, "http://ubabot.frubar.net", 10.0, "Drinks:", "tom-thumb", (255, 255, 255), (0, 0, 0))
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
     t.loop(d.draw)
138
     t.loop(d.draw)

Loading…
Cancel
Save