question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Get paremeters entered by a widget

See original GitHub issue

Hello,

After tweaking the parameters, I would like to know if it is possible to get the values back entered in the widget?

I suspect that it is in viewer.window But not sure then in which subsection could be.

Thank you

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:20 (12 by maintainers)

github_iconTop GitHub Comments

1reaction
tlambert03commented, Jun 24, 2021

you could connect the widget.changed event to a function that stores your parameters:

from magicgui import magicgui

PARAMS = {}

@magicgui
def func(param1: int, param2: str): ...


@func.changed.connect
def store_params(event):
    widget = event.value
    PARAMS[widget.name] = {
        n: p.default for n, p in widget.__signature__.parameters.items()
    }


func.show(run=True)
# this will only print after you close the widget
print(PARAMS)

you might also be interested in looking through some of the code we did in https://github.com/clEsperanto/napari_pyclesperanto_assistant (which is a similar pipeline of processing using magicgui for input). Basically, the user interactively sets up a chain of processing events using magicgui widgets. Then the task graph can be collected using the to_dask method here … which outputs a dask task graph representing the functions and their arguments…

1reaction
tlambert03commented, Jun 22, 2021

another tip: If you want a dict of parameters like you have in your first example, the magicgui object has a __signature__ attribute that behaves like an inspect signature object that stays up to date:

In [1]: from magicgui import magicgui
   ...:
   ...: @magicgui
   ...: def gaussian(image: int, sigma: float = 1) -> int:
   ...:     ...
   ...:

In [2]: gaussian.sigma.value = 3

In [3]: {k: p.default for k,p in gaussian.__signature__.parameters.items()}
Out[3]: {'image': 0, 'sigma': 3.0}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Pass parameters from a custom widget to a script
Take a look at the widget and code I posted for scene control and modification and you'll see an example. The widget sets...
Read more >
pass parameter to page with widget via page url - ServiceNow
Solved: in service portal i have a page with one widget the server script on the widget needs a sysid i thought i...
Read more >
How can I get input parameters from url and execut...
I've got a web appbuilder app with a geoprocessing widget that I'd like to take a parameter from the url and execute the...
Read more >
Pass method as parameter to a widget - dart - Stack Overflow
@user3833732 when you add (), you are executing the function and getting the response when the code is run. When you skip the...
Read more >
Input Parameters in Widgets - Zoho Cares
This parameter contains the details of the operator who is accessing the widget. It is available in the detail handler and in the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found