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
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)
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)
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
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)
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)
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
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
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)
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)
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)
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)
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()
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)
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)
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)
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()
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)
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)
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)
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)
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)
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()
def test_invalid_end(self): """Test an invalid end color.""" with self.assertRaises(qtutils.QtValueError): utils.interpolate_color(self.white, Color(), 0)
def test_invalid_start(self): """Test an invalid start color.""" with self.assertRaises(qtutils.QtValueError): utils.interpolate_color(Color(), self.white, 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))
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)
def test_invalid_colorspace(self): """Test an invalid colorspace.""" with pytest.raises(ValueError): utils.interpolate_color(self.white, self.black, 10, QColor.Cmyk)
def test_invalid_colorspace(self): """Test an invalid colorspace.""" with self.assertRaises(ValueError): utils.interpolate_color(self.white, self.black, 10, QColor.Cmyk)
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)
def test_invalid_end(self): """Test an invalid end color.""" with pytest.raises(qtutils.QtValueError): utils.interpolate_color(self.white, Color(), 0)
def test_invalid_start(self): """Test an invalid start color.""" with pytest.raises(qtutils.QtValueError): utils.interpolate_color(Color(), self.white, 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)