Skip to content

Commit

Permalink
Update isIpy() to check for interactive notebook
Browse files Browse the repository at this point in the history
Improves compatibility with Spyder
  • Loading branch information
charwick committed Jul 23, 2021
1 parent f7cddc3 commit 2445fc7
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 9 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ The included [bootstrap model](https://github.com/charwick/helipad/blob/master/s

## Requirements

Helipad requires Python 3.6 or higher. The following libraries are also required:
Helipad requires Python 3.7 or higher. The following libraries are also required:

* [Matplotlib](https://matplotlib.org/) (for visualization)
* [Pandas](https://pandas.pydata.org/) (for data collection)
Expand Down
21 changes: 16 additions & 5 deletions helipad/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,22 @@

import warnings

def isIpy():
try:
__IPYTHON__
return True
except NameError: return False
#Pass True to check for any Ipython environment, including Spyder, for event loop purposes.
#Otherwise check specifically whether it's an interactive notebook. However, get_ipython() comes back
#undefined inside callbacks. So cache the value once, the first time it runs.
def isIpy(atall=False):
if atall:
try:
__IPYTHON__
return True
except NameError: return False

if not '__helipad_ipy' in globals():
try:
globals()['__helipad_ipy'] = 'InteractiveShell' in get_ipython().__class__.__name__
except NameError: globals()['__helipad_ipy'] = False

return __helipad_ipy

#Generic extensible item class to store structured data
class Item:
Expand Down
4 changes: 2 additions & 2 deletions helipad/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ async def run(self):
self.doHooks('visualRefresh', [self, self.visual])

elif getattr(self, 'cpanel', None):
if isIpy(): await asyncio.sleep(0.001) #Listen for keyboard input
if isIpy(True): await asyncio.sleep(0.001) #Listen for keyboard input
else: self.cpanel.parent.update() #Make sure we don't hang the interface if plotless

# Performance indicator
Expand Down Expand Up @@ -567,7 +567,7 @@ def start(self, *args):
#that the statement in the try block doesn't get executed…?
with warnings.catch_warnings():
warnings.simplefilter("ignore")
if not isIpy(): asyncio.run(self.run()) #If Tkinter, it needs an event loop
if not isIpy(True): asyncio.run(self.run()) #If Tkinter, it needs an event loop
else: asyncio.ensure_future(self.run()) #If Jupyter, it already has an event loop

def stop(self, *args):
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,5 @@
"Intended Audience :: Science/Research",
"Topic :: Scientific/Engineering :: Visualization"
],
python_requires='>=3.6',
python_requires='>=3.7',
)

0 comments on commit 2445fc7

Please sign in to comment.