forked from napari/napari
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathembed_ipython_.py
31 lines (21 loc) · 864 Bytes
/
embed_ipython_.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
"""
Embed IPython
=============
Start napari and land directly in an embedded ipython console with qt event loop.
A similar effect can be achieved more simply with `viewer.update_console(locals())`,
such as shown in https://github.com/napari/napari/blob/main/examples/update_console.py.
However, differently from `update_console`, this will start an independent
ipython console which can outlive the viewer.
.. tags:: gui
"""
from IPython.terminal.embed import InteractiveShellEmbed
import napari
# any code
text = 'some text'
# initialize viewer
viewer = napari.Viewer()
# embed ipython and run the magic command to use the qt event loop
sh = InteractiveShellEmbed()
sh.enable_gui('qt') # equivalent to using the '%gui qt' magic
sh() # open the embedded shell
# From there, you can access the script's scope, such as the variables `text` and `viewer`