|
@@ -0,0 +1,73 @@
|
|
1
|
+#!/usr/bin/env python3
|
|
2
|
+
|
|
3
|
+# ----------------------------------------------------------------------------
|
|
4
|
+# "THE BEER-WARE LICENSE" (Revision 42):
|
|
5
|
+# <xythobuz@xythobuz.de> wrote this file. As long as you retain this notice
|
|
6
|
+# you can do whatever you want with this stuff. If we meet some day, and you
|
|
7
|
+# think this stuff is worth it, you can buy me a beer in return. Thomas Buck
|
|
8
|
+# ----------------------------------------------------------------------------
|
|
9
|
+
|
|
10
|
+import time
|
|
11
|
+import qrcode
|
|
12
|
+import util
|
|
13
|
+
|
|
14
|
+class QRScreen:
|
|
15
|
+ def __init__(self, g, d, t = 10.0, c1 = (0, 0, 0), c2 = (255, 255, 255)):
|
|
16
|
+ self.gui = g
|
|
17
|
+ self.time = t
|
|
18
|
+ self.c1 = c1
|
|
19
|
+ self.c2 = c2
|
|
20
|
+
|
|
21
|
+ qr = qrcode.QRCode(
|
|
22
|
+ box_size = 1,
|
|
23
|
+ border = 0,
|
|
24
|
+ )
|
|
25
|
+ qr.add_data(d)
|
|
26
|
+ qr.make(fit = True)
|
|
27
|
+
|
|
28
|
+ if util.isPi():
|
|
29
|
+ # work-around for weird bug in old qrcode lib?
|
|
30
|
+ self.image = qr.make_image(fill_color = "black", back_color = "white")
|
|
31
|
+ self.c1 = (0, 0, 0)
|
|
32
|
+ self.c2 = (255, 255, 255)
|
|
33
|
+ else:
|
|
34
|
+ self.image = qr.make_image(fill_color = self.c1, back_color = self.c2)
|
|
35
|
+
|
|
36
|
+ self.xOff = int((self.gui.width - self.image.width) / 2)
|
|
37
|
+ self.yOff = int((self.gui.height - self.image.height) / 2)
|
|
38
|
+
|
|
39
|
+ self.restart()
|
|
40
|
+
|
|
41
|
+ def restart(self):
|
|
42
|
+ self.start = time.time()
|
|
43
|
+
|
|
44
|
+ def finished(self):
|
|
45
|
+ return (time.time() - self.start) >= self.time
|
|
46
|
+
|
|
47
|
+ def draw(self):
|
|
48
|
+ # fill border, if needed
|
|
49
|
+ if self.c2 != (0, 0, 0):
|
|
50
|
+ for x in range(0, self.gui.width):
|
|
51
|
+ for y in range(0, self.yOff):
|
|
52
|
+ self.gui.set_pixel(x, y, self.c2)
|
|
53
|
+ for y in range(0, self.gui.height - self.image.height - self.yOff):
|
|
54
|
+ self.gui.set_pixel(x, y + self.yOff + self.image.height, self.c2)
|
|
55
|
+ for y in range(0, self.image.height):
|
|
56
|
+ for x in range(0, self.xOff):
|
|
57
|
+ self.gui.set_pixel(x, y + self.yOff, self.c2)
|
|
58
|
+ for x in range(0, self.gui.width - self.image.width - self.xOff):
|
|
59
|
+ self.gui.set_pixel(x + self.xOff + self.image.width, y + self.yOff, self.c2)
|
|
60
|
+
|
|
61
|
+ for x in range(0, self.image.width):
|
|
62
|
+ for y in range(0, self.image.height):
|
|
63
|
+ v = self.image.getpixel((x, y))
|
|
64
|
+ if isinstance(v, int):
|
|
65
|
+ v = (v, v, v)
|
|
66
|
+ self.gui.set_pixel(x + self.xOff, y + self.yOff, v)
|
|
67
|
+
|
|
68
|
+if __name__ == "__main__":
|
|
69
|
+ import util
|
|
70
|
+ t = util.getTarget()
|
|
71
|
+
|
|
72
|
+ d = QRScreen(t, "Hello World")
|
|
73
|
+ t.debug_loop(d.draw)
|