-
Notifications
You must be signed in to change notification settings - Fork 1
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
Conversation
|
||
def __init__(self, wrapped: Widget, name: str = '') -> None: | ||
super().__init__() | ||
self.enable_box = Checkbox(description='Use Parameter', style=default_style) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
@property | ||
def value(self) -> Any: | ||
return self.wrapped.value |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
essreduce/src/ess/reduce/ui.py
Lines 115 to 127 in 024224a
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
essreduce/src/ess/reduce/ui.py
Lines 130 to 147 in 024224a
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...?
tests/widget_test.py
Outdated
|
||
@pytest.mark.filterwarnings( | ||
'ignore::DeprecationWarning' | ||
) # Ignore deprecation warning from widget library |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
def test_collect_values_from_disabled_switchable_widget() -> None: | ||
from ess.reduce.ui import collect_values |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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...?
4f55bbc
to
67295da
Compare
Fixes #57
Preview
Screen.Recording.2024-08-08.at.15.30.22.mov