Exemple #1
0
 def __init__(self):
     self.labelAlignment = Qt.AlignCenter
     self.labelOrientation = Qt.Horizontal
     self.spacing = 2
     self.symbol = None
     self.style = QwtPlotMarker.NoLine
     self.xValue = 0.0
     self.yValue = 0.0
     self.label = QwtText()
     self.pen = QPen()
Exemple #2
0
    def paintEvent(self, event):
        """ """
        self.build_paths()

        painter = QPainter(self)
        painter.setRenderHint(QPainter.Antialiasing)

        painter.fillPath(self.round_rect_path, self.color_back)
        painter.fillPath(self.top_rect_path, self.color_top)
        painter.strokePath(self.round_rect_path, QPen(Qt.gray, 1))
Exemple #3
0
 def setPen(self, *args):
     """
     Build and/or assign a pen, depending on the arguments.
     
     .. py:method:: setPen(color, width, style)
     
         Build and assign a pen
 
         In Qt5 the default pen width is 1.0 ( 0.0 in Qt4 ) what makes it
         non cosmetic (see `QPen.isCosmetic()`). This method signature has 
         been introduced to hide this incompatibility.
         
         :param QColor color: Pen color
         :param float width: Pen width
         :param Qt.PenStyle style: Pen style
     
     .. py:method:: setPen(pen)
     
         Assign a pen
 
         :param QPen pen: New pen
     
     .. seealso::
     
         :py:meth:`pen()`, :py:meth:`brush()`
     """
     if len(args) == 3:
         color, width, style = args
         pen = QPen(color, width, style)
     elif len(args) == 1:
         (pen, ) = args
     else:
         raise TypeError(
             "%s().setPen() takes 1 or 3 argument(s) (%s given)" %
             (self.__class__.__name__, len(args)))
     if pen != self.__data.pen:
         if isinstance(pen, QColor):
             pen = QPen(pen)
         else:
             assert isinstance(pen, QPen)
         self.__data.pen = pen
         self.legendChanged()
         self.itemChanged()
Exemple #4
0
 def paintEvent(self, event):
     """Fills the panel background using QPalette."""
     if self.isVisible() and self.position != self.Position.FLOATING:
         # fill background
         self._background_brush = QBrush(QColor(
             self.editor.sideareas_color))
         self._foreground_pen = QPen(
             QColor(self.palette().windowText().color()))
         painter = QPainter(self)
         painter.fillRect(event.rect(), self._background_brush)
Exemple #5
0
    def addMark(self, new_mark: VideoSliderMark, update: bool = True):
        """Adds a marked value to the slider.

        Args:
            new_mark: value to mark
            update: Whether to redraw slider with new mark.

        Returns:
            None.
        """
        # check if mark is within slider range
        if new_mark.val > self._val_max:
            return
        if new_mark.val < self._val_min:
            return

        self._marks.add(new_mark)

        v_top_pad = self._header_height + 1
        v_bottom_pad = 1
        v_top_pad += new_mark.top_pad
        v_bottom_pad += new_mark.bottom_pad

        width = new_mark.visual_width

        v_offset = v_top_pad

        height = new_mark.get_height(container_height=self.box_rect.height() -
                                     self._header_height)

        color = new_mark.QColor
        pen = QPen(color, 0.5)
        pen.setCosmetic(True)
        brush = QBrush(color) if new_mark.filled else QBrush()

        line = self.scene.addRect(-width // 2, v_offset, width, height, pen,
                                  brush)
        self._mark_items[new_mark] = line

        if new_mark.mark_type == "tick":
            # Show tick mark behind other slider marks
            self._mark_items[new_mark].setZValue(0)

            # Add a text label to show in header area
            mark_label_text = (
                # sci notation if large
                f"{new_mark.val + self.tick_index_offset:g}")
            self._mark_labels[new_mark] = self.scene.addSimpleText(
                mark_label_text, self._base_font)
        else:
            # Show in front of tick marks and behind track lines
            self._mark_items[new_mark].setZValue(1)

        if update:
            self._update_visual_positions()
Exemple #6
0
    def paint(self, painter, option, index):
        """Override Qt method."""
        QItemDelegate.paint(self, painter, option, index)
        column = index.column()
        row = index.row()
        rect = option.rect

        # Draw borders
        # pen = QPen()
        # pen.setWidth(1)
        # pen.setColor(QColor('#cdcdcd'))
        # painter.setPen(pen)
        # painter.drawLine(rect.topLeft(), rect.topRight())

        if column in [C.COL_NAME, C.COL_DESCRIPTION, C.COL_VERSION]:
            pen = QPen()
            pen.setWidth(1)
            pen.setColor(QColor('#ddd'))
            painter.setPen(pen)
            painter.drawLine(rect.topRight(), rect.bottomRight())

        if (row == self.current_hover_row()
                or row == self.current_row() and self.has_focus_or_context()):
            pen = QPen()
            pen.setWidth(1)
            if row == self.current_row():
                pen.setColor(QColor('#007041'))
            else:
                pen.setColor(QColor('#43b02a'))
            painter.setPen(pen)
            painter.drawLine(rect.topLeft(), rect.topRight())
            painter.drawLine(rect.bottomLeft(), rect.bottomRight())

        if (row == self.current_row() and self.has_focus_or_context()
                and column in [C.COL_START]):
            pen = QPen()
            pen.setWidth(10)
            pen.setColor(QColor('#007041'))
            painter.setPen(pen)
            dyt = QPoint(0, 5)
            dyb = QPoint(0, 4)
            painter.drawLine(rect.bottomLeft() - dyb, rect.topLeft() + dyt)
Exemple #7
0
 def __init__(self):
     QMainWindow.__init__(self)
     view = MapGraphicsView(tileSource=MapTileSourceHere())
     self.setCentralWidget(view)
     view.scene().setCenter(31.789339, 41.450508)
     view.setOptimizationFlag(QGraphicsView.DontSavePainterState, True)
     view.setRenderHint(QPainter.Antialiasing, True)
     view.setRenderHint(QPainter.SmoothPixmapTransform, True)
     pointItem = view.scene().addCircle(31.789339, 44.860767, 3.0)
     pointItem.setBrush(Qt.black)
     pointItem.setToolTip('31.789339, 41.450508')
     pointItem.setFlag(QGraphicsItem.ItemIsSelectable, True)
     pointItem = view.scene().addCircle(31.789339, 44.860767, 5.0)
     pointItem.setBrush(Qt.green)
     pointItem.setPen(QPen(Qt.NoPen))
     pointItem.setToolTip('%f, %f' % (31.789339, 44.860767))
     pointItem.setFlag(QGraphicsItem.ItemIsSelectable, True)
     lineItem = view.scene().addLine(32.859741, 39.933365, 31.789339,
                                     41.450508)
     lineItem.setPen(QPen(QBrush(Qt.blue), 3.0))
Exemple #8
0
    def drawStar(self, qp):
        """Draw a star in the preview pane.

        Parameters
        ----------
        qp: QPainter object
        """
        width = self.rect().width()
        height = self.rect().height()
        col = QColor(135, 206, 235)
        pen = QPen(col, self._value)
        pen.setJoinStyle(Qt.PenJoinStyle.MiterJoin)
        qp.setPen(pen)

        path = QPainterPath()

        # draw pentagram
        star_center_x = width / 2
        star_center_y = height / 2
        # make sure the star equal no matter the size of the qframe
        if width < height:
            # not taking it all the way to the edge so the star has room to grow
            radius_outer = width * 0.35
        else:
            radius_outer = height * 0.35

        # start at the top point of the star and move counter clockwise to draw the path.
        # every other point is the shorter radius (1/(1+golden_ratio)) of the larger radius
        golden_ratio = (1 + np.sqrt(5)) / 2
        radius_inner = radius_outer / (1 + golden_ratio)
        theta_start = np.pi / 2
        theta_inc = (2 * np.pi) / 10
        for n in range(11):
            theta = theta_start + (n * theta_inc)
            theta = np.mod(theta, 2 * np.pi)
            if np.mod(n, 2) == 0:
                # use radius_outer
                x = radius_outer * np.cos(theta)
                y = radius_outer * np.sin(theta)

            else:
                # use radius_inner
                x = radius_inner * np.cos(theta)
                y = radius_inner * np.sin(theta)

            x_adj = star_center_x - x
            y_adj = star_center_y - y + 3
            if n == 0:

                path.moveTo(x_adj, y_adj)
            else:
                path.lineTo(x_adj, y_adj)

        qp.drawPath(path)
Exemple #9
0
    def paint(self, painter, styles, widget=None):
        pen1 = QPen(Qt.SolidLine)
        pen1.setColor(QColor(128, 128, 128))
        painter.setPen(pen1)

        brush1 = QBrush(Qt.SolidPattern)
        brush1.setColor(self.color)
        painter.setBrush(brush1)

        painter.setRenderHint(QPainter.Antialiasing)  # 反锯齿
        painter.drawRoundedRect(self.boundingRect(), 10, 10)
Exemple #10
0
 def __init__(self,
              other_item,
              text,
              parent=None,
              min_zoom_visibility=None):
     QGraphicsSimpleTextItem.__init__(self, text, parent=parent)
     MapItem.__init__(self)
     self.other_item = other_item
     self._min_zoom = min_zoom_visibility
     self._border = QGraphicsRectItem(parent=self)
     self._border.setPen(QPen(Qt.NoPen))
     self._border.setBrush(QBrush(QColor(190, 190, 190, 160)))
Exemple #11
0
 def draw(self, painter, xMap, yMap, canvasRect):
     self.update_text()
     x, y = self.get_top_left(xMap, yMap, canvasRect)
     x0, y0 = self.get_origin(xMap, yMap, canvasRect)
     painter.save()
     self.marker.drawSymbols(painter, [QPointF(x0, y0)])
     painter.restore()
     sz = self.text.size()
     self.draw_frame(painter, x, y, sz.width(), sz.height())
     painter.setPen(QPen(QColor(self.labelparam.color)))
     painter.translate(x, y)
     self.text.drawContents(painter)
Exemple #12
0
    def paintEvent(self, event):
        painter = QPainter()
        painter.begin(self.pixmap)
        painter.drawPixmap(0, 0, self.pixmap)

        pen1 = QPen(QColor(self.c1), 1)
        pen2 = QPen(QColor(self.c2), 2)

        painter.setPen(pen1)
        y = self.size - 1
        for x in range(self.size):
            painter.drawLine(0, x, y, x)
            y = y - 1

        painter.setPen(pen2)
        y = 1
        for x in range(self.size, 0, -1):
            painter.drawLine(y, x, self.size, x)
            y = y + 1

        painter.end()
Exemple #13
0
    def __init__(self, *args):
        QwtPlot.__init__(self, *args)

        self.setTitle("Interactive Plot")

        self.setCanvasColor(Qt.darkCyan)

        grid = QwtPlotGrid()
        grid.attach(self)
        grid.setMajorPen(QPen(Qt.white, 0, Qt.DotLine))

        self.setAxisScale(QwtPlot.xBottom, 0.0, 100.0)
        self.setAxisScale(QwtPlot.yLeft, 0.0, 100.0)

        # Avoid jumping when label with 3 digits
        # appear/disappear when scrolling vertically
        scaleDraw = self.axisScaleDraw(QwtPlot.yLeft)
        scaleDraw.setMinimumExtent(
            scaleDraw.extent(self.axisWidget(QwtPlot.yLeft).font())
        )

        self.plotLayout().setAlignCanvasToScales(True)

        self.__insertCurve(Qt.Vertical, Qt.blue, 30.0)
        self.__insertCurve(Qt.Vertical, Qt.magenta, 70.0)
        self.__insertCurve(Qt.Horizontal, Qt.yellow, 30.0)
        self.__insertCurve(Qt.Horizontal, Qt.white, 70.0)

        self.replot()

        scaleWidget = self.axisWidget(QwtPlot.yLeft)
        scaleWidget.setMargin(10)

        self.__colorBar = ColorBar(Qt.Vertical, scaleWidget)
        self.__colorBar.setRange(QColor(Qt.red), QColor(Qt.darkBlue))
        self.__colorBar.setFocusPolicy(Qt.TabFocus)
        self.__colorBar.colorSelected.connect(self.setCanvasColor)

        # we need the resize events, to lay out the color bar
        scaleWidget.installEventFilter(self)

        # we need the resize events, to lay out the wheel
        self.canvas().installEventFilter(self)

        scaleWidget.setWhatsThis(
            "Selecting a value at the scale will insert a new curve."
        )
        self.__colorBar.setWhatsThis(
            "Selecting a color will change the background of the plot."
        )
        self.axisWidget(QwtPlot.xBottom).setWhatsThis(
            "Selecting a value at the scale will insert a new curve."
        )
Exemple #14
0
    def __init__(self, *args):
        QFrame.__init__(self, *args)

        self.xMap = QwtScaleMap()
        self.xMap.setScaleInterval(-0.5, 10.5)
        self.yMap = QwtScaleMap()
        self.yMap.setScaleInterval(-1.1, 1.1)

        # frame style
        self.setFrameStyle(QFrame.Box | QFrame.Raised)
        self.setLineWidth(2)
        self.setMidLineWidth(3)

        # calculate values
        self.x = np.arange(0, 10.0, 10.0 / 27)
        self.y = np.sin(self.x) * np.cos(2 * self.x)

        # make curves with different styles
        self.curves = []
        self.titles = []
        # curve 1
        self.titles.append("Style: Sticks, Symbol: Ellipse")
        curve = QwtPlotCurve()
        curve.setPen(QPen(Qt.red))
        curve.setStyle(QwtPlotCurve.Sticks)
        curve.setSymbol(
            QwtSymbol(QwtSymbol.Ellipse, QBrush(Qt.yellow), QPen(Qt.blue),
                      QSize(5, 5)))
        self.curves.append(curve)
        # curve 2
        self.titles.append("Style: Lines, Symbol: None")
        curve = QwtPlotCurve()
        curve.setPen(QPen(Qt.darkBlue))
        curve.setStyle(QwtPlotCurve.Lines)
        self.curves.append(curve)
        # curve 3
        self.titles.append("Style: Lines, Symbol: None, Antialiased")
        curve = QwtPlotCurve()
        curve.setPen(QPen(Qt.darkBlue))
        curve.setStyle(QwtPlotCurve.Lines)
        curve.setRenderHint(QwtPlotItem.RenderAntialiased)
        self.curves.append(curve)
        # curve 4
        self.titles.append("Style: Steps, Symbol: None")
        curve = QwtPlotCurve()
        curve.setPen(QPen(Qt.darkCyan))
        curve.setStyle(QwtPlotCurve.Steps)
        self.curves.append(curve)
        # curve 5
        self.titles.append("Style: NoCurve, Symbol: XCross")
        curve = QwtPlotCurve()
        curve.setStyle(QwtPlotCurve.NoCurve)
        curve.setSymbol(
            QwtSymbol(QwtSymbol.XCross, QBrush(), QPen(Qt.darkMagenta),
                      QSize(5, 5)))
        self.curves.append(curve)

        # attach data, using Numeric
        for curve in self.curves:
            curve.setData(self.x, self.y)
Exemple #15
0
 def __draw_paths(self) -> None:
     """Draw paths."""
     pen = QPen()
     pen.setWidth(self.path_width)
     for i, path in enumerate(self.path.path):
         if self.monochrome:
             pen.setColor(color_qt('gray'))
         elif self.vpoints[i].color is None:
             pen.setColor(color_qt('green'))
         else:
             pen.setColor(QColor(*self.vpoints[i].color))
         self.painter.setPen(pen)
         self.draw_curve(path)
Exemple #16
0
 def test_changeconfig(self):
     obj = QwtSymbol(QwtSymbol.Rect, QBrush(Qt.black), QPen(Qt.yellow),
                     QSize(3, 3))
     sym = SymbolParam(_("Symbol"))
     sym.update_param(obj)
     sym.write_config(CONF, "sym", "")
     sym = SymbolParam(_("Symbol"))
     sym.read_config(CONF, "sym", "")
     self.assertEqual(sym.marker, "Rect")
     self.assertEqual(sym.size, 3)
     self.assertEqual(sym.edgecolor, "#ffff00")
     self.assertEqual(sym.facecolor, "#000000")
     sym.build_symbol()
Exemple #17
0
    def _generatePicture(self, p=QPainter()):
        p.setPen(QPen(QColor("#aaaaaa")))
        p.setBrush(QBrush(QColor(80, 80, 80, 210), Qt.SolidPattern))
        p.drawRoundedRect(self._bRect, 2, 2)

        for n in range(0, 180, 1):
            v = n / 180.0
            a = self.cm(v)
            color = QColor.fromRgbF(a[0], a[1], a[2])

            p.setBrush(QBrush(color))
            p.setPen(QPen(color))
            p.drawRect(QRect(5, 190 - n, 20, -1))

        p.setBrush(QBrush(Qt.transparent))
        p.setPen(QPen(QColor("#FFFFFF")))
        tickRect = QRectF(32, 6, self._bRect.width() - 32, 11)
        p.drawText(tickRect, self.fontFlags, "{}".format(self.v_max))
        # tickRect = QRectF(32, 94, self._bRect.width() - 32, 11)
        # p.drawText(tickRect, self.fontFlags, "{}".format(self.v_max - (self.v_max - self.v_min) / 2.))
        tickRect = QRectF(32, 184, self._bRect.width() - 32, 11)
        p.drawText(tickRect, self.fontFlags, "{}".format(self.v_min))
Exemple #18
0
    def __init__(self, parent=None):
        super(VLine, self).__init__(parent)
        self.chartItemFlags = ChartItemFlags.FLAG_NO_AUTO_RANGE

        self._x = None
        self._label = None

        self._pen = QPen(QBrush(Qt.green), 1.0, Qt.SolidLine)
        self._pen.setCosmetic(True)
        self._brush = QBrush(QColor(255, 255, 255, 0))

        finfo = np.finfo(np.float32)
        self.b_rect = QRectF(0, finfo.min / 2.0, 0, finfo.max)
Exemple #19
0
 def __init__(self,
              longitude,
              latitude,
              text,
              parent=None,
              min_zoom_visibility=None):
     QGraphicsSimpleTextItem.__init__(self, text, parent=parent)
     MapItem.__init__(self)
     self._min_zoom = min_zoom_visibility
     self._lon, self._lat = longitude, latitude
     self._border = QGraphicsRectItem(parent=self)
     self._border.setPen(QPen(Qt.NoPen))
     self._border.setBrush(QBrush(QColor(190, 190, 190, 160)))
Exemple #20
0
    def paintEvent(self, event):
        """Override Qt method."""
        painter = QPainter(self)
        painter.setOpacity(self.current_opacity)

        max_width = (
            SASS_VARIABLES.WIDGET_CONTENT_TOTAL_WIDTH - 2 *
            SASS_VARIABLES.WIDGET_CONTENT_PADDING - 2 *
            SASS_VARIABLES.WIDGET_CONTENT_MARGIN
        )

        # Hover top
        br = self.label_icon.rect().bottomRight()
        tl = self.label_icon.rect().topLeft() + QPoint(1, 1)
        y = br.y() + self.label_text.height() - 2
        #        br_new = QPoint(br.x() + 2, y) - QPoint(1, 1)
        br_new = QPoint(max_width - 1, y) - QPoint(1, 1)
        rect_hover = QRect(tl, br_new)  # 2 is the border

        pen = QPen(Qt.NoPen)
        brush = QBrush(Qt.SolidPattern)
        brush.setColor(QColor('#fff'))
        painter.setBrush(brush)
        painter.setPen(pen)
        painter.drawRect(rect_hover)

        font = self.font()
        font.setPointSize(10)
        painter.setFont(font)
        pen = QPen()
        pen.setColor(QColor('black'))
        painter.setPen(pen)
        td = self.text_document
        td.setPageSize(QSizeF(rect_hover.size()))
        td.setHtml(self.summary)
        td.drawContents(painter)

        self.raise_()
Exemple #21
0
    def __init__(self, pos=None, parent=None):
        QGraphicsObject.__init__(self, parent=parent)
        MapItem.__init__(self)
        self.setZValue(200.0)

        self._anchorPos = QPointF(pos) if pos is not None else QPointF(
            10.0, 10.0)

        self._border = QGraphicsRectItem(parent=self)
        self._border.setPen(QPen(Qt.NoPen))
        self._border.setBrush(QBrush(QColor(190, 190, 190, 160)))

        self._entries = list()
        self._entriesGroup = QGraphicsItemGroup(parent=self)
Exemple #22
0
    def __init__(self,
                 shape: Shape,
                 size: int,
                 key: Optional[int] = None,
                 **kwargs):
        super().__init__()
        self._shape = shape
        self._size = size
        self.key = key
        self.info = kwargs

        self._pen = QPen()
        self._pen.setWidthF(0.25)
        self._brush = QBrush()
Exemple #23
0
    def __draw_path(self) -> None:
        """Draw a path.

        A simple function than main canvas.
        """
        pen = QPen()
        for i, path in enumerate(self.path.path):
            color = color_qt('Green')
            if f"P{i}" in self.target_path:
                color = color_qt('Dark-Orange')
            pen.setColor(color)
            pen.setWidth(self.path_width)
            self.painter.setPen(pen)
            self.draw_curve(path)
Exemple #24
0
    def __init__(self, *args, unattended=False):
        QwtPlot.__init__(self, *args)

        self.setCanvasBackground(Qt.white)
        self.alignScales()

        # Initialize data
        self.x = np.arange(0.0, 100.1, 0.5)
        self.y = np.zeros(len(self.x), np.float)
        self.z = np.zeros(len(self.x), np.float)

        self.setTitle("A Moving QwtPlot Demonstration")
        self.insertLegend(QwtLegend(), QwtPlot.BottomLegend)

        self.curveR = QwtPlotCurve("Data Moving Right")
        self.curveR.attach(self)
        self.curveL = QwtPlotCurve("Data Moving Left")
        self.curveL.attach(self)

        self.curveL.setSymbol(
            QwtSymbol(QwtSymbol.Ellipse, QBrush(), QPen(Qt.yellow),
                      QSize(7, 7)))

        self.curveR.setPen(QPen(Qt.red))
        self.curveL.setPen(QPen(Qt.blue))

        mY = QwtPlotMarker()
        mY.setLabelAlignment(Qt.AlignRight | Qt.AlignTop)
        mY.setLineStyle(QwtPlotMarker.HLine)
        mY.setYValue(0.0)
        mY.attach(self)

        self.setAxisTitle(QwtPlot.xBottom, "Time (seconds)")
        self.setAxisTitle(QwtPlot.yLeft, "Values")

        self.startTimer(10 if unattended else 50)
        self.phase = 0.0
Exemple #25
0
    def __init__(self, *args):
        QWidget.__init__(self, *args)
        layout = QGridLayout(self)
        # try to create a plot for SciPy arrays

        # make a curve and copy the data
        numpy_curve = QwtPlotCurve("y = lorentzian(x)")
        x = np.arange(0.0, 10.0, 0.01)
        y = lorentzian(x)
        numpy_curve.setData(x, y)
        # here, we know we can plot NumPy arrays
        numpy_plot = QwtPlot(self)
        numpy_plot.setTitle("numpy array")
        numpy_plot.setCanvasBackground(Qt.white)
        numpy_plot.plotLayout().setCanvasMargin(0)
        numpy_plot.plotLayout().setAlignCanvasToScales(True)
        # insert a curve and make it red
        numpy_curve.attach(numpy_plot)
        numpy_curve.setPen(QPen(Qt.red))
        layout.addWidget(numpy_plot, 0, 0)
        numpy_plot.replot()

        # create a plot widget for lists of Python floats
        list_plot = QwtPlot(self)
        list_plot.setTitle("Python list")
        list_plot.setCanvasBackground(Qt.white)
        list_plot.plotLayout().setCanvasMargin(0)
        list_plot.plotLayout().setAlignCanvasToScales(True)
        x = drange(0.0, 10.0, 0.01)
        y = [lorentzian(item) for item in x]
        # insert a curve, make it red and copy the lists
        list_curve = QwtPlotCurve("y = lorentzian(x)")
        list_curve.attach(list_plot)
        list_curve.setPen(QPen(Qt.red))
        list_curve.setData(x, y)
        layout.addWidget(list_plot, 0, 1)
        list_plot.replot()
Exemple #26
0
 def setLinePen(self, *args):
     """
     Build and/or assigna a line pen, depending on the arguments.
     
     .. py:method:: setLinePen(color, width, style)
         :noindex:
     
         Build and assign a line pen
 
         In Qt5 the default pen width is 1.0 ( 0.0 in Qt4 ) what makes it
         non cosmetic (see `QPen.isCosmetic()`). This method signature has 
         been introduced to hide this incompatibility.
         
         :param QColor color: Pen color
         :param float width: Pen width
         :param Qt.PenStyle style: Pen style
     
     .. py:method:: setLinePen(pen)
         :noindex:
     
         Specify a pen for the line.
 
         :param QPen pen: New pen
     
     .. seealso::
     
         :py:meth:`pen()`, :py:meth:`brush()`
     """
     if len(args) == 1 and isinstance(args[0], QPen):
         (pen,) = args
     elif len(args) in (1, 2, 3):
         color = args[0]
         width = 0.0
         style = Qt.SolidLine
         if len(args) > 1:
             width = args[1]
             if len(args) > 2:
                 style = args[2]
         pen = QPen(color, width, style)
         self.setLinePen(pen)
     else:
         raise TypeError(
             "%s().setLinePen() takes 1, 2 or 3 argument(s) "
             "(%s given)" % (self.__class__.__name__, len(args))
         )
     if pen != self.__data.pen:
         self.__data.pen = pen
         self.legendChanged()
         self.itemChanged()
Exemple #27
0
 def __init__(self, parent=None):
     self._brush = QBrush(QColor(0, 255, 0), Qt.SolidPattern)
     self._original_brush = None
     self._rotation = 0
     self._pen_style = Qt.SolidLine
     self._pen = QPen(self._pen_style)
     self._pen.setCosmetic(True)
     self._pen_width = 1.0
     self._pen_color = QColor(0, 0, 0)
     self._pen.setWidthF(self._pen_width)
     self._pen.setColor(self._pen_color)
     self._original_pen_style = self._pen_style
     self._original_pen_color = self._pen_color
     super(BaseSymbolIcon, self).__init__(parent)
     self.setObjectName("icon")
Exemple #28
0
 def paint(self, painter, fill=False, canvas=None):
     scale = self.get_scale(canvas)
     mainwindow = Shape.application_class.get_main_window()
     color = self.label_color or mainwindow.lineColor or DEFAULT_LINE_COLOR
     pen = QPen(color)
     # Try using integer sizes for smoother drawing(?)
     pen.setWidth(max(1, int(round(self.line_width / scale))))
     painter.setPen(pen)
     # Draw all vertices
     self.paint_vertices(painter, self.points, scale, self._highlightIndex,
                         self._highlightMode)
     line_path = self.get_line_path(self.points, self.shape_type)
     painter.drawPath(line_path)
     if fill:
         painter.fillPath(line_path, color)
Exemple #29
0
    def __init__(self, *args):
        QFrame.__init__(self, *args)

        self.setFrameStyle(QFrame.Box | QFrame.Raised)
        self.setLineWidth(2)
        self.setMidLineWidth(3)

        p = QPalette()
        p.setColor(self.backgroundRole(), QColor(30, 30, 50))
        self.setPalette(p)
        # make curves and maps
        self.tuples = []
        # curve 1
        curve = QwtPlotCurve()
        curve.setPen(QPen(QColor(150, 150, 200), 2))
        curve.setStyle(QwtPlotCurve.Lines)
        curve.setSymbol(
            QwtSymbol(QwtSymbol.XCross, QBrush(), QPen(Qt.yellow, 2),
                      QSize(7, 7)))
        self.tuples.append(
            (curve, QwtScaleMap(0, 100, -1.5,
                                1.5), QwtScaleMap(0, 100, 0.0, 2 * np.pi)))
        # curve 2
        curve = QwtPlotCurve()
        curve.setPen(QPen(QColor(200, 150, 50), 1, Qt.DashDotDotLine))
        curve.setStyle(QwtPlotCurve.Sticks)
        curve.setSymbol(
            QwtSymbol(QwtSymbol.Ellipse, QBrush(Qt.blue), QPen(Qt.yellow),
                      QSize(5, 5)))
        self.tuples.append(
            (curve, QwtScaleMap(0, 100, 0.0,
                                2 * np.pi), QwtScaleMap(0, 100, -3.0, 1.1)))
        # curve 3
        curve = QwtPlotCurve()
        curve.setPen(QPen(QColor(100, 200, 150)))
        curve.setStyle(QwtPlotCurve.Lines)
        self.tuples.append(
            (curve, QwtScaleMap(0, 100, -1.1,
                                3.0), QwtScaleMap(0, 100, -1.1, 3.0)))
        # curve 4
        curve = QwtPlotCurve()
        curve.setPen(QPen(Qt.red))
        curve.setStyle(QwtPlotCurve.Lines)
        self.tuples.append(
            (curve, QwtScaleMap(0, 100, -5.0,
                                1.1), QwtScaleMap(0, 100, -1.1, 5.0)))
        # data
        self.phase = 0.0
        self.base = np.arange(0.0, 2.01 * np.pi, 2 * np.pi / (USize - 1))
        self.uval = np.cos(self.base)
        self.vval = np.sin(self.base)
        self.uval[1::2] *= 0.5
        self.vval[1::2] *= 0.5
        self.newValues()
        # start timer
        self.tid = self.startTimer(250)
Exemple #30
0
 def cizdir(self):
     if len(self.gpslongitude)==2:
         pointItem = self.view3.scene().addCircle(self.gpslongitude[1], self.gpslatitude[1], 5.0)
         pointItem.setBrush(Qt.green)
         pointItem.setPen(QPen(Qt.NoPen))
         pointItem.setToolTip('%f, %f' % (self.gpslongitude[1],self.gpslatitude[1]))
         pointItem.setFlag(QGraphicsItem.ItemIsSelectable, True)
         pointItem2 = self.view5.scene().addCircle(self.gpslongitude[1], self.gpslatitude[1], 5.0)
         pointItem2.setBrush(Qt.green)
         pointItem2.setPen(QPen(Qt.NoPen))
         pointItem2.setToolTip('%f, %f' % (self.gpslongitude[1],self.gpslatitude[1]))
         pointItem2.setFlag(QGraphicsItem.ItemIsSelectable, True)
     else:
         pointItem = self.view3.scene().addCircle(self.gpslong, self.gpslat, 5.0)
         pointItem.setBrush(Qt.blue)
         pointItem.setPen(QPen(Qt.NoPen))
         pointItem.setToolTip('%f, %f' % (self.gpslong,self.gpslat))
         pointItem.setFlag(QGraphicsItem.ItemIsSelectable, True)
         pointItem2 = self.view5.scene().addCircle(self.gpslong, self.gpslat, 5.0)
         pointItem2.setBrush(Qt.blue)
         pointItem2.setToolTip('%f, %f' % (self.gpslong,self.gpslat))
         pointItem2.setFlag(QGraphicsItem.ItemIsSelectable, True)          
     self.view3.scene().update()
     self.view3.setOptimizationFlag(QGraphicsView.DontSavePainterState, True)
     self.view3.setRenderHint(QPainter.Antialiasing, True)
     self.view3.setRenderHint(QPainter.SmoothPixmapTransform, True)
     self.view5.scene().update()
     self.view5.setOptimizationFlag(QGraphicsView.DontSavePainterState, True)
     self.view5.setRenderHint(QPainter.Antialiasing, True)
     self.view5.setRenderHint(QPainter.SmoothPixmapTransform, True)
     self.view3.scene().setItemIndexMethod(QGraphicsScene.NoIndex)
     self.view3.setTransformationAnchor(QGraphicsView.AnchorUnderMouse)
     self.view3.setResizeAnchor(QGraphicsView.AnchorViewCenter)
     self.view5.scene().setItemIndexMethod(QGraphicsScene.NoIndex)
     self.view5.setTransformationAnchor(QGraphicsView.AnchorUnderMouse)
     self.view5.setResizeAnchor(QGraphicsView.AnchorViewCenter)