def save(self): """ Saves the snapshot based on the current region. """ # close down the snapshot widget if self.hideWindow(): self.hideWindow().hide() self.hide() QApplication.processEvents() time.sleep(1) # create the pixmap to save wid = QApplication.desktop().winId() if not self._region.isNull(): x = self._region.x() y = self._region.y() w = self._region.width() h = self._region.height() else: x = self.x() y = self.y() w = self.width() h = self.height() pixmap = QPixmap.grabWindow(wid, x, y, w, h) pixmap.save(self.filepath()) self.close() self.deleteLater() if self.hideWindow(): self.hideWindow().show()
def capture(rect=None, filepath='', prompt=True, hideWindow=None): """ Prompts the user to capture the screen. :param rect | <QRect> filepath | <str> prompt | <bool> :return (<str> filepath, <bool> accepted) """ widget = XSnapshotWidget(QApplication.desktop()) widget.setRegion(rect) widget.setHideWindow(hideWindow) widget.setFilepath(filepath) widget.move(1, 1) widget.resize(QApplication.desktop().size()) if prompt or not filepath: widget.show() else: widget.save()