def _lighten_with_alpha(self, hue_pixmap):
        from pyvmmonitor_qt.qt.QtGui import QPixmap
        from pyvmmonitor_qt.qt_utils import painter_on
        from pyvmmonitor_qt.qt.QtGui import QRadialGradient
        from pyvmmonitor_qt.qt.QtGui import QBrush

        size = self._wheel_size

        # Create a gradient to lighten up the center
        alpha_channel_pixmap = QPixmap(size, size)
        alpha_channel_pixmap.fill(Qt.transparent)
        radius = (size / 2) - 4
        rg = QRadialGradient(size / 2, size / 2, radius, size / 2, size / 2)

        delta = 0.1
        v = 0.0
        for _ in range(10):
            v += delta
            rg.setColorAt(v, QColor.fromHsvF(0, 0, 1.0, 1.0 - v))

        with painter_on(alpha_channel_pixmap, True) as painter:
            painter.setPen(Qt.NoPen)
            painter.setBrush(QBrush(rg))
            painter.drawEllipse(0, 0, size, size)

        with painter_on(hue_pixmap, True) as painter:
            # Draw the alpha channel pixmap on top of the hue.
            painter.drawPixmap(0, 0, alpha_channel_pixmap)

        return hue_pixmap
    def _lighten_with_alpha(self, hue_pixmap):
        from pyvmmonitor_qt.qt.QtGui import QPixmap
        from pyvmmonitor_qt.qt_utils import painter_on
        from pyvmmonitor_qt.qt.QtGui import QRadialGradient
        from pyvmmonitor_qt.qt.QtGui import QBrush

        size = self._wheel_size

        # Create a gradient to lighten up the center
        alpha_channel_pixmap = QPixmap(size, size)
        alpha_channel_pixmap.fill(Qt.transparent)
        radius = (size / 2) - 4
        rg = QRadialGradient(size / 2, size / 2, radius, size / 2, size / 2)

        delta = 0.1
        v = 0.0
        for _ in range(10):
            v += delta
            rg.setColorAt(v, QColor.fromHsvF(0, 0, 1.0, 1.0 - v))

        with painter_on(alpha_channel_pixmap, True) as painter:
            painter.setPen(Qt.NoPen)
            painter.setBrush(QBrush(rg))
            painter.drawEllipse(0, 0, size, size)

        with painter_on(hue_pixmap, True) as painter:
            # Draw the alpha channel pixmap on top of the hue.
            painter.drawPixmap(0, 0, alpha_channel_pixmap)

        return hue_pixmap
Example #3
0
def create_tiled_pixmap(width, height, brush_square_len):
    '''
    Creates a pixmap which is tiled (to be used as a background when drawing transparent colors).
    :param width: pixmap width
    :param height: pixmap height
    :param brush_square_len: len of each square to be drawn.
    '''
    from pyvmmonitor_qt.qt.QtGui import QPixmap, QBrush
    from pyvmmonitor_qt.qt_utils import painter_on
    from pyvmmonitor_qt.qt.QtCore import Qt
    brush_square_len *= 2  # Double because we'll create a pattern that's twice the size.
    p = QPixmap(brush_square_len, brush_square_len)
    middle = brush_square_len / 2
    with painter_on(p, antialias=False) as pix_painter:
        pix_painter.fillRect(0, 0, brush_square_len, brush_square_len, Qt.white)
        pix_painter.fillRect(0, 0, middle, middle, Qt.gray)
        pix_painter.fillRect(middle, middle, brush_square_len, brush_square_len, Qt.gray)
        pix_painter.end()
        brush = QBrush(p)

    p2 = QPixmap(width, height)
    with painter_on(p2, antialias=False) as pix_painter:
        pix_painter.fillRect(
            0, 0, width, height, brush)
    return p2
    def paintEvent(self, ev):
        from pyvmmonitor_qt.qt_utils import painter_on
        from pyvmmonitor_qt.qt.QtGui import QColor
        from pyvmmonitor_qt.qt.QtCore import Qt
        from pyvmmonitor_qt.qt.QtGui import QBrush

        QPixmapWidget.paintEvent(self, ev)
        pixmap = self._pixmap
        triangle_path = self._triangle_path
        pixmap_offset = self._pixmap_offset
        if pixmap is None or triangle_path is None or pixmap_offset is None:
            return

        # After painting, also show the value selected.
        with painter_on(self, True) as painter:
            painter.setPen(Qt.lightGray)

            translation = [pixmap_offset[0], pixmap_offset[1]]
            translation[1] += (pixmap.height() + 2)
            translation[0] += (self.normalized_value * pixmap.width())  # calculate the position
            translation[0] -= (self._triangle_size / 2)

            path = triangle_path.translated(translation[0], translation[1])
            painter.fillPath(path, QBrush(QColor(30, 30, 30)))
            painter.drawPath(path)
    def _create_pixmap(self):
        '''
        Creates a qpixmap with the gradient.
        '''
        from pyvmmonitor_qt.qt.QtGui import QLinearGradient
        from pyvmmonitor_qt.qt.QtCore import Qt
        from pyvmmonitor_qt.qt_utils import painter_on
        from pyvmmonitor_qt.qt.QtGui import QBrush
        from pyvmmonitor_qt import qt_painter_path
        from pyvmmonitor_qt.qt_pixmap_widget import create_tiled_pixmap
        w, h = self._w, self._h
        triangle_size = int(min(w, h) * .3)
        if triangle_size < 10:
            triangle_size = 10
        w *= .9
        h *= .9

        # pixmap = QPixmap(w, h)
        # Note: we could do the tiling only if there was actually some alpha.
        pixmap = create_tiled_pixmap(w, h, min(w, h) // 3)
        gradient = QLinearGradient(0, h // 2, w, h // 2)
        gradient.setStops(self._gradient_stops)
        with painter_on(pixmap, True) as painter:
            painter.setBrush(QBrush(gradient))
            painter.setPen(Qt.NoPen)
            painter.drawRect(0, 0, w, h)

        self._triangle_path = qt_painter_path.create_equilateral_triangle_painter_path(
            triangle_size)
        self._triangle_size = triangle_size

        return pixmap
    def _create_hue_pixmap(self):
        '''
        Create a simple hue pixmap where we change the hue in a conical gradient.
        '''
        from pyvmmonitor_qt.qt.QtGui import QPixmap
        from pyvmmonitor_qt.qt.QtGui import QBrush
        from pyvmmonitor_qt.qt_utils import painter_on
        from pyvmmonitor_qt.qt.QtGui import QConicalGradient

        stops = 360
        delta = 1.0 / stops
        v = 0.0
        size = self._wheel_size

        pixmap = QPixmap(size, size)
        pixmap.fill(Qt.transparent)

        degrees = 360
        gradient = QConicalGradient(size / 2, size / 2, degrees)
        for _stop in range(stops):
            v += delta
            # we do 1.0 - v to have blue on top (just a matter of taste really).
            color = QColor.fromHsvF(1.0 - v, 1.0, 1.0)
            gradient.setColorAt(v, color)

        with painter_on(pixmap, True) as painter:
            painter.setPen(Qt.NoPen)
            painter.setBrush(QBrush(gradient))
            painter.drawEllipse(0, 0, size, size)

        return pixmap
    def paintEvent(self, ev):
        from pyvmmonitor_qt.qt_utils import painter_on
        from pyvmmonitor_core import math_utils
        import math

        QPixmapWidget.paintEvent(self, ev)
        color = self._model.color
        if color is None or self._pixmap is None:
            return

        # After the pixmap is drawn, draw the selected hue/saturation.
        hue, saturation = color.hsvHueF(), color.hsvSaturationF()
        size = self._pixmap.width()
        center = self._center
        degrees = hue * 360
        distance = saturation * (size / 2)

        pointer_size = self._pointer_size
        delta = pointer_size / 2

        pt = math_utils.create_point(center, math.radians(degrees), distance)
        rect = pt[0] - delta, pt[1] - delta, pointer_size, pointer_size
        rect2 = rect[0] - 1, rect[1] - 1, rect[2] + 2, rect[3] + 2

        with painter_on(self, True) as painter:
            painter.setPen(Qt.white)
            painter.drawEllipse(*rect)
            painter.setPen(Qt.black)
            painter.drawEllipse(*rect2)
    def paintEvent(self, ev):
        from pyvmmonitor_qt.qt_utils import painter_on
        from pyvmmonitor_qt.qt.QtGui import QColor
        from pyvmmonitor_qt.qt.QtCore import Qt
        from pyvmmonitor_qt.qt.QtGui import QBrush

        QPixmapWidget.paintEvent(self, ev)
        pixmap = self._pixmap
        triangle_path = self._triangle_path
        pixmap_offset = self._pixmap_offset
        if pixmap is None or triangle_path is None or pixmap_offset is None:
            return

        # After painting, also show the value selected.
        with painter_on(self, True) as painter:
            painter.setPen(Qt.lightGray)

            translation = [pixmap_offset[0], pixmap_offset[1]]
            translation[1] += (pixmap.height() + 2)
            translation[0] += (self.normalized_value * pixmap.width()
                               )  # calculate the position
            translation[0] -= (self._triangle_size / 2)

            path = triangle_path.translated(translation[0], translation[1])
            painter.fillPath(path, QBrush(QColor(30, 30, 30)))
            painter.drawPath(path)
    def paintEvent(self, ev):
        from pyvmmonitor_qt.qt_utils import painter_on
        from pyvmmonitor_core import math_utils
        import math

        QPixmapWidget.paintEvent(self, ev)
        color = self._model.color
        if color is None or self._pixmap is None:
            return

        # After the pixmap is drawn, draw the selected hue/saturation.
        hue, saturation = color.hsvHueF(), color.hsvSaturationF()
        size = self._pixmap.width()
        center = self._center
        degrees = hue * 360
        distance = saturation * (size / 2)

        pointer_size = self._pointer_size
        delta = pointer_size / 2

        pt = math_utils.create_point(center, math.radians(degrees), distance)
        rect = pt[0] - delta, pt[1] - delta, pointer_size, pointer_size
        rect2 = rect[0] - 1, rect[1] - 1, rect[2] + 2, rect[3] + 2

        with painter_on(self, True) as painter:
            painter.setPen(Qt.white)
            painter.drawEllipse(*rect)
            painter.setPen(Qt.black)
            painter.drawEllipse(*rect2)
    def _create_pixmap(self):
        '''
        Creates a qpixmap with the gradient.
        '''
        from pyvmmonitor_qt.qt.QtGui import QLinearGradient
        from pyvmmonitor_qt.qt.QtCore import Qt
        from pyvmmonitor_qt.qt_utils import painter_on
        from pyvmmonitor_qt.qt.QtGui import QBrush
        from pyvmmonitor_qt import qt_painter_path
        from pyvmmonitor_qt.qt_pixmap_widget import create_tiled_pixmap
        w, h = self._w, self._h
        triangle_size = int(min(w, h) * .3)
        if triangle_size < 10:
            triangle_size = 10
        w *= .9
        h *= .9

        # pixmap = QPixmap(w, h)
        # Note: we could do the tiling only if there was actually some alpha.
        pixmap = create_tiled_pixmap(w, h, min(w, h) // 3)
        gradient = QLinearGradient(0, h // 2, w, h // 2)
        gradient.setStops(self._gradient_stops)
        with painter_on(pixmap, True) as painter:
            painter.setBrush(QBrush(gradient))
            painter.setPen(Qt.NoPen)
            painter.drawRect(0, 0, w, h)

        self._triangle_path = qt_painter_path.create_equilateral_triangle_painter_path(
            triangle_size)
        self._triangle_size = triangle_size

        return pixmap
Example #11
0
    def paintEvent(self, event):
        """ Paint the line numbers.
        """
        with painter_on(self, antialias=True) as painter:
            painter.setFont(self.font)
            if self.background_color is not None:
                painter.fillRect(event.rect(), self.background_color)

            cw = self.parent()
            block = cw.firstVisibleBlock()
            blocknum = block.blockNumber()
            top = cw.blockBoundingGeometry(block).translated(
                cw.contentOffset()).top()
            bottom = top + int(cw.blockBoundingRect(block).height())

            while block.isValid() and top <= event.rect().bottom():
                if block.isVisible() and bottom >= event.rect().top():
                    painter.setPen(self.foreground_color)
                    painter.drawText(0, top, self.width() - 2,
                                     self.fontMetrics().height(),
                                     QtCore.Qt.AlignRight, str(blocknum + 1))
                block = block.next()
                top = bottom
                bottom = top + int(cw.blockBoundingRect(block).height())
                blocknum += 1
Example #12
0
    def paintEvent(self, ev):
        from pyvmmonitor_qt.qt_utils import painter_on
        pixmap = self._pixmap
        widget_size = self._w, self._h

        if pixmap is None or (
                self._regenerate_pixmap_on_resize and widget_size != self._last_widget_size):
            pixmap = self.force_create_pixmap()

            if pixmap is None:
                self._last_widget_size = None
                return

            pixmap_size = pixmap.width(), pixmap.height()
            self._last_widget_size = widget_size
        else:
            pixmap_size = pixmap.width(), pixmap.height()

        with painter_on(self, False) as painter:
            # Draws the pixmap centered in the widget.
            diff = int((widget_size[0] - pixmap_size[0]) / 2), \
                int((widget_size[1] - pixmap_size[1]) / 2)

            self._pixmap_offset = diff
            painter.drawPixmap(diff[0], diff[1], pixmap)
    def _create_hue_pixmap(self):
        '''
        Create a simple hue pixmap where we change the hue in a conical gradient.
        '''
        from pyvmmonitor_qt.qt.QtGui import QPixmap
        from pyvmmonitor_qt.qt.QtGui import QBrush
        from pyvmmonitor_qt.qt_utils import painter_on
        from pyvmmonitor_qt.qt.QtGui import QConicalGradient

        stops = 360
        delta = 1.0 / stops
        v = 0.0
        size = self._wheel_size

        pixmap = QPixmap(size, size)
        pixmap.fill(Qt.transparent)

        degrees = 360
        gradient = QConicalGradient(size / 2, size / 2, degrees)
        for _stop in range(stops):
            v += delta
            # we do 1.0 - v to have blue on top (just a matter of taste really).
            color = QColor.fromHsvF(1.0 - v, 1.0, 1.0)
            gradient.setColorAt(v, color)

        with painter_on(pixmap, True) as painter:
            painter.setPen(Qt.NoPen)
            painter.setBrush(QBrush(gradient))
            painter.drawEllipse(0, 0, size, size)

        return pixmap
 def paintEvent(self, ev):
     color = self._model.color
     from pyvmmonitor_qt.qt_utils import painter_on
     with painter_on(self, False) as painter:
         radius = self.width() / 5
         painter.setBrush(color)
         size = self.width() - 2
         painter.drawRoundedRect(0, 0, size, size, radius, radius)
 def paintEvent(self, ev):
     color = self._model.color
     from pyvmmonitor_qt.qt_utils import painter_on
     with painter_on(self, False) as painter:
         radius = self.width() / 5
         painter.setBrush(color)
         size = self.width() - 2
         painter.drawRoundedRect(0, 0, size, size, radius, radius)
Example #16
0
    def paintEvent(self, event):
        """ Paint the line numbers.
        """
        with painter_on(self, antialias=True) as painter:
            if self.background_color is not None:
                painter.fillRect(event.rect(), self.background_color)

            cw = self.parent()

            pixels_per_block = self.height() / float(cw.blockCount())

            for line in self.info_lines:
                painter.fillRect(QtCore.QRect(0, line * pixels_per_block, self.width(), 3),
                                 QtCore.Qt.green)

            for line in self.warn_lines:
                painter.fillRect(QtCore.QRect(0, line * pixels_per_block, self.width(), 3),
                                 QtCore.Qt.yellow)

            for line in self.error_lines:
                painter.fillRect(QtCore.QRect(0, line * pixels_per_block, self.width(), 3),
                                 QtCore.Qt.red)
Example #17
0
 def paintEvent(self, event):
     """ Paint the line numbers.
     """
     with painter_on(self, antialias=True) as painter:
         painter.fillRect(event.rect(), QtCore.Qt.lightGray)