Skip to content

Commit

Permalink
Added namespaces to actions
Browse files Browse the repository at this point in the history
- also added check_action with default implementation
  • Loading branch information
hweichelt committed Jun 5, 2024
1 parent ecda321 commit 0cf4088
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ readme = "README.md"
dependencies = [
"clingo>=5.7.1",
"autoflake",
"textual[syntax]",
"textual==0.62.0",
]
classifiers = [
"Development Status :: 4 - Beta",
Expand Down
18 changes: 14 additions & 4 deletions src/clingexplaid/cli/textual_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -319,15 +319,15 @@ 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:
"""
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):
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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")

Expand Down Expand Up @@ -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:
"""
Expand Down

0 comments on commit 0cf4088

Please sign in to comment.