Created
February 2, 2011 02:53
-
-
Save snim2/807169 to your computer and use it in GitHub Desktop.
Captures screenshots and displays them
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python | |
| # | |
| # Capture and display screenshots. | |
| # Requires ImageMagick, PIL and PyGame. | |
| # | |
| import os | |
| import pygame | |
| from pygame.locals import * | |
| __author__ = 'Sarah Mount' | |
| __date__ = 'Feb 2011' | |
| def get_screen_resolution(fname='screen.jpg'): | |
| # Uses Python Image Library | |
| import Image | |
| cmd = "import -window root %s" % fname | |
| os.system(cmd) | |
| im = Image.open(fname) | |
| return im.size | |
| def get_shot(fname='screen.jpg'): | |
| # Grab a single screenshot | |
| # Just to find the screen resolution | |
| # We could use ImageGrab from the PIL libraries, | |
| # but currently they are Windows only. | |
| cmd = "import -window root %s" % fname | |
| os.system(cmd) | |
| surface = pygame.image.load(fname) | |
| surface.convert() # Makes blitting a bit faster | |
| return surface | |
| def screenie(): | |
| # Set up PyGame | |
| pygame.init() | |
| display = pygame.display.set_mode(get_screen_resolution(), 0) | |
| while True: | |
| capture = get_shot() | |
| print 'Bliting screenshot' | |
| display.blit(capture, (0,0)) | |
| # Deal with QUIT events | |
| for e in pygame.event.get(): | |
| if e.type == QUIT: | |
| return | |
| if __name__ == '__main__': | |
| screenie() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment