Skip to content

Commit 6a41711

Browse files
committed
Remove duplication of notebook check code
1 parent d3758f0 commit 6a41711

File tree

1 file changed

+1
-50
lines changed

1 file changed

+1
-50
lines changed

vpython/vpython.py

Lines changed: 1 addition & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -26,55 +26,6 @@
2626
'quad', 'radio', 'ring', 'simple_sphere', 'sleep', 'slider', 'sphere',
2727
'standardAttributes', 'text', 'textures', 'triangle', 'vertex',
2828
'wtext']
29-
vec = vector # synonyms in GlowScript
30-
31-
def __checkisnotebook(): # returns True if running in Jupyter notebook
32-
try:
33-
shell = get_ipython().__class__.__name__
34-
if shell == 'ZMQInteractiveShell': # Jupyter notebook or qtconsole?
35-
return True
36-
elif shell == 'TerminalInteractiveShell': # Terminal running IPython?
37-
return False
38-
else:
39-
return False # Other type (?)
40-
except NameError:
41-
return False # Probably standard Python interpreter
42-
_isnotebook = __checkisnotebook()
43-
44-
if _isnotebook:
45-
#### Imports for Jupyter VPython
46-
import IPython
47-
if IPython.__version__ >= '4.0.0' :
48-
import ipykernel
49-
import notebook
50-
from ipykernel.comm import Comm
51-
if (ipykernel.__version__ >= '5.0.0'):
52-
53-
import asyncio
54-
async def wsperiodic():
55-
while True:
56-
if ws_queue.qsize() > 0:
57-
data = ws_queue.get()
58-
d = json.loads(data)
59-
for m in d:
60-
# Must send events one at a time to GW.handle_msg because bound events need the loop code:
61-
msg = {'content':{'data':[m]}} # message format used by notebook
62-
baseObj.glow.handle_msg(msg)
63-
64-
await asyncio.sleep(0)
65-
66-
loop = asyncio.get_event_loop()
67-
loop.create_task(wsperiodic())
68-
69-
else:
70-
import IPython.html.nbextensions
71-
from IPython.kernel.comm.comm import Comm
72-
from IPython.display import HTML
73-
from IPython.display import display
74-
from IPython.display import Javascript
75-
from IPython.core.getipython import get_ipython
76-
from jupyter_core.paths import jupyter_data_dir
77-
from . import __version__, __gs_version__
7829

7930
__p = platform.python_version()
8031
_ispython3 = (__p[0] == '3')
@@ -379,7 +330,7 @@ def __del__(self):
379330
# and sent as a block to the browser at render times.
380331

381332
class GlowWidget(object):
382-
def __init__(self, wsport = None, wsuri = None):
333+
def __init__(self, wsport=None, wsuri=None):
383334
global sender
384335
baseObj.glow = self
385336
if _isnotebook:

0 commit comments

Comments
 (0)