Python RGB Matrix games and animations https://www.xythobuz.de/ledmatrix_v2.html
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

manager.py 1.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #!/usr/bin/env python3
  2. import time
  3. class Manager:
  4. def __init__(self, g):
  5. self.gui = g
  6. self.screens = []
  7. self.index = 0
  8. self.restart()
  9. def restart(self):
  10. self.lastTime = time.time()
  11. def add(self, s, d = None):
  12. v = (s, d)
  13. self.screens.append(v)
  14. def loop(self):
  15. self.screens[self.index][0].draw()
  16. if self.screens[self.index][1] == None:
  17. # let screen decide when it is done
  18. if self.screens[self.index][0].finished():
  19. self.index = (self.index + 1) % len(self.screens)
  20. self.lastTime = time.time()
  21. self.screens[self.index][0].restart()
  22. else:
  23. # use given timeout
  24. if (time.time() - self.lastTime) > self.screens[self.index][1]:
  25. self.index = (self.index + 1) % len(self.screens)
  26. self.lastTime = time.time()
  27. self.screens[self.index][0].restart()
  28. if __name__ == "__main__":
  29. from splash import SplashScreen
  30. #from weather import WeatherScreen
  31. from draw import ScrollText
  32. from solid import Solid
  33. from life import GameOfLife
  34. import platform
  35. t = None
  36. if platform.machine() == "armv7l":
  37. from pi import PiMatrix
  38. t = PiMatrix()
  39. else:
  40. from test import TestGUI
  41. t = TestGUI()
  42. m = Manager(t)
  43. m.add(SplashScreen(t), 2)
  44. m.add(Solid(t, 1.0))
  45. #m.add(WeatherScreen(t), 4)
  46. #m.add(Solid(t, 1.0))
  47. m.add(ScrollText(t, "This appears once"))
  48. m.add(Solid(t, 1.0))
  49. m.add(ScrollText(t, "And this twice...", 2))
  50. m.add(Solid(t, 1.0))
  51. m.add(GameOfLife(t, 20, (0, 255, 0), (0, 0, 0), 20.0))
  52. m.add(Solid(t, 1.0))
  53. m.restart()
  54. t.debug_loop(m.loop)