No built-in scheme name for syntax is causing the app breaking
Opened this issue · 2 comments
diegoulloao commented
Hey, just testing the custom themes feature you've just released! Making my own version of neofusion
theme for Posting :)
I just realized of this bug: if I set a theme name for syntax that's not built-in with the app, it crashes.
Traceback
╭───────────────────────────────────────────────────────────── Traceback (most recent call last) ─────────────────────────────────────────────────────────────╮ │ /Users/diego/.local/pipx/venvs/posting/lib/python3.12/site-packages/posting/widgets/text_area.py:218 in on_mount │ │ │ │ 215 │ │ self.register_theme(DRACULA_THEME) ╭────────── locals ──────────╮ │ │ 216 │ │ empty = len(self.text) == 0 │ empty = True │ │ │ 217 │ │ self.set_class(empty, "empty") │ self = ResponseTextArea() │ │ │ ❱ 218 │ │ self.on_theme_change(self.app.themes[self.app.theme]) ╰────────────────────────────╯ │ │ 219 │ │ self.app.theme_change_signal.subscribe(self, self.on_theme_change) │ │ 220 │ │ │ 221 │ def on_theme_change(self, theme: Theme) -> None: │ │ │ │ /Users/diego/.local/pipx/venvs/posting/lib/python3.12/site-packages/posting/widgets/text_area.py:222 in on_theme_change │ │ │ │ 219 │ │ self.app.theme_change_signal.subscribe(self, self.on_theme_change) │ │ 220 │ │ │ 221 │ def on_theme_change(self, theme: Theme) -> None: │ │ ❱ 222 │ │ self.theme = theme.syntax │ │ 223 │ │ self.refresh() │ │ 224 │ │ │ 225 │ @on(TextArea.Changed) │ │ │ │ ╭─────────────────────────────────────────── locals ───────────────────────────────────────────╮ │ │ │ self = ResponseTextArea() │ │ │ │ theme = Theme( │ │ │ │ │ name='neofusion', │ │ │ │ │ primary='#e8e5b5', │ │ │ │ │ secondary='#fd5e3a', │ │ │ │ │ background='#06101e', │ │ │ │ │ surface='#052839', │ │ │ │ │ panel=None, │ │ │ │ │ warning='#e8e5b5', │ │ │ │ │ error='#fd5e3a', │ │ │ │ │ success='#35b5ff', │ │ │ │ │ accent='#66def9', │ │ │ │ │ dark=True, │ │ │ │ │ syntax='neofusion', │ │ │ │ │ author='Diego Ulloa', │ │ │ │ │ description='neofusion theme for Posting blending lava red and ice blue colors', │ │ │ │ │ homepage='https://github.com/diegoulloao/neofusion.posting/' │ │ │ │ ) │ │ │ ╰──────────────────────────────────────────────────────────────────────────────────────────────╯ │ │ │ │ /Users/diego/.local/pipx/venvs/posting/lib/python3.12/site-packages/textual/widgets/_text_area.py:723 in _watch_theme │ │ │ │ 720 │ def _watch_theme(self, theme: str) -> None: ╭────────── locals ──────────╮ │ │ 721 │ │ """We set the styles on this widget when the theme changes, to ensure that │ self = ResponseTextArea() │ │ │ 722 │ │ if padding is applied, the colors match.""" │ theme = 'neofusion' │ │ │ ❱ 723 │ │ self._set_theme(theme) ╰────────────────────────────╯ │ │ 724 │ │ │ 725 │ def _app_dark_toggled(self) -> None: │ │ 726 │ │ self._set_theme(self._theme.name) │ │ │ │ /Users/diego/.local/pipx/venvs/posting/lib/python3.12/site-packages/textual/widgets/_text_area.py:737 in _set_theme │ │ │ │ 734 │ │ except KeyError: ╭───────────── locals ──────────────╮ │ │ 735 │ │ │ theme_object = TextAreaTheme.get_builtin_theme(theme) │ self = ResponseTextArea() │ │ │ 736 │ │ │ if theme_object is None: │ theme = 'neofusion' │ │ │ ❱ 737 │ │ │ │ raise ThemeDoesNotExist( │ theme_object = None │ │ │ 738 │ │ │ │ │ f"{theme!r} is not a builtin theme, or it has not been registered. " ╰───────────────────────────────────╯ │ │ 739 │ │ │ │ │ f"To use a custom theme, register it first using `register_theme`, " │ │ 740 │ │ │ │ │ f"then switch to that theme by setting the `TextArea.theme` attribut │ ╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ThemeDoesNotExist: 'neofusion' is not a builtin theme, or it has not been registered. To use a custom theme, register it first using `register_theme`, then switch to that theme by setting the `TextArea.theme` attribute.NOTE: 1 of 3 errors shown. Run with textual run --dev to see all errors.
darrenburns commented
Thanks! Yeah, I should probably show a nicer error message in that case. Going forward, I'll try to have the syntax be customisable via this file too. For now, you can just leave `syntax blank.
diegoulloao commented
That would be nice, thank you.