Changeset 3039
- Timestamp:
- 02/12/08 14:08:51 (10 months ago)
- Files:
-
- ipython/trunk/IPython/Extensions/ipy_leo.py (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
ipython/trunk/IPython/Extensions/ipy_leo.py
r3038 r3039 1 1 import IPython.ipapi 2 import IPython.genutils 3 2 4 ip = IPython.ipapi.get() 5 leo = ip.user_ns['leox'] 6 c,g = leo.c, leo.g 3 7 4 8 from IPython.external.simplegeneric import generic … … 16 20 17 21 def add_var(self,varname): 18 ip = self.getapi()19 leo = ip.user_ns['leox']20 c,g = leo.c, leo.g21 22 nodename = '@ipy-var ' + varname 22 23 p2 = g.findNodeAnywhere(c,nodename) … … 31 32 32 33 def add_file(self,fname): 33 ip = self.getapi()34 leo = ip.user_ns['leox']35 c,g = leo.c, leo.g36 34 p2 = c.currentPosition().insertAfter() 37 35 38 def push_from_leo(p): 39 print "Pushed from leo",p 40 leo = ip.user_ns['leox'] 41 c,g = leo.c, leo.g 42 36 def push_script(p): 43 37 script = g.getScript(c,p,useSelectedText=False,forcePythonSentinels=True,useSentinels=True) 44 38 script = g.splitLines(script + '\n') 45 39 script = ''.join(z for z in script if z.strip()) 46 40 ip.runlines(script) 41 print "- Script end -" 42 43 def eval_body(body): 44 print "eval",body 45 try: 46 val = ip.ev(body) 47 except: 48 # just use stringlist if it's not completely legal python expression 49 val = IPython.genutils.SList(body.splitlines()) 50 return val 51 52 def push_variable(p,varname): 53 body = p.bodyString() 54 val = eval_body(body.strip()) 55 ip.user_ns[varname] = val 56 57 def push_from_leo(p): 58 # headstring without @ are just scripts 59 if not p.headString().startswith('@'): 60 push_script(p) 61 return 62 tup = p.headString().split(None,1) 63 # @ipy foo is variable foo 64 if len(tup) == 2 and tup[0] == '@ipy': 65 varname = tup[1] 66 push_variable(p,varname) 67 return 68 47 69 ip.user_ns['leox'].push = push_from_leo 48 49 50 70 51 71 def leo_f(self,s): … … 59 79 60 80 ip.expose_magic('leo',leo_f) 61 62 63 64 65 66 67 68
