|
3 | 3 | from textual.app import App, ComposeResult
|
4 | 4 | from textual.containers import Container, Horizontal
|
5 | 5 | from textual.widgets import Button, Footer, MarkdownViewer, Header, TextArea, Select, Label
|
6 |
| -from textual import log |
7 | 6 |
|
8 | 7 | from exercises_utils import EXERCISES_DIR, ExercisesUtils
|
9 | 8 | from project_generators.base_project_generator import BaseProjectGenerator
|
@@ -43,67 +42,57 @@ def compose(self) -> ComposeResult:
|
43 | 42 | def on_mount(self) -> None:
|
44 | 43 | """Initial setup when the app starts."""
|
45 | 44 | self.show_menu()
|
| 45 | + menu = self.query_one("#menu") |
| 46 | + menu.notify(title="Hello World!", message="Pick an exercise you find interesting, read it by clicking on " |
| 47 | + "'View', create a template for a project by clicking on 'Start " |
| 48 | + "Project', and once you are done implementing the exercise, " |
| 49 | + "you can verify you did everything right by clicking on 'Run " |
| 50 | + "Tests'. Pretty Simple. But not easy :)\n\n" |
| 51 | + "Also... don't forget to read the README.md file once you click " |
| 52 | + "'Start Project'", timeout=30) |
46 | 53 |
|
47 | 54 | def show_menu(self) -> None:
|
48 |
| - """Display the menu with available exercises.""" |
49 |
| - log("entered show menu") |
50 | 55 | menu = self.query_one("#menu")
|
51 | 56 | menu.remove_children()
|
| 57 | + |
52 | 58 | exercises = list(EXERCISES_DIR.glob("*.md"))
|
53 |
| - log(f"exercises = {exercises}") |
54 |
| - log(f"map = {self.files_view_names}") |
55 | 59 | exercise_names = [(self.files_view_names[exercise.stem], exercise.stem) for exercise in exercises]
|
56 | 60 | select_file_widget = Select(options=exercise_names, prompt="Select Exercise", id="exercise_select", classes="menu_widget", tooltip="Select an exercise to preview")
|
| 61 | + |
57 | 62 | menu.mount(select_file_widget)
|
58 | 63 | menu.mount(Button("View", id="view", variant="primary", classes="menu_widget"))
|
59 |
| - menu.mount(Button("Run Tests", id="test", variant="success", classes="menu_widget")) |
60 |
| - |
61 |
| - # select_lang_widget = Select(options=[('python', 'python'), ('javascript', 'javascript')], prompt="Select Programming Language", id="lang_select", classes="menu_widget", tooltip="Select a language to create your project's template") |
62 |
| - # menu.mount(select_lang_widget) |
63 | 64 | menu.mount(Button("Start Project", id="start", variant="warning", classes="menu_widget"))
|
| 65 | + menu.mount(Button("Run Tests", id="test", variant="success", classes="menu_widget")) |
64 | 66 |
|
65 | 67 | async def on_button_pressed(self, event: Button.Pressed) -> None:
|
66 |
| - """Handle button press events.""" |
67 | 68 | button_id = event.button.id
|
68 | 69 | select_widget = self.query_one("#exercise_select", Select)
|
69 | 70 | exercise_name = select_widget.value
|
70 | 71 | selected_exercise = EXERCISES_DIR / f"{exercise_name}.md"
|
71 | 72 |
|
72 |
| - # select_lang_widget = self.query_one("#lang_select", Select) |
73 |
| - # lang = select_lang_widget.value |
74 |
| - |
75 |
| - if button_id in ('view', 'test'): |
76 |
| - if exercise_name == Select.BLANK: |
77 |
| - select_widget.notify("Please select a file", severity="error", timeout=5) |
78 |
| - return |
79 |
| - |
80 |
| - if button_id == "view": |
81 |
| - self.current_markdown_path = selected_exercise |
82 |
| - markdown_viewer = self.query_one("#markdown_viewer", MarkdownViewer) |
83 |
| - await markdown_viewer.go(selected_exercise) |
84 |
| - self.query_one("#content").display = True |
85 |
| - |
86 |
| - elif button_id == "test": |
87 |
| - log("about to test") |
88 |
| - self.run_tests(exercise_name) |
89 |
| - |
90 |
| - if button_id == 'start': |
91 |
| - if exercise_name == Select.BLANK: |
92 |
| - select_widget.notify("Please select a file", severity="error", timeout=5) |
93 |
| - return |
94 |
| - # if lang == Select.BLANK: |
95 |
| - # select_lang_widget.notify("Please select a language", severity="error") |
96 |
| - # return |
| 73 | + if exercise_name == Select.BLANK: |
| 74 | + select_widget.notify("Please select a file", severity="error", timeout=5) |
| 75 | + return |
| 76 | + |
| 77 | + if button_id == "view": |
| 78 | + self.current_markdown_path = selected_exercise |
| 79 | + markdown_viewer = self.query_one("#markdown_viewer", MarkdownViewer) |
| 80 | + await markdown_viewer.go(selected_exercise) |
| 81 | + self.query_one("#content").display = True |
| 82 | + |
| 83 | + elif button_id == "test": |
| 84 | + self.run_tests(exercise_name) |
| 85 | + |
| 86 | + elif button_id == 'start': |
97 | 87 | self.start_project(exercise_name)
|
98 | 88 |
|
99 | 89 | def start_project(self, exercise_name: str) -> None:
|
100 | 90 | test_output = self.query_one("#test_output", TextArea)
|
101 | 91 | project_path = BaseProjectGenerator().generate(exercise_name)
|
102 |
| - test_output.notify(f'Creating project structure for lang project {exercise_name}') |
| 92 | + test_output.notify(f'Creating project structure for project {exercise_name}') |
103 | 93 | ExercisesUtils.open_file_in_explorer(project_path)
|
104 | 94 |
|
105 | 95 | def run_tests(self, exercise_name: str) -> None:
|
106 |
| - """Run tests for the selected exercise and display the output.""" |
107 | 96 | test_output = self.query_one("#test_output", TextArea)
|
108 | 97 | docker_compose_file_name = ExercisesUtils.get_resource_path(f"exercises_test_suites/docker_compose_{exercise_name}.yml")
|
109 | 98 | command = f"docker-compose -f {docker_compose_file_name} up --build"
|
|
0 commit comments