Beispiel #1
0
    def paintEvent(self, e):
        #define the painter
        painter = QPainter(self)

        #define a brush for the background of the axis area
        brush = QtGui.QBrush()
        brush.setColor(QtGui.QColor('black'))
        brush.setStyle(Qt.SolidPattern)

        #define a rectangle to fill the axis area background
        rect = QtCore.QRect(0, 0,
                            painter.device().width(),
                            painter.device().height())
        painter.fillRect(rect, brush)

        #define width and height for centering
        w = self.width()
        h = self.height()

        title = QtGui.QPen()
        title.setColor(QtGui.QColor('white'))
        painter.setPen(title)
        painter.setOpacity(1)
        font = QtGui.QFont()

        #set up the text labels
        font.setBold(True)
        font.setPointSize(18)
        painter.setFont(font)
        painter.drawText(QRect(0, 0, w, h), Qt.AlignCenter | Qt.AlignCenter,
                         self.plotTitle)
Beispiel #2
0
    def paint_over_unavailable_regions(self, filter_name):
        painter = QPainter()
        painter.begin(self)
        pen = QPen(Qt.transparent)
        painter.setPen(pen)
        brush = QBrush(self.colors[filter_name], Qt.SolidPattern)
        painter.setBrush(brush)
        if len(self.images.get(filter_name, [])) == 0:
            return
        width = painter.device().width() - 2 * self.handle_width
        height = painter.device().height()
        step = width / len(self.images[filter_name])
        position = self.handle_width
        index = 0
        while index < len(self.images[filter_name]):
            start = position
            while index < len(self.images[filter_name]) and not self.images[filter_name][index]:
                position += step
                index += 1

            if start != position:
                painter.drawRect(start, 0, position - start, height)

            position += step
            index += 1
        painter.end()
Beispiel #3
0
    def paintEvent(self, event):
        # pylint: disable = unused-argument
        painter = QPainter(self)
        painter.setRenderHint(QPainter.Antialiasing)
        width = painter.device().width()
        height = painter.device().height()

        # Gradient draw pass
        gradient = QLinearGradient(0, 0, width, 0)
        for stop, color in self.gradient.items():
            gradient.setColorAt(stop, QColor(*color))
        painter.fillRect(0, 0, width, height, gradient)

        # Handles draw pass
        pen = QPen()
        pen.setWidth(3)
        pen.setColor(QColor(255, 255, 255, 191))
        painter.setPen(pen)

        y = height / 2
        for pos in self.gradient.keys():
            x = pos * width
            painter.drawLine(
                QPoint(x, y - 12),
                QPoint(x, y + 12)
            )
            painter.drawEllipse(QPoint(x, y), 6, 6)

        painter.end()
Beispiel #4
0
    def paintEvent(self, event):
        """Draws the current state of the game in the window. """
        painter = QPainter(self)
        brush = QBrush()

        window_width = painter.device().width()
        window_height = painter.device().height()

        # Paint background
        brush.setColor(QColor(BACKGROUND_COLOR))
        brush.setStyle(Qt.SolidPattern)
        background = QRect(0, 0, window_width, window_height)
        painter.fillRect(background, brush)

        # Keep game centered in window
        start_x = (window_width - GAME_WIDTH) / 2
        start_y = (window_height - GAME_HEIGHT) / 2
        cell_width = GAME_WIDTH / N_COLS
        cell_height = GAME_HEIGHT / N_ROWS

        # Paint living cells
        for i in range(N_ROWS):
            for j in range(N_COLS):
                if self._cells[i][j].alive:
                    # Get cell color based on age
                    brush.setColor(QColor(self._cells[i][j].get_color()))

                    # Calculate cell coordinates
                    cell_x = start_x + cell_width * j
                    cell_y = start_y + cell_height * i

                    # Draw cell in window
                    cell = QRect(cell_x, cell_y, cell_width, cell_height)
                    painter.fillRect(cell, brush)
Beispiel #5
0
    def paintEvent(self, e):
        painter = QPainter(self)

        brush = QtGui.QBrush()
        brush.setColor(QColor('black'))
        brush.setStyle(Qt.SolidPattern)
        painter.setBrush(brush)
        rect = QtCore.QRect(0, 0,
                            painter.device().width(),
                            painter.device().height())
        painter.fillRect(rect, brush)

        keyframes_indices = self.parent.selected_text_template.keyframes.keyframes_frames_indices
        slider = self.parent.frames_slider

        pen = QPen()
        pen.setWidth(5)
        pen.setColor(QColor('red'))
        painter.setPen(pen)

        brush = QtGui.QBrush()
        brush.setColor(QColor('red'))
        brush.setStyle(Qt.SolidPattern)
        painter.setBrush(brush)

        for frame_ind in keyframes_indices:
            position = QStyle.sliderPositionFromValue(slider.minimum(),
                                                      slider.maximum(),
                                                      frame_ind,
                                                      slider.width())
            painter.drawEllipse(position, 10, 2, 2)

        painter.end()
Beispiel #6
0
    def paintEvent(self, e):
        #define the painter
        painter = QPainter(self)

        #define a brush for the background of the axis area
        brush = QtGui.QBrush()
        brush.setColor(QtGui.QColor('black'))
        brush.setStyle(Qt.SolidPattern)

        #define a rectangle to fill the axis area background
        rect = QtCore.QRect(0, 0,
                            painter.device().width(),
                            painter.device().height())
        painter.fillRect(rect, brush)

        #define the height and width of the area to be able to divide the ticks properly
        w = rect.width()
        h = rect.height()

        # draw opacity tick marker for x axis
        tick = QtGui.QPen()
        tick.setColor(QtGui.QColor('white'))
        painter.setPen(tick)
        painter.setOpacity(1)
        painter.drawLine(6 * w / 6, 0, 6 * w / 6, 5)
        painter.drawLine(5 * w / 6, 0, 5 * w / 6, 5)
        painter.drawLine(4 * w / 6, 0, 4 * w / 6, 5)
        painter.drawLine(3 * w / 6, 0, 3 * w / 6, 5)
        painter.drawLine(2 * w / 6, 0, 2 * w / 6, 5)
        painter.drawLine(1 * w / 6, 0, 1 * w / 6, 5)
        painter.drawLine(0 * w / 6, 0, 0 * w / 6, 5)
        #draw horizontal axis marker line
        painter.drawLine(0, 0, w, 0)

        # draw text
        x_label = QtGui.QPen()
        x_label.setColor(QtGui.QColor('white'))
        painter.setPen(x_label)
        painter.setOpacity(1)
        font = QtGui.QFont()

        #set up the text labels
        font.setBold(True)
        font.setPointSize(10)
        painter.setFont(font)
        painter.drawText(6 * w / 6 - 9, 20, '0')
        painter.drawText(5 * w / 6 - 7, 20, '10')
        painter.drawText(4 * w / 6 - 7, 20, '20')
        painter.drawText(3 * w / 6 - 7, 20, '30')
        painter.drawText(2 * w / 6 - 7, 20, '40')
        painter.drawText(1 * w / 6 - 7, 20, '50')
        painter.drawText(0 * w / 6 - 0, 20, '60')
        painter.drawText(QRect(0, 0, w, h), Qt.AlignCenter | Qt.AlignBottom,
                         'Time [seconds past]')
Beispiel #7
0
    def paintEvent(self, event):
        painter = QPainter(self)

        painter.setBrush(Qt.darkGreen)
        painter.drawRect(self.rect())

        img_rect = self.img.rect()
        dev_rect = QRect(0, 0,
                         painter.device().width(),
                         painter.device().height())
        img_rect.moveCenter(dev_rect.center())

        painter.drawPixmap(img_rect.topLeft(), self.img)
Beispiel #8
0
    def paintEvent(self, e):
        #define the painter
        painter = QPainter(self)

        #define a brush for the background of the axis area
        brush = QtGui.QBrush()
        brush.setColor(QtGui.QColor('black'))
        brush.setStyle(Qt.SolidPattern)

        #define a rectangle to fill the axis area background
        rect = QtCore.QRect(0, 0,
                            painter.device().width(),
                            painter.device().height())
        painter.fillRect(rect, brush)
Beispiel #9
0
    def paintEvent(self, e):
        if self.v == 100:
            return

        p = QPainter(self)
        brush = QBrush(QColor(self.c[0], self.c[1], self.c[1], 127))
        p.setBrush(brush)
        pen = QPen()
        pen.setStyle(Qt.NoPen)
        p.setPen(pen)

        start = 16 * 90 - 16 * 360 * (self.v / 100)
        span = -16 * 360 * (1 - (self.v / 100))
        # start = 90*16 - 120*16
        # span = -(360-120)*16
        size = p.device().width()
        rect = QRectF(0, 0, size, size)
        # print(str(self.v)+str(self.val[1])+str(span))

        p.drawPie(rect, start, span)
    def redraw(self, painter: QtGui.QPainter, event) -> None:
        # if the button is hidden then there is nothing to draw
        if self._state == ICWidgetState.Hidden:
            return

        ########################################
        # draw the label area
        ########################################
        temp_width = painter.device().width()
        temp_height = painter.device().height()

        # define the rectangle to draw the button
        rect = QtCore.QRectF(3, 3, temp_width - 6, temp_height - 6)

        # path to be drawn
        path = QtGui.QPainterPath()
        path.setFillRule(Qt.WindingFill)
        path.addRoundedRect(rect, 10, 10)

        # brush to fill the area
        brush = QtGui.QLinearGradient(rect.topLeft(), rect.bottomRight())
        if self._state == ICWidgetState.Transparent:
            brush.setColorAt(0, self.background_color)
            brush.setColorAt(1, self.background_color)
        else:
            brush.setColorAt(0, self._container_color_dark)
            brush.setColorAt(1, self._container_color_light)

        painter.setBrush(brush)

        # define the border pen
        if self._state == ICWidgetState.Transparent:
            pen = QtGui.QPen(self.background_color)
        else:
            pen = QtGui.QPen(self._container_border_color)

        if self.in_focus:
            pen.setWidth(3)
        else:
            pen.setWidth(1)

        pen.setCapStyle(Qt.RoundCap)
        pen.setJoinStyle(Qt.RoundJoin)
        painter.setPen(pen)

        # draw the rectangle
        painter.drawPath(path)

        ########################################
        # draw the text only if the button is visible
        ########################################
        if self._state in (ICWidgetState.VisibleEnabled,
                           ICWidgetState.VisibleDisabled):
            # adjust the coordinate system for the border
            painter.translate(3, 3)
            temp_height -= 6
            temp_width -= 6

            ########################################
            # draw the name and unit
            ########################################
            fnt = painter.font()
            fnt.setBold(True)
            fnt.setPixelSize(self._name_text_size)
            painter.setFont(fnt)
            pen.setColor(self._name_color)
            painter.setPen(pen)
            half_width = 0.5 * temp_width
            rect = QtCore.QRectF(0, temp_height - (self._name_text_size + 5),
                                 half_width, self._name_text_size + 5)
            painter.drawText(rect, Qt.AlignRight, str(self._name))

            # draw the unit
            fnt.setPixelSize(self._unit_text_size)
            painter.setFont(fnt)
            rect = QtCore.QRectF(half_width,
                                 temp_height - (self._unit_text_size + 5),
                                 half_width, self._unit_text_size + 5)
            painter.drawText(rect, Qt.AlignLeft, " ({})".format(self._unit))

            # adjust for remaining height
            temp_height -= max(self._name_text_size, self._unit_text_size)

            ########################################
            # draw the value
            ########################################
            fnt.setPixelSize(self._value_text_size)
            painter.setFont(fnt)
            pen.setColor(self._value_color)
            painter.setPen(pen)

            # calculate dimension for the text and rotary gauge
            font_matrices = QtGui.QFontMetrics(fnt)
            text_size = font_matrices.horizontalAdvance(str(self._value))
            box_length = sqrt(2) * (max(text_size, self._value_text_size + 5) +
                                    5)

            # draw the value
            rect = QtCore.QRectF(10, (temp_height -
                                      (self._value_text_size + 5)) / 2,
                                 temp_width - 20, self._value_text_size + 5)
            painter.drawText(rect, Qt.AlignCenter,
                             self._text_format.format(self._value))

            ########################################
            # main gauge
            ########################################
            # create the gradient
            half_height = 0.5 * temp_height
            gradient = QtGui.QConicalGradient(half_width, half_height, 90)
            if self.alarm_activated:
                gradient.setColorAt(0, self._gauge_color_alarm_light)
                gradient.setColorAt(1, self._gauge_color_alarm_dark)
            else:
                gradient.setColorAt(0, self._gauge_color_normal_light)
                gradient.setColorAt(1, self._gauge_color_normal_dark)

            painter.setBrush(gradient)
            pen.setBrush(gradient)
            painter.setPen(pen)

            # calculate the path
            path = QtGui.QPainterPath()
            path.setFillRule(Qt.OddEvenFill)
            theta = 360 * (self._value - self._gauge_range_min) / (
                self._gauge_range_max - self._gauge_range_min)

            # smaller radius
            half_box_length = box_length / 2
            rect = QtCore.QRectF(half_width - half_box_length,
                                 half_height - half_box_length, box_length,
                                 box_length)
            path.moveTo(half_width, half_height - half_box_length)
            path.arcTo(rect, 90, -theta)
            pos = path.currentPosition()

            # bigger radius
            bigger_box_half_length = min(half_width, half_height) - 10
            rect_big = QtCore.QRectF(half_width - bigger_box_half_length,
                                     half_height - bigger_box_half_length,
                                     2 * bigger_box_half_length,
                                     2 * bigger_box_half_length)
            new_x = half_width + (pos.x() - half_width
                                  ) * bigger_box_half_length / half_box_length
            new_y = half_height + (pos.y() - half_height
                                   ) * bigger_box_half_length / half_box_length
            path.lineTo(new_x, new_y)
            path.arcTo(rect_big, 90 - theta, theta)
            path.closeSubpath()

            # paint the gauge
            painter.drawPath(path)

            # draw gauge border
            pen = QtGui.QPen(self._container_border_color)
            pen.setWidth(1)
            pen.setCapStyle(Qt.RoundCap)
            pen.setJoinStyle(Qt.RoundJoin)
            painter.setPen(pen)
            painter.setBrush(QtGui.QBrush())
            painter.drawEllipse(rect)
            painter.drawEllipse(rect_big)

            ########################################
            # target line
            ########################################
            if self._target_tracking:
                theta = 360 * (self._target_value - self._gauge_range_min) / (
                    self._gauge_range_max - self._gauge_range_min)

                # calculate the path
                path = QtGui.QPainterPath()
                path.arcMoveTo(rect, 90 - theta)
                pos = path.currentPosition()
                new_x = half_width + (pos.x(
                ) - half_width) * bigger_box_half_length / half_box_length
                new_y = half_height + (pos.y(
                ) - half_height) * bigger_box_half_length / half_box_length
                path.lineTo(new_x, new_y)

                # set up the pen
                pen.setColor(self._target_color)
                pen.setWidth(2)
                painter.setPen(pen)
                painter.drawPath(path)

            ########################################
            # min max lines
            ########################################
            if self._cycle_min_tracking:
                theta = 360 * (self._cycle_min - self._gauge_range_min) / (
                    self._gauge_range_max - self._gauge_range_min)

                # calculate the path
                path = QtGui.QPainterPath()
                path.arcMoveTo(rect, 90 - theta)
                pos = path.currentPosition()
                new_x = half_width + (pos.x(
                ) - half_width) * bigger_box_half_length / half_box_length
                new_y = half_height + (pos.y(
                ) - half_height) * bigger_box_half_length / half_box_length
                path.lineTo(new_x, new_y)

                # set up the pen
                pen.setColor(self._min_max_color)
                pen.setWidth(2)
                painter.setPen(pen)
                painter.drawPath(path)

            if self._cycle_max_tracking:
                theta = 360 * (self._cycle_max - self._gauge_range_min) / (
                    self._gauge_range_max - self._gauge_range_min)

                # calculate the path
                path = QtGui.QPainterPath()
                path.arcMoveTo(rect, 90 - theta)
                pos = path.currentPosition()
                new_x = half_width + (pos.x(
                ) - half_width) * bigger_box_half_length / half_box_length
                new_y = half_height + (pos.y(
                ) - half_height) * bigger_box_half_length / half_box_length
                path.lineTo(new_x, new_y)

                # set up the pen
                pen.setColor(self._min_max_color)
                pen.setWidth(2)
                painter.setPen(pen)
                painter.drawPath(path)

            ########################################
            # upper and lower alarm lines
            ########################################
            if self._alarm_lower_level_set:
                theta = 360 * (self._alarm_lower_level - self._gauge_range_min
                               ) / (self._gauge_range_max -
                                    self._gauge_range_min)

                # calculate the path
                path = QtGui.QPainterPath()
                path.arcMoveTo(rect, 90 - theta)
                pos = path.currentPosition()
                new_x = half_width + (pos.x(
                ) - half_width) * bigger_box_half_length / half_box_length
                new_y = half_height + (pos.y(
                ) - half_height) * bigger_box_half_length / half_box_length
                path.lineTo(new_x, new_y)

                # set up the pen
                pen.setColor(self._alarm_color)
                pen.setWidth(2)
                painter.setPen(pen)
                painter.drawPath(path)

            if self._alarm_upper_level_set:
                theta = 360 * (self._alarm_upper_level - self._gauge_range_min
                               ) / (self._gauge_range_max -
                                    self._gauge_range_min)

                # calculate the path
                path = QtGui.QPainterPath()
                path.arcMoveTo(rect, 90 - theta)
                pos = path.currentPosition()
                new_x = half_width + (pos.x(
                ) - half_width) * bigger_box_half_length / half_box_length
                new_y = half_height + (pos.y(
                ) - half_height) * bigger_box_half_length / half_box_length
                path.lineTo(new_x, new_y)

                # set up the pen
                pen.setColor(self._alarm_color)
                pen.setWidth(2)
                painter.setPen(pen)
                painter.drawPath(path)
    def redraw(self, painter: QtGui.QPainter, vertical_offset: float = 0) -> None:
        # if the button is hidden then there is nothing to draw
        if self._state == ICWidgetState.Hidden:
            return

        # the size of the button is determined by the size of the widget
        tmp_width = painter.device().width()
        tmp_height = painter.device().height()

        # define the rectangle to draw the button
        rect = QtCore.QRectF(5, 5, tmp_width - 10, tmp_height - 10)

        # a linear gradient brush is used to fill the button
        brush = QtGui.QLinearGradient(rect.topRight(), rect.bottomRight())
        # if the widget is transparent then the rect is drawn using background color
        if self._state == ICWidgetState.Transparent:
            brush.setColorAt(0, self.background_color)
            brush.setColorAt(1, self.background_color)
        else:
            brush.setColorAt(0, self._button_color_light)
            brush.setColorAt(1, self._button_color_dark)

        # set the brush
        painter.setBrush(brush)

        # define the pen that with rounded cap and join style
        if not self.in_focus:
            pen = QtGui.QPen()
            pen.setWidth(1)
        else:
            pen = QtGui.QPen(self.focus_color)
            pen.setWidth(3)
        pen.setCapStyle(Qt.RoundCap)
        pen.setJoinStyle(Qt.RoundJoin)

        # set the pen to use the brush and set the painter pen
        if not self.in_focus:
            pen.setBrush(brush)
        painter.setPen(pen)

        # define the path that needs to be drawn
        path = QtGui.QPainterPath()
        path.setFillRule(Qt.WindingFill)
        path.addRoundedRect(rect, 10, 10)
        painter.drawPath(path)

        # draw the text only if the button is visible
        if self._state in (ICWidgetState.VisibleEnabled, ICWidgetState.VisibleDisabled):
            # define the font for drawing
            fnt = painter.font()
            fnt.setBold(True)
            fnt.setPixelSize(self._text_size)
            painter.setFont(fnt)

            # select the font color based on if the button is enabled or not
            if self._state == ICWidgetState.VisibleEnabled:
                pen.setColor(self._text_color_enabled)
            else:
                pen.setColor(self._text_color_disabled)
            painter.setPen(pen)

            # draw the text
            rect = QtCore.QRectF(10, tmp_height / 2 - 0.5 * (self._text_size + 5) + vertical_offset, tmp_width - 20, self._text_size + 5)
            painter.drawText(rect, Qt.AlignCenter, str(self._name))
Beispiel #12
0
def drawIconWithShadow(icon: QIcon,
                       rect: QRect,
                       p: QPainter,
                       iconMode: QIcon.Mode = None,
                       dipRadius: int = None,
                       color: QColor = None,
                       dipOffset: QPoint = None):
    if iconMode is None:
        iconMode = QIcon.Normal
    if color is None:
        color = QColor(0, 0, 0, 130)
    if dipRadius is None:
        dipRadius = 3
    if dipOffset is None:
        dipOffset = QPoint(1, -2)

    devicePixelRatio: int = p.device().devicePixelRatio()
    pixmapName = "icon %s %s %s %s" % (icon.cacheKey(), iconMode,
                                       rect.height(), devicePixelRatio)
    cache = QPixmapCache.find(pixmapName)
    if cache is None:
        # High-dpi support: The in parameters (rect, radius, offset) are in
        # device-independent pixels. The call to QIcon::pixmap() below might
        # return a high-dpi pixmap, which will in that case have a devicePixelRatio
        # different than 1. The shadow drawing caluculations are done in device
        # pixels.
        window = p.device().window().windowHandle()
        px = icon.pixmap(window, rect.size(), iconMode)
        radius = dipRadius * devicePixelRatio
        offset = dipOffset * devicePixelRatio
        cache = QPixmap(px.size() + QSize(radius * 2, radius * 2))
        cache.fill(Qt.transparent)
        cachePainter = QPainter(cache)

        if iconMode == QIcon.Disabled:
            hasDisabledState = len(icon.availableSizes()) == len(
                icon.availableSizes(QIcon.Disabled))
            if not hasDisabledState:
                px = disabledSideBarIcon(icon.pixmap(window, rect.size()))
        elif TOOLBAR_ICON_SHADOW:
            # Draw shadow
            tmp = QImage(px.size() + QSize(radius * 2, radius * 2 + 1),
                         QImage.Format_ARGB32_Premultiplied)
            tmp.fill(Qt.transparent)

            tmpPainter = QPainter(tmp)
            tmpPainter.setCompositionMode(QPainter.CompositionMode_Source)
            tmpPainter.drawPixmap(
                QRect(radius, radius, px.width(), px.height()), px)
            tmpPainter.end()

            # blur the alpha channel
            blurred = QImage(tmp.size(), QImage.Format_ARGB32_Premultiplied)
            blurred.fill(Qt.transparent)
            blurPainter = QPainter(blurred)
            #qt_blurImage(blurPainter, tmp, radius, False, True)
            # implement qt_blurImage via QLabel with QGraphicsBlurEffect
            # FIXME: alignment is broken
            scene = QGraphicsScene()
            item = QGraphicsPixmapItem(QPixmap.fromImage(tmp))
            effect = QGraphicsBlurEffect()
            effect.setBlurRadius(radius)
            item.setGraphicsEffect(effect)
            scene.addItem(item)
            scene.render(blurPainter)
            blurPainter.end()
            tmp = blurred

            # blacken the image...
            tmpPainter.begin(tmp)
            tmpPainter.setCompositionMode(QPainter.CompositionMode_SourceIn)
            tmpPainter.fillRect(tmp.rect(), color)
            tmpPainter.end()

            tmpPainter.begin(tmp)
            tmpPainter.setCompositionMode(QPainter.CompositionMode_SourceIn)
            tmpPainter.fillRect(tmp.rect(), color)
            tmpPainter.end()

            # draw the blurred drop shadow...
            cachePainter.drawImage(
                QRect(0, 0,
                      cache.rect().width(),
                      cache.rect().height()), tmp)

        # Draw the actual pixmap...
        cachePainter.drawPixmap(
            QRect(
                QPoint(radius, radius) + offset, QSize(px.width(),
                                                       px.height())), px)
        cachePainter.end()
        cache.setDevicePixelRatio(devicePixelRatio)
        QPixmapCache.insert(pixmapName, cache)

    targetRect = cache.rect()
    targetRect.setSize(targetRect.size() / cache.devicePixelRatio())
    targetRect.moveCenter(rect.center() - dipOffset)
    p.drawPixmap(targetRect, cache)
Beispiel #13
0
    def redraw(self, painter: QtGui.QPainter, event) -> None:
        # if the button is hidden then there is nothing to draw
        if self._state == ICWidgetState.Hidden:
            return

        # draw the label area
        tmp_width = painter.device().width()
        tmp_height = painter.device().height()

        # define the rectangle to draw the button
        rect = QtCore.QRectF(3, 3, tmp_width-6, tmp_height-6)

        # path to be drawn
        path = QtGui.QPainterPath()
        path.setFillRule(Qt.WindingFill)
        path.addRoundedRect(rect, 10, 10)

        # brush to fill the area
        brush = QtGui.QLinearGradient(rect.topRight(), rect.bottomRight())
        if self._state == ICWidgetState.Transparent:
            brush.setColorAt(0, self.background_color)
            brush.setColorAt(1, self.background_color)
        else:
            brush.setColorAt(0, self._label_color_dark)
            brush.setColorAt(0.5, self._label_color_light)
            brush.setColorAt(1, self._label_color_dark)
        painter.setBrush(brush)

        # define the border pen
        if self._state == ICWidgetState.Transparent:
            pen = QtGui.QPen(self.background_color)
        else:
            pen = QtGui.QPen(self._border_color)
        if self.in_focus:
            pen.setWidth(3)
        else:
            pen.setWidth(1)
        pen.setCapStyle(Qt.RoundCap)
        pen.setJoinStyle(Qt.RoundJoin)
        painter.setPen(pen)

        # draw the rectangle
        painter.drawPath(path)

        # draw the text only if the button is visible
        if self._state in (ICWidgetState.VisibleEnabled, ICWidgetState.VisibleDisabled):
            # draw the name
            fnt = painter.font()
            fnt.setBold(True)
            fnt.setPixelSize(self._name_text_size)
            painter.setFont(fnt)
            pen.setColor(self._name_color)
            painter.setPen(pen)
            rect = QtCore.QRect(10, 10, tmp_width - 20, self._name_text_size + 5)
            painter.drawText(rect, Qt.AlignLeft, str(self._name))

            # draw the value
            fnt.setPixelSize(self._value_text_size)
            painter.setFont(fnt)
            pen.setColor(self._value_color)
            painter.setPen(pen)
            rect = QtCore.QRect(10, tmp_height - (self._value_text_size + 15), tmp_width - 20, self._value_text_size + 5)
            if self.__type == ICTextLabelType.LabelText:
                painter.drawText(rect, Qt.AlignRight, self._value)
            elif self.__type == ICTextLabelType.LabelInteger:
                painter.drawText(rect, Qt.AlignRight, str(self._value))
            else:
                painter.drawText(rect, Qt.AlignRight, self._text_format.format(self._value))
Beispiel #14
0
    def paintEvent(self, e):
        #define the painter
        painter = QPainter(self)

        #define a brush for the rectangle to fill in the background
        brush = QtGui.QBrush()
        brush.setColor(QtGui.QColor('black'))
        brush.setStyle(Qt.SolidPattern)

        #fill in the background of the canvas area
        rect = QtCore.QRect(0, 0,
                            painter.device().width(),
                            painter.device().height())
        painter.fillRect(rect, brush)

        #define the height and width of the area to be able to divide the ticks properly
        w = rect.width()
        h = rect.height()

        # draw opacity tick marker for x axis
        tick = QtGui.QPen()
        tick.setColor(QtGui.QColor('white'))

        painter.setPen(tick)
        painter.setOpacity(1)

        #draw the top and right lines
        painter.drawLine(w - 1, 0, w - 1, h)
        painter.drawLine(0, 0, w - 1, 0)

        #draw on-canvas lines, dashed, to help see values
        painter.setOpacity(0.2)
        tick.setStyle(Qt.DashLine)
        painter.setPen(tick)

        #horizontal lines
        painter.drawLine(0, 4 * h / 5, w, 4 * h / 5)
        painter.drawLine(0, 3 * h / 5, w, 3 * h / 5)
        painter.drawLine(0, 2 * h / 5, w, 2 * h / 5)
        painter.drawLine(0, 1 * h / 5, w, 1 * h / 5)

        #vertical lines
        painter.drawLine(5 * w / 6, 0, 5 * w / 6, h)
        painter.drawLine(4 * w / 6, 0, 4 * w / 6, h)
        painter.drawLine(3 * w / 6, 0, 3 * w / 6, h)
        painter.drawLine(2 * w / 6, 0, 2 * w / 6, h)
        painter.drawLine(1 * w / 6, 0, 1 * w / 6, h)

        #define scale values for plot
        mx = (0 - w) / (60 - 0)
        bx = w
        my = (0 - h) / (self.parent()._VAxes.vertAxisMax -
                        self.parent()._VAxes.vertAxisMin)
        by = h - my * self.parent()._VAxes.vertAxisMin

        #define pens for plots
        painter.setOpacity(1)
        colorA = QtGui.QPen()
        colorA.setColor(QtGui.QColor('red'))
        colorB = QtGui.QPen()
        colorB.setColor(QtGui.QColor('blue'))
        colorC = QtGui.QPen()
        colorC.setColor(QtGui.QColor('green'))
        colorD = QtGui.QPen()
        colorD.setColor(QtGui.QColor('yellow'))

        showA = self.parent().enables[0] == True and self.parent(
        ).display[0] == True
        showB = self.parent().enables[1] == True and self.parent(
        ).display[1] == True
        showC = self.parent().enables[2] == True and self.parent(
        ).display[2] == True
        showD = self.parent().enables[3] == True and self.parent(
        ).display[3] == True

        for i in range(len(self.valuesA) - 1):
            xPt1 = self.times[i]
            xPt2 = self.times[i + 1]

            if showA:
                yPt1 = self.valuesA[i]
                yPt2 = self.valuesA[i + 1]
                painter.setPen(colorA)
                painter.drawLine(mx * xPt1 + bx, my * yPt1 + by,
                                 mx * xPt2 + bx, my * yPt2 + by)

            if showB:
                yPt1 = self.valuesB[i]
                yPt2 = self.valuesB[i + 1]
                painter.setPen(colorB)
                painter.drawLine(mx * xPt1 + bx, my * yPt1 + by,
                                 mx * xPt2 + bx, my * yPt2 + by)

            if showC:
                yPt1 = self.valuesC[i]
                yPt2 = self.valuesC[i + 1]
                painter.setPen(colorC)
                painter.drawLine(mx * xPt1 + bx, my * yPt1 + by,
                                 mx * xPt2 + bx, my * yPt2 + by)

            if showD:
                yPt1 = self.valuesD[i]
                yPt2 = self.valuesD[i + 1]
                painter.setPen(colorD)
                painter.drawLine(mx * xPt1 + bx, my * yPt1 + by,
                                 mx * xPt2 + bx, my * yPt2 + by)
Beispiel #15
0
    def paintEvent(self, e):
        #define the painter
        painter = QPainter(self)

        #define a brush for the background of the axis area
        brush = QtGui.QBrush()
        brush.setColor(QtGui.QColor('black'))
        brush.setStyle(Qt.SolidPattern)

        #define a rectangle to fill the axis area background
        rect = QtCore.QRect(0, 0,
                            painter.device().width(),
                            painter.device().height())
        painter.fillRect(rect, brush)

        #define the height and width of the area to be able to divide the ticks properly
        w = rect.width()
        h = rect.height()

        # draw opacity tick marker for x axis
        tick = QtGui.QPen()
        tick.setColor(QtGui.QColor('white'))
        painter.setPen(tick)
        painter.setOpacity(1)
        painter.drawLine(w, 5 * h / 5 - 1, w - 5, 5 * h / 5 - 1)
        painter.drawLine(w, 4 * h / 5, w - 5, 4 * h / 5)
        painter.drawLine(w, 3 * h / 5, w - 5, 3 * h / 5)
        painter.drawLine(w, 2 * h / 5, w - 5, 2 * h / 5)
        painter.drawLine(w, 1 * h / 5, w - 5, 1 * h / 5)
        painter.drawLine(w, 0 * h / 5, w - 5, 0 * h / 5)
        #draw vertical axis marker line
        painter.drawLine(w - 1, 0, w - 1, h)

        # draw text
        x_label = QtGui.QPen()
        x_label.setColor(QtGui.QColor('white'))
        painter.setPen(x_label)
        painter.setOpacity(1)
        font = QtGui.QFont()

        #set up the text labels
        font.setBold(True)
        font.setPointSize(10)
        painter.setFont(font)
        #use the externally set maximum and minimum values
        t0 = str(self.vertAxisMin)
        t1 = str(self.vertAxisMin +
                 (self.vertAxisMax - self.vertAxisMin) * 1 / 5)
        t2 = str(self.vertAxisMin +
                 (self.vertAxisMax - self.vertAxisMin) * 2 / 5)
        t3 = str(self.vertAxisMin +
                 (self.vertAxisMax - self.vertAxisMin) * 3 / 5)
        t4 = str(self.vertAxisMin +
                 (self.vertAxisMax - self.vertAxisMin) * 4 / 5)
        t5 = str(self.vertAxisMin +
                 (self.vertAxisMax - self.vertAxisMin) * 5 / 5)
        painter.drawText(QRect(w - 45, 5 * h / 5 - 16, 40, 20),
                         Qt.AlignRight | Qt.AlignVCenter, t0)
        painter.drawText(QRect(w - 45, 4 * h / 5 - 10, 40, 20),
                         Qt.AlignRight | Qt.AlignVCenter, t1)
        painter.drawText(QRect(w - 45, 3 * h / 5 - 10, 40, 20),
                         Qt.AlignRight | Qt.AlignVCenter, t2)
        painter.drawText(QRect(w - 45, 2 * h / 5 - 10, 40, 20),
                         Qt.AlignRight | Qt.AlignVCenter, t3)
        painter.drawText(QRect(w - 45, 1 * h / 5 - 10, 40, 20),
                         Qt.AlignRight | Qt.AlignVCenter, t4)
        painter.drawText(QRect(w - 45, 0 * h / 5 - 4, 40, 20),
                         Qt.AlignRight | Qt.AlignVCenter, t5)
        painter.translate(0, h)
        painter.rotate(-90.0)

        #pull in the axis label from outside the class
        painter.drawText(QRect(0, 0, h, w / 2), Qt.AlignCenter | Qt.AlignTop,
                         self.axisLabel)