Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No built-in scheme name for syntax is causing the app breaking #61

Open
diegoulloao opened this issue Jul 25, 2024 · 2 comments
Open

No built-in scheme name for syntax is causing the app breaking #61

diegoulloao opened this issue Jul 25, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@diegoulloao
Copy link
Contributor

diegoulloao commented Jul 25, 2024

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.

.../themes/neofusion.yml
Screenshot 3

@diegoulloao diegoulloao changed the title No built-in scheme name for syntax is breaking the app No built-in scheme name for syntax is causing the app break Jul 25, 2024
@darrenburns
Copy link
Owner

darrenburns commented Jul 25, 2024

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
Copy link
Contributor Author

diegoulloao commented Jul 25, 2024

That would be nice, thank you.

@diegoulloao diegoulloao changed the title No built-in scheme name for syntax is causing the app break No built-in scheme name for syntax is causing the app breaking Jul 27, 2024
@darrenburns darrenburns added the bug Something isn't working label Aug 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants