Skip to content

Commit

Permalink
added textual GUI first test
Browse files Browse the repository at this point in the history
  • Loading branch information
hweichelt committed May 9, 2024
1 parent 9388fae commit 1b4b6e3
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 3 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",
"textual[syntax]",
]
classifiers = [
"Development Status :: 4 - Beta",
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
autoflake==2.3.1
clingo==5.7.1
pre-commit==3.7.0
textual==0.58.1
textual[syntax]==0.58.1
9 changes: 8 additions & 1 deletion src/clingexplaid/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,21 @@
from clingo.application import clingo_main

from .cli.clingo_app import ClingoExplaidApp
from .cli.textual_gui import ClingexplaidTextualApp

RUN_TEXTUAL_GUI = False


def main() -> None:
"""
Run the main function.
"""

clingo_main(ClingoExplaidApp(sys.argv[0]), sys.argv[1:] + ["-V0"])
if RUN_TEXTUAL_GUI:
app = ClingexplaidTextualApp()
app.run()
else:
clingo_main(ClingoExplaidApp(sys.argv[0]), sys.argv[1:] + ["-V0"])


if __name__ == "__main__":
Expand Down
102 changes: 102 additions & 0 deletions src/clingexplaid/cli/textual_gui.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
from textual.app import App, ComposeResult
from textual.containers import Vertical, VerticalScroll
from textual.widgets import Button, Checkbox, Collapsible, Footer, Input, Label, Select, Tabs


class ClingexplaidTextualApp(App):
"""A textual app for a terminal GUI to use the clingexplaid functionality"""

BINDINGS = [("ctrl+x", "exit", "Exit")]
CSS = """
Screen {
layout: grid;
grid-size: 2 1;
grid-columns: 1fr 2fr
}
.box {
height: 100%;
border: round #455A64;
padding: 1;
}
#top-cell {
layout: grid;
grid-size: 1;
grid-rows: auto 1fr;
}
#main-config {
layout: grid;
grid-size: 2;
grid-columns: auto 1fr;
grid-gutter: 1;
}
#main-config Label {
padding: 1 2;
background: #263238;
width: 100%;
}
#files {
layout: grid;
grid-size: 1;
grid-rows: 1fr auto;
}
#files Button{
width: 100%;
}
#files VerticalScroll{
background: #000;
}
#files VerticalScroll Checkbox{
width: 100%;
}
.no-padding-top{
padding-top: 0;
}
"""

def __init__(self):
super(ClingexplaidTextualApp, self).__init__()

def compose(self) -> ComposeResult:
yield Vertical(
Vertical(
Label("Mode"),
Select(((line, line) for line in ["SOLVE", "MUS"]), allow_blank=False),
Label("Models"),
Input(placeholder="Number of Models (Default: 1)", type="number"),
id="main-config",
classes="box",
),
Vertical(
VerticalScroll(
Checkbox("encoding.lp"),
Checkbox("instance_1.lp"),
Checkbox("instance_2.lp"),
Checkbox("instance_3.lp"),
Checkbox("instance_4.lp"),
),
Button("Add a new file"),
classes="box",
id="files",
),
id="top-cell",
)
yield VerticalScroll(
Tabs("Tab 1", "Tab 2", "Tab 3"),
Collapsible(title="Model 1", collapsed=True),
Collapsible(title="Model 2", collapsed=True),
Collapsible(title="Model 3", collapsed=True),
classes="box no-padding-top",
)
yield Footer()

def action_exit(self):
self.exit()

0 comments on commit 1b4b6e3

Please sign in to comment.