Skip to content

Commit d2a0f10

Browse files
committed
Separate main menu screen
1 parent 8364e75 commit d2a0f10

File tree

1 file changed

+45
-37
lines changed

1 file changed

+45
-37
lines changed

tools/config_editor/app.py

+45-37
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
try:
3434
from textual.app import App, ComposeResult
3535
from textual.containers import VerticalScroll
36+
from textual.screen import Screen
3637
from textual.widgets import Button, Header, Label
3738
except ImportError:
3839
print("Please install the \"textual-dev\" package before running this script.")
@@ -42,43 +43,20 @@
4243
from editor import EditorScreen
4344
from compile import CompileScreen
4445

45-
class ConfigEditorApp(App):
46-
# Main application class
47-
48-
# Set the root and script paths
49-
SCRIPT_PATH = os.path.abspath(os.path.dirname(__file__))
50-
ROOT_PATH = os.path.abspath(os.path.join(SCRIPT_PATH, "..", ".."))
51-
52-
# Set the application options
53-
setting_enable_copy = True
54-
55-
# Options to be set by the command line arguments
56-
setting_target = ""
57-
setting_arduino_path = ""
58-
setting_arduino_branch = ""
59-
setting_idf_branch = ""
60-
setting_idf_commit = ""
61-
setting_debug_level = ""
62-
63-
ENABLE_COMMAND_PALETTE = False
64-
CSS_PATH = "style.tcss"
65-
SCREENS = {
66-
"settings": SettingsScreen(),
67-
"compile": CompileScreen(),
68-
"editor": EditorScreen(),
69-
}
46+
class MainScreen(Screen):
47+
# Main screen class
7048

7149
def on_button_pressed(self, event: Button.Pressed) -> None:
7250
# Event handler called when a button is pressed
7351
if event.button.id == "compile-button":
7452
print("Compile button pressed")
75-
self.push_screen("compile")
53+
self.app.push_screen("compile")
7654
elif event.button.id == "settings-button":
7755
print("Settings button pressed")
78-
self.push_screen("settings")
56+
self.app.push_screen("settings")
7957
elif event.button.id == "editor-button":
8058
print("Editor button pressed")
81-
self.push_screen("editor")
59+
self.app.push_screen("editor")
8260
elif event.button.id == "quit-button":
8361
print("Quit button pressed")
8462
quit()
@@ -99,15 +77,45 @@ def on_mount(self) -> None:
9977
self.sub_title = "Main Menu"
10078
print("Using Python version: " + sys.version)
10179
print("App started. Initial Options:")
102-
print("Root path: " + self.ROOT_PATH)
103-
print("Script path: " + self.SCRIPT_PATH)
104-
print("Target: " + str(self.setting_target))
105-
print("Enable Copy: " + str(self.setting_enable_copy))
106-
print("Arduino Path: " + str(self.setting_arduino_path))
107-
print("Arduino Branch: " + str(self.setting_arduino_branch))
108-
print("IDF Branch: " + str(self.setting_idf_branch))
109-
print("IDF Commit: " + str(self.setting_idf_commit))
110-
print("IDF Debug Level: " + str(self.setting_debug_level))
80+
print("Root path: " + self.app.ROOT_PATH)
81+
print("Script path: " + self.app.SCRIPT_PATH)
82+
print("Target: " + str(self.app.setting_target))
83+
print("Enable Copy: " + str(self.app.setting_enable_copy))
84+
print("Arduino Path: " + str(self.app.setting_arduino_path))
85+
print("Arduino Branch: " + str(self.app.setting_arduino_branch))
86+
print("IDF Branch: " + str(self.app.setting_idf_branch))
87+
print("IDF Commit: " + str(self.app.setting_idf_commit))
88+
print("IDF Debug Level: " + str(self.app.setting_debug_level))
89+
90+
class ConfigEditorApp(App):
91+
# Main application class
92+
93+
# Set the root and script paths
94+
SCRIPT_PATH = os.path.abspath(os.path.dirname(__file__))
95+
ROOT_PATH = os.path.abspath(os.path.join(SCRIPT_PATH, "..", ".."))
96+
97+
# Set the application options
98+
setting_enable_copy = True
99+
100+
# Options to be set by the command line arguments
101+
setting_target = ""
102+
setting_arduino_path = ""
103+
setting_arduino_branch = ""
104+
setting_idf_branch = ""
105+
setting_idf_commit = ""
106+
setting_debug_level = ""
107+
108+
ENABLE_COMMAND_PALETTE = False
109+
CSS_PATH = "style.tcss"
110+
SCREENS = {
111+
"main": MainScreen(),
112+
"settings": SettingsScreen(),
113+
"compile": CompileScreen(),
114+
"editor": EditorScreen(),
115+
}
116+
117+
def on_mount(self) -> None:
118+
self.push_screen("main")
111119

112120
def arduino_default_path():
113121
sys_name = platform.system()

0 commit comments

Comments
 (0)