From 53cc66ed1ffc83e5aa05da1ae232c728477fe0c1 Mon Sep 17 00:00:00 2001 From: Pete Jemian Date: Thu, 13 Feb 2020 08:34:48 -0600 Subject: [PATCH] fixes #151 --- profile_bluesky/startup/00-instrument.py | 2 +- .../{console_session.py => collection.py} | 2 +- .../instrument/framework/initialize.py | 4 ++-- .../startup/instrument/mpl/__init__.py | 20 +++++++++++++++++++ .../startup/instrument/mpl/console.py | 3 +++ .../startup/instrument/mpl/notebook.py | 14 +++++++++++++ 6 files changed, 41 insertions(+), 4 deletions(-) rename profile_bluesky/startup/instrument/{console_session.py => collection.py} (93%) create mode 100644 profile_bluesky/startup/instrument/mpl/notebook.py diff --git a/profile_bluesky/startup/00-instrument.py b/profile_bluesky/startup/00-instrument.py index a9c928a..9a32be9 100644 --- a/profile_bluesky/startup/00-instrument.py +++ b/profile_bluesky/startup/00-instrument.py @@ -3,7 +3,7 @@ start bluesky in IPython session for XPCS """ -from instrument.console_session import * +from instrument.collection import * # show_ophyd_symbols() # print_RE_md(printing=False) diff --git a/profile_bluesky/startup/instrument/console_session.py b/profile_bluesky/startup/instrument/collection.py similarity index 93% rename from profile_bluesky/startup/instrument/console_session.py rename to profile_bluesky/startup/instrument/collection.py index c960df6..b4d8f69 100644 --- a/profile_bluesky/startup/instrument/console_session.py +++ b/profile_bluesky/startup/instrument/collection.py @@ -6,7 +6,7 @@ from .session_logs import * logger.info(__file__) -from .mpl.console import * +from .mpl import * logger.info("bluesky framework") diff --git a/profile_bluesky/startup/instrument/framework/initialize.py b/profile_bluesky/startup/instrument/framework/initialize.py index 8b89934..e487b05 100644 --- a/profile_bluesky/startup/instrument/framework/initialize.py +++ b/profile_bluesky/startup/instrument/framework/initialize.py @@ -58,8 +58,8 @@ # callback_db['post_run_verify'] = RE.subscribe(post_run(verify_files_saved), 'stop') # Make plots update live while scans run. -from bluesky.utils import install_qt_kicker -install_qt_kicker() +from bluesky.utils import install_kicker +install_kicker() # convenience imports # from bluesky.callbacks import * diff --git a/profile_bluesky/startup/instrument/mpl/__init__.py b/profile_bluesky/startup/instrument/mpl/__init__.py index e69de29..86f5647 100644 --- a/profile_bluesky/startup/instrument/mpl/__init__.py +++ b/profile_bluesky/startup/instrument/mpl/__init__.py @@ -0,0 +1,20 @@ + +def isnotebook(): + """ + see: https://stackoverflow.com/a/39662359/1046449 + """ + try: + shell = get_ipython().__class__.__name__ + return shell == 'ZMQInteractiveShell' + # return True # Jupyter notebook or qtconsole + #elif shell == 'TerminalInteractiveShell': + # return False # Terminal running IPython + #else: + # return False # Other type (?) + except NameError: + return False # Probably standard Python interpreter + +if isnotebook(): + from .notebook import * +else: + from .console import * diff --git a/profile_bluesky/startup/instrument/mpl/console.py b/profile_bluesky/startup/instrument/mpl/console.py index a0ac331..6b4d886 100644 --- a/profile_bluesky/startup/instrument/mpl/console.py +++ b/profile_bluesky/startup/instrument/mpl/console.py @@ -5,5 +5,8 @@ __all__ = ['plt',] +from ..session_logs import * +logger.info(__file__) + import matplotlib.pyplot as plt plt.ion() diff --git a/profile_bluesky/startup/instrument/mpl/notebook.py b/profile_bluesky/startup/instrument/mpl/notebook.py new file mode 100644 index 0000000..fe34a32 --- /dev/null +++ b/profile_bluesky/startup/instrument/mpl/notebook.py @@ -0,0 +1,14 @@ + +""" +Configure matplotlib in interactive mode for Jupyter notebook +""" + +__all__ = ['plt',] + +from ..session_logs import * +logger.info(__file__) + +# %matplotlib notebook +get_ipython().magic('matplotlib notebook') +import matplotlib.pyplot as plt +plt.ion()