--- a/Snapshot/SnapshotRegionGrabber.py Tue Oct 15 22:03:54 2013 +0200 +++ b/Snapshot/SnapshotRegionGrabber.py Fri Oct 18 23:00:41 2013 +0200 @@ -10,8 +10,8 @@ from __future__ import unicode_literals # __IGNORE_WARNING__ from PyQt4.QtCore import pyqtSignal, Qt, QRect, QPoint, QTimer, qVersion -from PyQt4.QtGui import QWidget, QPixmap, QColor, QRegion, QApplication, QPainter, \ - QPalette, QToolTip, QPaintEngine, QPen, QBrush +from PyQt4.QtGui import QWidget, QPixmap, QColor, QRegion, QApplication, \ + QPainter, QPalette, QToolTip, QPaintEngine, QPen, QBrush def drawRect(painter, rect, outline, fill=QColor()): @@ -94,8 +94,8 @@ self.__RHandle, self.__BHandle] self.__helpTextRect = QRect() self.__helpText = self.trUtf8( - "Select a region using the mouse. To take the snapshot, press the Enter key" - " or double click. Press Esc to quit.") + "Select a region using the mouse. To take the snapshot, press" + " the Enter key or double click. Press Esc to quit.") self.__pixmap = QPixmap() @@ -164,11 +164,13 @@ if self.__showHelp: painter.setPen(textColor) painter.setBrush(textBackgroundColor) - self.__helpTextRect = painter.boundingRect(self.rect().adjusted(2, 2, -2, -2), + self.__helpTextRect = painter.boundingRect( + self.rect().adjusted(2, 2, -2, -2), Qt.TextWordWrap, self.__helpText).translated( -self.__desktop.x(), -self.__desktop.y()) self.__helpTextRect.adjust(-2, -2, 4, 2) - drawRect(painter, self.__helpTextRect, textColor, textBackgroundColor) + drawRect(painter, self.__helpTextRect, textColor, + textBackgroundColor) painter.drawText(self.__helpTextRect.adjusted(3, 3, -3, -3), Qt.TextWordWrap, self.__helpText) @@ -210,7 +212,8 @@ boundingRect.moveBottomLeft(QPoint(r.right() + 3, r.bottom())) textRect.moveBottomLeft(QPoint(r.right() + 5, r.bottom())) - # If the above didn't catch it, you are running on a very tiny screen... + # If the above didn't catch it, you are running on a very + # tiny screen... drawRect(painter, boundingRect, textColor, textBackgroundColor) painter.drawText(textRect, Qt.AlignHCenter, txt) @@ -220,11 +223,13 @@ self.__updateHandles() painter.setPen(Qt.NoPen) painter.setBrush(handleColor) - painter.setClipRegion(self.__handleMask(SnapshotRegionGrabber.StrokeMask)) + painter.setClipRegion( + self.__handleMask(SnapshotRegionGrabber.StrokeMask)) painter.drawRect(self.rect()) handleColor.setAlpha(60) painter.setBrush(handleColor) - painter.setClipRegion(self.__handleMask(SnapshotRegionGrabber.FillMask)) + painter.setClipRegion( + self.__handleMask(SnapshotRegionGrabber.FillMask)) painter.drawRect(self.rect()) def resizeEvent(self, evt): @@ -283,14 +288,16 @@ p = evt.pos() r = self.rect() self.__selection = self.__normalizeSelection( - QRect(self.__dragStartPoint, self.__limitPointToRect(p, r))) + QRect(self.__dragStartPoint, + self.__limitPointToRect(p, r))) elif self.__mouseOverHandle is None: # moving the whole selection r = self.rect().normalized() s = self.__selectionBeforeDrag.normalized() p = s.topLeft() + evt.pos() - self.__dragStartPoint r.setBottomRight( - r.bottomRight() - QPoint(s.width(), s.height()) + QPoint(1, 1)) + r.bottomRight() - QPoint(s.width(), + s.height()) + QPoint(1, 1)) if not r.isNull() and r.isValid(): self.__selection.moveTo(self.__limitPointToRect(p, r)) else: @@ -315,7 +322,8 @@ r.setRight(r.right() + offset.x()) r.setTopLeft(self.__limitPointToRect(r.topLeft(), self.rect())) - r.setBottomRight(self.__limitPointToRect(r.bottomRight(), self.rect())) + r.setBottomRight( + self.__limitPointToRect(r.bottomRight(), self.rect())) self.__selection = self.__normalizeSelection(r) self.update() @@ -337,13 +345,17 @@ else: self.setCursor(Qt.CrossCursor) else: - if self.__mouseOverHandle in [self.__TLHandle, self.__BRHandle]: + if self.__mouseOverHandle in [self.__TLHandle, + self.__BRHandle]: self.setCursor(Qt.SizeFDiagCursor) - elif self.__mouseOverHandle in [self.__TRHandle, self.__BLHandle]: + elif self.__mouseOverHandle in [self.__TRHandle, + self.__BLHandle]: self.setCursor(Qt.SizeBDiagCursor) - elif self.__mouseOverHandle in [self.__LHandle, self.__RHandle]: + elif self.__mouseOverHandle in [self.__LHandle, + self.__RHandle]: self.setCursor(Qt.SizeHorCursor) - elif self.__mouseOverHandle in [self.__THandle, self.__BHandle]: + elif self.__mouseOverHandle in [self.__THandle, + self.__BHandle]: self.setCursor(Qt.SizeVerCursor) def mouseReleaseEvent(self, evt): @@ -394,14 +406,17 @@ self.__LHandle.moveTopLeft(QPoint(r.x(), r.y() + r.height() // 2 - s2)) self.__THandle.moveTopLeft(QPoint(r.x() + r.width() // 2 - s2, r.y())) - self.__RHandle.moveTopRight(QPoint(r.right(), r.y() + r.height() // 2 - s2)) - self.__BHandle.moveBottomLeft(QPoint(r.x() + r.width() // 2 - s2, r.bottom())) + self.__RHandle.moveTopRight( + QPoint(r.right(), r.y() + r.height() // 2 - s2)) + self.__BHandle.moveBottomLeft( + QPoint(r.x() + r.width() // 2 - s2, r.bottom())) def __handleMask(self, maskType): """ Private method to calculate the handle mask. - @param maskType type of the mask to be used (SnapshotRegionGrabber.FillMask or + @param maskType type of the mask to be used + (SnapshotRegionGrabber.FillMask or SnapshotRegionGrabber.StrokeMask) @return calculated mask (QRegion) """ @@ -476,8 +491,10 @@ pt = QPainter() pt.begin(pixmap2) if pt.paintEngine().hasFeature(QPaintEngine.PorterDuff): - pt.setRenderHints(QPainter.Antialiasing | \ - QPainter.HighQualityAntialiasing | QPainter.SmoothPixmapTransform, + pt.setRenderHints( + QPainter.Antialiasing | \ + QPainter.HighQualityAntialiasing | \ + QPainter.SmoothPixmapTransform, True) pt.setBrush(Qt.black) pt.setPen(QPen(QBrush(Qt.black), 0.5)) @@ -487,7 +504,8 @@ pt.setClipRegion(translatedEll) pt.setCompositionMode(QPainter.CompositionMode_Source) - pt.drawPixmap(pixmap2.rect(), self.__pixmap, ell.boundingRect()) + pt.drawPixmap(pixmap2.rect(), self.__pixmap, + ell.boundingRect()) pt.end() self.grabbed.emit(pixmap2)