Skip to content

Commit

Permalink
interactive: toggle condense/uncondense button (4/7) (#1799)
Browse files Browse the repository at this point in the history
Added uncondense button functionality.
  • Loading branch information
dshaaban01 authored Nov 17, 2023
1 parent fb57655 commit 40f2fba
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
11 changes: 11 additions & 0 deletions tests/interactive/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,9 @@ async def test_buttons():
assert isinstance(app.current_module, ModuleOp)
assert app.current_module.is_structurally_equivalent(expected_module)

# assert initial state of condense_mode is False
assert app.condense_mode is False

# press "Condense" button
await pilot.click("#condense_button")

Expand All @@ -261,9 +264,17 @@ async def test_buttons():
)

await pilot.pause()
# assert after "Condense Button" is clicked that the state and condensed_pass list change accordingly
assert app.condense_mode is True
assert app.available_pass_list == condensed_list

# press "Uncondense" button
await pilot.click("#uncondense_button")

await pilot.pause()
# assert after "Condense Button" is clicked that the state changes accordingly
assert app.condense_mode is False


@pytest.mark.asyncio()
async def test_passes():
Expand Down
11 changes: 9 additions & 2 deletions xdsl/interactive/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ def condensed_pass_list(input: builtin.ModuleOp) -> tuple[type[ModulePass], ...]
cloned_module = input.clone()
cloned_ctx = ctx.clone()
value().apply(cloned_ctx, cloned_module)

if not input.is_structurally_equivalent(cloned_module):
rhs = (*selections, value)
selections = tuple(rhs)
Expand Down Expand Up @@ -114,6 +113,7 @@ def compose(self) -> ComposeResult:
yield Button("Copy Query", id="copy_query_button")
yield Button("Clear Passes", id="clear_passes_button")
yield Button("Condense", id="condense_button")
yield Button("Uncondense", id="uncondense_button")
with ScrollableContainer(id="selected_passes"):
yield self.selected_query_label
with Horizontal(id="bottom_container"):
Expand All @@ -127,7 +127,6 @@ def compose(self) -> ComposeResult:

def on_mount(self) -> None:
"""Configure widgets in this application before it is first shown."""

# register's the theme for the Input/Output TextArea's
self.input_text_area.theme = "vscode_dark"
self.output_text_area.theme = "vscode_dark"
Expand All @@ -137,6 +136,7 @@ def on_mount(self) -> None:
self.query_one(
"#passes_list_view"
).border_title = "Choose a pass or multiple passes to be applied."

self.query_one("#selected_passes").border_title = "Selected passes/query"

for n, _ in ALL_PASSES:
Expand Down Expand Up @@ -196,6 +196,7 @@ def update_current_module(self) -> None:
input_text = self.input_text_area.text
if (input_text) == "":
self.current_module = None
self.current_condensed_pass_list = ()
return
try:
ctx = MLContext(True)
Expand Down Expand Up @@ -260,6 +261,12 @@ def clear_passes(self, event: Button.Pressed) -> None:
@on(Button.Pressed, "#condense_button")
def condense(self, event: Button.Pressed) -> None:
self.condense_mode = True
self.add_class("condensed")

@on(Button.Pressed, "#uncondense_button")
def uncondense(self, event: Button.Pressed) -> None:
self.condense_mode = False
self.remove_class("condensed")


def main():
Expand Down
13 changes: 13 additions & 0 deletions xdsl/interactive/app.tcss
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,16 @@ Screen {
grid-rows: 45% 55%;
background: $surface;
}

# Button
#uncondense_button{
display: none;
}

.condensed #condense_button {
display: none;
}

.condensed #uncondense_button {
display: block;
}

0 comments on commit 40f2fba

Please sign in to comment.