A Raspberry Pi pipeline viewer
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.

70 lines
1.8 KiB

  1. #!/usr/bin/env python
  2. # encoding: utf-8
  3. import sys
  4. import pygame
  5. class RasPipe:
  6. size = width, height = 320, 240
  7. font_size = 30
  8. black = (0, 0, 0)
  9. white = (255,255,255)
  10. input_buffer_size = 100
  11. input_lines = []
  12. def __init__(self, infile):
  13. self.infile = infile
  14. pygame.init()
  15. self.screen = pygame.display.set_mode(self.size)
  16. self.font = pygame.font.Font(None, self.font_size)
  17. def run(self):
  18. line = self.infile.readline()
  19. while line:
  20. for event in pygame.event.get():
  21. if event.type == pygame.QUIT:
  22. sys.exit()
  23. self.scale_display()
  24. self.screen.fill(self.black)
  25. # Get last 7 lines of input...
  26. to_render = self.input_lines[-self.display_lines:]
  27. # ...and scroll them up the display.
  28. y = 0
  29. for render_line in to_render:
  30. y += self.font_size
  31. text_surface = self.font.render(render_line.rstrip(), True, self.white)
  32. rect = text_surface.get_rect(center=(160, y))
  33. self.screen.blit(text_surface, rect)
  34. pygame.display.flip()
  35. pygame.time.wait(100);
  36. self.input_lines.append(line)
  37. line = self.infile.readline()
  38. def scale_display(self):
  39. original_font_size = self.font_size
  40. # How big should our font be?
  41. if len(self.input_lines) > 20:
  42. self.font_size = 20
  43. if len(self.input_lines) > 50:
  44. self.font_size = 15
  45. if len(self.input_lines) > 100:
  46. self.font_size = 10
  47. if self.font_size != original_font_size:
  48. self.font = pygame.font.Font(None, self.font_size)
  49. # How many lines of text to display?
  50. self.display_lines = (self.size[1] / self.font_size) - 1
  51. rp = RasPipe(sys.stdin)
  52. rp.run()