def _update_widgets(self):
     _BaseColorsWidget._update_widgets(self)
     if self.update_colors_in_slider:
         color = self._model.color
         h, s, v = self._get_color_params(color)
         self._widget_1.set_gradient_stops(
             [(x / 100, QColor.fromHsvF(h, x / 100., v)) for x in range(101)])
         self._widget_2.set_gradient_stops(
             [(x / 100, QColor.fromHsvF(h, s, x / 100.)) for x in range(101)])
 def _update_widgets(self):
     _BaseColorsWidget._update_widgets(self)
     if self.update_colors_in_slider:
         color = self._model.color
         h, s, v = self._get_color_params(color)
         self._widget_1.set_gradient_stops([
             (x / 100, QColor.fromHsvF(h, x / 100., v)) for x in range(101)
         ])
         self._widget_2.set_gradient_stops([
             (x / 100, QColor.fromHsvF(h, s, x / 100.)) for x in range(101)
         ])
def test_hsv_widget(qtapi, hsv_widget):
    from pyvmmonitor_qt.qt.QtGui import QColor
    assert hsv_widget.model is not None

    hsv_widget.model.color = QColor.fromHsvF(0.5, 0.5, 0.5)
    assert hsv_widget._hue_widget._slider.value == 360 * .5

    hsv_widget.model.color = QColor.fromHsvF(0.1, 0.5, 0.5)
    assert hsv_widget._hue_widget._slider.value == 360 * .1

    hsv_widget._hue_widget._slider.value = 360 * .4
    assert hsv_widget.model.color == QColor.fromHsvF(0.4, 0.5, 0.5)
def test_hsv_widget(qtapi, hsv_widget):
    from pyvmmonitor_qt.qt.QtGui import QColor
    assert hsv_widget.model is not None

    hsv_widget.model.color = QColor.fromHsvF(0.5, 0.5, 0.5)
    assert hsv_widget._hue_widget._slider.value == 360 * .5

    hsv_widget.model.color = QColor.fromHsvF(0.1, 0.5, 0.5)
    assert hsv_widget._hue_widget._slider.value == 360 * .1

    hsv_widget._hue_widget._slider.value = 360 * .4
    assert hsv_widget.model.color == QColor.fromHsvF(0.4, 0.5, 0.5)
    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 _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 _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 _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 _on_mouse_pos(self, pos):
        saturation = self.saturation_from_point(*pos)
        hue = self.hue_from_point(*pos)

        # Update the model for the new saturation / hue.
        value = self._model.color.valueF()
        color = QColor.fromHsvF(hue, saturation, value)
        self._model.color = color
Ejemplo n.º 10
0
    def _on_mouse_pos(self, pos):
        saturation = self.saturation_from_point(*pos)
        hue = self.hue_from_point(*pos)

        # Update the model for the new saturation / hue.
        value = self._model.color.valueF()
        color = QColor.fromHsvF(hue, saturation, value)
        self._model.color = color
Ejemplo n.º 11
0
    def _create_label_widgets(self):
        hue_colors = [
            (hue / 360., QColor.fromHsvF(hue / 360., 1.0, 1.0)) for hue in range(361)]
        self._widget_0 = _LabelGradientAndInt(self, 'H', hue_colors, (0, 360))
        self._widget_0.slider.setObjectName('Hue')

        self._widget_1 = _LabelGradientAndInt(self, 'S', limits=self._saturation_limits)
        self._widget_1.slider.setObjectName('Saturation')

        self._widget_2 = _LabelGradientAndInt(self, 'V', limits=self._value_limits)
        self._widget_2.slider.setObjectName('Value')
        self.update_colors_in_slider = True
Ejemplo n.º 12
0
    def _create_label_widgets(self):
        hue_colors = [(hue / 360., QColor.fromHsvF(hue / 360., 1.0, 1.0))
                      for hue in range(361)]
        self._widget_0 = _LabelGradientAndInt(self, 'H', hue_colors, (0, 360))
        self._widget_0.slider.setObjectName('Hue')

        self._widget_1 = _LabelGradientAndInt(self,
                                              'S',
                                              limits=self._saturation_limits)
        self._widget_1.slider.setObjectName('Saturation')

        self._widget_2 = _LabelGradientAndInt(self,
                                              'V',
                                              limits=self._value_limits)
        self._widget_2.slider.setObjectName('Value')
        self.update_colors_in_slider = True
Ejemplo n.º 13
0
 def _create_color_from_params(self, params):
     return QColor.fromHsvF(*params)
Ejemplo n.º 14
0
 def _create_color_from_params(self, params):
     return QColor.fromHsvF(*params)