File: embed_ipython_.py

package info (click to toggle)
napari 0.6.6-3
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 12,036 kB
  • sloc: python: 112,264; xml: 72; makefile: 44; sh: 5
file content (31 lines) | stat: -rw-r--r-- 864 bytes parent folder | download
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`