Bladeren bron

kind of fix manager

Thomas Buck 1 jaar geleden
bovenliggende
commit
ca04c1c52f
5 gewijzigde bestanden met toevoegingen van 32 en 31 verwijderingen
  1. 1
    1
      camp_pico.py
  2. 1
    1
      camp_small.py
  3. 26
    25
      manager.py
  4. 3
    3
      net.py
  5. 1
    1
      scroll.py

+ 1
- 1
camp_pico.py Bestand weergeven

@@ -62,7 +62,7 @@ d.fail(fail)
62 62
 
63 63
 # Main "Menu"
64 64
 m = Manager(t, i)
65
-m.add(QRScreen(t, img_data, 15.0))
65
+m.add(QRScreen(t, img_data, 15.0, None, None, (255, 255, 255), (0, 0, 0)))
66 66
 m.add(Solid(t, 1.0))
67 67
 m.add(d) # HTTP Check, either "success" or "fail"
68 68
 m.add(Solid(t, 1.0))

+ 1
- 1
camp_small.py Bestand weergeven

@@ -25,7 +25,7 @@ import util
25 25
 #url = "http://ubabot.frubar.net"
26 26
 url = "http://www.xythobuz.de"
27 27
 
28
-scroll_speed = 15
28
+scroll_speed = 50
29 29
 
30 30
 # Need to import InputWrapper before initializing RGB Matrix on Pi
31 31
 i = util.getInput()

+ 26
- 25
manager.py Bestand weergeven

@@ -42,50 +42,51 @@ class Manager:
42 42
         keys = self.input.get()
43 43
 
44 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)
45
+            self.switch_to(-1, False)
53 46
         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)
47
+            self.switch_to(1, False)
62 48
 
63 49
         self.old_keys = keys.copy()
64 50
 
65
-    def child_count(self, i):
51
+    def child_count(self, i, update_flag):
66 52
         if i > 0:
67
-            index = int(self.index / self.step_size)
68
-            l = int(len(self.screens) / self.step_size)
53
+            if update_flag:
54
+                index = self.index
55
+                l = len(self.screens)
56
+            else:
57
+                index = int(self.index / self.step_size)
58
+                l = int(len(self.screens) / self.step_size)
59
+            #print(self.index, len(self.screens), index, l, (index >= (l - 1)))
69 60
             return index >= (l - 1)
70 61
         else:
71 62
             return self.index <= 0
72 63
 
73
-    def switch_to(self, i, update_flag):
64
+    def switch_this_to(self, i, update_flag):
74 65
         self.lastTime = time.time()
75 66
 
76 67
         if update_flag:
77
-            self.done = (self.index == 0)
78
-
79 68
             # go through all for normal operation
80 69
             self.index = (self.index + i) % len(self.screens)
81 70
         else:
82 71
             # use step_size for button presses
83 72
             self.index = int((int(self.index / self.step_size) + i) * self.step_size) % len(self.screens)
84 73
 
74
+        self.done = self.child_count(i, update_flag)
75
+
85 76
         #print("Manager ", len(self.screens), " switch to ", self.index, update_flag)
86 77
 
87 78
         self.screens[self.index][0].restart()
88 79
 
80
+    def switch_to(self, i, update_flag):
81
+        c = self.screens[self.index][0]
82
+        if hasattr(c, "switch_to") and hasattr(c, "child_count"):
83
+            if c.child_count(i, update_flag):
84
+                self.switch_this_to(i, update_flag)
85
+            else:
86
+                c.switch_to(i, update_flag)
87
+        else:
88
+            self.switch_this_to(i, update_flag)
89
+
89 90
     def draw(self):
90 91
         if self.input != None:
91 92
             self.buttons()
@@ -117,15 +118,15 @@ if __name__ == "__main__":
117 118
     splash.draw()
118 119
     t.loop_end()
119 120
 
120
-    m = Manager(t, i)
121
-
122 121
     sub = Manager(t)
123 122
     sub.add(ScrollText(t, "Hello", "ib8x8u"))
124 123
     sub.add(Solid(t, 1.0, (0, 255, 0)))
125 124
     sub.add(ScrollText(t, "World", "ib8x8u"))
126 125
     sub.add(Solid(t, 1.0, (0, 0, 255)))
126
+
127
+    m = Manager(t, i)
127 128
     m.add(sub)
128
-    m.add(Solid(t, 1.0))
129
+    m.add(Solid(t, 1.0, (255, 255, 0)))
129 130
 
130 131
     m.add(ScrollText(t, "This appears once", "ib8x8u"))
131 132
     m.add(Solid(t, 1.0))

+ 3
- 3
net.py Bestand weergeven

@@ -29,14 +29,14 @@ class CheckHTTP:
29 29
         self.failScreen = f
30 30
 
31 31
     # Compatibility to Manager button events
32
-    def child_count(self, i):
32
+    def child_count(self, i, update_flag):
33 33
         self.request()
34 34
         if self.response:
35 35
             if hasattr(self.successScreen, "child_count"):
36
-                return self.successScreen.child_count(i)
36
+                return self.successScreen.child_count(i, update_flag)
37 37
         else:
38 38
             if hasattr(self.failScreen, "child_count"):
39
-                return self.failScreen.child_count(i)
39
+                return self.failScreen.child_count(i, update_flag)
40 40
         return True
41 41
 
42 42
     # Compatibility to Manager button events

+ 1
- 1
scroll.py Bestand weergeven

@@ -78,7 +78,7 @@ if __name__ == "__main__":
78 78
 
79 79
         fontName = filename[:-4]
80 80
         s = fontName + " Abcdefgh " + fontName
81
-        m.add(ScrollText(t, s, fontName, 1, 75, (0, 255, 0), (0, 0, 25)))
81
+        m.add(ScrollText(t, s, fontName, 1, 50, (0, 255, 0), (0, 0, 25)))
82 82
 
83 83
     m.restart()
84 84
     util.loop(t, m.draw)

Laden…
Annuleren
Opslaan