Esempio n. 1
0
    def draw_value(self, painter):

        self.initCoordinateSystem(painter)

        color = QColor(Qt.blue)
        if self.mPointer.value() >= self.mPointer.nominal():
            color = QColor(0, 200, 0)
        if self.mPointer.value() >= self.mPointer.critical():
            color = QColor(Qt.red)

        factor = (self.mPointer.value() - self.mPointer.minimal()) / (
            self.mPointer.maximal() - self.mPointer.minimal())

        painter.setFont(self.mValueFont)
        st = "{} ℃".format(self.mPointer.value())
        Size = painter.fontMetrics().size(Qt.TextSingleLine, st)
        painter.drawText(QPointF(Size.width() / -2, 307 - Size.height()), st)

        slug = QLinearGradient(0.0, 0.0, 5.0, 0.0)
        tank = QRadialGradient(0.0, 267.0, 10.0, -5.0, 262.0)

        slug.setSpread(QGradient.ReflectSpread)
        tank.setSpread(QGradient.ReflectSpread)

        color.setHsv(color.hue(), color.saturation(), color.value())
        slug.setColorAt(1.0, color)
        tank.setColorAt(1.0, color)

        color.setHsv(color.hue(), color.saturation() - 200, color.value())
        slug.setColorAt(0.0, color)
        tank.setColorAt(0.0, color)

        painter.setPen(Qt.NoPen)
        painter.setBrush(slug)

        offset = 10

        temp = 224 * factor

        height = temp + offset

        if 231 < temp:
            height = 231 + offset
        if offset - 5 >= height:
            height = offset - 5

        painter.drawRect(-5, 252 + offset - height, 10, height)

        painter.setBrush(tank)
        painter.drawEllipse(QRectF(-10.0, 257.5, 20.0, 20.0))

        painter.end()
    def rgbUpdated(self):
        qclr = QColor(self.rSlider.value(), self.gSlider.value(),
                      self.bSlider.value())
        self.currentSelectedColor = qclr

        self.hBox.setValue(qclr.hue())
        self.hSlider.setValue(qclr.hue())
        self.sBox.setValue(qclr.saturation())
        self.sSlider.setValue(qclr.saturation())
        self.vBox.setValue(qclr.value())
        self.vSlider.setValue(qclr.value())

        self.setCurrentColor()
Esempio n. 3
0
    def changeHue(self):
        for row_pixel in range(self.image.width()):
            for col_pixel in range(self.image.height()):
                current_val = QColor(self.image.pixel(row_pixel, col_pixel))

                hue = current_val.hue()

                current_val.setHsv(hue, current_val.saturation(),
                                   current_val.value(), current_val.alpha())
                self.image.setPixelColor(row_pixel, col_pixel, current_val)

        self.setPixmap(QPixmap().fromImage(self.image))
Esempio n. 4
0
    def drawTemperature(self, painter):

        if self.value >= self.critical:
            color = QColor(255, 0, 0)

        elif self.value >= self.normal:
            color = QColor(0, 200, 0)

        else:
            color = QColor(0, 0, 255)

        scale = QLinearGradient(0, 0, 5, 0)
        bulb = QRadialGradient(0, 267.0, 10, -5, 262)

        scale.setSpread(QGradient.ReflectSpread)
        bulb.setSpread(QGradient.ReflectSpread)

        color.setHsv(color.hue(), color.saturation(), color.value())
        scale.setColorAt(1, color)
        bulb.setColorAt(1, color)

        color.setHsv(color.hue(), color.saturation() - 200, color.value())
        scale.setColorAt(0, color)
        bulb.setColorAt(0, color)

        factor = self.value - self.m_min
        factor = (factor / self.m_max) - self.m_min

        temp = SCALE_HEIGHT * factor
        height = temp + OFFSET

        painter.setPen(Qt.NoPen)
        painter.setBrush(scale)
        painter.drawRect(-5, 252 + OFFSET - height, 10, height)
        painter.setBrush(bulb)
        rect = QRectF(-10, 258, 20, 20)
        painter.drawEllipse(rect)
Esempio n. 5
0
def adjustSaturation(image: QImage, value) -> QImage:
    width, height = image.width(), image.height()
    newImage = QImage(width, height, QImage.Format_RGBA8888)
    for h in range(height):
        for w in range(width):
            pixel = QColor(image.pixel(h, w)).toHsl()
            H = pixel.hue()
            S = pixel.saturation() + value
            L = pixel.lightness()
            S = bound(0, 255, S)
            pixel.setHsl(H, S, L)
            newImage.setPixel(
                h, w,
                qRgba(pixel.red(), pixel.green(), pixel.blue(), pixel.alpha()))
    return newImage
Esempio n. 6
0
 def applyGroupeDegrade(self, groupe_id: str, color: QColor) -> List[dict]:
     with db_session:
         groupe = self.db.GroupeMatiere[groupe_id]
         matiere_count = groupe.matieres.count()
         if not matiere_count:
             return []
         elif matiere_count == 1:
             matiere_count = 2
         groupe.bgColor = color.toRgb()
         color = color.toHsv()
         saturation = max(color.saturation(), 40)
         ajout = (saturation - 40) / (matiere_count - 1)
         for mat in self.db.Matiere.get_by_position(groupe_id):
             mat.bgColor = color.toRgb()
             color.setHsv(color.hue(),
                          color.saturation() - round(ajout), color.value())
     with db_session:
         return self.get_matieres(groupe_id)
Esempio n. 7
0
    QToolTip,
    QStatusBar,
)


def limit_to_255(value: float) -> int:
    return 255 if value > 255 else 0 if value < 0 else int(value)


_isMacHost = True
BASE_COLOR = QColor("#666666")
SIDEBAR_FONT_SIZE = (10 if _isMacHost else 7.5) * 1.2
MODEBAR_ICON_SIZE = 64
TOOLBAR_ICON_SHADOW = True
FLAT_STYLE = False
HIGHLIGHT_COLOR = QColor.fromHsv(BASE_COLOR.hue(), BASE_COLOR.saturation(),
                                 limit_to_255(BASE_COLOR.value() * 1.16))
SHADOW_COLOR = QColor.fromHsv(BASE_COLOR.hue(),
                              limit_to_255(BASE_COLOR.saturation() * 1.1),
                              limit_to_255(BASE_COLOR.value() * 0.70))
BORDER_COLOR = QColor.fromHsv(BASE_COLOR.hue(), BASE_COLOR.saturation(),
                              limit_to_255(BASE_COLOR.value() / 2))
FancyToolButtonSelectedColor = QColor("#32000000")
FancyToolButtonHoverColor = QColor("#28ffffff")
FancyTabWidgetDisabledSelectedTextColor = QColor("#ffffffff")
FancyTabWidgetDisabledUnselectedTextColor = QColor("#78ffffff")
FancyTabWidgetEnabledSelectedTextColor = QColor("#ffcccccc")
FancyTabWidgetEnabledUnselectedTextColor = QColor("#ffffffff")


def disabledSideBarIcon(enabledicon: QPixmap) -> QPixmap:
Esempio n. 8
0
class ColorPicker(QWidget):
    primaryColorChanged = pyqtSignal(QColor)
    secondaryColorChanged = pyqtSignal(QColor)

    def __init__(self, parent=None):
        super(ColorPicker, self).__init__(parent)

        self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)

        self._primarySelectedColor = QColor()
        self._secondarySelectedColor = QColor()

        self._activeColorIndex = ColorIndex.Primary

        self._controlPressed = False
        self._altPressed = False

        self._palette = ColorPalette()

        # Initialize Sliders

        self._hueSlider = ColorSlider(0, 359)
        self._hueSlider.set_color_at(0.0, QColor(255, 0, 0))
        self._hueSlider.set_color_at(0.16, QColor(255, 255, 0))
        self._hueSlider.set_color_at(0.33, QColor(0, 255, 0))
        self._hueSlider.set_color_at(0.5, QColor(0, 255, 255))
        self._hueSlider.set_color_at(0.76, QColor(0, 0, 255))
        self._hueSlider.set_color_at(0.85, QColor(255, 0, 255))
        self._hueSlider.set_color_at(1.0, QColor(255, 0, 0))

        self._hueSlider.label = 'Hue'

        self._satSlider = ColorSlider(0, 255)
        self._satSlider.label = 'Saturation'

        self._valSlider = ColorSlider(0, 255)
        self._valSlider.label = 'Value'
        self._valSlider.start_color = QColor("black")

        self._redSlider = ColorSlider(0, 255)
        self._redSlider.label = 'Red'

        self._redSlider.start_color = QColor("black")
        self._redSlider.end_color = QColor("red")

        self._greenSlider = ColorSlider(0, 255)
        self._greenSlider.label = 'Green'

        self._greenSlider.start_color = QColor("black")
        self._greenSlider.end_color = QColor("green")

        self._blueSlider = ColorSlider(0, 255)
        self._blueSlider.label = 'Blue'

        self._blueSlider.start_color = QColor("black")
        self._blueSlider.end_color = QColor("blue")

        self._alphaSlider = ColorSlider(0, 255)
        self._alphaSlider.label = 'Alpha'

        self._alphaSlider.start_color = QColor("black")
        self._alphaSlider.end_color = QColor("black")
        self._alphaSlider.value = 255

        # Initialize Color Box
        self._colorBox = ColorBox(self._primarySelectedColor, self._secondarySelectedColor)

        # Set Initial Colors

        self.primary_color = QColor('black')

        self.secondary_color = QColor('white')

        # Initialize Layout

        self._layout = QVBoxLayout()
        self._layout.setAlignment(Qt.AlignTop)
        self._layout.setContentsMargins(0, 0, 0, 0)

        self._layout.addWidget(self._palette)
        self._layout.addWidget(self._colorBox)
        self._layout.addWidget(self._hueSlider)
        self._layout.addWidget(self._satSlider)
        self._layout.addWidget(self._valSlider)
        self._layout.addWidget(self._redSlider)
        self._layout.addWidget(self._greenSlider)
        self._layout.addWidget(self._blueSlider)
        self._layout.addWidget(self._alphaSlider)

        self.setLayout(self._layout)

        # Initialize Events

        self._init_events()

        # Set Style

        self.setStyleSheet("background-color: #333")

    # ========== PUBLIC API =======================================================================

    @property
    def primary_color(self):
        return self._primarySelectedColor

    @primary_color.setter
    def primary_color(self, value):

        if self._primarySelectedColor is None:
            self._primarySelectedColor = QColor()

        self._primarySelectedColor.setRgba(value.rgba())
        self._on_primary_color_changed(update_alpha_value=True)

        self._primarySelectedColor = value

    @property
    def secondary_color(self):
        return self._secondarySelectedColor

    @secondary_color.setter
    def secondary_color(self, value):

        if self._secondarySelectedColor is None:
            self._secondarySelectedColor = QColor()

        self._secondarySelectedColor.setRgba(value.rgba())
        self._on_secondary_color_changed(update_alpha_value=True)

        self._secondarySelectedColor = value

    def set_color_hue(self, h, color_index=None):

        color_index = color_index or ColorIndex.Primary

        store_alpha = self._primarySelectedColor.alpha()

        if color_index == ColorIndex.Primary:

            self._primarySelectedColor.setHsv(h, self._primarySelectedColor.saturation(),
                                              self._primarySelectedColor.value())
            self._primarySelectedColor.setAlpha(store_alpha)

            self._on_primary_color_changed(update_alpha_value=False)

        elif color_index == ColorIndex.Secondary:

            self._secondarySelectedColor.setHsv(h, self._secondarySelectedColor.saturation(),
                                                self._secondarySelectedColor.value())
            self._secondarySelectedColor.setAlpha(store_alpha)

            self._on_secondary_color_changed()

    def set_color_saturation(self, s, color_index=None):

        color_index = color_index or ColorIndex.Primary

        store_alpha = self._primarySelectedColor.alpha()

        if color_index == ColorIndex.Primary:

            self._primarySelectedColor.setHsv(self._primarySelectedColor.hue(),
                                              s,
                                              self._primarySelectedColor.value())
            self._primarySelectedColor.setAlpha(store_alpha)
            self._on_primary_color_changed(update_alpha_value=False)

        elif color_index == ColorIndex.Secondary:

            self._secondarySelectedColor.setHsv(self._secondarySelectedColor.hue(), s,
                                                self._secondarySelectedColor.value())
            self._secondarySelectedColor.setAlpha(store_alpha)
            self._on_secondary_color_changed(update_alpha_value=False)

    def set_color_value(self, v, color_index=None):

        color_index = color_index or ColorIndex.Primary

        store_alpha = self._primarySelectedColor.alpha()

        if color_index == ColorIndex.Primary:

            self._primarySelectedColor.setHsv(self._primarySelectedColor.hue(),
                                              self._primarySelectedColor.saturation(),
                                              v)
            self._primarySelectedColor.setAlpha(store_alpha)
            self._on_primary_color_changed(update_alpha_value=False)

        elif color_index == ColorIndex.Secondary:

            self._secondarySelectedColor.setHsv(self._secondarySelectedColor.hue(),
                                                self._secondarySelectedColor.saturation(), v)
            self._secondarySelectedColor.setAlpha(store_alpha)
            self._on_secondary_color_changed(update_alpha_value=False)

    def set_color_red(self, r, color_index=None):

        color_index = color_index or ColorIndex.Primary

        if color_index == ColorIndex.Primary:

            self._primarySelectedColor.setRed(r)
            self._on_primary_color_changed(update_alpha_value=False)

        elif color_index == ColorIndex.Secondary:

            self._secondarySelectedColor.setRed(r)
            self._on_secondary_color_changed(update_alpha_value=False)

    def set_color_green(self, g, color_index=None):

        color_index = color_index or ColorIndex.Primary

        if color_index == ColorIndex.Primary:

            self._primarySelectedColor.setGreen(g)
            self._on_primary_color_changed(update_alpha_value=False)

        elif color_index == ColorIndex.Secondary:

            self._secondarySelectedColor.setGreen(g)
            self._on_secondary_color_changed(update_alpha_value=False)

    def set_color_blue(self, b, color_index=None):

        color_index = color_index or ColorIndex.Primary

        if color_index == ColorIndex.Primary:

            self._primarySelectedColor.setBlue(b)
            self._on_primary_color_changed(update_alpha_value=False)

        elif color_index == ColorIndex.Secondary:

            self._secondarySelectedColor.setBlue(b)
            self._on_secondary_color_changed(update_alpha_value=False)

    def set_color_alpha(self, a, color_index=None):

        color_index = color_index or ColorIndex.Primary

        if color_index == ColorIndex.Primary:

            self._primarySelectedColor.setAlpha(a)
            self._on_primary_color_changed(update_alpha_value=False)

        elif color_index == ColorIndex.Secondary:

            self._secondarySelectedColor.setAlpha(a)
            self._on_secondary_color_changed(update_alpha_value=False)

    def select_next_color_on_palette(self):

        self._palette.move_color_selection(1)

    def select_previous_color_on_palette(self):

        self._palette.move_color_selection(-1)

    def select_next_ramp_on_palette(self):

        self._palette.move_ramp_selection(1)

    def select_previous_ramp_on_palette(self):

        self._palette.move_ramp_selection(-1)

    def switch_active_color(self):

        if self._activeColorIndex == ColorIndex.Primary:
            self._activeColorIndex = ColorIndex.Secondary

        else:
            self._activeColorIndex = ColorIndex.Primary

        self._colorBox.set_active_color_index(self._activeColorIndex)
        self._palette.switch_slot()

        self.update()

    def _init_events(self):

        self._palette.colorHovered.connect(self._on_palette_color_hovered)
        self._palette.colorSelected.connect(self._on_palette_color_changed)
        self._palette.mouseLeave.connect(self.on_palette_mouse_leave)

        self._hueSlider.valueChanged.connect(self._on_hue_slider_value_changed)
        self._satSlider.valueChanged.connect(self._on_sat_slider_value_changed)
        self._valSlider.valueChanged.connect(self._on_val_slider_value_changed)

        self._redSlider.valueChanged.connect(self._on_red_slider_value_changed)
        self._greenSlider.valueChanged.connect(self._on_green_slider_value_changed)
        self._blueSlider.valueChanged.connect(self._on_blue_slider_value_changed)

        self._alphaSlider.valueChanged.connect(self._on_alpha_slider_value_changed)

        self._colorBox.mouseClicked.connect(self._on_color_box_clicked)

    def _update_sliders(self, update_alpha_value=None):
        color = (self._primarySelectedColor
                 if self._activeColorIndex == ColorIndex.Primary
                 else self._secondarySelectedColor)

        # HUE
        self._hueSlider.value = color.hue()

        # SATURATION

        self._satSlider.start_color = QColor.fromHsv(color.hue(), 0, color.value())
        self._satSlider.end_color = QColor.fromHsv(color.hue(), 255, color.value())
        self._satSlider.value = color.saturation()

        # VALUE

        self._valSlider.end_color = QColor.fromHsv(color.hue(), color.saturation(), 255)
        self._valSlider.value = color.value()

        # RGB

        self._redSlider.value = color.red()
        self._greenSlider.value = color.green()
        self._blueSlider.value = color.blue()

        # ALPHA

        alpha_color = QColor(color)

        alpha_color.setAlpha(0)
        self._alphaSlider.start_color = alpha_color

        alpha_color.setAlpha(255)
        self._alphaSlider.end_color = alpha_color

        if update_alpha_value:
            self._alphaSlider.value = color.alpha()

    def _on_primary_color_changed(self, update_alpha_value=None):

        self._colorBox.primary_color = self._primarySelectedColor

        self._update_sliders(update_alpha_value)

        self.update()

        self.primaryColorChanged.emit(self._primarySelectedColor)

    def _on_secondary_color_changed(self, update_alpha_value=None):

        self._colorBox.secondary_color = self._secondarySelectedColor

        self._update_sliders(update_alpha_value)

        self.update()

        self.secondaryColorChanged.emit(self._secondarySelectedColor)

    def _on_palette_color_hovered(self, color):

        self._colorBox.preview_color = color
        self.update()

    def on_palette_mouse_leave(self):

        self._colorBox.preview_color = None
        self.update()

    def _on_palette_color_changed(self, color, color_index):

        if color_index == ColorIndex.Primary:
            self._activeColorIndex = ColorIndex.Primary
            self.primary_color = color
            self._colorBox.set_active_color_index(ColorIndex.Primary)

        elif color_index == ColorIndex.Secondary:
            self._activeColorIndex = ColorIndex.Secondary
            self.secondary_color = color
            self._colorBox.set_active_color_index(ColorIndex.Secondary)

    def _on_hue_slider_value_changed(self, value):

        self.set_color_hue(value, self._activeColorIndex)

    def _on_sat_slider_value_changed(self, value):

        self.set_color_saturation(value, self._activeColorIndex)

    def _on_val_slider_value_changed(self, value):

        self.set_color_value(value, self._activeColorIndex)

    def _on_red_slider_value_changed(self, value):

        self.set_color_red(value, self._activeColorIndex)

    def _on_green_slider_value_changed(self, value):

        self.set_color_green(value, self._activeColorIndex)

    def _on_blue_slider_value_changed(self, value):

        self.set_color_blue(value, self._activeColorIndex)

    def _on_alpha_slider_value_changed(self, value):

        self.set_color_alpha(value, self._activeColorIndex)

    def _on_color_box_clicked(self, color_box_index):

        if color_box_index != self._activeColorIndex:

            if color_box_index == 0:
                self._activeColorIndex = ColorIndex.Primary
            elif color_box_index == 1:
                self._activeColorIndex = ColorIndex.Secondary

            self._palette.switch_slot()