-
Notifications
You must be signed in to change notification settings - Fork 319
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
make plot updates work outside ipython notebook #155
Closed
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
5c070d0
make plot updates work outside ipython notebook
eendebakpt 7b07d7a
add checks on environment
eendebakpt 16407b9
added helper functions
eendebakpt 9d42c29
Merge branch 'master' into outside-notebook
alexcjohnson 9859784
lint
alexcjohnson 7c77790
bring back in_ipynb
alexcjohnson File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 |
---|---|---|
|
@@ -5,8 +5,10 @@ | |
import math | ||
import sys | ||
import io | ||
import os | ||
import numpy as np | ||
import json | ||
from IPython import get_ipython | ||
|
||
_tprint_times = {} | ||
|
||
|
@@ -25,20 +27,45 @@ def default(self, obj): | |
else: | ||
return super(NumpyJSONEncoder, self).default(obj) | ||
|
||
|
||
def tprint(string, dt=1, tag='default'): | ||
""" Print progress of a loop every dt seconds """ | ||
"""Print progress of a loop every dt seconds.""" | ||
ptime = _tprint_times.get(tag, 0) | ||
if (time.time() - ptime) > dt: | ||
print(string) | ||
_tprint_times[tag] = time.time() | ||
|
||
|
||
def is_interactive(): | ||
"""Return True if we are running in any interactive environment.""" | ||
import __main__ as main | ||
return not hasattr(main, '__file__') | ||
|
||
|
||
def in_spyder(): | ||
"""Return True if we are running in the Spyder environment.""" | ||
return bool(any('SPYDER' in name for name in os.environ)) | ||
|
||
|
||
def in_ipynb(): | ||
"""Return True if we are running in an IPython / Jupyter notebook.""" | ||
try: | ||
cfg = get_ipython().config | ||
if cfg['IPKernelApp']['parent_appname'] == 'ipython-notebook': | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
return True | ||
else: | ||
return False | ||
except NameError: | ||
return False | ||
|
||
|
||
def in_notebook(): | ||
''' | ||
Returns True if the code is running with a ipython or jypyter | ||
""" | ||
Return True if we are running in ipython or jypyter. | ||
|
||
This could mean we are connected to a notebook, but this is not guaranteed. | ||
see: http://stackoverflow.com/questions/15411967 | ||
''' | ||
""" | ||
return 'ipy' in repr(sys.stdout) | ||
|
||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we support
.halt()
as the update widget does? I'm not sure if we make the use of this everywhere we should right now in notebooks, but there should be some way to stop the updater when it's no longer needed.