from textual.screen import ModalScreen from textual.widgets import Label, Select, TabbedContent, TabPane, Switch from textual.containers import Vertical, HorizontalGroup, VerticalGroup from textual.binding import Binding class SettingsScreen(ModalScreen): border_title = "Settings" DEFAULT_CSS = """ SettingsScreen { align: center middle; #window { border: panel $primary; background: $background; width: 65%; height: 65%; padding: 1; } TabPane { padding: 1; } .setting { padding: 0 2; content-align: center middle; .setting-name { text-style: bold; } .setting-desc { text-style: dim; width: 100%; min-width: 30; } VerticalGroup { width: 50%; min-width: 20; } Select { max-width: 30; } } } """ BINDINGS = [ Binding("escape", "close", "Close") ] def __init__(self): super().__init__() def action_close(self): self.dismiss() def on_switch_changed(self, event: Switch.Changed): if event.switch.id == "word-wrap": self.app.query_one("#code-editor").soft_wrap = event.value self.app.config_handler.set("editor", "word_wrap", str(int(event.value))) def on_select_changed(self, event: Select.Changed): if event.select.id == "colour-theme": self.app.theme = event.value self.app.config_handler.set("appearance", "colour_theme", str(event.value)) def compose(self): with Vertical(id="window") as window: window.border_title = "Settings" with TabbedContent(): with TabPane("Appearance"): with HorizontalGroup(classes="setting"): with VerticalGroup(): yield Label("Colour Theme", classes="setting-name") yield Label("Colour theme used for the entire Berry app. You can get more themes with plugins!", classes="setting-desc") yield Select.from_values( (theme_name for theme_name in self.app._registered_themes.keys() if theme_name != "textual-ansi"), allow_blank=False, id="colour-theme", value=self.app.theme ) with TabPane("Editor"): with HorizontalGroup(classes="setting"): with VerticalGroup(): yield Label("Word Wrap", classes="setting-name") yield Label("Enable word wrap in the code editor.", classes="setting-desc") yield Switch(value=bool(int(self.app.config_handler.get("editor", "word_wrap"))), id="word-wrap") with TabPane("Plugins"): with HorizontalGroup(classes="setting"): with VerticalGroup(): yield Label("Plugins Enabled", classes="setting-name") yield Label("Enable or disable Lua plugins. This requires a restart.", classes="setting-desc") yield Switch(value=True)