Attachment 'DesktopScreenShotPIL.py'

Download

   1 """
   2 Desktop_ScreenShot_Using_PIL_Demo.py
   3 Original file name: screen.py
   4 
   5 Simplified from :
   6 http ://www.techontour.com/programming/2008/09/17/linux-windows-usage-surveillance-in-python/
   7 
   8 "Linux [and Microsoft] Windows Usage Surveillance in Python"
   9 "Part 1 : Python Screen Capture"
  10 
  11 September 17th, 2008 by Skilla Repok
  12 
  13 -----
  14 
  15 ImageMagick and its add-on package for WX.Python also has the ability to take screenshots,
  16 but is a cross-platform package.
  17 
  18 As far as I know, PIL is only available for MSW platforms.
  19 
  20 Ray Pasco   2010-03-23
  21 pascor(at)verizon(dot)net
  22 
  23 """
  24 
  25 import os, sys, platform
  26 import shutil
  27 
  28 isMSW = False
  29 if os.name == 'nt' :
  30     isMSW = True
  31     import ImageGrab
  32 else :      # Assume Linux/GTK
  33     from config import launchCommand
  34 #end if
  35 
  36 #------------------------------------------------------------------------------
  37 
  38 def GrabScreen( filename ) :
  39     """
  40     Capture a screen shot of the current Desktop.
  41     For MSW platforms, only.
  42     """
  43 
  44     if platform.system() =='Windows' :
  45         img = ImageGrab.grab()      # ImageGrab is a module from the PIL package
  46         img.save( filename )        #  similar to the Image module.
  47         
  48     else :      # ??? Is this a Linux hack or always a perfectly acceptable command line :
  49         launchCommand( '/usr/bin/xwd -display  :0 -root -out %s' % filename )
  50     #end if
  51     
  52 #end def
  53 
  54 #==============================================================================
  55 
  56 if __name__ == '__main__'  :
  57     
  58     GrabScreen( 'Desktop_ScreenShot_Using_PIL_Demo.png' )
  59     
  60 #end if

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.
  • [get | view] (2011-04-02 19:08:14, 23.2 KB) [[attachment:BitmapManip.py]]
  • [get | view] (2011-03-27 19:21:24, 1.6 KB) [[attachment:DesktopScreenShotPIL.py]]
  • [get | view] (2012-12-25 18:23:31, 8.7 KB) [[attachment:ImgConv.py]]
  • [get | view] (2011-06-06 16:22:42, 4.6 KB) [[attachment:ScreenShotWX.py]]
  • [get | view] (2011-06-06 16:22:51, 3.9 KB) [[attachment:ScreenShotWX_Demo.py]]
  • [get | view] (2011-05-16 01:34:32, 8.5 KB) [[attachment:Win32IconImagePlugin.py]]
 All files | Selected Files: delete move to page copy to page

You are not allowed to attach a file to this page.

NOTE: To edit pages in this wiki you must be a member of the TrustedEditorsGroup.