def test_theme_broken_meta(my_theme): (my_theme / "theme.json").open(mode="w", encoding="utf-8").write( str('{"titlewrong": xyz"bla"}')) assert theme_choices() == sorted([ ("my_theme", "my_theme"), ])
def test_ui_theme_registration(): var = config_variable_registry["ui_theme"]() assert var.domain() == ConfigDomainGUI assert var.group() == ConfigVariableGroupUserInterface valuespec = var.valuespec() assert isinstance(valuespec, DropdownChoice) assert valuespec.choices() == theme_choices()
def fixture_my_theme(theme_dirs, monkeypatch): theme_path = theme_dirs[0] my_dir = theme_path / "my_theme" my_dir.mkdir() (my_dir / "theme.json").open(mode="w", encoding="utf-8").write( str(json.dumps({"title": "Määh Theme :-)"}))) # Update the theme choices after introducing a new theme here monkeypatch.setattr(theme, "theme_choices", theme_choices()) return my_dir
def test_theme_choices_override(theme_dirs, my_theme): local_theme_path = theme_dirs[1] my_dir = local_theme_path / "my_theme" my_dir.mkdir() (my_dir / "theme.json").open(mode="w", encoding="utf-8").write( str(json.dumps({"title": "Fixed theme"}))) assert theme_choices() == sorted([ ("my_theme", "Fixed theme"), ])
def test_theme_choices_local_theme(theme_dirs, my_theme): local_theme_path = theme_dirs[1] my_dir = local_theme_path / "my_improved_theme" my_dir.mkdir() (my_dir / "theme.json").open(mode="w", encoding="utf-8").write( str(json.dumps({"title": "Määh Bettr Theme :-D"}))) assert theme_choices() == sorted([ ("my_theme", "Määh Theme :-)"), ("my_improved_theme", "Määh Bettr Theme :-D"), ])
def page(self) -> AjaxPageResult: themes = [theme for theme, _title in theme_choices()] current_theme = theme.get() try: theme_index = themes.index(current_theme) except ValueError: raise MKUserError(None, _("Could not determine current theme.")) if len(themes) == theme_index + 1: new_theme = themes[0] else: new_theme = themes[theme_index + 1] _set_user_attribute("ui_theme", new_theme) return {}
def valuespec(self): return Alternative( title=_("User interface theme"), orientation="horizontal", elements=[ FixedValue( None, title=_("Use the default theme"), totext="", ), DropdownChoice( title=_("Set custom theme"), choices=theme_choices(), ), ], )
def test_theme_choices_normal(my_theme): assert theme_choices() == [("my_theme", "Määh Theme :-)")]
def test_theme_choices_empty(theme_dirs): assert theme_choices() == []