COMPASS  5.0.0
End-to-end AO simulation tool using GPU acceleration
ipython_embed.py
1 try:
2  from IPython.terminal.prompts import Prompts, Token
3  from IPython.terminal.embed import embed as std_embed
4 
5  class CustomPrompt(Prompts):
6  name = ""
7 
8  def __init__(self, shell):
9  Prompts.__init__(self, shell)
10 
11  def setName(self, name):
12  self.name = name
13 
14  def in_prompt_tokens(self, cli=None):
15  return [
16  (Token.Prompt, self.name),
17  (Token.Prompt, ' In ['),
18  (Token.PromptNum, str(self.shell.execution_count)),
19  (Token.Prompt, ']: '),
20  ]
21 
22  def out_prompt_tokens(self):
23  return [
24  (Token.OutPrompt, self.name),
25  (Token.OutPrompt, ' Out['),
26  (Token.OutPromptNum, str(self.shell.execution_count)),
27  (Token.OutPrompt, ']: '),
28  ]
29 
30  def embed(name: str="", loc_vars: dict=None):
31  from traitlets.config import Config
32 
33  glob_vars = globals()
34  if loc_vars is None:
35  glob_vars.update(locals())
36  else:
37  glob_vars.update(loc_vars)
38 
39  cfg = Config()
40  cfg.InteractiveShellApp.gui = "qt5"
41  cfg.TerminalInteractiveShell.prompts_class = CustomPrompt
42  CustomPrompt.name = name
43  std_embed(config=cfg,
44  banner1='Dropping into IPython, type %gui qt5 to unlock GUI')
45 
46 except ImportError:
47  import code
48 
49  def embed(name: str="", loc_vars: dict=None):
50  import sys
51  sys.ps1 = name + " >>> "
52  sys.ps2 = name + " ... "
53 
54  glob_vars = globals()
55  if loc_vars is None:
56  glob_vars.update(locals())
57  else:
58  glob_vars.update(loc_vars)
59  shell = code.InteractiveConsole(glob_vars)
60  shell.interact()
shesha.util.ipython_embed.CustomPrompt.in_prompt_tokens
def in_prompt_tokens(self, cli=None)
Definition: ipython_embed.py:14
shesha.util.ipython_embed.CustomPrompt
Definition: ipython_embed.py:5
shesha.util.ipython_embed.embed
def embed(str name="", dict loc_vars=None)
Definition: ipython_embed.py:30
shesha.util.ipython_embed.CustomPrompt.__init__
def __init__(self, shell)
Definition: ipython_embed.py:8
shesha.util.ipython_embed.CustomPrompt.name
string name
Definition: ipython_embed.py:6
shesha.util.ipython_embed.CustomPrompt.setName
def setName(self, name)
Definition: ipython_embed.py:11
shesha.util.ipython_embed.CustomPrompt.out_prompt_tokens
def out_prompt_tokens(self)
Definition: ipython_embed.py:22