Advertisement
Guest User

python framebuffer

a guest
Oct 4th, 2015
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.14 KB | None | 0 0
  1. import os
  2. import pygame
  3. import time
  4. import random
  5.  
  6. class pyscope :
  7. screen = None;
  8.  
  9. def __init__(self):
  10. "Ininitializes a new pygame screen using the framebuffer"
  11. # Based on "Python GUI in Linux frame buffer"
  12. # http://www.karoltomala.com/blog/?p=679
  13. disp_no = os.getenv("DISPLAY")
  14. if disp_no:
  15. print "I'm running under X display = {0}".format(disp_no)
  16.  
  17. # Check which frame buffer drivers are available
  18. # Start with fbcon since directfb hangs with composite output
  19. drivers = ['fbcon', 'directfb', 'svgalib']
  20. found = False
  21. for driver in drivers:
  22. # Make sure that SDL_VIDEODRIVER is set
  23. if not os.getenv('SDL_VIDEODRIVER'):
  24. os.putenv('SDL_VIDEODRIVER', driver)
  25. try:
  26. pygame.display.init()
  27. except pygame.error:
  28. print 'Driver: {0} failed.'.format(driver)
  29. continue
  30. found = True
  31. break
  32.  
  33. if not found:
  34. raise Exception('No suitable video driver found!')
  35.  
  36. size = (pygame.display.Info().current_w, pygame.display.Info().current_h)
  37. print "Framebuffer size: %d x %d" % (size[0], size[1])
  38. self.screen = pygame.display.set_mode(size, pygame.FULLSCREEN)
  39. # Clear the screen to start
  40. self.screen.fill((0, 0, 0))
  41. # Initialise font support
  42. pygame.font.init()
  43. # Render the screen
  44. pygame.display.update()
  45.  
  46. def __del__(self):
  47. "Destructor to make sure pygame shuts down, etc."
  48.  
  49. def test(self):
  50. # Fill the screen with red (255, 0, 0)
  51. red = (255, 0, 0)
  52. self.screen.fill(red)
  53. # Update the display
  54. pygame.display.update()
  55.  
  56. # Create an instance of the PyScope class
  57. scope = pyscope()
  58. scope.test()
  59. time.sleep(10)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement