-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add demo of all available widgets * Add file picker widget to widget_demo.py
- Loading branch information
1 parent
b1ba82e
commit ad79e0a
Showing
1 changed file
with
43 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
"""Widget demonstration of magicgui.""" | ||
|
||
from enum import Enum | ||
from datetime import datetime | ||
import math | ||
from pathlib import Path | ||
|
||
from magicgui import event_loop, magicgui | ||
|
||
|
||
class Medium(Enum): | ||
"""Enum for various media and their refractive indices.""" | ||
|
||
Glass = 1.520 | ||
Oil = 1.515 | ||
Water = 1.333 | ||
Air = 1.0003 | ||
|
||
|
||
@magicgui(call_button="Calculate", result={"disabled": True, "fixedWidth": 100}) | ||
def widget_demo( | ||
boolean=True, | ||
integer=1, | ||
float=3.14159, | ||
string="Text goes here", | ||
dropdown=Medium.Glass, | ||
datetime=datetime.now(), | ||
filename=Path.home() | ||
): | ||
"""Run some computation.""" | ||
print("Running some computation...") | ||
return "Result!" | ||
|
||
|
||
with event_loop(): | ||
# the original function still works | ||
# we can create a gui | ||
gui = widget_demo.Gui(show=True) | ||
# we can list for changes to parameters in the gui | ||
# ... these also trigger for direct parameter access on the gui object | ||
gui.string_changed.connect(print) | ||
# we can connect a callback function to the __call__ event on the function | ||
gui.called.connect(lambda x: gui.set_widget("result", str(x), position=-1)) |