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-24 07:09:06 PST
Message User: vivainio
Date: 2008-02-24 07:09:06-0800
Log:
 Cleaned up ipython.py a lot, support for chancing document (commander).
 
 ipy_leo api changed, so you need new branch of ipython:
 bzr branch http://bazaar.launch​pad.net/~villemvaini​o/ipython/ileo-exp
 

File Changes:

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

File [changed]: ipython.py
Url: http://leo.tigris.or​g/source/browse/leo/​plugins/ipython.py?r​1=1.13&r2=1.14
Delta lines: +24 -32
---------------------
--- ipython.py 2008-02-14 08:08:06-0800 1.13
+++ ipython.py 2008-02-24 07:09:04-0800 1.14
@@ -175,26 +175,33 @@
 
         '''The start-ipython command'''
 
+ c = self.c
         global gIPythonStarted
+ try:
+ import ipy_leo
+ except ImportError:
+ self.error("ipy_leo.py extension not available - upgrade your IPython!")
+ return
 
         if gIPythonStarted:
- return self.error('IPython is already running')
+ # if we are already running, just inject a new commander for current document
+
+ leox = leoInterface(c,g) # inject leox into the namespace.
+ ipy_leo.update_commander(leox)
+ return
 
         try:
- c = self.c
- #self.ipshell = IPShellEmbed() # Create object to be bound to .api.
+
 
             api = IPython.ipapi
             self.message('creating IPython shell...')
- gIPythonStarted = True # Do this *before* calling ipshell.
+ gIPythonStarted = True
             leox = leoInterface(c,g) # inject leox into the namespace.
- my_ns = { 'leox': leox }
+ my_ns = { '_leo': leox }
             ses = api.make_session(my_ns)
             self.ip = ses.IP.getapi()
- try:
- self.ip.ex('import ipy_leo')
- except ImportError:
- self.error("ipy_leo.py extension not available - consider upgrading your IPython!")
+ ipy_leo_m = self.ip.load('ipy_leo')
+ ipy_leo_m.update_com​mander(leox)
 
             c.inCommand = False # Disable the command lockout logic, just as for scripts.
             sys.argv = []
@@ -226,33 +233,18 @@
     #@-node:ekr.20080204​075924:error & message
     #@+node:ekr.20080201​150746.2:pushToIPyth​on
     def pushToIPython (self,script=None):
- '''Execute the data to Ipython.
- Use the presently selected body text if no script is given.'''
+ ''' Push the node to IPython'''
         if not gIPythonStarted:
             self.startIpython() # Does not return
         else:
+ if script:
+ self.ip.runlines(script)
+ return
             c = self.c ; p = c.currentPosition()
             sys.argv = [] # Clear the argv vector.
- try:
- # if ipython has defined leox.push, call push(p)
- push = self.ip.user_ns['leox'].push
+ push = self.ip.user_ns['_leo'].push
                 push(p)
                 return
- except AttributeError:
- # ipython has not defined 'push' (old version?). Just execute the node
- self.error("Your IPython version is obsolete, please upgrade!")
-
- # The rest of this is probably never executed with up-to-date IPython
- # Get the script.
- if script is None:
- # script = g.splitLines(p.bodyString() + '\n')
- script = g.getScript(c,p,useS​electedText=False,fo​rcePythonSentinels=T​rue,useSentinels=Tru​e)
- script = g.splitLines(script + '\n')
- script = ''.join([z for z in script if z.strip()])
- # print 'script\n',script
-
- # Run the script.
- self.ip.runlines(script)
     #@-node:ekr.20080201​150746.2:pushToIPyth​on
     #@+node:ekr.20080204​083034:started
     def started (self):

« 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-24 07:09:06 PST
Messages per page: