def ensure_on_screen(rect): """ Ensure that the given rect is contained on screen. If the origin of the rect is not contained within the closest desktop screen, the rect will be moved so that it is fully on the closest screen. If the rect is larger than the closest screen, the origin will never be less than the screen origin. Parameters ---------- rect : QRect The geometry rect of interest. Returns ------- result : QRect The potentially adjusted QRect which fits on the screen. """ d = QApplication.desktop() pos = rect.topLeft() drect = d.screenGeometry(pos) if not drect.contains(pos): x = pos.x() if x < drect.x() or x > drect.right(): dw = drect.width() - rect.width() x = max(drect.x(), drect.x() + dw) y = pos.y() if x < drect.top() or y > drect.bottom(): dh = drect.height() - rect.height() y = max(drect.y(), drect.y() + dh) rect = QRect(x, y, rect.width(), rect.height()) return rect
def snapshot(self): """ Take a snapshot of the window and close it. """ widget = self.view.proxy.widget framesize = widget.window().frameSize() QPixmap.grabWindow(QApplication.desktop().winId(), widget.x(), widget.y(), framesize.width(), framesize.height()).save(self.path) widget.close()
def snapshot(self): """ Take a snapshot of the window and close it. """ widget = self.view.proxy.widget framesize = widget.window().frameSize() screen = QApplication.primaryScreen() screen.grabWindow( QApplication.desktop().winId(), widget.x(), widget.y(), framesize.width(), framesize.height() ).save(self.path) self.view.close()