Пример #1
0
 def test_0_100(self, colors, colorspace):
     """Test 0% and 100% in different colorspaces."""
     white = qtutils.interpolate_color(colors.white, colors.black, 0,
                                       colorspace)
     black = qtutils.interpolate_color(colors.white, colors.black, 100,
                                       colorspace)
     assert Color(white) == colors.white
     assert Color(black) == colors.black
Пример #2
0
 def test_interpolation_alpha(self, colorspace):
     """Test interpolation of colorspace's alpha."""
     start = Color(0, 0, 0, 30)
     stop = Color(0, 0, 0, 100)
     color = qtutils.interpolate_color(start, stop, 50, colorspace)
     expected = Color(0, 0, 0, 65)
     assert Color(color) == expected
Пример #3
0
 def test_interpolation_none(self, percentage, expected):
     """Test an interpolation with a gradient turned off."""
     color = qtutils.interpolate_color(testutils.Color(0, 0, 0),
                                       testutils.Color(255, 255, 255),
                                       percentage, None)
     assert isinstance(color, QColor)
     assert testutils.Color(color) == testutils.Color(*expected)
Пример #4
0
 def test_interpolation_hsv(self):
     """Test an interpolation in the HSV colorspace."""
     start = Color()
     stop = Color()
     start.setHsv(0, 40, 100)
     stop.setHsv(0, 20, 200)
     color = qtutils.interpolate_color(start, stop, 50, QColor.Hsv)
     expected = Color()
     expected.setHsv(0, 30, 150)
     assert Color(color) == expected
Пример #5
0
 def _on_load_progress(self, tab, perc):
     """Adjust tab indicator on load progress."""
     try:
         idx = self._tab_index(tab)
     except TabDeletedError:
         # We can get signals for tabs we already deleted...
         return
     start = config.cache['colors.tabs.indicator.start']
     stop = config.cache['colors.tabs.indicator.stop']
     system = config.cache['colors.tabs.indicator.system']
     color = qtutils.interpolate_color(start, stop, perc, system)
     self.widget.set_tab_indicator_color(idx, color)
     self.widget.update_tab_title(idx)
     if idx == self.widget.currentIndex():
         self._update_window_title()
Пример #6
0
 def _on_load_finished(self, tab, ok):
     """Adjust tab indicator when loading finished."""
     try:
         idx = self._tab_index(tab)
     except TabDeletedError:
         # We can get signals for tabs we already deleted...
         return
     if ok:
         start = config.cache['colors.tabs.indicator.start']
         stop = config.cache['colors.tabs.indicator.stop']
         system = config.cache['colors.tabs.indicator.system']
         color = qtutils.interpolate_color(start, stop, 100, system)
     else:
         color = config.cache['colors.tabs.indicator.error']
     self.widget.set_tab_indicator_color(idx, color)
     if idx == self.widget.currentIndex():
         tab.private_api.handle_auto_insert_mode(ok)
Пример #7
0
    def get_status_color(self, position):
        """Choose an appropriate color for presenting the download's status.

        Args:
            position: The color type requested, can be 'fg' or 'bg'.
        """
        assert position in ["fg", "bg"]
        start = getattr(config.val.colors.downloads.start, position)
        stop = getattr(config.val.colors.downloads.stop, position)
        system = getattr(config.val.colors.downloads.system, position)
        error = getattr(config.val.colors.downloads.error, position)
        if self.error_msg is not None:
            assert not self.successful
            return error
        elif self.stats.percentage() is None:
            return start
        else:
            return qtutils.interpolate_color(
                start, stop, self.stats.percentage(), system)
Пример #8
0
 def test_interpolation_rgb(self):
     """Test an interpolation in the RGB colorspace."""
     color = qtutils.interpolate_color(Color(0, 40, 100), Color(0, 20, 200),
                                       50, QColor.Rgb)
     assert Color(color) == Color(0, 30, 150)
Пример #9
0
 def test_invalid_colorspace(self, colors):
     """Test an invalid colorspace."""
     with pytest.raises(ValueError):
         qtutils.interpolate_color(colors.white, colors.black, 10,
                                   QColor.Cmyk)
Пример #10
0
 def test_invalid_percentage(self, colors, perc):
     """Test an invalid percentage."""
     with pytest.raises(ValueError):
         qtutils.interpolate_color(colors.white, colors.white, perc)
Пример #11
0
 def test_invalid_end(self, colors):
     """Test an invalid end color."""
     with pytest.raises(qtutils.QtValueError):
         qtutils.interpolate_color(colors.white, Color(), 0)
Пример #12
0
 def test_invalid_start(self, colors):
     """Test an invalid start color."""
     with pytest.raises(qtutils.QtValueError):
         qtutils.interpolate_color(Color(), colors.white, 0)