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-14 07:54:51 PST
Message User: vivainio
Date: 2008-02-14 07:54:51-0800
Log:
 radical simplification of ipython bridge

File Changes:

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

File [changed]: ipython.py
Url: http://leo.tigris.or​g/source/browse/leo/​plugins/ipython.py?r​1=1.11&r2=1.12
Delta lines: +5 -153
---------------------
--- ipython.py 2008-02-12 12:07:50-0800 1.11
+++ ipython.py 2008-02-14 07:54:49-0800 1.12
@@ -136,24 +136,6 @@
         # Inject the controller into the commander.
         c.ipythonController = ipythonController(c)
 #@-node:ekr.20080201​143145.5:onCreate
-#@+node:ekr.2008020​4103804.1:createNode​
-def createNode(c,parent,head,body):
-
- '''A convenience method for use the leoInterface classes.'''
-
- c.beginUpdate()
- try:
- p = c.insertHeadline()
- p.moveToLastChildOf(parent)
- c.setHeadString(p,head)
- c.setBodyString(p,body)
- c.frame.tree.expandA​llAncestors(p)
- c.selectPosition(p)
- finally:
- c.endUpdate()
- return p
-
-#@-node:ekr.2008020​4103804.1:createNode​
 #@-node:ekr.20080201​144219:Module-level functions
 #@+node:ekr.20080201​143145.6:class ipythonController
 class ipythonController:
@@ -167,22 +149,12 @@
     def __init__ (self,c):
 
         self.c = c
- self.last_index = 0 # The index of the last result shown.
- self.last_p = None # The last-created results node.
- self.root = None # The root of the results tree.
-
- # Options...
- self.createNodes = True # True: print results in log pane.
- self.printResults = False # True: create results nodes.
+
         self.leoxName = c.config.getString('​ipython-interface-ob​ject-name') or 'leox'
- self.resultsName = c.config.getString('​ipython-results-node​-headline') or '@ipython-results'
 
         # Set by .startIPython...
         self.api = None
- self.d_out = {}
- self.in_list = []
         self.ip = None # The _ip var returned by ipshell.IP.getapi()
- self.ipshell = None
 
         self.createCommands()
     #@-node:ekr.20080201​143145.7:ctor
@@ -195,7 +167,6 @@
 
         table = (
             ('start-ipython', self.startIPython),
- ('get-ipython-results', self.getIPythonResults),
             ('push-to-ipython', self.pushToIPythonCommand),
         )
 
@@ -229,8 +200,7 @@
             try:
                 self.ip.ex('import ipy_leo')
             except ImportError:
- g.es("ipy_leo.py extension not available - consider upgrading your IPython!")
- self.in_list, self.d_out = ip.IP.input_hist, ip.IP.output_hist
+ self.error("ipy_leo.py extension not available - consider upgrading your IPython!")
 
             c.inCommand = False # Disable the command lockout logic, just as for scripts.
             sys.argv = []
@@ -240,18 +210,6 @@
             self.error('exception creating IPython shell')
             g.es_exception()
     #@-node:ekr.20080201​143319.10:startIPyth​on
- #@+node:ekr.20080201​150746.1:getIPythonR​esults
- def getIPythonResults (self,event=None):
-
- '''The get-ipython-results command.
-
- IPython must be started, but need not be inited.'''
-
- if not gIPythonStarted:
- self.startIpython() # Does not return
- else:
- self.showResults()
- #@-node:ekr.20080201​150746.1:getIPythonR​esults
     #@+node:ekr.20080204​111314:pushToIPython​Command
     def pushToIPythonCommand​(self,event=None):
 
@@ -263,21 +221,6 @@
     #@-node:ekr.20080204​111314:pushToIPython​Command
     #@-node:ekr.20080201​151802.1:Commands
     #@+node:ekr.20080201​151802.2:Utils...
- #@+node:ekr.20080201​143319.12:createRoot​
- def createRoot (self):
-
- c = self.c
-
- if self.root: return self.root
-
- self.root = g.findNodeAnywhere(c​,self.resultsName)
- if not self.root:
- self.root = p.insertAfter()
- c.setHeadString(self.root,tag)
- c.setBodyString(self​.root,'@nocolor\n\​n')
-
- return self.root
- #@-node:ekr.20080201​143319.12:createRoot​
     #@+node:ekr.20080204​075924:error & message
     def error (self,s):
 
@@ -303,8 +246,10 @@
                 return
             except AttributeError:
                 # ipython has not defined 'push' (old version?). Just execute the node
+ self.error("Your IPython version is obsolete, please upgrade!")
                 pass
 
+ # 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')
@@ -316,45 +261,6 @@
             # Run the script.
             self.ip.runlines(script)
     #@-node:ekr.20080201​150746.2:pushToIPyth​on
- #@+node:ekr.20080201​143319.11:showResult​s & helper
- def showResults (self):
-
- c = self.c
-
- c.beginUpdate()
- try:
- for key in self.d_out.keys():
- if int(key) > self.last_index:
- in_val = self.in_list[int(key)]
- out_val = self.d_out.get(key)
- self.showResult(key,​in_val,out_val)
- self.last_index = int(key)
- finally:
- if self.last_p:
- c.selectPosition(self.last_p)
- c.endUpdate()
- #@+node:ekr.20080201​143319.13:showResult​
- def showResult (self,n,in_val,out_val):
-
- c = self.c
-
- if self.printResults:
- tabName = 'IPython'
- g.es('in [%s]: %s' % (n,in_val),tabName=tabName)
- g.es('out[%s]: %s' % (n,out_val),tabName=tabName)
-
- if self.createNodes:
- if not self.last_p:
- self.createRoot()
- self.last_p = self.root.copy()
- p2 = self.root.insertAsLastChild()
- self.last_p = p2.copy()
- c.setHeadString(p2,'result %s' % (n))
- c.setBodyString(p2,'%s\n%s' % (
- 'in [%s]: %s' % (n,in_val),
- 'out[%s]: %s' % (n,out_val)))
- #@-node:ekr.20080201​143319.13:showResult​
- #@-node:ekr.20080201​143319.11:showResult​s & helper
     #@+node:ekr.20080204​083034:started
     def started (self):
 
@@ -364,52 +270,6 @@
     #@-node:ekr.20080201​151802.2:Utils...
     #@-others
 #@-node:ekr.20080201​143145.6:class ipythonController
-#@+node:ekr.2008020​4103804.2:class leoInterfaceResults
-class leoInterfaceResults:
-
- '''A class representing the saved results of IPython computations.
-
- results.a = x # creates a results node in the Leo outline.
- x = results.a # returns the saved results in a.
- '''
-
-
- #@ @+others
- #@+node:ekr.20080204162955:ctor
- def __init__(self,c,g,root):
-
- assert(root)
-
- self._c = c
- self._g = g
- self._root = root
-
- self._inited = True # Disable any further attributes.
- #@-node:ekr.20080204162955:ctor
- #@+node:ekr.20080204​162955.1:__getattr__​
- def __getattr__(self, key):
-
- for p in self._root.children_iter():
- if p.headString() == key:
- break
- else:
- raise AttributeError
-
- return IPython.genutils.SLi​st(p.bodyString().sp​litlines())
- #@-node:ekr.20080204​162955.1:__getattr__​
- #@+node:ekr.20080204​162955.2:__setattr__​
- def __setattr__(self, item, value):
-
- if self.__dict__.has_ke​y('_inited'):
- # print '__setattr__.result'​,'item',item,'value'​,value
- createNode(self._c,s​elf._root,head=item,​body=str(value))
- else:
- # Allow attributes to be set in the ctor.
- # print '__setattr__','item'​,item,'value',value
- self.__dict__ [item] = value
- #@-node:ekr.20080204​162955.2:__setattr__​
- #@-others
-#@-node:ekr.2008020​4103804.2:class leoInterfaceResults
 #@+node:ekr.20080204​103804.3:class leoInterface
 class leoInterface:
 
@@ -420,14 +280,6 @@
 
     def __init__(self,c,g,ta​g='@ipython-results'​):
         self.c, self.g = c,g
- # Find or create the parent for all results nodes.
- self.root = g.findNodeAnywhere(c,tag)
- if not self.root:
- parent = c.currentPosition()
- self.root = createNode(c=c,paren​t=parent,head=tag,bo​dy='')
- # Create the results interface object.
- self.results = leoInterfaceResults(​c,g,self.root)
-#@nonl
 #@-node:ekr.20080204​103804.3:class leoInterface
 #@-others
 #@nonl

« 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-14 07:54:51 PST
Messages per page: