Exemplo n.º 1
0
    def rgb_changed(self, *args):
        if self.changing:
            return

        r, g, b = self.spin_r.value(), self.spin_g.value(), self.spin_b.value()
        rgb = QColor(r, g, b)
        h, s, l = rgb.hue(), rgb.saturation(), rgb.lightness()

        self.changing = True
        self.spin_h.setValue(h)
        self.spin_s.setValue(s)
        self.spin_l.setValue(l)
        self.changing = False

        self.rgb_led.set_rgb_value(r, g, b)
        self.label_color.setStyleSheet('QLabel {{ background: #{:02x}{:02x}{:02x} }}'.format(r, g, b))
Exemplo n.º 2
0
    def rgb_changed(self, *args):
        if self.changing:
            return

        r, g, b = self.spin_r.value(), self.spin_g.value(), self.spin_b.value()
        rgb = QColor(r, g, b)
        h, s, l = rgb.hue(), rgb.saturation(), rgb.lightness()

        self.changing = True
        self.spin_h.setValue(h)
        self.spin_s.setValue(s)
        self.spin_l.setValue(l)
        self.changing = False

        self.rgb_led_button.set_color(r, g, b)
        self.label_color.setStyleSheet(
            'QLabel {{ background: #{:02x}{:02x}{:02x} }}'.format(r, g, b))
Exemplo n.º 3
0
    def setBaseColor(cls, newcolor: QColor):
        """
        Sets the base color and makes sure all top level widgets are updated.
        It tries to ensure that the actual used colors are within
        reasonable bounds while generating the actual baseColor
        from the users request.
        :param newcolor: New color to be set
        """
        cls._requestedBaseColor = newcolor

        color = QColor()
        color.setHsv(newcolor.hue(),
                     newcolor.saturation() * 0.7,
                     64 + newcolor.value() / 3)

        if color.isValid() and color != cls._baseColor:
            cls._baseColor = color
            for widget in QApplication.topLevelWidgets():
                widget.update()
Exemplo n.º 4
0
class Theme():
    navigationWidgetHeight = 24
    buttonTextColor = QColor(0x4c4c4c)
    def __init__(self):
        self._baseColor = QColor(0x666666)
        self._usePixmapCache = True
        self._initTheme()
    
    def getBaseColor(self):
        return self._baseColor
    
    def setBaseColor(self, color):
        self_baseColor = color
        self._initTheme()
        
    baseColor = property(getBaseColor, setBaseColor)
    
    def getPanelTextColor(self):
        return Qt.white
        
    panelTextColor = property(getPanelTextColor)
    
    def usePixmapCache(self):
        return self._usePixmapCache
        
    def getSidebarFontSize(self):
        return 7.5
    
    sidebarFontSize = property(getSidebarFontSize)
    
    def verticalGradient(self, painter, spanRect, clipRect):
        key = 'fancy vertical gradient %d %d %d %d %d'%(spanRect.width(), spanRect.height(), clipRect.width(),
                                             clipRect.height(), self.baseColor.rgb())
        pixmap = QPixmap()
        p = painter
        rect = QRect(clipRect)
        
        if self._usePixmapCache and not QPixmapCache.find(key, pixmap):
            pixmap = QPixmap(clipRect.size())
            p = QPainter(pixmap)
            rect = QRect(0, 0, clipRect.width(), clipRect.height())
        
        base = self.baseColor
        grad = QLinearGradient(QPointF(spanRect.topRight()), QPointF(spanRect.topLeft()))
        grad.setColorAt(0, self.highlightColor)
        grad.setColorAt(0.301, base)
        grad.setColorAt(1, self.shadowColor)
        p.fillRect(rect, grad)
        
        light = QColor(255, 255, 255, 80)
        p.setPen(light)
        p.drawLine(rect.topRight() - QPoint(1, 0), rect.bottomRight() - QPoint(1, 0))
        
        if self._usePixmapCache and not QPixmapCache.find(key, pixmap):
            painter.drawPixmap(clipRect.topLeft(), pixmap)
            p.end()
            del p
            QPixmapCache.insert(key, pixmap)
    
    def horizontalGradient(self, painter, spanRect, clipRect):
        key = 'fancy vertical gradient %d %d %d %d %d'%(spanRect.width(), spanRect.height(), clipRect.width(),
                                             clipRect.height(), self.baseColor.rgb())
        pixmap = QPixmap()
        p = painter
        rect = QRect(clipRect)
        
        if self._usePixmapCache and not QPixmapCache.find(key, pixmap):
            pixmap = QPixmap(clipRect.size())
            p = QPainter(pixmap)
            rect = QRect(0, 0, clipRect.width(), clipRect.height())
        
        base = self.baseColor
        grad = QLinearGradient(QPointF(rect.topLeft()), QPointF(rect.bottomLeft()))
        grad.setColorAt(0, self.highlightColor.lighter(120))
        if rect.height() == self.navigationWidgetHeight:
            grad.setColorAt(0.4, self.highlightColor)
            grad.setColorAt(0.401, base)
        grad.setColorAt(1, self.shadowColor)
        p.fillRect(rect, grad)
        
        shadowGradient = QLinearGradient(QPointF(spanRect.topLeft()), QPointF(spanRect.topRight()))
        shadowGradient.setColorAt(0, QColor(0, 0, 0, 30))
        highlight = self.highlightColor.lighter(130)
        highlight.setAlpha(100)
        shadowGradient.setColorAt(0.7, highlight)
        shadowGradient.setColorAt(1, QColor(0, 0, 0, 40))
        p.fillRect(rect, shadowGradient)
    
        if self._usePixmapCache and not QPixmapCache.find(key, pixmap):
            painter.drawPixmap(clipRect.topLeft(), pixmap)
            p.end()
            del p
            QPixmapCache.insert(key, pixmap)
        
    def menuGradient(self, painter, spanRect, clipRect):
        pass
    
    def mergedColors(self, colorA, colorB, factor = 50):
        maxFactor = 100
        color = QColor(colorA)
        return color
        
    def _initTheme(self):
        self.borderColor = QColor(self._baseColor)
        self.borderColor.setHsv(self._baseColor.hue(),
                                self._baseColor.saturation(),
                                self._baseColor.value()/2)
        self.shadowColor = QColor(self._baseColor)
        self.shadowColor.setHsv(self._baseColor.hue(),
                                clamp(self._baseColor.saturation() * 1.1),
                                clamp(self._baseColor.value() * 0.70))
        self.highlightColor = QColor(self._baseColor)
        self.highlightColor.setHsv(self._baseColor.hue(),
                                clamp(self._baseColor.saturation()),
                                clamp(self._baseColor.value() * 1.16))