Interactive ipython_config.py
Alan Bromborsky <abrombo <at> verizon.net>
2012-02-01 16:21:22 GMT
Is there a way of making ipython_config.py interactive so that one could
interactively load different startup profiles from a menu. I tried the
following -
import sys
GAbasic = """from sympy import *
from sympy.galgebra.GA import *
import sympy.galgebra.latex_ex as tex
print 'Basic mode'
%load_ext GAprinting"""
GA_2D = """from sympy import *
from sympy.galgebra.GA import *
import sympy.galgebra.latex_ex as tex
(x,y) = make_symbols('x y')
(ex,ey) = MV.setup('e_x e_y',metric='[1,1]',coords=(x,y))
tex.Format(redir=False)
print '2D mode'
%load_ext GAprinting
"""
GA_3D = """from sympy import *
from sympy.galgebra.GA import *
import sympy.galgebra.latex_ex as tex
(x,y,z) = make_symbols('x y z')
(ex,ey,ez) = MV.setup('e_x e_y e_z',metric='[1,1,1]',coords=(x,y,z))
tex.Format(redir=False)
print '3D mode'
%load_ext GAprinting
"""
GA_ST = """from sympy import *
from sympy.galgebra.GA import *
import sympy.galgebra.latex_ex as tex
(t,x,y,z) = make_symbols('t x y z')
(et,ex,ey,ez) = MV.setup('e_t e_x e_y
e_z',metric='[1,-1,-1,-1]',coords=(t,x,y,z))
tex.Format(redir=False)
print 'Spacetime mode'
%load_ext GAprinting
"""
LINES = [0,GAbasic,GA_2D,GA_3D,GA_ST]
prompt = """
Available Extension Modes
0 - Sympy
1 - Basic GA
2 - 2D Euclidian GA
3 - 3D Euclidian GA
4 - 4D Spacetime GA
Enter Mode: """
MODE = 2
try:
MODE= raw_input(prompt)
except EOFError:
print 'Keep going'
print 'mode =',int(MODE)
lines = LINES[int(MODE)]
c = get_config()
app = c.InteractiveShellApp
c.InteractiveShell.editor = 'geany'
# This can be used at any point in a config file to load a sub config
# and merge it into the current one.
load_subconfig('ipython_config.py', profile='default')
print lines
# You have to make sure that attributes that are containers already
# exist before using them. Simple assigning a new list will override
# all previous values.
if hasattr(app, 'exec_lines'):
app.exec_lines.append(lines)
else:
app.exec_lines = [lines]
I keep getting a read EOF error and the profile is never loaded.