diff --git a/python/screen_grab/screen_grab.py b/python/screen_grab/screen_grab.py index 2ff75f15..325c9b25 100644 --- a/python/screen_grab/screen_grab.py +++ b/python/screen_grab/screen_grab.py @@ -15,6 +15,8 @@ from sgtk.platform.qt import QtCore, QtGui import sgtk +QT_MAJOR = int(QtCore.qVersion().split(".")[0]) # Works for PySide* and PyQt* + class ScreenGrabber(QtGui.QDialog): """ @@ -332,10 +334,26 @@ def get_desktop_pixmap(rect): :returns: Captured image :rtype: :class:`~PySide.QtGui.QPixmap` """ - desktop = QtGui.QApplication.desktop() - return QtGui.QPixmap.grabWindow( - desktop.winId(), rect.x(), rect.y(), rect.width(), rect.height() - ) + desktop_id = QtGui.QApplication.desktop().winId() + x_y_w_h = rect.x(), rect.y(), rect.width(), rect.height() + + if QT_MAJOR == 5: + screen = QtGui.QApplication.primaryScreen() + try: + pixmap = screen.grabWindow(desktop_id, *x_y_w_h) + except TypeError as error: + if "quintptr" in str(error): + ptr_type = getattr(__builtins__, "long", int) # Py3 safe long + pixmap = screen.grabWindow(ptr_type(desktop_id), *x_y_w_h) + else: + raise + elif QT_MAJOR == 4: + pixmap = QtGui.QPixmap.grabWindow(desktop_id, *x_y_w_h) + else: + message = "Screen capture not implmented for Qt %d" + raise NotImplementedError(message % QT_MAJOR) + + return pixmap # Backwards compatibility, as this used to be a module-level