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

Optional widget wrapper #73

Merged
merged 5 commits into from
Aug 13, 2024
Merged

Optional widget wrapper #73

merged 5 commits into from
Aug 13, 2024

Conversation

YooSunYoung
Copy link
Member

@YooSunYoung YooSunYoung commented Aug 13, 2024

Fixes #71

I don't like how it looks but it works...

Optional

image

Switchable & Optional

Screen.Recording.2024-08-13.at.10.10.20.mov

@YooSunYoung YooSunYoung marked this pull request as ready for review August 13, 2024 08:41
@jokasimr
Copy link
Contributor

I saw this before but didn't understand it. What is a switchable widget? When is it used?

@jokasimr jokasimr self-requested a review August 13, 2024 08:58
@YooSunYoung
Copy link
Member Author

YooSunYoung commented Aug 13, 2024

I saw this before but didn't understand it. What is a switchable widget? When is it used?

@jokasimr
Switchable widget is when you don't want to set the parameter at all in the workflow
and
Optional widget is when you want to set it as None.
It's handled by the attributes of Parameter object, switchable and optional.

Maybe I should add this information in the developer's gui page...

@SimonHeybrock
Copy link
Member

I saw this before but didn't understand it. What is a switchable widget? When is it used?

TL;DR: When you have a parameter param: SomeType | None (aka Optional[SomeType]).

@jokasimr
Copy link
Contributor

TL;DR: When you have a parameter param: SomeType | None (aka Optional[SomeType]).

From @YooSunYoung s explanation that sounds more like an optional widget.

@YooSunYoung
Copy link
Member Author

I added the explanation in the developers document

@jokasimr
Copy link
Contributor

Instead of making switchable widgets, maybe we should just add a long multiple-select widget containing all domain types (parameters) in the workflow. When you select some of them, they show up in the ParameterBox widget and you can assign their values. When you select a set of outputs, the multiple select list of parameters selects the required parameters to produce the outputs.

This would help by

  1. removing the need to have switchable parameters/widgets, simplifying the gui
  2. make it easy to add support for changing intermediate values, the user just needs to select them manually from the parameter multiple select widget

@YooSunYoung
Copy link
Member Author

@jokasimr I created a separate issue regarding your suggestion. #74

def __init__(self, wrapped: Widget, name: str = '', **kwargs) -> None:
self.name = name
self.wrapped = wrapped
self._option_box = RadioButtons(
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe it's simpler to use a single checkbox here? That would let us remove the layout code, since we would not have to manually place the two radio elements on the same line.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm thinking something like:

import ipywidgets as ipw

c = ipw.Checkbox(description='')
s = ipw.Stack([ipw.Label('None'), ipw.Text()], selected_index=0)
ipw.dlink((c, 'value'), (s, 'selected_index'))
ipw.HBox([c, s])

Screenshot from 2024-08-13 12-49-20
Screenshot from 2024-08-13 12-49-31

Copy link
Contributor

Choose a reason for hiding this comment

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

Or, same but using .disabled like you did in this PR.

Copy link
Contributor

Choose a reason for hiding this comment

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

But it doesn't matter much. If you think it's better like it is just go with that.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah I didn't want to use checkbox because we are using it for switchable. Maybe we can update it once we fix the switchable as you suggested...!

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 made this note in the #74


# Make the wrapped radio box horizontal
self.add_class("widget-optional")
_style_html = HTML(
Copy link
Contributor

Choose a reason for hiding this comment

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

see comment above about checkbox, I think that would let us remove this

@@ -56,7 +57,23 @@ def wrapper(param: Parameter) -> widgets.Widget:
return wrapper


def optional_widget(
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this decorator meant to be used elsewhere? Right now it's only used in one place as far as I can tell.
Maybe we can just put the logic inside that function for now and make it a decorator later if the logic is reused elsewhere?

Copy link
Member Author

Choose a reason for hiding this comment

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

We can't put it inside because of the singledispatch decorator.
You'll have to do it in every dispatch registered functions.

Copy link
Contributor

Choose a reason for hiding this comment

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

Aha I see

@YooSunYoung YooSunYoung merged commit 04390d0 into main Aug 13, 2024
3 checks passed
@YooSunYoung YooSunYoung deleted the optional-widget branch August 13, 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
Archived in project
Development

Successfully merging this pull request may close these issues.

[UI] Optional Parameter and Widget
3 participants