Changeset 3039

Show
Ignore:
Timestamp:
02/12/08 14:08:51 (10 months ago)
Author:
vivainio
Message:

ipy_leo: handle @ipy varname on leox.push()

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • ipython/trunk/IPython/Extensions/ipy_leo.py

    r3038 r3039  
    11import IPython.ipapi 
     2import IPython.genutils 
     3 
    24ip = IPython.ipapi.get() 
     5leo = ip.user_ns['leox'] 
     6c,g = leo.c, leo.g 
    37 
    48from IPython.external.simplegeneric import generic  
     
    1620 
    1721def add_var(self,varname): 
    18     ip = self.getapi() 
    19     leo = ip.user_ns['leox'] 
    20     c,g = leo.c, leo.g 
    2122    nodename = '@ipy-var ' + varname 
    2223    p2 = g.findNodeAnywhere(c,nodename) 
     
    3132 
    3233def add_file(self,fname): 
    33     ip = self.getapi() 
    34     leo = ip.user_ns['leox'] 
    35     c,g = leo.c, leo.g 
    3634    p2 = c.currentPosition().insertAfter() 
    3735 
    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      
     36def push_script(p):    
    4337    script = g.getScript(c,p,useSelectedText=False,forcePythonSentinels=True,useSentinels=True) 
    4438    script = g.splitLines(script + '\n') 
    4539    script = ''.join(z for z in script if z.strip()) 
    4640    ip.runlines(script) 
     41    print "- Script end -" 
     42     
     43def 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     
     52def push_variable(p,varname): 
     53    body = p.bodyString() 
     54    val = eval_body(body.strip()) 
     55    ip.user_ns[varname] = val 
     56     
     57def 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     
    4769ip.user_ns['leox'].push = push_from_leo     
    48          
    49      
    5070     
    5171def leo_f(self,s): 
     
    5979 
    6080ip.expose_magic('leo',leo_f) 
    61  
    62  
    63      
    64      
    65      
    66      
    67      
    68