Python PyQt5.QtGui.QTransform() Examples

The following are code examples for showing how to use PyQt5.QtGui.QTransform(). They are from open source Python projects. You can vote up the examples you like or vote down the ones you don't like.

Example 1
Project: Cyphus   Author: FuriousDCSL   File: BSEditor.py    GNU General Public License v3.0 6 votes vote down vote up
def update(self,song,level):
        self.gs.clear()
        print(self.song.pos)
        self.song = song
        self.cursorExists=False
        self.song.pos = 0
        self.play(0)
        self.pause()
        self.updatescreen()

        if self.spectrogramDisplay:
            self.spectrogramPixMap = QPixmap(spectrogram_dir+song.audioFile+'.png')
            width = self.spectrogramPixMap.width()
            height = self.spectrogramPixMap.height()

            self.spectrogramPixMap = self.gs.addPixmap(self.spectrogramPixMap)
            self.spectrogramPixMap.setRotation(90)
            self.spectrogramPixMap.setTransform(QTransform().scale(-1,(self.song.lengthInSeconds*self.pixPSec)/width))
        self.drawGrid(self.song.levels[level])
        self.drawArrowDemo(self.song.levels[level])
        #self.play(0) 
Example 2
Project: htm-teul   Author: sebnarvaez   File: VirtualWorld.py    GNU General Public License v2.0 6 votes vote down vote up
def dance(self):
        """
        Make the P1 dance
        """
        p1 = self._objects['P1']
        x = p1.x
        y = p1.y

        cell = self.worldGrid[y][x]

        for i in xrange(4):
            cell.objectLeaves('P1')
            p1.pixmap = p1.pixmap.transformed(QTransform().scale(-1, 1))
            cell.objectArrives('P1', p1)
            time.sleep(0.2)

        return self._formatReturnMessage('P1: ¡Sabor!') 
Example 3
Project: PyPoly2d   Author: volodinroman   File: scene.py    MIT License 6 votes vote down vote up
def mousePressEvent(self,event):
        """When we press mouse button on the scene canvas"""

        if event.button() == QtCore.Qt.LeftButton:
            self._createItem = True

            if self.itemAt(event.scenePos(), QtGui.QTransform()):
                #if we pressed over an item
                self._createItem = False

            elif self.selectedItems():
                #if we already have items selected - then deselect
                self._createItem = False

        self.update()
        super(Scene, self).mousePressEvent(event) 
Example 4
Project: lector   Author: zdenop   File: ocrwidget.py    GNU General Public License v2.0 6 votes vote down vote up
def prepareDimensions(self):
        #set scene size and view scale
        scene = self.scene()
        scene.setSize()

        vw = float(self.width())
        vh = float(self.height())
        iw = float(scene.im.size[0])
        ih = float(scene.im.size[1])
        ratio = min(vw/iw, vh/ih)
        # TODO: check this - there was QMatrix
        # self.setMatrix(QTransform(.95*ratio, 0., 0., .95*ratio, 0., 0.))

        OcrArea.resizeBorder = 5 / ratio
        self.areaBorder = 2 / ratio
        self.areaTextSize = 10 / ratio

        #show image
        scene.generateQtImage()
        self.resetCachedContent()
        scene.isModified = False 
Example 5
Project: Computer-graphics   Author: Panda-Lewandowski   File: lab7.py    MIT License 5 votes vote down vote up
def mouseMoveEvent(self, event):
        global now, w
        if w.input_rect:
            if now is None:
                now = event.scenePos()
            else:
                self.removeItem(self.itemAt(now, QTransform()))
                p = event.scenePos()
                self.addRect(now.x(), now.y(), abs(now.x() - p.x()), abs(now.y() - p.y())) 
Example 6
Project: Computer-graphics   Author: Panda-Lewandowski   File: lab7.py    MIT License 5 votes vote down vote up
def clipping(win):
    buf = win.scene.itemAt(now, QTransform()).rect()
    win.clip = [buf.left(), buf.right(), buf.top(),  buf.bottom()]
    for b in win.lines:
        pass
        win.pen.setColor(blue)
        cohen_sutherland(b, win.clip, win)
        win.pen.setColor(red) 
Example 7
Project: GeoMop   Author: GeoMop   File: diagram_structures.py    GNU General Public License v3.0 5 votes vote down vote up
def zoom(self, value):
        """zoom property, if zoom is too different, recount pen width, set brush transform"""
        self._zoom = value
        ratio = self._recount_zoom/value
        self.pen_changed = False
        if ratio>1.2 or ratio<0.8:
            self.pen_changed = True
            self.pen = QtGui.QPen(QtCore.Qt.black, 1.4/value)
            self.bpen = QtGui.QPen(QtCore.Qt.black, 3.5/value)
            self.no_pen = QtGui.QPen(QtCore.Qt.black, 5/value, QtCore.Qt.NoPen)
            self._recount_zoom = value

            square_size = 20
            self.brush_selected.setTransform(QtGui.QTransform(square_size / value, 0, 0, square_size / value, 0, 0))
        self.position_set = True 
Example 8
Project: GeoMop   Author: GeoMop   File: mainwindow.py    GNU General Public License v3.0 5 votes vote down vote up
def _display(self, view_rect):
        """moving"""
        self.diagramView.setSceneRect(
            cfg.diagram.x, 
            cfg.diagram.y, 
            view_rect.width()/cfg.diagram.zoom, 
            view_rect.height()/cfg.diagram.zoom)
        transform = QtGui.QTransform(cfg.diagram.zoom, 0, 0,cfg.diagram.zoom, 0, 0)
        self.diagramView.setTransform(transform) 
Example 9
Project: PyPipboyApp   Author: matzman666   File: globalmapwidget.py    GNU General Public License v3.0 5 votes vote down vote up
def setZoomLevel(self, zoom, mapposx, mapposy):
        self.mapItem.setTransform(QtGui.QTransform.fromScale(zoom, zoom))
        self.gwidget.mapScene.setSceneRect(self.mapItem.sceneBoundingRect())
        if mapposx >= 0 and mapposy >=0:
            self.gwidget.mapView.centerOn(mapposx * zoom, mapposy * zoom) 
Example 10
Project: vimiv-qt   Author: karlch   File: imtransform.py    GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, handler):
        self._handler = weakref.ref(handler)
        self._transform = QTransform()
        self._rotation_angle = 0
        self._flip_horizontal = self._flip_vertical = False 
Example 11
Project: vidcutter   Author: ozmartian   File: graphicseffects.py    GNU General Public License v3.0 5 votes vote down vote up
def draw(self, painter: QPainter) -> None:
        if self.sourceIsPixmap():
            pixmap, offset = self.sourcePixmap(Qt.LogicalCoordinates, QGraphicsEffect.PadToEffectiveBoundingRect)
        else:
            pixmap, offset = self.sourcePixmap(Qt.DeviceCoordinates, QGraphicsEffect.PadToEffectiveBoundingRect)
            painter.setWorldTransform(QTransform())
        painter.setBrush(Qt.black)
        painter.drawRect(pixmap.rect())
        painter.setOpacity(self.opacity)
        painter.drawPixmap(offset, pixmap) 
Example 12
Project: yoso   Author: ip1981   File: Workspace.py    Do What The F*ck You Want To Public License 5 votes vote down vote up
def mouseDoubleClickEvent(self, event):
        item = self.itemAt(event.scenePos(), QTransform())
        if item != None and item.type() == BBOX:
            self.removeItem(item)
            self.invalidate()
            self.saveLabels() 
Example 13
Project: axopy   Author: axopy   File: canvas.py    MIT License 5 votes vote down vote up
def __init__(self, width, height, x=0, y=0, color='#333333',
                 penwidth=0.01):
        self.penwidth = penwidth

        qitem = QtWidgets.QGraphicsRectItem(x, y, width, height)
        qitem.setTransformOriginPoint(width/2, height/2)
        qitem.setTransform(QtGui.QTransform().translate(-width/2, -height/2))
        super(Rectangle, self).__init__(qitem)

        self.pos = x, y
        self.color = color 
Example 14
Project: Mastering-GUI-Programming-with-Python   Author: PacktPublishing   File: tankity_tank_tank_tank.py    MIT License 5 votes vote down vote up
def __init__(self, color, y_pos, side=TOP):
        super().__init__()
        self.side = side
        # Define the tank's lookp
        self.bitmap = qtg.QBitmap.fromData(qtc.QSize(8, 8), self.TANK_BM)
        transform = qtg.QTransform()
        transform.scale(4, 4)  # scale to 32x32
        if self.side == self.TOP:  # We're pointing down
            transform.rotate(180)
        self.bitmap = self.bitmap.transformed(transform)
        self.pen = qtg.QPen(qtg.QColor(color))

        # Define the tank's position
        if self.side == self.BOTTOM:
            y_pos -= self.bitmap.height()
        self.setPos(0, y_pos)

        # Move the tank
        self.animation = qtc.QPropertyAnimation(self, b'x')
        self.animation.setStartValue(0)
        self.animation.setEndValue(SCREEN_WIDTH - self.bitmap.width())
        self.animation.setDuration(2000)
        self.animation.finished.connect(self.toggle_direction)
        if self.side == self.TOP:
            self.toggle_direction()
        self.animation.start()

        # create a bullet
        bullet_y = (
            y_pos - self.bitmap.height()
            if self.side == self.BOTTOM
            else y_pos + self.bitmap.height()
        )
        self.bullet = Bullet(bullet_y, self.side == self.BOTTOM) 
Example 15
Project: SpriteMator   Author: rafaelvasco   File: display_base_widget.py    Apache License 2.0 4 votes vote down vote up
def __init__(self):

        super(Display, self).__init__()

        self.setScene(QGraphicsScene())

        self._spriteObject = DisplaySpriteObject()

        self.scene().addItem(self._spriteObject)

        self._backgroundColor = None

        self._backLightOn = True

        self._lightBackgroundPixmap = ResourcesCache.get("CheckerTileLight")

        self._darkBackgroundPixmap = ResourcesCache.get("CheckerTileDark")

        self._lastFocusPoint = QPoint()

        self._fitInView = False

        self._panning = False

        self._leftMousePressed = False

        self._spacePressed = False

        self._dragPos = QPoint()

        self._storedTransform = QTransform()

        self.setTransformationAnchor(QGraphicsView.AnchorViewCenter)

        self.setResizeAnchor(QGraphicsView.AnchorViewCenter)

        self.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)

        self.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)

        self.setRenderHint(QPainter.Antialiasing, False)

        self.setOptimizationFlag(QGraphicsView.DontAdjustForAntialiasing)

        self.setMouseTracking(True)

        self.setStyleSheet("border: 0px;") 
Example 16
Project: Computer-graphics   Author: Panda-Lewandowski   File: lab7.py    MIT License 4 votes vote down vote up
def add_bars(win):
    global now
    if now is None:
        QMessageBox.warning(win, "Внимание!", "Не введен отсекатель!")
        return
    buf = win.scene.itemAt(now, QTransform())
    if buf is None:
        QMessageBox.warning(win, "Внимание!", "Не введен отсекатель!")
    else:
        buf = buf.rect()
        win.clip = [buf.left(), buf.right(), buf.top(),  buf.bottom()]

        t = abs(win.clip[2] - win.clip[3]) * 0.8
        k = abs(win.clip[0] - win.clip[1]) * 0.8
        # задаем граничные отрезки
        win.pen.setColor(red)
        w.lines.append([[win.clip[0], win.clip[2] + t],  [win.clip[0], win.clip[3] - t]])
        add_row(w)
        i = w.table.rowCount() - 1
        item_b = QTableWidgetItem("[{0}, {1}]".format(win.clip[0], win.clip[2] + t))
        item_e = QTableWidgetItem("[{0}, {1}]".format(win.clip[0], win.clip[3] - t))
        w.table.setItem(i, 0, item_b)
        w.table.setItem(i, 1, item_e)
        win.scene.addLine(win.clip[0], win.clip[2] + t,  win.clip[0], win.clip[3] - t, win.pen)

        w.lines.append([[win.clip[1], win.clip[2] + t],  [win.clip[1], win.clip[3] - t]])
        add_row(w)
        i = w.table.rowCount() - 1
        item_b = QTableWidgetItem("[{0}, {1}]".format(win.clip[1], win.clip[2] + t))
        item_e = QTableWidgetItem("[{0}, {1}]".format(win.clip[1], win.clip[3] - t))
        w.table.setItem(i, 0, item_b)
        w.table.setItem(i, 1, item_e)
        win.scene.addLine(win.clip[1], win.clip[3] - t,  win.clip[1], win.clip[2] + t, win.pen)

        w.lines.append([[win.clip[0] + k, win.clip[2]], [win.clip[1] - k, win.clip[2]]])
        add_row(w)
        i = w.table.rowCount() - 1
        item_b = QTableWidgetItem("[{0}, {1}]".format(win.clip[0] + k, win.clip[2]))
        item_e = QTableWidgetItem("[{0}, {1}]".format(win.clip[1] - k, win.clip[2]))
        w.table.setItem(i, 0, item_b)
        w.table.setItem(i, 1, item_e)
        win.scene.addLine(win.clip[0] + k, win.clip[2], win.clip[1] - k, win.clip[2], win.pen)

        w.lines.append([[win.clip[0] + k, win.clip[3]], [win.clip[1] - k, win.clip[3]]])
        add_row(w)
        i = w.table.rowCount() - 1
        item_b = QTableWidgetItem("[{0}, {1}]".format(win.clip[0] + k, win.clip[3]))
        item_e = QTableWidgetItem("[{0}, {1}]".format(win.clip[1] - k, win.clip[3]))
        w.table.setItem(i, 0, item_b)
        w.table.setItem(i, 1, item_e)
        win.scene.addLine(win.clip[0] + k, win.clip[3], win.clip[1] - k, win.clip[3], win.pen) 
Example 17
Project: PyNoder   Author: johnroper100   File: graph_view.py    GNU General Public License v3.0 4 votes vote down vote up
def frameNodes(self, nodes):
        if len(nodes) == 0:
            return

        def computeWindowFrame():
            windowRect = self.rect()
            windowRect.setLeft(windowRect.left() + 10)
            windowRect.setRight(windowRect.right() - 10)
            windowRect.setTop(windowRect.top() + 10)
            windowRect.setBottom(windowRect.bottom() - 10)
            return windowRect

        nodesRect = None
        for node in nodes:
            nodeRectF = node.transform().mapRect(node.rect())
            nodeRect = QtCore.QRect(nodeRectF.x(), nodeRectF.y(), nodeRectF.width(), nodeRectF.height())
            if nodesRect is None:
                nodesRect = nodeRect
            else:
                nodesRect = nodesRect.united(nodeRect)

        windowRect = computeWindowFrame()

        scaleX = float(windowRect.width()) / float(nodesRect.width())
        scaleY = float(windowRect.height()) / float(nodesRect.height())
        if scaleY > scaleX:
            scale = scaleX
        else:
            scale = scaleY

        if scale < 1.0:
            self.setTransform(QtGui.QTransform.fromScale(scale, scale))
        else:
            self.setTransform(QtGui.QTransform())

        sceneRect = self.sceneRect()
        pan = sceneRect.center() - nodesRect.center()
        sceneRect.translate(-pan.x(), -pan.y())
        self.setSceneRect(sceneRect)

        # Update the main panel when reframing.
        self.update() 
Example 18
Project: PyQt   Author: PyQt5   File: FlipWidget.py    GNU General Public License v3.0 4 votes vote down vote up
def paintEvent(self, event):
        super(FlipWidget, self).paintEvent(event)

        if hasattr(self, 'image1') and hasattr(self, 'image2') and self.isVisible():

            painter = QPainter(self)
            painter.setRenderHint(QPainter.Antialiasing, True)
            painter.setRenderHint(QPainter.SmoothPixmapTransform, True)

            # 变换
            transform = QTransform()
            # 把圆心设置为矩形中心
            transform.translate(self.width() / 2, self.height() / 2)

            if self._angle >= -90 and self._angle <= 90:
                # 当翻转角度在90范围内显示第一张图,且从大图缩放到小图的过程
                painter.save()
                # 设置翻转角度
                transform.rotate(self._angle, Qt.YAxis)
                painter.setTransform(transform)
                # 缩放图片高度
                width = self.image1.width() / 2
                height = int(self.image1.height() *
                             (1 - abs(self._angle / self.Scale) / 100))
                image = self.image1.scaled(
                    self.image1.width(), height,
                    Qt.IgnoreAspectRatio, Qt.SmoothTransformation)
                painter.drawPixmap(
                    QPointF(-width, -height / 2), image)
                painter.restore()
            else:
                # 当翻转角度在90范围内显示第二张图,且从小图缩放到原图的过程
                painter.save()
                if self._angle > 0:
                    angle = 180 + self._angle
                else:
                    angle = self._angle - 180
                # 设置翻转角度, 注意这里角度有差异
                transform.rotate(angle, Qt.YAxis)
                painter.setTransform(transform)
                # 缩放图片高度
                width = self.image2.width() / 2
                height = int(self.image2.height() *
                             (1 - ((360 - abs(angle)) / self.Scale / 100)))
                image = self.image2.scaled(
                    self.image2.width(), height,
                    Qt.IgnoreAspectRatio, Qt.SmoothTransformation)
                painter.drawPixmap(
                    QPointF(-width, -height / 2), image)
                painter.restore()