File: callable.py

package info (click to toggle)
magicgui 0.9.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 21,796 kB
  • sloc: python: 11,202; makefile: 11; sh: 9
file content (33 lines) | stat: -rw-r--r-- 658 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
"""# Callable functions demo

This example demonstrates handling callable functions with magicgui.
"""

from magicgui import magicgui


def f(x: int, y="a string") -> str:
    """Example function F."""
    return f"{y} {x}"


def g(x: int = 6, y="another string") -> str:
    """Example function G."""
    return f"{y} asdfsdf {x}"


@magicgui(call_button=True, func={"choices": ["f", "g"]})
def example(func="f"):
    """Ëxample function."""
    pass


def update(f: str):
    """Update function."""
    if len(example) > 2:
        del example[1]
    example.insert(1, magicgui(globals()[f]))


example.func.changed.connect(update)
example.show(run=True)