def interact_ipython(header='', *args, **kwargs): def pre_prompt_hook(_): R.gInterpreter.EndOfLineAction() # Interact is a callable which starts an ipython shell if not interact_ipython_: interact_ipython_ = InteractiveShellEmbed(banner1=UP_LINE) # needed for graphics to work correctly interact_ipython_.set_hook('pre_prompt_hook', pre_prompt_hook) stack_depth = kwargs.pop("stack_depth", 0) + 2 interact_ipython_(header, *args, **kwargs)
def interact_ipython(header='', *args, **kwargs): global interact_ipython_ def pre_prompt_hook(_): R.gInterpreter.EndOfLineAction() # Interact is a callable which starts an ipython shell if not interact_ipython_: interact_ipython_ = InteractiveShellEmbed(banner1=UP_LINE) # needed for graphics to work correctly interact_ipython_.set_hook('pre_prompt_hook', pre_prompt_hook) stack_depth = kwargs.pop("stack_depth", 0) + 2 kwargs["stack_depth"] = stack_depth interact_ipython_(header, *args, **kwargs)
def start_shell(self, msg = ""): status_msg = [] status_msg.append(msg) #load convenient modules self.user_ns['time'] = time #find the available devices items = self.config._device_cache.items() items.sort() status_msg.append("Available devices:") for name, device in items: status_msg.append("\t%s" % name) #add device name to the user name space self.user_ns[name] = device #find the available controllers items = self.config._controller_cache.items() items.sort() status_msg.append("Available controllers:") for name, controller in items: status_msg.append("\t%s" % name) #add controller name to the user name space self.user_ns[name] = controller #add all the special commands to the namespace self.user_ns.update(self.commands) #complete the status message status_msg.append('') status_msg.append("-- Hit Ctrl-D to exit. --") status_msg = '\n'.join(status_msg) #start the shell ipshell = None # try: ipshell = IPYTHON_SHELL(user_ns = self.user_ns, banner1 = status_msg) #FIXME change made for ipython >= 0.13 #set up hooks ipshell.set_hook('shutdown_hook',self.shutdown_hook) ipshell.mainloop() #FIXME change made for ipython >= 0.13
# Now start the ipython shell. Due to (non-backward-compatible) changes in # ipython with version 0.11, we must support both versions until 0.11 or # greater is in common use. try: # IPython >= 0.11 from distutils.version import StrictVersion from IPython import __version__ as ipython_version if StrictVersion(ipython_version) < StrictVersion('1.0.0'): from IPython.frontend.terminal.embed import InteractiveShellEmbed else: from IPython.terminal.embed import InteractiveShellEmbed from IPython.config.loader import Config cfg = Config() prompt_config = cfg.PromptManager if ipython_version == '0.11': cfg.InteractiveShellEmbed.prompt_in1 = "BDSM [\#]: " else: prompt_config.in_template = "BDSM [\#]: " cfg.InteractiveShellEmbed.autocall = 2 ipshell = InteractiveShellEmbed(config=cfg, banner1=banner, user_ns=locals()) ipshell.set_hook('complete_command', _opts_completer, re_key='.*') except ImportError: # IPython < 0.11 from IPython.Shell import IPShellEmbed argv = ['-prompt_in1', 'BDSM [\#]: ', '-autocall', '2'] ipshell = IPShellEmbed(argv=argv, banner=banner, user_ns=locals()) ipshell.IP.set_hook('complete_command', _opts_completer, re_key='.*') ipshell()
from IPython.frontend.terminal.embed import InteractiveShellEmbed have_ipython = True except ImportError: interact = interact_plain else: # ROOT has a bug causing it to print (Bool_t)1 to the console. # This is fixed in defaults.py if rootpy is imported under the ipython # interpreter, but at this point that is too late, so we need to try again _finalSetup = getattr(R.__class__, "_ModuleFacade__finalSetup", None) if _finalSetup: _orig_func = getattr(_finalSetup, "_orig_func", None) if _orig_func: _finalSetup = _orig_func fix_ipython_startup(_finalSetup) # Interact is a callable which starts an ipython shell interact_ipython_ = InteractiveShellEmbed(banner1=UP_LINE) # needed for graphics to work correctly def pre_prompt_hook(_): R.gInterpreter.EndOfLineAction() interact_ipython_.set_hook('pre_prompt_hook', pre_prompt_hook) def interact_ipython(header='', *args, **kwargs): stack_depth = kwargs.pop("stack_depth", 0) + 2 interact_ipython_(header, *args, **kwargs) interact = interact_ipython
# Now start the ipython shell. Due to (non-backward-compatible) changes in # ipython with version 0.11, we must support both versions until 0.11 or # greater is in common use. try: # IPython >= 0.11 from distutils.version import StrictVersion from IPython import __version__ as ipython_version if StrictVersion(ipython_version) < StrictVersion('1.0.0'): from IPython.frontend.terminal.embed import InteractiveShellEmbed else: from IPython.terminal.embed import InteractiveShellEmbed from IPython.config.loader import Config cfg = Config() prompt_config = cfg.PromptManager if ipython_version == '0.11': cfg.InteractiveShellEmbed.prompt_in1 = "BDSM [\#]: " else: prompt_config.in_template = "BDSM [\#]: " cfg.InteractiveShellEmbed.autocall = 2 ipshell = InteractiveShellEmbed(config=cfg, banner1=banner, user_ns=locals()) ipshell.set_hook('complete_command', _opts_completer, re_key = '.*') except ImportError: # IPython < 0.11 from IPython.Shell import IPShellEmbed argv = ['-prompt_in1','BDSM [\#]: ','-autocall','2'] ipshell = IPShellEmbed(argv=argv, banner=banner, user_ns=locals()) ipshell.IP.set_hook('complete_command', _opts_completer, re_key = '.*') ipshell()