コード例 #1
0
    def draw_color_bar(self, painter, rect):
        h1, s1, v1, _ = self.light.getHsv()
        h2, s2, v2, _ = self.dark.getHsv()

        painter.save()
        painter.setClipRect(rect)
        painter.setClipping(True)
        #painter.fillRect(rect, QBrush(self.dark))

        if self.orientation == Qt.Horizontal:
            num_intervalls = rect.width()
        else:
            num_intervalls = rect.height()

        section = QRect()

        num_intervalls_shown = num_intervalls * self.height / 100
        l = range(num_intervalls - num_intervalls_shown, num_intervalls)
        l.reverse()
        for i in l:
            if self.orientation == Qt.Horizontal:
                section.setRect(rect.x() + i, rect.y(), 1, rect.heigh())
            else:
                section.setRect(rect.x(), rect.y() + i, rect.width(), 1)

            ratio = float(i) / float(num_intervalls)
            color = QColor()
            color.setHsv(h1 + int(ratio * (h2 - h1) + 0.5),
                         s1 + int(ratio * (s2 - s1) + 0.5),
                         v1 + int(ratio * (v2 - v1) + 0.5))

            painter.fillRect(section, color)

        painter.restore()
コード例 #2
0
ファイル: servo.py プロジェクト: tewdreyer/brickv
    def draw_color_bar(self, painter, rect):
        h1, s1, v1, _ = self.light.getHsv()
        h2, s2, v2, _ = self.dark.getHsv()

        painter.save()
        painter.setClipRect(rect)
        painter.setClipping(True)
        # painter.fillRect(rect, QBrush(self.dark))

        if self.orientation == Qt.Horizontal:
            num_intervalls = rect.width()
        else:
            num_intervalls = rect.height()

        section = QRect()

        num_intervalls_shown = num_intervalls * self.height / 100
        l = range(num_intervalls - num_intervalls_shown, num_intervalls)
        l.reverse()
        for i in l:
            if self.orientation == Qt.Horizontal:
                section.setRect(rect.x() + i, rect.y(), 1, rect.heigh())
            else:
                section.setRect(rect.x(), rect.y() + i, rect.width(), 1)

            ratio = float(i) / float(num_intervalls)
            color = QColor()
            color.setHsv(
                h1 + int(ratio * (h2 - h1) + 0.5), s1 + int(ratio * (s2 - s1) + 0.5), v1 + int(ratio * (v2 - v1) + 0.5)
            )

            painter.fillRect(section, color)

        painter.restore()
コード例 #3
0
ファイル: Processing_Object.py プロジェクト: Dahaniel/ILTIS
 def calc_colors(self,nColors,HSVsubset=(0,360),HSVoffset=0):
     h = sp.linspace(HSVsubset[0],HSVsubset[1],nColors,endpoint=False).astype('int')
     h = self.add_circular_offset(h,HSVoffset,HSVsubset[1]).tolist()
     s = [255] * nColors
     v = [255] * nColors
     colors = []
     for n in range(nColors):
         Color = QColor()
         Color.setHsv(h[n],s[n],v[n])
         colors.append(Color.getRgb())
     return colors
コード例 #4
0
 def calc_colors(self, nColors, HSVsubset=(0, 360), HSVoffset=0):
     h = sp.linspace(HSVsubset[0], HSVsubset[1], nColors,
                     endpoint=False).astype('int')
     h = self.add_circular_offset(h, HSVoffset, HSVsubset[1]).tolist()
     s = [255] * nColors
     v = [255] * nColors
     colors = []
     for n in range(nColors):
         Color = QColor()
         Color.setHsv(h[n], s[n], v[n])
         colors.append(Color.getRgb())
     return colors
コード例 #5
0
ファイル: restedit.py プロジェクト: eblot/ezsphinx
 def _generate_formats(self):
     """generate background colors for restedit warnings"""
     if self._formats:
         return
     format = self.document().findBlock(0).blockFormat()
     self._formats[0] = format
     hues = (120, 60, 30, 0)
     for lvl, hue in enumerate(hues):
         format = QTextBlockFormat(format)
         color = QColor()
         color.setHsv(hue, 95, 255)
         format.setBackground(color)
         self._formats[lvl+1] = format.toBlockFormat()
コード例 #6
0
ファイル: GameServer.py プロジェクト: archee-byte/Jeopy
    def endGame(self):
        hue = 0
        hueInc = 360 / len(self.scores.items())

        for e in self.scores.items():
            color = QColor()
            color.setHsv(hue, 255, 240)
            hue += hueInc - 1
            self.scores[e[0]] = (e[1][0], color.getRgbF())

        # actually ending the game here...
        for player in self.players.values():
            player[0].endGame()
        self.gameEnded.emit()
コード例 #7
0
ファイル: __init__.py プロジェクト: nerdocs/MedUX
    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()
コード例 #8
0
def arbitaryColor(amount, max):
    color = QColor()
    color.setHsv(240 * amount / float(max - 1), 255, 255)
    return color
コード例 #9
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))
コード例 #10
0
def color(h, s, v):
	c = QColor()
	c.setHsv(h, s, v)
	return c.name()