1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
   |  
# -*- coding: utf-8 -*-
 
import sys
import subprocess
from PyQt4 import QtGui, QtCore
 
def grab_screen():
    return QtGui.QPixmap.grabWindow(QtGui.QApplication.desktop().winId())
 
def get_area_geometry():
    rep = subprocess.Popen(["import", "-identify", "/dev/null"],
                            universal_newlines=True,
                            stdout=subprocess.PIPE).communicate()
 
    try:
        items = rep[0].split()
        w, h = items[2].split('x')
        x, y = items[3].split('+')[-2:]
    except Exception as why:
        print('Suprocess return: %s' % str(rep))
        print(why)
        sys.exit()
 
    return [int(i) for i in (x, y, w, h)]
 
def shoot_area():
    left, up, width, height = get_area_geometry()
    screen = grab_screen()
    img = screen.copy(QtCore.QRect(left, up, width, height))
    img.save('myScreenshot.png')
 
if __name__ == '__main__':
    app = QtGui.QApplication([])
    shoot_area() | 
Partager