Esempio n. 1
0
 def test_valid_percentages_hsl(self):
     """Test 0% and 100% in the HSL colorspace."""
     white = utils.interpolate_color(self.white, self.black, 0, QColor.Hsl)
     black = utils.interpolate_color(self.white, self.black, 100,
                                     QColor.Hsl)
     assert Color(white) == self.white
     assert Color(black) == self.black
Esempio n. 2
0
 def test_valid_percentages_hsv(self):
     """Test 0% and 100% in the HSV colorspace."""
     white = utils.interpolate_color(self.white, self.black, 0, QColor.Hsv)
     black = utils.interpolate_color(self.white, self.black, 100,
                                     QColor.Hsv)
     self.assertEqual(Color(white), self.white)
     self.assertEqual(Color(black), self.black)
Esempio n. 3
0
 def test_valid_percentages_hsl(self):
     """Test 0% and 100% in the HSL colorspace."""
     white = utils.interpolate_color(self.white, self.black, 0, QColor.Hsl)
     black = utils.interpolate_color(self.white, self.black, 100,
                                     QColor.Hsl)
     self.assertEqual(Color(white), self.white)
     self.assertEqual(Color(black), self.black)
Esempio n. 4
0
 def test_valid_percentages_hsv(self):
     """Test 0% and 100% in the HSV colorspace."""
     white = utils.interpolate_color(self.white, self.black, 0, QColor.Hsv)
     black = utils.interpolate_color(self.white, self.black, 100,
                                     QColor.Hsv)
     assert Color(white) == self.white
     assert Color(black) == self.black
Esempio n. 5
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 = utils.interpolate_color(start, stop, 50, QColor.Hsv)
     expected = Color()
     expected.setHsv(0, 30, 150)
     self.assertEqual(Color(color), expected)
Esempio n. 6
0
 def test_interpolation_hsl(self):
     """Test an interpolation in the HSL colorspace."""
     start = Color()
     stop = Color()
     start.setHsl(0, 40, 100)
     stop.setHsl(0, 20, 200)
     color = utils.interpolate_color(start, stop, 50, QColor.Hsl)
     expected = Color()
     expected.setHsl(0, 30, 150)
     self.assertEqual(Color(color), expected)
Esempio n. 7
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 = utils.interpolate_color(start, stop, 50, QColor.Hsv)
     expected = Color()
     expected.setHsv(0, 30, 150)
     assert Color(color) == expected
Esempio n. 8
0
 def test_interpolation_hsl(self):
     """Test an interpolation in the HSL colorspace."""
     start = Color()
     stop = Color()
     start.setHsl(0, 40, 100)
     stop.setHsl(0, 20, 200)
     color = utils.interpolate_color(start, stop, 50, QColor.Hsl)
     expected = Color()
     expected.setHsl(0, 30, 150)
     assert Color(color) == expected
Esempio n. 9
0
 def bg_color(self):
     """Background color to be shown."""
     start = config.get('colors', 'downloads.bg.start')
     stop = config.get('colors', 'downloads.bg.stop')
     system = config.get('colors', 'downloads.bg.system')
     if self._percentage() is None:
         return start
     else:
         return utils.interpolate_color(start, stop, self._percentage(),
                                        system)
Esempio n. 10
0
 def on_load_progress(self, tab, perc):
     """Adjust tab indicator on load progress."""
     try:
         idx = self.indexOf(tab)
     except RuntimeError:
         # We can get signals for tabs we already deleted...
         return
     start = config.get('colors', 'tabs.indicator.start')
     stop = config.get('colors', 'tabs.indicator.stop')
     system = config.get('colors', 'tabs.indicator.system')
     color = utils.interpolate_color(start, stop, perc, system)
     self.tabBar().set_tab_indicator_color(idx, color)
Esempio n. 11
0
 def on_load_progress(self, tab, perc):
     """Adjust tab indicator on load progress."""
     try:
         idx = self.indexOf(tab)
     except RuntimeError:
         # We can get signals for tabs we already deleted...
         return
     start = config.get('colors', 'tabs.indicator.start')
     stop = config.get('colors', 'tabs.indicator.stop')
     system = config.get('colors', 'tabs.indicator.system')
     color = utils.interpolate_color(start, stop, perc, system)
     self.tabBar().set_tab_indicator_color(idx, color)
Esempio n. 12
0
 def bg_color(self):
     """Background color to be shown."""
     start = config.get('colors', 'downloads.bg.start')
     stop = config.get('colors', 'downloads.bg.stop')
     system = config.get('colors', 'downloads.bg.system')
     error = config.get('colors', 'downloads.bg.error')
     if self.error_msg is not None:
         return error
     elif self._percentage() is None:
         return start
     else:
         return utils.interpolate_color(start, stop, self._percentage(),
                                        system)
Esempio n. 13
0
 def bg_color(self):
     """Background color to be shown."""
     start = config.get('colors', 'downloads.bg.start')
     stop = config.get('colors', 'downloads.bg.stop')
     system = config.get('colors', 'downloads.bg.system')
     error = config.get('colors', 'downloads.bg.error')
     if self.error_msg is not None:
         assert not self.successful
         return error
     elif self.stats.percentage() is None:
         return start
     else:
         return utils.interpolate_color(
             start, stop, self.stats.percentage(), system)
Esempio n. 14
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.get('colors', 'tabs.indicator.start')
     stop = config.get('colors', 'tabs.indicator.stop')
     system = config.get('colors', 'tabs.indicator.system')
     color = utils.interpolate_color(start, stop, perc, system)
     self.set_tab_indicator_color(idx, color)
     self.update_tab_title(idx)
     if idx == self.currentIndex():
         self.update_window_title()
Esempio n. 15
0
 def on_load_finished(self, tab, ok):
     """Adjust tab indicator when loading finished."""
     try:
         idx = self.indexOf(tab)
     except RuntimeError:
         # We can get signals for tabs we already deleted...
         return
     if ok:
         start = config.get('colors', 'tabs.indicator.start')
         stop = config.get('colors', 'tabs.indicator.stop')
         system = config.get('colors', 'tabs.indicator.system')
         color = utils.interpolate_color(start, stop, 100, system)
     else:
         color = config.get('colors', 'tabs.indicator.error')
     self.tabBar().set_tab_indicator_color(idx, color)
Esempio n. 16
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.get('colors', 'tabs.indicator.start')
     stop = config.get('colors', 'tabs.indicator.stop')
     system = config.get('colors', 'tabs.indicator.system')
     color = utils.interpolate_color(start, stop, perc, system)
     self.set_tab_indicator_color(idx, color)
     self.update_tab_title(idx)
     if idx == self.currentIndex():
         self.update_window_title()
Esempio n. 17
0
 def on_load_finished(self, tab, ok):
     """Adjust tab indicator when loading finished."""
     try:
         idx = self.indexOf(tab)
     except RuntimeError:
         # We can get signals for tabs we already deleted...
         return
     if ok:
         start = config.get('colors', 'tab.indicator.start')
         stop = config.get('colors', 'tab.indicator.stop')
         system = config.get('colors', 'tab.indicator.system')
         color = utils.interpolate_color(start, stop, 100, system)
     else:
         color = config.get('colors', 'tab.indicator.error')
     self.tabBar().set_tab_indicator_color(idx, color)
Esempio n. 18
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 = utils.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)
Esempio n. 19
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.get('colors', 'tabs.indicator.start')
         stop = config.get('colors', 'tabs.indicator.stop')
         system = config.get('colors', 'tabs.indicator.system')
         color = utils.interpolate_color(start, stop, 100, system)
     else:
         color = config.get('colors', 'tabs.indicator.error')
     self.set_tab_indicator_color(idx, color)
     self.update_tab_title(idx)
     if idx == self.currentIndex():
         self.update_window_title()
Esempio n. 20
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.get('colors', 'tabs.indicator.start')
         stop = config.get('colors', 'tabs.indicator.stop')
         system = config.get('colors', 'tabs.indicator.system')
         color = utils.interpolate_color(start, stop, 100, system)
     else:
         color = config.get('colors', 'tabs.indicator.error')
     self.set_tab_indicator_color(idx, color)
     self.update_tab_title(idx)
     if idx == self.currentIndex():
         self.update_window_title()
Esempio n. 21
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.val.colors.tabs.indicator.start
         stop = config.val.colors.tabs.indicator.stop
         system = config.val.colors.tabs.indicator.system
         color = utils.interpolate_color(start, stop, 100, system)
     else:
         color = config.val.colors.tabs.indicator.error
     self.widget.set_tab_indicator_color(idx, color)
     self.widget.update_tab_title(idx)
     if idx == self.widget.currentIndex():
         self._update_window_title()
         tab.handle_auto_insert_mode(ok)
Esempio n. 22
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.val.colors.tabs.indicator.start
         stop = config.val.colors.tabs.indicator.stop
         system = config.val.colors.tabs.indicator.system
         color = utils.interpolate_color(start, stop, 100, system)
     else:
         color = config.val.colors.tabs.indicator.error
     self.widget.set_tab_indicator_color(idx, color)
     self.widget.update_tab_title(idx)
     if idx == self.widget.currentIndex():
         self._update_window_title()
         tab.handle_auto_insert_mode(ok)
Esempio n. 23
0
    def on_load_finished(self, tab):
        """Adjust tab indicator when loading finished.

        We don't take loadFinished's ok argument here as it always seems to be
        true when the QWebPage has an ErrorPageExtension implemented.
        See https://github.com/The-Compiler/qutebrowser/issues/84
        """
        try:
            idx = self.indexOf(tab)
        except RuntimeError:
            # We can get signals for tabs we already deleted...
            return
        if tab.page().error_occured:
            color = config.get('colors', 'tabs.indicator.error')
        else:
            start = config.get('colors', 'tabs.indicator.start')
            stop = config.get('colors', 'tabs.indicator.stop')
            system = config.get('colors', 'tabs.indicator.system')
            color = utils.interpolate_color(start, stop, 100, system)
        self.tabBar().set_tab_indicator_color(idx, color)
Esempio n. 24
0
    def on_load_finished(self, tab):
        """Adjust tab indicator when loading finished.

        We don't take loadFinished's ok argument here as it always seems to be
        true when the QWebPage has an ErrorPageExtension implemented.
        See https://github.com/The-Compiler/qutebrowser/issues/84
        """
        try:
            idx = self.indexOf(tab)
        except RuntimeError:
            # We can get signals for tabs we already deleted...
            return
        if tab.page().error_occured:
            color = config.get('colors', 'tabs.indicator.error')
        else:
            start = config.get('colors', 'tabs.indicator.start')
            stop = config.get('colors', 'tabs.indicator.stop')
            system = config.get('colors', 'tabs.indicator.system')
            color = utils.interpolate_color(start, stop, 100, system)
        self.tabBar().set_tab_indicator_color(idx, color)
Esempio n. 25
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"]
        # pylint: disable=bad-config-option
        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)
        # pylint: enable=bad-config-option
        if self.error_msg is not None:
            assert not self.successful
            return error
        elif self.stats.percentage() is None:
            return start
        else:
            return utils.interpolate_color(start, stop,
                                           self.stats.percentage(), system)
Esempio n. 26
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'.
        """
        # pylint: disable=bad-config-call
        # WORKAROUND for https://bitbucket.org/logilab/astroid/issue/104/
        assert position in ("fg", "bg")
        start = config.get('colors', 'downloads.{}.start'.format(position))
        stop = config.get('colors', 'downloads.{}.stop'.format(position))
        system = config.get('colors', 'downloads.{}.system'.format(position))
        error = config.get('colors', 'downloads.{}.error'.format(position))
        if self.error_msg is not None:
            assert not self.successful
            return error
        elif self.stats.percentage() is None:
            return start
        else:
            return utils.interpolate_color(
                start, stop, self.stats.percentage(), system)
Esempio n. 27
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'.
        """
        # pylint: disable=bad-config-call
        # WORKAROUND for https://bitbucket.org/logilab/astroid/issue/104/
        assert position in ["fg", "bg"]
        start = config.get('colors', 'downloads.{}.start'.format(position))
        stop = config.get('colors', 'downloads.{}.stop'.format(position))
        system = config.get('colors', 'downloads.{}.system'.format(position))
        error = config.get('colors', 'downloads.{}.error'.format(position))
        if self.error_msg is not None:
            assert not self.successful
            return error
        elif self.stats.percentage() is None:
            return start
        else:
            return utils.interpolate_color(start, stop,
                                           self.stats.percentage(), system)
Esempio n. 28
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"]
        # pylint: disable=bad-config-option
        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)
        # pylint: enable=bad-config-option
        if self.error_msg is not None:
            assert not self.successful
            return error
        elif self.stats.percentage() is None:
            return start
        else:
            return utils.interpolate_color(start, stop,
                                           self.stats.percentage(), system)
Esempio n. 29
0
    def on_load_finished(self, tab):
        """Adjust tab indicator when loading finished.

        We don't take loadFinished's ok argument here as it always seems to be
        true when the QWebPage has an ErrorPageExtension implemented.
        See https://github.com/The-Compiler/qutebrowser/issues/84
        """
        try:
            idx = self._tab_index(tab)
        except TabDeletedError:
            # We can get signals for tabs we already deleted...
            return
        if tab.page().error_occurred:
            color = config.get("colors", "tabs.indicator.error")
        else:
            start = config.get("colors", "tabs.indicator.start")
            stop = config.get("colors", "tabs.indicator.stop")
            system = config.get("colors", "tabs.indicator.system")
            color = utils.interpolate_color(start, stop, 100, system)
        self.set_tab_indicator_color(idx, color)
        self.update_tab_title(idx)
        if idx == self.currentIndex():
            self.update_window_title()
Esempio n. 30
0
 def test_invalid_end(self):
     """Test an invalid end color."""
     with self.assertRaises(qtutils.QtValueError):
         utils.interpolate_color(self.white, Color(), 0)
Esempio n. 31
0
 def test_invalid_start(self):
     """Test an invalid start color."""
     with self.assertRaises(qtutils.QtValueError):
         utils.interpolate_color(Color(), self.white, 0)
Esempio n. 32
0
 def test_interpolation_rgb(self):
     """Test an interpolation in the RGB colorspace."""
     color = utils.interpolate_color(Color(0, 40, 100), Color(0, 20, 200),
                                     50, QColor.Rgb)
     self.assertEqual(Color(color), Color(0, 30, 150))
Esempio n. 33
0
 def test_invalid_percentage(self):
     """Test an invalid percentage."""
     with pytest.raises(ValueError):
         utils.interpolate_color(self.white, self.white, -1)
     with pytest.raises(ValueError):
         utils.interpolate_color(self.white, self.white, 101)
Esempio n. 34
0
 def test_invalid_colorspace(self):
     """Test an invalid colorspace."""
     with pytest.raises(ValueError):
         utils.interpolate_color(self.white, self.black, 10, QColor.Cmyk)
Esempio n. 35
0
 def test_invalid_colorspace(self):
     """Test an invalid colorspace."""
     with self.assertRaises(ValueError):
         utils.interpolate_color(self.white, self.black, 10, QColor.Cmyk)
Esempio n. 36
0
 def test_interpolation_rgb(self):
     """Test an interpolation in the RGB colorspace."""
     color = utils.interpolate_color(Color(0, 40, 100), Color(0, 20, 200),
                                     50, QColor.Rgb)
     assert Color(color) == Color(0, 30, 150)
Esempio n. 37
0
 def test_invalid_end(self):
     """Test an invalid end color."""
     with pytest.raises(qtutils.QtValueError):
         utils.interpolate_color(self.white, Color(), 0)
Esempio n. 38
0
 def test_invalid_start(self):
     """Test an invalid start color."""
     with pytest.raises(qtutils.QtValueError):
         utils.interpolate_color(Color(), self.white, 0)
Esempio n. 39
0
 def test_invalid_percentage(self):
     """Test an invalid percentage."""
     with self.assertRaises(ValueError):
         utils.interpolate_color(self.white, self.white, -1)
     with self.assertRaises(ValueError):
         utils.interpolate_color(self.white, self.white, 101)