Attachment 'ScreenShotWX_Demo.py'

Download

   1 """
   2 Demo app for ScreenShotWX.py
   3 
   4 1) Capture the entire main screen; 
   5 2) Capture 4 arbitrary (1/16th area) portions of the main screen.
   6 
   7 
   8 Ray Pasco
   9 pascor(at)verizon.net
  10 2011-06-06
  11 
  12 """
  13 import sys
  14 import wx
  15 
  16 import ScreenShotWX as ssw
  17 
  18 #------------------------------------------------------------------------------
  19 
  20 def WhatsInstalled() :
  21 
  22     # What Python and wxPython versions are installed ?
  23     import os, platform
  24     
  25     if os.name == 'nt' :
  26         print 'Windows  ', platform.win32_ver()[1]
  27     else :
  28         print 'Platform ', platform.system()
  29     #end if
  30     print 'Python   ', sys.version
  31     addon_pkgs = [ ('Wx Version',  'wx.VERSION_STRING'),
  32                    ('Wx Platform', 'wx.PlatformInfo'),  ]
  33                    
  34     for addonStr, attribute in addon_pkgs :
  35         try :
  36             print addonStr, eval( attribute )
  37         except NameError :
  38             print
  39     #end for
  40     
  41 #end WhatsInstalled def
  42 
  43 #==============================================================================
  44 
  45 if __name__ == '__main__' :
  46     """
  47     1) Capture the entire main screen; 
  48     2) Capture 4 arbitrary (1/16th area) portions of the main screen.
  49     Save all shots to separate files.
  50     """
  51     WhatsInstalled()    # Print this platform's Python and wxPython versions.
  52     
  53     # Need to access WX functionality without using MainLoop().
  54     thisApp = wx.App( redirect=False )
  55     
  56     """
  57     The primary desktop screen area excluding the Taskbar.
  58     This isn't implemented in MSW WX Version 2.8.11.0
  59         captureBmapSize = wx.Display( 1 ).GetClientArea()   
  60     """
  61     
  62     # Capture the entire primary Desktop screen.
  63     captureBmapSize = (wx.SystemSettings.GetMetric( wx.SYS_SCREEN_X ), 
  64                        wx.SystemSettings.GetMetric( wx.SYS_SCREEN_Y ) )
  65     print '>>>>  Screen Size ', captureBmapSize
  66     
  67     captureStartPos = (0, 0)    # Arbitrary U-L position anywhere within the screen
  68     bitmap = ssw.ScreenCapture( captureStartPos, captureBmapSize )
  69     
  70     fileBasename = 'ScreenShotWX_Demo'
  71     fileExt = '.png'
  72     filename = fileBasename + '_WholeScreen' + fileExt
  73     print '     ', filename
  74     bitmap.SaveFile( filename, wx.BITMAP_TYPE_PNG )
  75     
  76     #----------------------------------
  77     
  78     """
  79     Take 4 small screenshots for demonstration purposes. 
  80     Each will be 1/16th of the screen area
  81       on a diagonal path from the U-L to the Lower-Right of the main screen.
  82     
  83     Apparently, wx.SYS_SCREEN_X and  wx.SYS_SCREEN_Y only apply to the main screen
  84       and not to any Exrended Desktop. 
  85       Use wx.Display( n ) to query any extended Desktop screen sizes.
  86     """
  87     numShots = 4
  88     shotBitmapSize = (wx.SystemSettings.GetMetric( wx.SYS_SCREEN_X ) / numShots,
  89                       wx.SystemSettings.GetMetric( wx.SYS_SCREEN_Y ) / numShots  )
  90     print '\n>>>>  shotBitmapSize', shotBitmapSize
  91     
  92     ## On my system there's an extended Desktop screen above the primary screen.
  93     ## It happens to have the same geometry as the main screen (but this isn't required).
  94     ## So, screen shots can be made there simply by using negative Y ordinate values:
  95     #startPos = (0, -800)     # First shot will start in the upper-left extension screen corner.
  96     
  97     # Capture portions of the main screen:
  98     startPos = (0, 0)     # First shot origin is at the upper-left corner of the main screen.
  99     for shotCtr in range( numShots ) :
 100         
 101         print '----  startPos', startPos
 102         
 103         bitmap = ssw.ScreenCapture( startPos, shotBitmapSize )
 104         
 105         filename = "%s_%i%s" % (fileBasename, shotCtr, fileExt)
 106         print '     ', filename
 107         bitmap.SaveFile( filename, wx.BITMAP_TYPE_PNG )
 108         
 109         # Increment the starting Coordinate.
 110         startPos = tuple( [i + j for i, j  in zip( startPos, shotBitmapSize ) ] ) 
 111         print
 112         
 113     #end for
 114     
 115 #end if __name__

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.