##// END OF EJS Templates
ipy_leo: @a anchors, @ipy-results is back (for collecting new nodes, if it exists)
Ville M. Vainio -
Show More
@@ -42,7 +42,9 b' def all_cells():'
42 d = {}
42 d = {}
43 for p in c.allNodes_iter():
43 for p in c.allNodes_iter():
44 h = p.headString()
44 h = p.headString()
45 if not valid_attribute(h):
45 if h.startswith('@a '):
46 d[h.lstrip('@a ').strip()] = p.parent().copy()
47 elif not valid_attribute(h):
46 continue
48 continue
47 d[h] = p.copy()
49 d[h] = p.copy()
48 return d
50 return d
@@ -154,7 +156,7 b' class LeoWorkbook:'
154 cells = all_cells()
156 cells = all_cells()
155 p = cells.get(key, None)
157 p = cells.get(key, None)
156 if p is None:
158 if p is None:
157 p = add_var(key,None)
159 p = add_var(key)
158
160
159 return LeoNode(p)
161 return LeoNode(p)
160
162
@@ -167,28 +169,24 b' class LeoWorkbook:'
167 ip.user_ns['wb'] = LeoWorkbook()
169 ip.user_ns['wb'] = LeoWorkbook()
168
170
169
171
170 _dummyval = object()
172
171 @IPython.generics.complete_object.when_type(LeoWorkbook)
173 @IPython.generics.complete_object.when_type(LeoWorkbook)
172 def workbook_complete(obj, prev):
174 def workbook_complete(obj, prev):
173 return all_cells().keys()
175 return all_cells().keys()
174
176
175
177
176 def add_var(varname, value = _dummyval):
178 def add_var(varname):
177 c.beginUpdate()
179 c.beginUpdate()
178 try:
180 try:
179 p2 = g.findNodeAnywhere(c,varname)
181 p2 = g.findNodeAnywhere(c,varname)
180 if not c.positionExists(p2):
182 if p2:
181 p2 = c.currentPosition().insertAfter()
183 return
182 c.setHeadString(p2,varname)
184
183
185 rootpos = g.findNodeAnywhere(c,'@ipy-results')
184 c.setCurrentPosition(p2)
186 if not rootpos:
185 if value is _dummyval:
187 rootpos = c.currentPosition()
186 val = ip.user_ns[varname]
188 p2 = rootpos.insertAsLastChild()
187 else:
189 c.setHeadString(p2,varname)
188 val = value
189 if val is not None:
190 formatted = format_for_leo(val)
191 c.setBodyString(p2,formatted)
192 return p2
190 return p2
193 finally:
191 finally:
194 c.endUpdate()
192 c.endUpdate()
@@ -204,7 +202,6 b' def push_script(p):'
204 script = g.getScript(c,p,useSelectedText=False,forcePythonSentinels=False,useSentinels=False)
202 script = g.getScript(c,p,useSelectedText=False,forcePythonSentinels=False,useSentinels=False)
205
203
206 script = g.splitLines(script + '\n')
204 script = g.splitLines(script + '\n')
207 script = ''.join(z for z in script if z.strip())
208
205
209 ip.runlines(script)
206 ip.runlines(script)
210
207
@@ -221,7 +218,7 b' def push_script(p):'
221 es('<%d> %s' % (idx, pprint.pformat(ohist[idx],width = 40)))
218 es('<%d> %s' % (idx, pprint.pformat(ohist[idx],width = 40)))
222
219
223 if not has_output:
220 if not has_output:
224 es('ipy run: %s' %( p.headString(),))
221 es('ipy run: %s (%d LL)' %( p.headString(),len(script)))
225 finally:
222 finally:
226 c.endUpdate()
223 c.endUpdate()
227
224
@@ -236,12 +233,13 b' def eval_body(body):'
236
233
237 def push_plain_python(p):
234 def push_plain_python(p):
238 script = g.getScript(c,p,useSelectedText=False,forcePythonSentinels=False,useSentinels=False)
235 script = g.getScript(c,p,useSelectedText=False,forcePythonSentinels=False,useSentinels=False)
236 lines = script.count('\n')
239 try:
237 try:
240 exec script in ip.user_ns
238 exec script in ip.user_ns
241 except:
239 except:
242 print " -- Exception in script:\n"+script + "\n --"
240 print " -- Exception in script:\n"+script + "\n --"
243 raise
241 raise
244 es('ipy plain: %s' % (p.headString(),))
242 es('ipy plain: %s (%d LL)' % (p.headString(),lines))
245
243
246 def push_from_leo(p):
244 def push_from_leo(p):
247 nod = LeoNode(p)
245 nod = LeoNode(p)
@@ -250,6 +248,10 b' def push_from_leo(p):'
250 push_plain_python(p)
248 push_plain_python(p)
251 return
249 return
252 if nod.b.startswith('@cl'):
250 if nod.b.startswith('@cl'):
251 p2 = g.findNodeAnywhere(c,'@ipy-results')
252 if p2:
253 es("=> @ipy-results")
254 LeoNode(p2).v = nod.v
253 es(nod.v)
255 es(nod.v)
254 return
256 return
255
257
@@ -285,6 +287,7 b' def leo_f(self,s):'
285 ip.expose_magic('leo',leo_f)
287 ip.expose_magic('leo',leo_f)
286
288
287 def leoref_f(self,s):
289 def leoref_f(self,s):
290 """ Quick reference for ILeo """
288 import textwrap
291 import textwrap
289 print textwrap.dedent("""\
292 print textwrap.dedent("""\
290 %leo file - open file in leo
293 %leo file - open file in leo
@@ -3,7 +3,7 b''
3 <leo_file>
3 <leo_file>
4 <leo_header file_format="2" tnodes="0" max_tnode_index="0" clone_windows="0"/>
4 <leo_header file_format="2" tnodes="0" max_tnode_index="0" clone_windows="0"/>
5 <globals body_outline_ratio="0.5">
5 <globals body_outline_ratio="0.5">
6 <global_window_position top="161" left="139" height="621" width="1280"/>
6 <global_window_position top="131" left="404" height="621" width="1280"/>
7 <global_log_window_position top="0" left="0" height="0" width="0"/>
7 <global_log_window_position top="0" left="0" height="0" width="0"/>
8 </globals>
8 </globals>
9 <preferences/>
9 <preferences/>
@@ -11,8 +11,8 b''
11 <vnodes>
11 <vnodes>
12 <v t="vivainio.20080218184525"><vh>@chapters</vh></v>
12 <v t="vivainio.20080218184525"><vh>@chapters</vh></v>
13 <v t="vivainio.20080218184540" a="E"><vh>@ipy-startup</vh>
13 <v t="vivainio.20080218184540" a="E"><vh>@ipy-startup</vh>
14 <v t="vivainio.20080218184613.1"><vh>b</vh></v>
14 <v t="vivainio.20080218184613.1" a="TV"><vh>b</vh></v>
15 <v t="vivainio.20080218200031" a="ETV"><vh>Some classes P</vh>
15 <v t="vivainio.20080218200031" a="E"><vh>Some classes P</vh>
16 <v t="vivainio.20080218190816"><vh>File-like access</vh></v>
16 <v t="vivainio.20080218190816"><vh>File-like access</vh></v>
17 <v t="vivainio.20080218200106"><vh>csv data</vh></v>
17 <v t="vivainio.20080218200106"><vh>csv data</vh></v>
18 <v t="vivainio.20080219225120"><vh>String list</vh></v>
18 <v t="vivainio.20080219225120"><vh>String list</vh></v>
General Comments 0
You need to be logged in to leave comments. Login now