def setup_shell(): banner = '+----------------------------------------------------------------+\n' banner += ' APSG ' banner += APSG_VERSION banner += ' [interactive shell] - http://ondrolexa.github.io/apsg\n' banner += '+----------------------------------------------------------------+\n' banner += '\n' banner += 'Commands: \n' banner += '\t"exit()" or press "Ctrl+ D" to exit the shell\n' banner += '\t"clear" to clear the shell screen\n' banner += '\n' banner += 'Documentation:\n' banner += '\thelp(Fol), ?Fol, Fol?, or Fol()? all do the same\n' banner += '\t"docs" will launch webbrowser showing documentation' banner += '\n' exit_msg = '\n... [Exiting the APSG interactive shell] ...\n' try: import IPython except: raise("ERROR: IPython Failed to load") try: from IPython.config.loader import Config from IPython.terminal.embed import InteractiveShellEmbed cfg = Config() cfg.PromptManager.in_template = "APSG:\\#> " cfg.PromptManager.out_template = "APSG:\\#: " apsgShell = InteractiveShellEmbed(config=cfg, banner1=banner, exit_msg = exit_msg) apsgShell.define_magic("clear", magic_clear) #apsgShell.define_magic("docs", magic_docs) except ImportError: try: from IPython.Shell import IPShellEmbed argsv = ['-pi1','APSG:\\#>','-pi2',' .\\D.:','-po','APSG:\\#>','-nosep'] apsgShell = IPShellEmbed(argsv) apsgShell.set_banner(banner) apsgShell.set_exit_msg(exit_msg) apsgShell.IP.api.expose_magic("clear", magic_clear) except ImportError: raise return apsgShell
def setup_shell(): banner = '+-----------------------------------------------------------+\n' banner += ' APSG ' banner += APSG_VERSION banner += ' [interactive shell] - http://ondrolexa.github.io/apsg\n' banner += '+-----------------------------------------------------------+\n' banner += '\n' banner += 'Commands: \n' banner += '\t"exit()" or press "Ctrl+ D" to exit the shell\n' banner += '\t"clear" to clear the shell screen\n' banner += '\n' banner += 'Documentation:\n' banner += '\thelp(Fol), ?Fol, Fol?, or Fol()? all do the same\n' banner += '\t"docs" will launch webbrowser showing documentation' banner += '\n' exit_msg = '\n... [Exiting the APSG interactive shell] ...\n' try: from traitlets.config import Config from IPython.terminal.embed import InteractiveShellEmbed cfg = Config() cfg.PromptManager.in_template = "APSG:\\#> " cfg.PromptManager.out_template = "APSG:\\#: " apsgShell = InteractiveShellEmbed(config=cfg, banner1=banner, exit_msg = exit_msg) apsgShell.define_magic("clear", magic_clear) #apsgShell.define_magic("docs", magic_docs) except ImportError: try: from IPython.Shell import IPShellEmbed argsv = ['-pi1','APSG:\\#>','-pi2',' .\\D.:','-po','APSG:\\#>','-nosep'] apsgShell = IPShellEmbed(argsv) apsgShell.set_banner(banner) apsgShell.set_exit_msg(exit_msg) apsgShell.IP.api.expose_magic("clear", magic_clear) except ImportError: raise("ERROR: IPython shell failed to load") return apsgShell
def setup_ipython(): try: import IPython from IPython.config.loader import Config from IPython.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.terminal.embed import InteractiveShellEmbed cfg = Config() cfg.PromptManager.in_template = "MyCV:\\#> " cfg.PromptManager.out_template = "MyCV:\\#: " #~ cfg.InteractiveShellEmbed.prompt_in1 = "MyCV:\\#> " #~ cfg.InteractiveShellEmbed.prompt_out="MyCV:\\#: " 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', 'MyCV:\\#>', '-pi2', ' .\\D.:', '-po', 'MyCV:\\#>', '-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()
class Ipshell: """ IPython facade to create custom ipython shell easily and fast """ def __init__(self, banner="", exitmsg="", listener=False, startdir=""): self.ipsh = InteractiveShellEmbed(banner1=banner, exit_msg=exitmsg, display_banner=True, user_ns={'division': division}) self.IP = self.ipsh.get_ipython() self.listener = listener if startdir: os.chdir(startdir) def addpath(self, pathlist): map(sys.path.append, pathlist) def magic(self, name): """ Decorator to register Ipython Magic """ def wrap(f): self.ipsh.define_magic(name, f) return wrap def set_magic(self, name, function): """ Register Ipython Magic """ self.ipsh.define_magic(name, function) def get_magic(self, magic): return self.IP.magic(magic) def exec_magic(self, magicfunction): """ Get Ipython Magic Function """ return self.IP.magic(magicfunction) def exec_magics(self, magiclist): map(self.IP.magic, magiclist) def get_ipython(self): return self.IP def load_modules(self, modules, hidden=False): for module in modules: object = __import__(module) self.ipsh.user_ns[module] = object if hidden: self.ipsh.user_ns_hidden.add(module) def load_functions_from_module(self, module, objlist, hidden=False): module = __import__(module) #print "module = ", module #print self.ipsh.user_ns_hidden for objname in objlist: #print "objname ", objname obj = getattr(module, objname) #self.ipsh.user_ns_hidden[objname] = obj self.ipsh.user_ns[objname] = obj if hidden: self.ipsh.user_ns_hidden.add(objname) def load_objects(self, dic_objects): self.ipsh.user_ns.update(dic_objects) def exec_ns(self, code): """ Execute code in the user namespace :param code: :return: """ exec(code, self.user_ns) @property def user_ns(self): """ Return User namespace """ return self.IP.user_ns def autoreload(self, enable=True): """ Set IPython shell to autoreload whenever you edit your file, your objects will be updated in ipython without the need to close and reopen ipython. """ if enable: self.exec_magic("load_ext autoreload") self.exec_magic("autoreload 2") else: self.exec_magic("autoreload 0") def autocall(self, enable=True): """ """ if enable: self.exec_magic("autocall") else: self.exec_magic("autocall 0") def run(self): """ Start Ipython Shell """ #self.ipsh.define_magic("get_ipsh", get_ipsh) self.ipsh()