Login | Register
My pages Projects Community openCollabNet

Discussions > cvs > CVS update: /leo/plugins/ipython.py

leo
Discussion topic

Back to topic list

CVS update: /leo/plugins/ipython.py

Author vivainio
Full name Ville M. Vainio
Date 2008-02-26 08:54:06 PST
Message User: vivainio
Date: 2008-02-26 08:54:06-0800
Log:
 ipython.py: Removed self.ip and use global gIP - it needs to be shared by all commanders. also do c.incommand=false on push

File Changes:

Directory: /leo/plugins/
========================

File [changed]: ipython.py
Url: http://leo.tigris.or​g/source/browse/leo/​plugins/ipython.py?r​1=1.15&r2=1.16
Delta lines: +12 -18
---------------------
--- ipython.py 2008-02-24 11:01:53-0800 1.15
+++ ipython.py 2008-02-26 08:54:03-0800 1.16
@@ -101,7 +101,9 @@
 #@nl
 
 # Globals
-gIPythonStarted = False # True: the start-ipythoncommand has been run.
+
+# IPython IPApi instance. Global, because only one can exist through the whole leo session
+gIP = None
 
 #@+others
 #@+node:ekr.20080201​144219:Module-level functions
@@ -146,10 +148,6 @@
     def __init__ (self,c):
 
         self.c = c
-
- # Set by .startIPython...
- self.ip = None # The _ip var returned by ipshell.IP.getapi()
-
         self.createCommands()
     #@-node:ekr.20080201​143145.7:ctor
     #@+node:ekr.20080204​080848:createCommand​s
@@ -176,14 +174,14 @@
         '''The start-ipython command'''
 
         c = self.c
- global gIPythonStarted
+ global gIP
         try:
             import ipy_leo
         except ImportError:
             self.error("ipy_leo.py extension not available - upgrade your IPython!")
             return
         
- if gIPythonStarted:
+ if gIP:
             # if we are already running, just inject a new commander for current document
             
             leox = leoInterface(c,g) # inject leox into the namespace.
@@ -191,16 +189,13 @@
             return
 
         try:
-
-
             api = IPython.ipapi
             self.message('creating IPython shell...')
- gIPythonStarted = True
             leox = leoInterface(c,g) # inject leox into the namespace.
             my_ns = { '_leo': leox }
             ses = api.make_session(my_ns)
- self.ip = ses.IP.getapi()
- ipy_leo_m = self.ip.load('ipy_leo')
+ gIP = ses.IP.getapi()
+ ipy_leo_m = gIP.load('ipy_leo')
             ipy_leo_m.update_com​mander(leox)
 
             c.inCommand = False # Disable the command lockout logic, just as for scripts.
@@ -234,23 +229,22 @@
     #@+node:ekr.20080201​150746.2:pushToIPyth​on
     def pushToIPython (self,script=None):
         ''' Push the node to IPython'''
- if not gIPythonStarted:
+ if not gIP:
             self.startIPython() # Does not return
         else:
             if script:
- self.ip.runlines(script)
+ gIP.runlines(script)
                 return
             c = self.c ; p = c.currentPosition()
             sys.argv = [] # Clear the argv vector.
- push = self.ip.user_ns['_leo'].push
+ push = gIP.user_ns['_leo'].push
+ c.inCommand = False # Disable the command lockout logic
             push(p)
             return
     #@-node:ekr.20080201​150746.2:pushToIPyth​on
     #@+node:ekr.20080204​083034:started
     def started (self):
-
- global gIPythonStarted
- return gIPythonStarted
+ return gIP
     #@-node:ekr.20080204​083034:started
     #@-node:ekr.20080201​151802.2:Utils...
     #@-others

« Previous message in topic | 1 of 1 | Next message in topic »

Messages

Show all messages in topic

CVS update: /leo/plugins/ipython.py vivainio Ville M. Vainio 2008-02-26 08:54:06 PST
Messages per page: