forked from pyapp-kit/magicgui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Example script for ineterminate progress bar with a long running comp…
…utation (pyapp-kit#579)
- Loading branch information
1 parent
2760ae7
commit e47338a
Showing
3 changed files
with
56 additions
and
1 deletion.
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
# Progress bars examples | ||
# Progress bar examples | ||
|
||
Examples of progress bars in magicgui. |
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,31 @@ | ||
"""# Indeterminate progress bar | ||
Example of an indeterminate progress bar for a long running computation | ||
of unknown time. | ||
""" | ||
import time | ||
|
||
from superqt.utils import thread_worker | ||
|
||
from magicgui import magicgui | ||
from magicgui.tqdm import tqdm | ||
|
||
|
||
@magicgui(call_button=True, layout="horizontal") | ||
def long_running(sleep_time=5): | ||
"""Long running computation with an indeterminate progress bar.""" | ||
# Here tqdm is not provided an iterable argument, or the 'total' kwarg | ||
# so it cannot calculate the expected number of iterations | ||
# which means it will create an indeterminate progress bar | ||
with tqdm() as pbar: | ||
# It is best practice to use a separate thread for long running computations | ||
# This makes the function non-blocking, you can still interact with the widget | ||
@thread_worker(connect={"finished": lambda: pbar.progressbar.hide()}) | ||
def sleep(secs): | ||
time.sleep(secs) | ||
|
||
sleep(sleep_time) | ||
|
||
|
||
long_running.show(run=True) |
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