starting work on actually saving settings

This commit is contained in:
SpookyDervish
2025-10-29 21:06:34 +11:00
parent 411ffdd471
commit c21af8508e
8 changed files with 72 additions and 29 deletions

22
main.py
View File

@@ -1,4 +1,4 @@
from textual.app import App, ComposeResult
from textual.app import App, ComposeResult, SystemCommand
from textual.widgets import Header, Footer, ContentSwitcher, DirectoryTree, Static, Button, TextArea, Tabs, Tab, RichLog, Input
from textual.containers import HorizontalGroup, Vertical
from textual.binding import Binding
@@ -36,7 +36,8 @@ class Berry(App):
Binding("ctrl+n", "new", "New File"),
Binding("ctrl+s", "save", "Save"),
Binding("ctrl+shift+s", "save_as", "Save As...", priority=True),
Binding("ctrl+f", "find", "Find", priority=True)
Binding("ctrl+f", "find", "Find", priority=True),
Binding("ctrl+f1", "settings", "Settings")
]
def __init__(self, path: str):
@@ -50,7 +51,7 @@ class Berry(App):
yield Button("📂")
yield Button("🔍")
with ContentSwitcher(initial="files"):
with ContentSwitcher(initial="files", id="sidebar-switcher"):
with Vertical(id="files"):
yield Static("EXPLORER")
yield DirectoryTree(self.path, id="directory")
@@ -63,7 +64,7 @@ class Berry(App):
first_tab,
id="file-tabs"
)
yield TextArea.code_editor(placeholder="This file is empty.", theme="css", id="code-editor", disabled=True)
yield TextArea.code_editor(placeholder="This file is empty.", theme="css", id="code-editor", disabled=True, soft_wrap=True)
#if os.name == "nt":
with Vertical(id="console-container"):
@@ -75,6 +76,13 @@ class Berry(App):
yield Footer()
yield PluginLoader()
def action_settings(self):
self.push_screen(SettingsScreen())
def get_system_commands(self, screen):
yield from super().get_system_commands(screen)
yield SystemCommand("Settings", "Open the settings menu", self.action_settings)
def on_input_submitted(self, event: Input.Submitted):
if event.input.id != "console-input":
return
@@ -301,8 +309,8 @@ class Berry(App):
def done_saving(self, result):
if result is None: return
with open(result, "wb") as f:
f.write(self.query_one("#code-editor").text.encode())
with open(result, "w", encoding="utf-8") as f:
f.write(self.query_one("#code-editor").text)
tabs: Tabs = self.query_one("#file-tabs")
tabs.active_tab.label = os.path.basename(result)
@@ -350,8 +358,6 @@ class Berry(App):
#else:
# self.query_one("#terminal").start()
self.push_screen(SettingsScreen())
if __name__ == "__main__":
app = Berry("./")
app.run()