From 0cf4088eef2fd7ba49925cb7c7dfb618b7a9fefd Mon Sep 17 00:00:00 2001 From: Hannes Weichelt Date: Wed, 5 Jun 2024 20:40:48 +0200 Subject: [PATCH] Added namespaces to actions - also added check_action with default implementation --- pyproject.toml | 2 +- src/clingexplaid/cli/textual_gui.py | 18 ++++++++++++++---- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 44feb14..743617b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -20,7 +20,7 @@ readme = "README.md" dependencies = [ "clingo>=5.7.1", "autoflake", - "textual[syntax]", + "textual==0.62.0", ] classifiers = [ "Development Status :: 4 - Beta", diff --git a/src/clingexplaid/cli/textual_gui.py b/src/clingexplaid/cli/textual_gui.py index 1680dea..f301655 100644 --- a/src/clingexplaid/cli/textual_gui.py +++ b/src/clingexplaid/cli/textual_gui.py @@ -121,7 +121,7 @@ async def selector_changed(self, event: Checkbox.Changed) -> None: # Updating the UI to show the reasons why validation failed if event.checkbox == self.query_one(Checkbox): self.toggle_active() - await self.run_action("update_config") + await self.run_action("app.update_config") class LabelInputWidget(SelectorWidget): @@ -319,7 +319,7 @@ async def input_changed(self, event: Input.Changed) -> None: else: self.remove_class("error") cast(Label, self.query_one("Label.error")).update("") - await self.run_action("update_config") + await self.run_action("app.update_config") @on(Button.Pressed) async def solve(self, event: Button.Pressed) -> None: @@ -327,7 +327,7 @@ async def solve(self, event: Button.Pressed) -> None: Callback for when the `ControlPanel`'s Button is changed. """ if event.button == self.query_one("#solve-button"): - await self.run_action("solve") + await self.run_action("app.solve") class SolverTreeView(Static): @@ -346,7 +346,7 @@ def compose(self) -> ComposeResult: yield LoadingIndicator() -class ClingexplaidTextualApp(App[int]): +class ClingexplaidTextualApp(App): """A textual app for a terminal GUI to use the clingexplaid functionality""" # pylint: disable=too-many-instance-attributes @@ -434,6 +434,8 @@ async def action_update_config(self) -> None: """ Action to update the solving config """ + self.refresh_bindings() + # update model number model_number_input = cast(Input, self.query_one("#model-number-input")) model_number = int(model_number_input.value) @@ -469,6 +471,8 @@ async def action_solve(self) -> None: """ Action to exit the textual application """ + self.refresh_bindings() + tree_view = self.query_one(SolverTreeView) solve_button = self.query_one("#solve-button") @@ -512,6 +516,12 @@ async def action_solve(self) -> None: end_string = "SAT" if self.model_count > 0 else "UNSAT" self.tree_cursor.add(end_string) + def check_action(self, action: str, parameters: tuple[object, ...]) -> bool | None: + """ + Check if any action may run + """ + return True + def textual_main() -> None: """