From 86df2d71b9ad8ebd4b5803d4325ca05d0069f95b Mon Sep 17 00:00:00 2001 From: karlch Date: Sun, 14 Jul 2024 09:18:53 +0200 Subject: [PATCH 1/2] Fix styling the library foreground color The option was not passed through to the library delegate and thus never applied. fixes #840 --- vimiv/config/_style_options.py | 2 +- vimiv/gui/library.py | 27 +++++++++++++++++---------- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/vimiv/config/_style_options.py b/vimiv/config/_style_options.py index efafef29..dfa2927b 100644 --- a/vimiv/config/_style_options.py +++ b/vimiv/config/_style_options.py @@ -17,7 +17,7 @@ "library.even.bg": "{base01}", "library.odd.bg": "{base01}", "library.selected.bg": "{base0d}", - "library.selected.fg": "{base07}", + "library.selected.fg": "{library.fg}", "library.search.highlighted.fg": "{base01}", "library.search.highlighted.bg": "{base04}", "library.scrollbar.width": "{image.scrollbar.width}", diff --git a/vimiv/gui/library.py b/vimiv/gui/library.py index 9ffcfdab..8a3f1311 100644 --- a/vimiv/gui/library.py +++ b/vimiv/gui/library.py @@ -512,6 +512,7 @@ def __init__(self): self.fg = styles.get("library.fg") self.dir_fg = styles.get("library.directory.fg") self.search_fg = styles.get("library.search.highlighted.fg") + self.selected_fg = styles.get("library.selected.fg") # QColor options for background drawing self.selection_bg = QColor(styles.get("library.selected.bg")) @@ -534,10 +535,11 @@ def paint(self, painter, option, index): option: The QStyleOptionViewItem. index: The QModelIndex. """ - self._draw_background(painter, option, index) - self._draw_text(painter, option, index) + is_selected = option.state & QStyle.StateFlag.State_Selected + self._draw_background(painter, option, index, is_selected) + self._draw_text(painter, option, index, is_selected) - def _draw_text(self, painter, option, index): + def _draw_text(self, painter, option, index, is_selected: bool): """Draw text for the library. Sets the font and the foreground color using html. The foreground color @@ -548,10 +550,11 @@ def _draw_text(self, painter, option, index): painter: The QPainter. option: The QStyleOptionViewItem. index: The QModelIndex. + is_selected: True if the text is for a selected item. """ text = index.model().data(index) painter.save() - color = self._get_foreground_color(index, text) + color = self._get_foreground_color(index, text, is_selected) text = self.elided(text, painter.fontMetrics(), option.rect.width() - 1) text = wrap_style_span(f"color: {color}; font: {self.font}", text) self.doc.setHtml(text) @@ -560,7 +563,7 @@ def _draw_text(self, painter, option, index): self.doc.drawContents(painter) painter.restore() - def _draw_background(self, painter, option, index): + def _draw_background(self, painter, option, index, is_selected: bool): """Draw the background rectangle of the text. The color depends on whether the item is selected, in an even row or in @@ -570,15 +573,16 @@ def _draw_background(self, painter, option, index): painter: The QPainter. option: The QStyleOptionViewItem. index: The QModelIndex. + is_selected: True if the background is for a selected item. """ - color = self._get_background_color(index, option.state) + color = self._get_background_color(index, is_selected) painter.save() painter.setBrush(color) painter.setPen(Qt.PenStyle.NoPen) painter.drawRect(option.rect) painter.restore() - def _get_foreground_color(self, index, text): + def _get_foreground_color(self, index, text, is_selected: bool): """Return the foreground color of an item. The color depends on highlighted as search result and whether it is a @@ -587,12 +591,15 @@ def _get_foreground_color(self, index, text): Args: index: Index of the element indicating even/odd/highlighted. text: Text indicating directory or not. + is_selected: True if the foreground is for a selected item. """ + if is_selected: + return self.selected_fg if index.model().is_highlighted(index): return self.search_fg return self.dir_fg if text.endswith("/") else self.fg - def _get_background_color(self, index, state): + def _get_background_color(self, index, is_selected: bool): """Return the background color of an item. The color depends on selected, highlighted as search result and @@ -600,9 +607,9 @@ def _get_background_color(self, index, state): Args: index: Index of the element indicating even/odd/highlighted. - state: State of the index indicating selected. + is_selected: True if the background is for a selected item. """ - if state & QStyle.StateFlag.State_Selected: + if is_selected: if api.modes.current() == api.modes.LIBRARY: return self.selection_bg return self.selection_bg_unfocus From f0cc56c8a15441da90940f0add4a477b8266e095 Mon Sep 17 00:00:00 2001 From: karlch Date: Sun, 14 Jul 2024 09:36:04 +0200 Subject: [PATCH 2/2] Mark integration/test_app as xfail Quick workaround as the test fails for unknown reasons under PyQt 5.15 from time-to-time. --- tests/integration/test_app.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/integration/test_app.py b/tests/integration/test_app.py index 58dd039d..11e18a68 100644 --- a/tests/integration/test_app.py +++ b/tests/integration/test_app.py @@ -9,6 +9,7 @@ import pytest import vimiv.app +from vimiv import qt from vimiv.utils import asyncrun @@ -18,6 +19,7 @@ def test_load_icon(qtbot): assert not icon.isNull() +@pytest.mark.xfail(qt.USE_PYQT5, reason="flaky under PyQt 5.15.10") def test_wait_for_running_processes(mocker): """Ensure any running threads are completed before the app exits."""