Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switchable widget. #67

Merged
merged 4 commits into from
Aug 9, 2024
Merged

Switchable widget. #67

merged 4 commits into from
Aug 9, 2024

Conversation

YooSunYoung
Copy link
Member

Fixes #57

Preview

Screen.Recording.2024-08-08.at.15.30.22.mov


def __init__(self, wrapped: Widget, name: str = '') -> None:
super().__init__()
self.enable_box = Checkbox(description='Use Parameter', style=default_style)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we have no text instead, and grey-out/disable the widget instead? Some widgets (like BinEdgeWidget) might be quite wide, so saving space would be good.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there's no text, it's hard to tell what's the check box is about.

And I couldn't find how to grey-out widgets without using java script api...
And disable is not a common property so it's also not an option.

Copy link
Member Author

@YooSunYoung YooSunYoung Aug 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, it's not that bad without the description.
I'll remove it.

Screen.Recording.2024-08-08.at.21.41.20.mov

Comment on lines +40 to +47
@property
def value(self) -> Any:
return self.wrapped.value
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should have a test to ensure that disabling the widget will disable setting a value on the pipeline.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a helper to handle SwitchableWidget

def collect_values(
parameter_box: widgets.VBox, param_keys: Iterable[Key]
) -> dict[Key, Any]:
return {
node: parameter_box.children[i].children[0].value
for i, node in enumerate(param_keys)
if (
not isinstance(
widget := parameter_box.children[i].children[0], SwitchWidget
)
)
or widget.enabled
}

and used it in the run_workflow

def run_workflow(_: widgets.Button) -> None:
workflow_constructor = cast(Callable[[], sciline.Pipeline], workflow_select.value)
selected_workflow = workflow_constructor()
outputs = possible_outputs_widget.value + typical_outputs_widget.value
registry = get_parameters(selected_workflow, outputs)
values = collect_values(parameter_box, registry.keys())
workflow = assign_parameter_values(selected_workflow, values)
with output:
compute_result = workflow.compute(
outputs, scheduler=sciline.scheduler.NaiveScheduler()
)
results.clear()
results.update(compute_result)
for i in compute_result.values():
display.display(display.HTML(i._repr_html_()))

And then added the test of collect_values helper instead of building workflow for testing.

https://github.com/scipp/essreduce/blob/switchable-widget/tests/widget_test.py

I guess it could also be tested in the higher-level, when we test the whole process.

But it requires registry and simulating selections and everything, so I suggest we do that in another PR.

What do you think...?


@pytest.mark.filterwarnings(
'ignore::DeprecationWarning'
) # Ignore deprecation warning from widget library
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is causing this warning? Is there no alternative?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought it was because of the widget library. But it was because how we set the style.
I fixed it and removed the mark.

Comment on lines +21 to +15
def test_collect_values_from_disabled_switchable_widget() -> None:
from ess.reduce.ui import collect_values
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you are kind of testing an implementation detail here: Someone might remove the collect_values function, change the mechanism, etc. When that happens, this test will need to be refactored, or worse, it will be removed.

Have you considered testing the actual observable behavior we want, i.e., create a Pipeline and check if those values are set by the UI? Is this too complicated to do in the current design? Would something like MVP or MVC make this easier?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I would rather do that once we have #68 done...?

Base automatically changed from param-class to main August 9, 2024 07:57
@YooSunYoung YooSunYoung merged commit 70bf1fa into main Aug 9, 2024
3 checks passed
@YooSunYoung YooSunYoung deleted the switchable-widget branch August 9, 2024 13:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[UI] Switchable Widget.
2 participants