##// END OF EJS Templates
Backport PR #5488: Added missing require and jquery from cdn....
Backport PR #5488: Added missing require and jquery from cdn. For some reason (I suppose some changes at the css level) the font size inside the input cells was fixed at 14 px... making the fonts really small in the reveal slideshows. This is really annoying... As a plus, I have also added the missing calls for require and jquery (as the full html template does). I think these fixes belong to 2.0, but I also know we are on the edge... so I hope to get it inside :wink: Cheers.

File last commit:

r16113:87737521
r16230:ba262623
Show More
embed_class_long.py
135 lines | 4.6 KiB | text/x-python | PythonLexer
fperez
Reorganized the directory for ipython/ to have its own dir, which is a bit...
r0 #!/usr/bin/env python
"""An example of how to embed an IPython shell into a running program.
Please see the documentation in the IPython.Shell module for more details.
Brian E. Granger
Minor edits and updates.
r16101 The accompanying file embed_class_short.py has quick code fragments for
fperez
Reorganized the directory for ipython/ to have its own dir, which is a bit...
r0 embedding which you can cut and paste in your code once you understand how
things work.
The code in this file is deliberately extra-verbose, meant for learning."""
Thomas Kluyver
Use print_function in example-embed
r6456 from __future__ import print_function
fperez
Reorganized the directory for ipython/ to have its own dir, which is a bit...
r0
# The basics to get you going:
Thomas Kluyver
Various polishing of interactive reference doc.
r15805 # IPython injects get_ipython into builtins, so you can know if you have nested
fperez
Reorganized the directory for ipython/ to have its own dir, which is a bit...
r0 # copies running.
# Try running this code both at the command line and from inside IPython (with
# %run example-embed.py)
MinRK
update embedding doc to reflect new API
r4124 from IPython.config.loader import Config
fperez
Reorganized the directory for ipython/ to have its own dir, which is a bit...
r0 try:
MinRK
update embedding doc to reflect new API
r4124 get_ipython
fperez
Reorganized the directory for ipython/ to have its own dir, which is a bit...
r0 except NameError:
nested = 0
MinRK
update embedding doc to reflect new API
r4124 cfg = Config()
MinRK
PromptManager fixes...
r5548 prompt_config = cfg.PromptManager
prompt_config.in_template = 'In <\\#>: '
prompt_config.in2_template = ' .\\D.: '
prompt_config.out_template = 'Out<\\#>: '
fperez
Reorganized the directory for ipython/ to have its own dir, which is a bit...
r0 else:
Thomas Kluyver
Use print_function in example-embed
r6456 print("Running nested copies of IPython.")
print("The prompts for the nested copy have been modified")
MinRK
update embedding doc to reflect new API
r4124 cfg = Config()
fperez
Reorganized the directory for ipython/ to have its own dir, which is a bit...
r0 nested = 1
# First import the embeddable shell class
Martin Spacek
Fix `frontend` deprecation warnings in several examples
r11360 from IPython.terminal.embed import InteractiveShellEmbed
fperez
Reorganized the directory for ipython/ to have its own dir, which is a bit...
r0
# Now create an instance of the embeddable shell. The first argument is a
# string with options exactly as you would type them if you were starting
# IPython at the system command line. Any parameters you want to define for
# configuration can thus be specified here.
MinRK
update embedding doc to reflect new API
r4124 ipshell = InteractiveShellEmbed(config=cfg,
banner1 = 'Dropping into IPython',
fperez
Reorganized the directory for ipython/ to have its own dir, which is a bit...
r0 exit_msg = 'Leaving Interpreter, back to program.')
# Make a second instance, you can have as many as you want.
MinRK
update embedding doc to reflect new API
r4124 cfg2 = cfg.copy()
MinRK
PromptManager fixes...
r5548 prompt_config = cfg2.PromptManager
prompt_config.in_template = 'In2<\\#>: '
MinRK
update embedding doc to reflect new API
r4124 if not nested:
MinRK
PromptManager fixes...
r5548 prompt_config.in_template = 'In2<\\#>: '
prompt_config.in2_template = ' .\\D.: '
prompt_config.out_template = 'Out<\\#>: '
MinRK
update embedding doc to reflect new API
r4124 ipshell2 = InteractiveShellEmbed(config=cfg,
banner1 = 'Second IPython instance.')
fperez
Reorganized the directory for ipython/ to have its own dir, which is a bit...
r0
Thomas Kluyver
Use print_function in example-embed
r6456 print('\nHello. This is printed from the main controller program.\n')
fperez
Reorganized the directory for ipython/ to have its own dir, which is a bit...
r0
# You can then call ipshell() anywhere you need it (with an optional
# message):
ipshell('***Called from top level. '
fperez
- Fix a bug introduced by r1357 which broke embedding....
r749 'Hit Ctrl-D to exit interpreter and continue program.\n'
'Note that if you use %kill_embedded, you can fully deactivate\n'
'This embedded instance so it will never turn on again')
fperez
Reorganized the directory for ipython/ to have its own dir, which is a bit...
r0
Thomas Kluyver
Use print_function in example-embed
r6456 print('\nBack in caller program, moving along...\n')
fperez
Reorganized the directory for ipython/ to have its own dir, which is a bit...
r0
#---------------------------------------------------------------------------
# More details:
MinRK
update embedding doc to reflect new API
r4124 # InteractiveShellEmbed instances don't print the standard system banner and
fperez
Reorganized the directory for ipython/ to have its own dir, which is a bit...
r0 # messages. The IPython banner (which actually may contain initialization
MinRK
update embedding doc to reflect new API
r4124 # messages) is available as get_ipython().banner in case you want it.
fperez
Reorganized the directory for ipython/ to have its own dir, which is a bit...
r0
MinRK
update embedding doc to reflect new API
r4124 # InteractiveShellEmbed instances print the following information everytime they
fperez
Reorganized the directory for ipython/ to have its own dir, which is a bit...
r0 # start:
# - A global startup banner.
# - A call-specific header string, which you can use to indicate where in the
# execution flow the shell is starting.
# They also print an exit message every time they exit.
# Both the startup banner and the exit message default to None, and can be set
# either at the instance constructor or at any other time with the
MinRK
update embedding doc to reflect new API
r4124 # by setting the banner and exit_msg attributes.
fperez
Reorganized the directory for ipython/ to have its own dir, which is a bit...
r0
# The shell instance can be also put in 'dummy' mode globally or on a per-call
# basis. This gives you fine control for debugging without having to change
# code all over the place.
# The code below illustrates all this.
# This is how the global banner and exit_msg can be reset at any point
MinRK
update embedding doc to reflect new API
r4124 ipshell.banner = 'Entering interpreter - New Banner'
ipshell.exit_msg = 'Leaving interpreter - New exit_msg'
fperez
Reorganized the directory for ipython/ to have its own dir, which is a bit...
r0
def foo(m):
s = 'spam'
MinRK
update embedding doc to reflect new API
r4124 ipshell('***In foo(). Try %whos, or print s or m:')
Thomas Kluyver
Use print_function in example-embed
r6456 print('foo says m = ',m)
fperez
Reorganized the directory for ipython/ to have its own dir, which is a bit...
r0
def bar(n):
s = 'eggs'
MinRK
update embedding doc to reflect new API
r4124 ipshell('***In bar(). Try %whos, or print s or n:')
Thomas Kluyver
Use print_function in example-embed
r6456 print('bar says n = ',n)
fperez
Reorganized the directory for ipython/ to have its own dir, which is a bit...
r0
# Some calls to the above functions which will trigger IPython:
Thomas Kluyver
Use print_function in example-embed
r6456 print('Main program calling foo("eggs")\n')
fperez
Reorganized the directory for ipython/ to have its own dir, which is a bit...
r0 foo('eggs')
# The shell can be put in 'dummy' mode where calls to it silently return. This
# allows you, for example, to globally turn off debugging for a program with a
# single call.
MinRK
update embedding doc to reflect new API
r4124 ipshell.dummy_mode = True
Thomas Kluyver
Use print_function in example-embed
r6456 print('\nTrying to call IPython which is now "dummy":')
fperez
Reorganized the directory for ipython/ to have its own dir, which is a bit...
r0 ipshell()
Thomas Kluyver
Use print_function in example-embed
r6456 print('Nothing happened...')
fperez
Reorganized the directory for ipython/ to have its own dir, which is a bit...
r0 # The global 'dummy' mode can still be overridden for a single call
Thomas Kluyver
Use print_function in example-embed
r6456 print('\nOverriding dummy mode manually:')
MinRK
update embedding doc to reflect new API
r4124 ipshell(dummy=False)
fperez
Reorganized the directory for ipython/ to have its own dir, which is a bit...
r0
# Reactivate the IPython shell
MinRK
update embedding doc to reflect new API
r4124 ipshell.dummy_mode = False
fperez
Reorganized the directory for ipython/ to have its own dir, which is a bit...
r0
Thomas Kluyver
Use print_function in example-embed
r6456 print('You can even have multiple embedded instances:')
fperez
Reorganized the directory for ipython/ to have its own dir, which is a bit...
r0 ipshell2()
Thomas Kluyver
Use print_function in example-embed
r6456 print('\nMain program calling bar("spam")\n')
fperez
Reorganized the directory for ipython/ to have its own dir, which is a bit...
r0 bar('spam')
Thomas Kluyver
Use print_function in example-embed
r6456 print('Main program finished. Bye!')