From cb9a60668a8d74983da61bacedbaa199cc87b993 Mon Sep 17 00:00:00 2001 From: tobi-wan-kenobi Date: Thu, 4 Jun 2020 20:56:31 +0200 Subject: [PATCH] [core/theme] Fix detection of "best matching theme" Previous code accepted the "first" hit in a theme - particularly, if a module is called "A" and a *different* module "B" uses "A" as state, a widget of module B with state A would be themed as *module* A, wrongly. Essentially, made sure that the last (most specific) themeing "wins". fixes #647 --- bumblebee_status/core/theme.py | 3 +-- tests/core/test_theme.py | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/bumblebee_status/core/theme.py b/bumblebee_status/core/theme.py index 48eba7d..5997d84 100644 --- a/bumblebee_status/core/theme.py +++ b/bumblebee_status/core/theme.py @@ -35,8 +35,7 @@ def merge_replace(value, new_value, key): if not isinstance(value, dict): return new_value if isinstance(new_value, dict): - util.algorithm.merge(value, new_value) - return value + return util.algorithm.merge(new_value, value) # right now, merging needs explicit pango support :( if "pango" in value: value["pango"]["full_text"] = new_value diff --git a/tests/core/test_theme.py b/tests/core/test_theme.py index 027a9b3..3ed6ea0 100644 --- a/tests/core/test_theme.py +++ b/tests/core/test_theme.py @@ -4,6 +4,13 @@ import types import core.theme import core.event import core.widget +import core.module + + +class TestModule(core.module.Module): + def __init__(self, widgets, config=core.config.Config([]), theme=None): + super().__init__(config, theme, widgets) + self.name = "test" class theme(unittest.TestCase): @@ -23,6 +30,10 @@ class theme(unittest.TestCase): self.walTheme = {"colors": ["wal"]} self.cycleValueTheme = {"defaults": {"fg": ["red", "green", "blue"]}} self.stateTheme = {"warning": {"fg": "yellow"}, "critical": {"fg": "red"}} + self.overlayTheme = { + "load": {"prefix": "a"}, + "test": {"load": {"prefix": "b"}, "prefix": "x"}, + } def test_invalid_theme(self): with self.assertRaises(RuntimeError): @@ -114,5 +125,21 @@ class theme(unittest.TestCase): widget.state = types.MethodType(lambda self: ["critical"], widget) self.assertEqual(self.stateTheme["critical"]["fg"], theme.get("fg", widget)) + def test_overlay(self): + widget = core.widget.Widget() + module = TestModule(widget) + theme = core.theme.Theme(raw_data=self.overlayTheme) + + self.assertEqual( + self.overlayTheme[module.name]["prefix"], theme.get("prefix", widget) + ) + + widget.state = types.MethodType(lambda self: ["load"], widget) + + self.assertEqual( + self.overlayTheme[module.name]["load"]["prefix"], + theme.get("prefix", widget), + ) + # vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4