Skip to content

Commit

Permalink
Detect jupyter
Browse files Browse the repository at this point in the history
  • Loading branch information
sylvielamythepaut committed Dec 5, 2018
1 parent adb19a3 commit 15f0470
Showing 1 changed file with 27 additions and 25 deletions.
52 changes: 27 additions & 25 deletions python/Magics/macro.py
Original file line number Diff line number Diff line change
Expand Up @@ -587,39 +587,41 @@ def inspect(self):
import threading
import tempfile

plot = _plot

def setjupyter():
try:
from IPython.display import Image
LOCK = threading.Lock()
_MAGICS_LOCK = threading.Lock()

def plot(*args):

with LOCK:
f, tmp = tempfile.mkstemp(".png")
os.close(f)
try:
# This function only seems to be defined in a Jupyter notebook context.
get_ipython()
plot = _jplot
except Exception:
plot = _plot

base, ext = os.path.splitext(tmp)

img = output(output_formats=["png"],
output_name_first_page_number='off',
output_name=base)

all = []
all.append(img)
for i in args :
all.append(i)
_plot(all)

image = Image(tmp)
os.unlink(tmp)
return image
except ImportError:
print ( "Not able to set up the jupyter environ")
def _jplot(*args):
from IPython.display import Image

with _MAGICS_LOCK:
f, tmp = tempfile.mkstemp(".png")
os.close(f)

base, ext = os.path.splitext(tmp)

img = output(
output_formats=["png"],
output_name_first_page_number='off',
output_name=base
)

all = [img]
all.extend(args)

_plot(all)

image = Image(tmp)
os.unlink(tmp)
return image


def wmsstyles(data):
Expand Down

0 comments on commit 15f0470

Please sign in to comment.