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

A "renderer" parameter for transforming the underlying value into a nicer display value #554

Open
Etherian opened this issue Apr 22, 2023 · 1 comment

Comments

@Etherian
Copy link

On elements where it makes sense, add a parameter that takes a callback which transforms the widget's underlying values into displayed ones that are nicer-looking and easier for the user to understand.

For example, I have a ComboBox of dictionaries like

from magicgui import ComboBox

ComboBox(
    value={'color': 'red', 'shape': 'square'},
    choices=[
        {'color': 'red', 'shape': 'square'},
        {'color': 'yellow', 'shape': 'circle'}
    ],
)

It would be nice if I could display something nicer for the user with

ComboBox(
    value={'color': 'red', 'shape': 'square'},
    choices=[
        {'color': 'red', 'shape': 'square'},
        {'color': 'yellow', 'shape': 'circle'}
    ],
    renderer=lambda val: f'val["color"] val["shape"]'
)
@tlambert03
Copy link
Member

yeah, I like that a lot! feel free to make a PR, or I will try to get around to it in the next few weeks.

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

No branches or pull requests

2 participants