def setupIpython(): try: import IPython from IPython.config.loader import Config from IPython.frontend.terminal.embed import InteractiveShellEmbed cfg = Config() cfg.PromptManager.in_template = "BinPy:\\#> " cfg.PromptManager.out_template = "BinPy:\\#: " bpyShell = InteractiveShellEmbed(config=cfg, banner1=banner, exit_msg=exit_msg) bpyShell.define_magic("clear", magic_clear) except ImportError: try: from IPython.Shell import IPShellEmbed argsv = ['-pi1', 'BinPY:\\#>', '-pi2', ' .\\D.:', '-po', 'BinPy:\\#>', '-nosep'] bpyShell = IPShellEmbed(argsv) bpyShell.set_banner(banner) bpyShell.set_exit_msg(exit_msg) except ImportError: raise return bpyShell()
def run_ipython(): import IPython from IPython.frontend.terminal.embed import InteractiveShellEmbed from django.conf import settings try: imported_objects = import_objects(options, self.style) cfgfile = "%s/.config/ipython/profile_default/ipython_config.py" % os.environ['HOME'] cfg = IPython.config.loader.PyFileConfigLoader(cfgfile).load_config() appname = "Welcome to the %s Shell.\n" % getattr(settings, "APPLICATION_NAME", "") ipshell = InteractiveShellEmbed(config=cfg, banner1=appname, user_ns=imported_objects) # An example how to define magics # the function _toggle_logging has to be provided by the PYTHONSTARTUP script, # see django_extensions/management/shells.py try: ipshell.define_magic('toggle_logging', imported_objects['_toggle_logging']) except: pass ipshell() except ImportError: # IPython < 0.11 # Explicitly pass an empty list as arguments, because otherwise # IPython would use sys.argv from this script. # Notebook not supported for IPython < 0.11. from IPython.Shell import IPShell imported_objects = import_objects(options, self.style) shell = IPShell(argv=[], user_ns=imported_objects) shell.mainloop()
def setupIpython(): try: import IPython from IPython.config.loader import Config from IPython.frontend.terminal.embed import InteractiveShellEmbed cfg = Config() cfg.PromptManager.in_template = "BinPy:\\#> " cfg.PromptManager.out_template = "BinPy:\\#: " bpyShell = InteractiveShellEmbed(config=cfg, banner1=banner, exit_msg=exit_msg) bpyShell.define_magic("clear", magic_clear) except ImportError: try: from IPython.Shell import IPShellEmbed argsv = [ '-pi1', 'BinPY:\\#>', '-pi2', ' .\\D.:', '-po', 'BinPy:\\#>', '-nosep' ] bpyShell = IPShellEmbed(argsv) bpyShell.set_banner(banner) bpyShell.set_exit_msg(exit_msg) except ImportError: raise return bpyShell()
def init_ipython(): from IPython.config.loader import Config from IPython.frontend.terminal.embed import InteractiveShellEmbed try: get_ipython except NameError: nested = 0 cfg = Config() else: print("Running nested copies of IPython.") print("The prompts for the nested copy have been modified") cfg = Config() nested = 1 ipshell = InteractiveShellEmbed( config=cfg, banner1='Stopping IO Loop and dropping to ipython') class shell_wrapper(object): def __init__(self): self.user_wants_out = False def __call__(self): ipshell( 'Ctrl-D, quit, exit all exit interpreter and continue program\n' 'If you need to kill the program %kill', stack_depth=3) return self.user_wants_out _shell_wrapper = shell_wrapper() def kill_program(self, parameter_s=''): _shell_wrapper.user_wants_out = True ipshell.exit() def really_die(self, etype, value, tb, tb_offset=None): _shell_wrapper.user_wants_out = True return None ipshell.define_magic("kill", kill_program) ipshell.confirm_exit = False ipshell.set_custom_exc((SystemExit, ), really_die) return _shell_wrapper
def setup_shell(): banner = "+----------------------------------------------------------------------+\n" banner += " PML Shell - built on IPython.\n" banner += "+----------------------------------------------------------------------+\n" banner += "Commands: \n" banner += "\t'tutorial' will begin the interactive tutorial.\n" banner += "\t'tutorial list' will display individual lessons in the tutorial.\n" banner += "\t'docs' will open up the online documentation in a web browser.\n" banner += "\t'exit', 'quit' or press 'CTRL + D' to exit the shell.\n" exit_message = "\n* Exiting PML shell, good bye! *\n" # XXX: this currently only supports IPython version 0.11 or higher! config = Config() config.PromptManager.in_template = "pml:\\#> " config.PromptManager.out_template = "pml:\\#: " pml_shell = InteractiveShellEmbed(config=config, banner1=banner, exit_msg=exit_message) pml_shell.define_magic("tutorial", magic_tutorial) pml_shell.define_magic("docs", magic_docs) return pml_shell
def setup_ipython(): try: import IPython from IPython.config.loader import Config from IPython.frontend.terminal.embed import InteractiveShellEmbed cfg = Config() cfg.PromptManager.in_template = "SimpleCV:\\#> " cfg.PromptManager.out_template = "SimpleCV:\\#: " #~ cfg.InteractiveShellEmbed.prompt_in1 = "SimpleCV:\\#> " #~ cfg.InteractiveShellEmbed.prompt_out="SimpleCV:\\#: " scvShell = InteractiveShellEmbed(config=cfg, banner1=banner, exit_msg=exit_msg) scvShell.define_magic("tutorial", magic_tutorial) scvShell.define_magic("clear", magic_clear) scvShell.define_magic("example", magic_examples) scvShell.define_magic("forums", magic_forums) scvShell.define_magic("walkthrough", magic_walkthrough) scvShell.define_magic("docs", magic_docs) except ImportError: try: from IPython.Shell import IPShellEmbed argsv = ['-pi1', 'SimpleCV:\\#>', '-pi2', ' .\\D.:', '-po', 'SimpleCV:\\#>', '-nosep'] scvShell = IPShellEmbed(argsv) scvShell.set_banner(banner) scvShell.set_exit_msg(exit_msg) scvShell.IP.api.expose_magic("tutorial", magic_tutorial) scvShell.IP.api.expose_magic("clear", magic_clear) scvShell.IP.api.expose_magic("example", magic_examples) scvShell.IP.api.expose_magic("forums", magic_forums) scvShell.IP.api.expose_magic("walkthrough", magic_walkthrough) scvShell.IP.api.expose_magic("docs", magic_docs) except ImportError: raise return scvShell()
def setup_ipython(): try: import IPython from IPython.config.loader import Config from IPython.frontend.terminal.embed import InteractiveShellEmbed cfg = Config() cfg.PromptManager.in_template = "SimpleCV:\\#> " cfg.PromptManager.out_template = "SimpleCV:\\#: " # ~ cfg.InteractiveShellEmbed.prompt_in1 = "SimpleCV:\\#> " # ~ cfg.InteractiveShellEmbed.prompt_out="SimpleCV:\\#: " scvShell = InteractiveShellEmbed(config=cfg, banner1=banner, exit_msg=exit_msg) scvShell.define_magic("tutorial", magic_tutorial) scvShell.define_magic("clear", magic_clear) scvShell.define_magic("example", magic_examples) scvShell.define_magic("forums", magic_forums) scvShell.define_magic("walkthrough", magic_walkthrough) scvShell.define_magic("docs", magic_docs) except ImportError: try: from IPython.Shell import IPShellEmbed argsv = ["-pi1", "SimpleCV:\\#>", "-pi2", " .\\D.:", "-po", "SimpleCV:\\#>", "-nosep"] scvShell = IPShellEmbed(argsv) scvShell.set_banner(banner) scvShell.set_exit_msg(exit_msg) scvShell.IP.api.expose_magic("tutorial", magic_tutorial) scvShell.IP.api.expose_magic("clear", magic_clear) scvShell.IP.api.expose_magic("example", magic_examples) scvShell.IP.api.expose_magic("forums", magic_forums) scvShell.IP.api.expose_magic("walkthrough", magic_walkthrough) scvShell.IP.api.expose_magic("docs", magic_docs) except ImportError: raise return scvShell()