implementing more settings
This commit is contained in:
33
settings.py
33
settings.py
@@ -3,6 +3,10 @@ from textual.widgets import Label, Select, TabbedContent, TabPane, Switch
|
||||
from textual.containers import Vertical, HorizontalGroup, VerticalGroup
|
||||
from textual.binding import Binding
|
||||
|
||||
from settings_store import ConfigHandler
|
||||
|
||||
import os
|
||||
|
||||
|
||||
class SettingsScreen(ModalScreen):
|
||||
border_title = "Settings"
|
||||
@@ -52,9 +56,24 @@ class SettingsScreen(ModalScreen):
|
||||
Binding("escape", "close", "Close")
|
||||
]
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.config_handler = ConfigHandler()
|
||||
|
||||
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.config_handler.set("editor", "word_wrap", str(int(event.value)))
|
||||
self.notify(str(int(event.value)))
|
||||
|
||||
def on_select_changed(self, event: Select.Changed):
|
||||
if event.select.id == "colour-theme":
|
||||
self.app.theme = event.value
|
||||
self.config_handler.set("appearance", "colour_theme", str(event.value))
|
||||
|
||||
def compose(self):
|
||||
with Vertical(id="window") as window:
|
||||
window.border_title = "Settings"
|
||||
@@ -63,14 +82,22 @@ class SettingsScreen(ModalScreen):
|
||||
with HorizontalGroup(classes="setting"):
|
||||
with VerticalGroup():
|
||||
yield Label("Colour Theme", classes="setting-name")
|
||||
yield Label("Colour theme used for the entire Berry app.", 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)
|
||||
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=True)
|
||||
yield Switch(value=bool(int(self.config_handler.get("editor", "word_wrap"))), id="word-wrap")
|
||||
with TabPane("Plugins"):
|
||||
with HorizontalGroup(classes="setting"):
|
||||
with VerticalGroup():
|
||||
|
||||
Reference in New Issue
Block a user