Пример #1
0
    def _appendToBrowser(self, style, text):
        """Convert text to HTML for inserting it to browser. Insert the HTML
        """
        text = cgi.escape(text)
        
        text = text.replace('\n', '<br/>')
        
        defBg = self._browser.palette().color(QPalette.Base)

        h, s, v, a = defBg.getHsvF()

        if style == 'out':
            pass
        elif style == 'in':
            if v > 0.5:  # white background
                v = v - (v / 8)  # make darker
            else:
                v = v + ((1 - v) / 4)  # make ligher
        elif style == 'err':
            if v < 0.5:  # dark background
                v = v + ((1 - v) / 4)  # make ligher
            
            h = 0
            s = .4
        elif style == 'hint':
            if v < 0.5:  # dark background
                v = v + ((1 - v) / 4)  # make ligher
            
            h = 0.33
            s = .4
        else:
            assert 0
        
        bg = QColor.fromHsvF(h, s, v)
        text = '<span style="background-color: %s;">%s</span>' % (bg.name(), text)
        
        scrollBar = self._browser.verticalScrollBar()
        oldValue = scrollBar.value()
        
        if False:
            # hlamer: It seems, it is more comfortant, if text is always scrolled
            scrollAtTheEnd = oldValue == scrollBar.maximum()
        else:
            scrollAtTheEnd = True
        
        self._browser.moveCursor(QTextCursor.End)
        self._browser.insertHtml(text)
        
        if scrollAtTheEnd:
            scrollBar.setValue(scrollBar.maximum())
        else:
            scrollBar.setValue(oldValue)
        
        while self._browser.document().characterCount() > 1024 * 1024:
            cursor = self._browser.cursorForPosition(QPoint(0, 0))
            cursor.select(cursor.LineUnderCursor)
            if not cursor.selectedText():
                cursor.movePosition(cursor.Down, cursor.KeepAnchor)
                cursor.movePosition(cursor.EndOfLine, cursor.KeepAnchor)
            cursor.removeSelectedText()
Пример #2
0
	def onTextHSVChanged( self, value ):
		if self.updating: return
		h = float( self.ui.numH.value() ) / 360.0
		s = self.ui.numS.value()
		v = self.ui.numV.value()
		color = QColor.fromHsvF( h, s, v )
		color.setAlphaF( self.currentColor.alphaF() )
		self.setColor( color )
		self.updateColorPlane()
Пример #3
0
def saturated(color, factor=150):
    """Return a saturated color.
    """
    h = color.hsvHueF()
    s = color.hsvSaturationF()
    v = color.valueF()
    a = color.alphaF()
    s = factor * s / 100.0
    s = max(min(1.0, s), 0.0)
    return QColor.fromHsvF(h, s, v, a).convertTo(color.spec())
Пример #4
0
def get_color(discrep):
    assert (discrep <= 1.0)
    assert (discrep >= 0.0)
    s_color = QColor("#00FF00")
    e_color = QColor("orange")
    hsv_start = numpy.array(s_color.getHsvF()[:-1])
    hsv_end = numpy.array(e_color.getHsvF()[:-1])
    hsv_mid = hsv_start * (1.0 - discrep) + hsv_end * discrep
    cmid = QColor.fromHsvF(hsv_mid[0], hsv_mid[1], hsv_mid[2], 1.0)
    return str(cmid.name()).upper()
Пример #5
0
def get_color( discrep ):
    assert( discrep <= 1.0 )
    assert( discrep >= 0.0 )
    s_color = QColor("#00FF00")
    e_color = QColor("orange")
    hsv_start = numpy.array( s_color.getHsvF()[:-1] )
    hsv_end = numpy.array( e_color.getHsvF()[:-1] )
    hsv_mid = hsv_start * (1.0 - discrep) + hsv_end * discrep
    cmid = QColor.fromHsvF( hsv_mid[0], hsv_mid[1], hsv_mid[2], 1.0 )
    return str( cmid.name( ) ).upper( )
Пример #6
0
def saturated(color, factor=150):
    """Return a saturated color.
    """
    h = color.hsvHueF()
    s = color.hsvSaturationF()
    v = color.valueF()
    a = color.alphaF()
    s = factor * s / 100.0
    s = max(min(1.0, s), 0.0)
    return QColor.fromHsvF(h, s, v, a).convertTo(color.spec())
Пример #7
0
def get_color( discrep ):
    assert( discrep <= 1.0 )
    assert( discrep >= 0.0 )
    e_color = QColor("#1f77b4")
    s_color = QColor("#ff7f0e")
    hsv_start = numpy.array( s_color.getHsvF()[:-1] )
    hsv_end = numpy.array( e_color.getHsvF()[:-1] )
    hsv_mid = hsv_start * (1.0 - discrep * 0.9) + hsv_end * discrep * 0.9
    cmid = QColor.fromHsvF( hsv_mid[0], hsv_mid[1], hsv_mid[2], 1.0 )
    return str( cmid.name( ) ).upper( )
Пример #8
0
    def _append_to_browser(self, style, text):
        """
        Convert text to HTML for inserting it to browser
        """
        assert style in ('in', 'out', 'err')

        text = cgi.escape(text)

        text = text.replace('\n', '<br/>')

        if style != 'out':
            def_bg = self._browser.palette().color(QPalette.Base)
            h, s, v, a = def_bg.getHsvF()

            if style == 'in':
                if v > 0.5:  # white background
                    v = v - (v / 8)  # make darker
                else:
                    v = v + ((1 - v) / 4)  # make ligher
            else:  # err
                if v < 0.5:
                    v = v + ((1 - v) / 4)  # make ligher

                if h == -1:  # make red
                    h = 0
                    s = .4
                else:
                    h = h + ((1 - h) * 0.5)  # make more red

            bg = QColor.fromHsvF(h, s, v).name()
            text = '<span style="background-color: %s; font-weight: bold;">%s</span>' % (str(bg), text)
        else:
            text = '<span>%s</span>' % text  # without span <br/> is ignored!!!

        scrollbar = self._browser.verticalScrollBar()
        old_value = scrollbar.value()
        scrollattheend = old_value == scrollbar.maximum()

        self._browser.moveCursor(QTextCursor.End)
        self._browser.insertHtml(text)

        """TODO When user enters second line to the input, and input is resized, scrollbar changes its positon
        and stops moving. As quick fix of this problem, now we always scroll down when add new text.
        To fix it correctly, srcoll to the bottom, if before intput has been resized,
        scrollbar was in the bottom, and remove next lien
        """
        scrollattheend = True

        if scrollattheend:
            scrollbar.setValue(scrollbar.maximum())
        else:
            scrollbar.setValue(old_value)
Пример #9
0
    def _append_to_browser(self, style, text):
        """
        Convert text to HTML for inserting it to browser
        """
        assert style in ('in', 'out', 'err')

        text = cgi.escape(text)

        text = text.replace('\n', '<br/>')

        if style != 'out':
            def_bg = self._browser.palette().color(QPalette.Base)
            h, s, v, a = def_bg.getHsvF()

            if style == 'in':
                if v > 0.5:  # white background
                    v = v - (v / 8)  # make darker
                else:
                    v = v + ((1 - v) / 4)  # make ligher
            else:  # err
                if v < 0.5:
                    v = v + ((1 - v) / 4)  # make ligher

                if h == -1:  # make red
                    h = 0
                    s = .4
                else:
                    h = h + ((1 - h) * 0.5)  # make more red

            bg = QColor.fromHsvF(h, s, v).name()
            text = '<span style="background-color: %s; font-weight: bold;">%s</span>' % (
                str(bg), text)
        else:
            text = '<span>%s</span>' % text  # without span <br/> is ignored!!!

        scrollbar = self._browser.verticalScrollBar()
        old_value = scrollbar.value()
        scrollattheend = old_value == scrollbar.maximum()

        self._browser.moveCursor(QTextCursor.End)
        self._browser.insertHtml(text)
        """TODO When user enters second line to the input, and input is resized, scrollbar changes its positon
        and stops moving. As quick fix of this problem, now we always scroll down when add new text.
        To fix it correctly, srcoll to the bottom, if before intput has been resized,
        scrollbar was in the bottom, and remove next lien
        """
        scrollattheend = True

        if scrollattheend:
            scrollbar.setValue(scrollbar.maximum())
        else:
            scrollbar.setValue(old_value)
Пример #10
0
 def data(self, index, role=Qt.DisplayRole):
     """Cell content"""
     if not index.isValid():
         return QVariant()
     value = self.get_value(index)
     if role == Qt.DisplayRole:
         return QVariant(self._format % value)
     elif role == Qt.TextAlignmentRole:
         return QVariant(int(Qt.AlignCenter|Qt.AlignVCenter))
     elif role == Qt.BackgroundColorRole and self.bgcolor_enabled:
         hue = self.hue0+self.dhue*(self.vmax-value)/(self.vmax-self.vmin)
         color = QColor.fromHsvF(hue, self.sat, self.val, self.alp)
         return QVariant(color)
     elif role == Qt.FontRole:
         return QVariant(get_font('arrayeditor'))
     return QVariant()
Пример #11
0
 def data(self, index, role=Qt.DisplayRole):
     """Cell content"""
     if not index.isValid():
         return QVariant()
     value = self.get_value(index)
     if role == Qt.DisplayRole:
         return QVariant(self._format % value)
     elif role == Qt.TextAlignmentRole:
         return QVariant(int(Qt.AlignCenter | Qt.AlignVCenter))
     elif role == Qt.BackgroundColorRole and self.bgcolor_enabled:
         hue = self.hue0 + self.dhue * (self.vmax - value) / (self.vmax -
                                                              self.vmin)
         color = QColor.fromHsvF(hue, self.sat, self.val, self.alp)
         return QVariant(color)
     elif role == Qt.FontRole:
         return QVariant(get_font('arrayeditor'))
     return QVariant()
Пример #12
0
 def data(self, index, role=Qt.DisplayRole):
     """Cell content"""
     if not index.isValid():
         return to_qvariant()
     value = self.get_value(index)
     if role == Qt.DisplayRole:
         if value is np.ma.masked:
             return ""
         else:
             return to_qvariant(self._format % value)
     elif role == Qt.TextAlignmentRole:
         return to_qvariant(int(Qt.AlignCenter | Qt.AlignVCenter))
     elif role == Qt.BackgroundColorRole and self.bgcolor_enabled and value is not np.ma.masked:
         hue = self.hue0 + self.dhue * (self.vmax - self.color_func(value)) / (self.vmax - self.vmin)
         hue = float(np.abs(hue))
         color = QColor.fromHsvF(hue, self.sat, self.val, self.alp)
         return to_qvariant(color)
     elif role == Qt.FontRole:
         return to_qvariant(get_font("arrayeditor"))
     return to_qvariant()
Пример #13
0
    def full_cream_color_ramp(count=10, start_hue=0, end_hue=0.66):
        """

        # info about HSV and RGB http://doc.qt.io/qt-4.8/qcolor.html

        :param count:
        :param start_hue:
        :param end_hue:
        :return: and array of count items with colors going from start_hue
        """
        S = 1.0
        V = 1.0
        r = []
        for i in range(0, count):
            H = end_hue * (float(i) / (count - 1))  # *360.0
            color = QColor.fromHsvF(H, S, V, 0.75)
            #r.append(color)
            # nope: other way around
            r.insert(0, color)
        return r
Пример #14
0
 def data(self, index, role=Qt.DisplayRole):
     """Cell content"""
     if not index.isValid():
         return to_qvariant()
     value = self.get_value(index)
     if role == Qt.DisplayRole:
         if value is np.ma.masked:
             return ''
         else:
             return to_qvariant(self._format % value)
     elif role == Qt.TextAlignmentRole:
         return to_qvariant(int(Qt.AlignCenter|Qt.AlignVCenter))
     elif role == Qt.BackgroundColorRole and self.bgcolor_enabled\
          and value is not np.ma.masked:
         hue = self.hue0+\
               self.dhue*(self.vmax-self.color_func(value))\
               /(self.vmax-self.vmin)
         hue = float(np.abs(hue))
         color = QColor.fromHsvF(hue, self.sat, self.val, self.alp)
         return to_qvariant(color)
     elif role == Qt.FontRole:
         return to_qvariant(get_font('arrayeditor'))
     return to_qvariant()
Пример #15
0
    def _appendToBrowser(self, style, text):
        """Convert text to HTML for inserting it to browser. Insert the HTML
        """
        text = cgi.escape(text)

        text = text.replace('\n', '<br/>')

        defBg = self._browser.palette().color(QPalette.Base)

        h, s, v, a = defBg.getHsvF()

        if style == 'out':
            pass
        elif style == 'in':
            if v > 0.5:  # white background
                v = v - (v / 8)  # make darker
            else:
                v = v + ((1 - v) / 4)  # make ligher
        elif style == 'err':
            if v < 0.5:  # dark background
                v = v + ((1 - v) / 4)  # make ligher

            h = 0
            s = .4
        elif style == 'hint':
            if v < 0.5:  # dark background
                v = v + ((1 - v) / 4)  # make ligher

            h = 0.33
            s = .4
        else:
            assert 0

        bg = QColor.fromHsvF(h, s, v)
        text = '<span style="background-color: %s;">%s</span>' % (bg.name(),
                                                                  text)

        scrollBar = self._browser.verticalScrollBar()
        oldValue = scrollBar.value()

        if False:
            # hlamer: It seems, it is more comfortable, if text is always scrolled
            scrollAtTheEnd = oldValue == scrollBar.maximum()
        else:
            scrollAtTheEnd = True

        self._browser.moveCursor(QTextCursor.End)
        self._browser.insertHtml(text)

        if scrollAtTheEnd:
            scrollBar.setValue(scrollBar.maximum())
        else:
            scrollBar.setValue(oldValue)

        while self._browser.document().characterCount() > 1024 * 1024:
            cursor = self._browser.cursorForPosition(QPoint(0, 0))
            cursor.select(cursor.LineUnderCursor)
            if not cursor.selectedText():
                cursor.movePosition(cursor.Down, cursor.KeepAnchor)
                cursor.movePosition(cursor.EndOfLine, cursor.KeepAnchor)
            cursor.removeSelectedText()
Пример #16
0
	def onColorBaseChanged( self, x,y,z ):
		if self.updating: return
		hue, s, v = z, x, 1.0 - y
		color = QColor.fromHsvF( hue, s, v )
		color.setAlphaF( self.currentColor.alphaF() )
		self.setColor( color )