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

[UI] Switchable Widget. #57

Closed
YooSunYoung opened this issue Aug 1, 2024 · 1 comment · Fixed by #67
Closed

[UI] Switchable Widget. #57

YooSunYoung opened this issue Aug 1, 2024 · 1 comment · Fixed by #67
Assignees
Labels
enhancement New feature or request

Comments

@YooSunYoung
Copy link
Member

Related to #28

We want a widget that wraps another widget.
If the switch is on, it should set the value from the child widget to the workflow,
if it's off, it should not be set at all.

We can either use checkbox or a accordion : D

@YooSunYoung YooSunYoung added the enhancement New feature or request label Aug 1, 2024
@YooSunYoung YooSunYoung self-assigned this Aug 1, 2024
@YooSunYoung YooSunYoung moved this from Triage to In progress in Development Board Aug 1, 2024
@SimonHeybrock SimonHeybrock mentioned this issue Aug 5, 2024
16 tasks
@YooSunYoung
Copy link
Member Author

import ipywidgets as widgets
from ess.reduce.parameter import Parameter


def make_text_widget(param: Parameter) -> widgets.Text:
    return widgets.Text(
        value=param.default,
        description=param.name,
    )


class OptionalWidget:
    def __init__(self, widget: widgets.Widget):
        self.underlying_widget = widget
        self.optional = widgets.Checkbox(description="Optional")
        self.widget = widgets.HBox(
            [
                self.underlying_widget,
                self.optional,
            ]
        )

    def value(self):
        if self.optional.value:
            return None
        return self.underlying_widget.value


sample_param = Parameter("sample", "Sample", "sample")


def wrap_as_optional(widget: widgets.Widget) -> widgets.VBox:
    return OptionalWidget(widget).widget


wrap_as_optional(make_text_widget(sample_param))

This is one of the ideas of optional widget.

Screenshot 2024-08-07 at 09 28 37

I'll open a PR of more trimmed version once param-class is polished first so that it doesn't become too big...?

@github-project-automation github-project-automation bot moved this from In progress to Done in Development Board Aug 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

1 participant