コード例 #1
0
ファイル: dag.py プロジェクト: timhowes/git-cola
    def __init__(self, source, dest):

        QtWidgets.QGraphicsItem.__init__(self)

        self.setAcceptedMouseButtons(Qt.NoButton)
        self.source = source
        self.dest = dest
        self.commit = source.commit
        self.setZValue(-2)

        dest_pt = Commit.item_bbox.center()

        self.source_pt = self.mapFromItem(self.source, dest_pt)
        self.dest_pt = self.mapFromItem(self.dest, dest_pt)
        self.line = QtCore.QLineF(self.source_pt, self.dest_pt)

        width = self.dest_pt.x() - self.source_pt.x()
        height = self.dest_pt.y() - self.source_pt.y()
        rect = QtCore.QRectF(self.source_pt, QtCore.QSizeF(width, height))
        self.bound = rect.normalized()

        # Choose a new color for new branch edges
        if self.source.x() < self.dest.x():
            color = EdgeColor.cycle()
            line = Qt.SolidLine
        elif self.source.x() != self.dest.x():
            color = EdgeColor.current()
            line = Qt.SolidLine
        else:
            color = EdgeColor.current()
            line = Qt.SolidLine

        self.pen = QtGui.QPen(color, 4.0, line, Qt.SquareCap, Qt.RoundJoin)
コード例 #2
0
    def __init__(self, port, graph, hOffset, color, connectionPointType):
        super(PortCircle, self).__init__(port)

        self.__port = port
        self._graph = graph
        self._connectionPointType = connectionPointType
        self.__connections = set()
        self._supportsOnlySingleConnections = connectionPointType == 'In'

        self.setSizePolicy(QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed))
        size = QtCore.QSizeF(self.__diameter, self.__diameter)
        self.setPreferredSize(size)
        self.setWindowFrameMargins(0, 0, 0, 0)

        self.transform().translate(self.__radius * hOffset, 0)

        self.__defaultPen = QtGui.QPen(QtGui.QColor(25, 25, 25), 1.0)
        self.__hoverPen = QtGui.QPen(QtGui.QColor(255, 255, 100), 1.5)

        self._ellipseItem = QtWidgets.QGraphicsEllipseItem(self)
        self._ellipseItem.setPen(self.__defaultPen)
        self._ellipseItem.setPos(size.width()/2, size.height()/2)
        self._ellipseItem.setRect(
            -self.__radius,
            -self.__radius,
            self.__diameter,
            self.__diameter,
            )
        if connectionPointType == 'In':
            self._ellipseItem.setStartAngle(270 * 16)
            self._ellipseItem.setSpanAngle(180 * 16)

        self.setColor(color)
        self.setAcceptHoverEvents(True)
コード例 #3
0
    def updateBar(self):
        #w=g.win
        w = self.w
        width_pixels = self.getValue('width_pixels')
        location = self.getValue('location')
        orientation = self.getValue('orientation')
        view = w.view
        textRect = w.scaleBarLabel.boundingRect()
        textWidth = textRect.width() * view.viewPixelSize()[0]
        textHeight = textRect.height() * view.viewPixelSize()[1]
        show_label = self.getValue('show_label')

        if location == 'Top Left':
            barPoint = QtCore.QPoint(0, 1.3 * textHeight)
            w.scaleBarLabel.setPos(
                QtCore.QPointF(width_pixels / 2 - textWidth / 2, 0))
        elif location == 'Top Right':
            barPoint = QtCore.QPoint(self.width - width_pixels,
                                     1.3 * textHeight)
            w.scaleBarLabel.setPos(
                QtCore.QPointF(self.width - width_pixels / 2 - textWidth / 2,
                               0))
        elif location == 'Lower Right':
            barPoint = QtCore.QPoint(self.width - width_pixels,
                                     self.height - 1.3 * textHeight)
            w.scaleBarLabel.setPos(
                QtCore.QPointF(self.width - width_pixels / 2 - textWidth / 2,
                               self.height - textHeight))
        elif location == 'Lower Left':
            barPoint = QtCore.QPoint(0, self.height - 1.3 * textHeight)
            w.scaleBarLabel.setPos(
                QtCore.QPointF(
                    QtCore.QPointF(width_pixels / 2 - textWidth / 2,
                                   self.height - textHeight)))
        if orientation == 'horizontal':
            w.scaleBarLabel.bar.setRect(
                QtCore.QRectF(barPoint,
                              QtCore.QSizeF(width_pixels, textHeight / 4)))
        elif orientation == 'vertical':
            w.scaleBarLabel.bar.setRect(
                QtCore.QRectF(barPoint,
                              QtCore.QSizeF(textHeight / 4, width_pixels)))

        if show_label == False:
            w.scaleBarLabel.hide()
コード例 #4
0
    def calibrate(self):
        ''' Require the user to aim the curson in the top left and bottom right corners to set the boundaries of the controller
		'''
        self.setFixedSize(self.size())
        self.reset()
        aimRect = QtCore.QRectF(self.graphicsView.mapToScene(0, 0),
                                self.graphicsView.mapToScene(20, 20))
        aim = QtWidgets.QGraphicsRectItem(aimRect)
        aim.setBrush(QtGui.QColor(255, 0, 0))
        self.scene.addItem(aim)
        font = QtGui.QFont("Helvetica", 15, 3)
        ti = self.scene.addText(
            'Position the laser in optimal top\n   left, then press any key',
            font=font)
        self.scene.keyPressEvent = lambda ev: setattr(
            self.scene, 'tempRect',
            QtCore.QRectF(self.scene.galvo.pos, QtCore.QSizeF()))
        while not hasattr(self.scene, 'tempRect'):
            QtWidgets.qApp.processEvents()
            time.sleep(.01)
        aimRect.moveTo(
            self.graphicsView.mapToScene(self.graphicsView.width() - 20,
                                         self.graphicsView.height() - 20))
        aim.setRect(aimRect)
        self.scene.keyPressEvent = lambda ev: self.scene.tempRect.setSize(
            QtCore.QSizeF(self.scene.galvo.pos.x() - self.scene.tempRect.x(),
                          self.scene.galvo.pos.y() - self.scene.tempRect.y()))
        ti.setPlainText(
            'Now position the laser in optimal bottom \n      right, and press a key'
        )
        while self.scene.tempRect.isEmpty():
            app.processEvents()
            time.sleep(.01)
        self.scene.removeItem(aim)
        self.scene.keyPressEvent = lambda ev: GalvoScene.keyPressEvent(
            self.scene, ev)
        self.scene.galvo.setBounds(self.scene.tempRect)
        del self.scene.tempRect
        self.scene.removeItem(ti)
        self.setMaximumSize(2000, 2000)
        self.setMinimumSize(0, 0)
コード例 #5
0
ファイル: imageview.py プロジェクト: osechet/git-cola
 def image_scene_rect(self):
     return QtCore.QRectF(self.graphics_pixmap.pos(),
                          QtCore.QSizeF(self.pixmap.size()))
コード例 #6
0
ファイル: port.py プロジェクト: kremersa/pyflowgraph
 def textSize(self):
     return QtCore.QSizeF(self.__textItem.textWidth(),
                          self.__font.pointSizeF())
コード例 #7
0
 def textSize(self):
     return QtCore.QSizeF(
         self.__fontMetrics.width(self.__text),
         self.__fontMetrics.height()
         )
コード例 #8
0
 def textSize(self):
     return QtCore.QSizeF(
         self.__textItem.textWidth(),
         self.__font.pointSizeF() + self.__labelBottomSpacing)
コード例 #9
0
    def __call__(self,
                 unit,
                 width_units,
                 width_pixels,
                 font_size,
                 color,
                 background,
                 location,
                 orientation,
                 show=True,
                 show_label=True,
                 keepSourceWindow=None):
        #w=g.win
        w = self.w
        if show:
            if hasattr(w, 'scaleBarLabel') and w.scaleBarLabel is not None:
                w.view.removeItem(w.scaleBarLabel.bar)
                w.view.removeItem(w.scaleBarLabel)
                try:
                    w.view.sigResized.disconnect(self.updateBar)
                except:
                    pass
            if location == 'Top Left':
                anchor = (0, 0)
                pos = [0, 0]
            elif location == 'Top Right':
                anchor = (0, 0)
                pos = [self.width, 0]
            elif location == 'Lower Right':
                anchor = (0, 0)
                pos = [self.width, self.height]
            elif location == 'Lower Left':
                anchor = (0, 0)
                pos = [0, self.height]

            if unit == 'micro':
                unitText = 'μm'
            elif unit == 'nano':
                unitText = 'nm'
            elif unit == 'pixels':
                unitText = 'px'

            w.scaleBarLabel = pg.TextItem(
                anchor=anchor,
                html=
                "<span style='font-size: {}pt;color:{};background-color:{};'>{} {}</span>"
                .format(font_size, color, background, width_units, unitText))
            w.scaleBarLabel.setPos(pos[0], pos[1])
            w.scaleBarLabel.flika_properties = {
                item['name']: item['value']
                for item in self.items
            }
            w.view.addItem(w.scaleBarLabel)
            if color == 'White':
                color255 = [255, 255, 255, 255]
            elif color == 'Black':
                color255 = [0, 0, 0, 255]
            textRect = w.scaleBarLabel.boundingRect()

            if location == 'Top Left':
                barPoint = QtCore.QPoint(0, textRect.height())
            elif location == 'Top Right':
                barPoint = QtCore.QPoint(-width_pixels, textRect.height())
            elif location == 'Lower Right':
                barPoint = QtCore.QPoint(-width_pixels, -textRect.height())
            elif location == 'Lower Left':
                barPoint = QtCore.QPoint(0, -textRect.height())

            if orientation == 'horizontal':
                bar = QtWidgets.QGraphicsRectItem(
                    QtCore.QRectF(
                        barPoint,
                        QtCore.QSizeF(width_pixels, int(font_size / 3))))
            elif orientation == 'vertical':
                bar = QtWidgets.QGraphicsRectItem(
                    QtCore.QRectF(
                        barPoint,
                        QtCore.QSizeF(int(font_size / 3), width_pixels)))
            bar.setPen(pg.mkPen(color255))
            bar.setBrush(pg.mkBrush(color255))
            w.view.addItem(bar)
            #bar.setParentItem(w.scaleBarLabel)
            w.scaleBarLabel.bar = bar
            w.view.sigResized.connect(self.updateBar)
            self.updateBar()

        else:
            if hasattr(w, 'scaleBarLabel') and w.scaleBarLabel is not None:
                w.view.removeItem(w.scaleBarLabel.bar)
                w.view.removeItem(w.scaleBarLabel)
                w.scaleBarLabel = None
                w.view.sigResized.disconnect(self.updateBar)
        return None
コード例 #10
0
        "QPushButton": QtWidgets.QPushButton(),
    },
    "PyQt_pickable": {
        "QByteArray": QtCore.QByteArray(bytes(range(256))),
        "QColor": QtGui.QColor(10, 20, 30, 40),
        ## "QChar": # n'a plus l'air d'exister dans PyQt5
        "QDate": QtCore.QDate(2020, 10, 31),
        "QDateTime": QtCore.QDateTime(2020, 10, 31, 20, 30),
        "QKeySequence": QtGui.QKeySequence(),
        ## "QLatin1Char": # n'a plus l'air d'exister dans PyQt5
        ## "QLatin1String"# n'a plus l'air d'exister dans PyQt5
        "QLine": QtCore.QLine(QtCore.QPoint(0, 1), QtCore.QPoint(2, 3)),
        "QLineF": QtCore.QLineF(QtCore.QPoint(0.0, 1.1), QtCore.QPoint(2.2, 3.3)),
        "QPen": QtGui.QPen(),
        "QBrush": QtGui.QBrush(),
        "QPoint": QtCore.QPoint(0, 1),
        "QPointF": QtCore.QPointF(0.0, 1.1),
        "QPolygon": QtGui.QPolygon([QtCore.QPoint(0, 1), QtCore.QPoint(2, 3)]),
        "QPolygonF": QtGui.QPolygonF([QtCore.QPoint(0.0, 1.1), QtCore.QPoint(2.2, 3.3)]),
        "QRect": QtCore.QRect(QtCore.QPoint(0, 1), QtCore.QPoint(2, 3)),
        "QRectF": QtCore.QRectF(QtCore.QPoint(0.0, 1.1), QtCore.QPoint(2.2, 3.3)),
        "QSize": QtCore.QSize(10, 20),
        "QSizeF": QtCore.QSizeF(10.5, 20.5),
        ## "QMatrix": # Support for the deprecated QMatrix class has been removed
        ## "QString": # n'a plus l'air d'exister dans PyQt5
        "QTime": QtCore.QTime(20, 30),
        "QTransform": QtGui.QTransform(),  # pas reducable dans documentation ?
        "QVector3D": QtGui.QVector3D(),  # pas reducable dans documentation ?
    },
}