Show More
@@ -77,10 +77,39 b" attribute_re = re.compile('^[a-zA-Z_][a-zA-Z0-9_]*$')" | |||||
77 | def valid_attribute(s): |
|
77 | def valid_attribute(s): | |
78 | return attribute_re.match(s) |
|
78 | return attribute_re.match(s) | |
79 |
|
79 | |||
|
80 | _rootnode = None | |||
|
81 | def rootnode(): | |||
|
82 | """ Get ileo root node (@ipy-root) | |||
|
83 | ||||
|
84 | if node has become invalid or has not been set, return None | |||
|
85 | ||||
|
86 | Note that the root is the *first* @ipy-root item found | |||
|
87 | """ | |||
|
88 | global _rootnode | |||
|
89 | if _rootnode is None: | |||
|
90 | return None | |||
|
91 | if c.positionExists(_rootnode.p): | |||
|
92 | return _rootnode | |||
|
93 | _rootnode = None | |||
|
94 | return None | |||
|
95 | ||||
80 | def all_cells(): |
|
96 | def all_cells(): | |
|
97 | global _rootnode | |||
81 | d = {} |
|
98 | d = {} | |
82 | for p in c.allNodes_iter(): |
|
99 | r = rootnode() | |
|
100 | if r is not None: | |||
|
101 | nodes = r.p.children_iter() | |||
|
102 | else: | |||
|
103 | nodes = c.allNodes_iter() | |||
|
104 | ||||
|
105 | for p in nodes: | |||
83 | h = p.headString() |
|
106 | h = p.headString() | |
|
107 | if h.strip() == '@ipy-root': | |||
|
108 | # update root node (found it for the first time) | |||
|
109 | _rootnode = LeoNode(p) | |||
|
110 | # the next recursive call will use the children of new root | |||
|
111 | return all_cells() | |||
|
112 | ||||
84 | if h.startswith('@a '): |
|
113 | if h.startswith('@a '): | |
85 | d[h.lstrip('@a ').strip()] = p.parent().copy() |
|
114 | d[h.lstrip('@a ').strip()] = p.parent().copy() | |
86 | elif not valid_attribute(h): |
|
115 | elif not valid_attribute(h): | |
@@ -307,14 +336,17 b' def workbook_complete(obj, prev):' | |||||
307 |
|
336 | |||
308 | def add_var(varname): |
|
337 | def add_var(varname): | |
309 | c.beginUpdate() |
|
338 | c.beginUpdate() | |
|
339 | r = rootnode() | |||
310 | try: |
|
340 | try: | |
|
341 | if r is None: | |||
311 | p2 = g.findNodeAnywhere(c,varname) |
|
342 | p2 = g.findNodeAnywhere(c,varname) | |
|
343 | else: | |||
|
344 | p2 = g.findNodeInChildren(c, r.p, varname) | |||
312 | if p2: |
|
345 | if p2: | |
313 | return LeoNode(p2) |
|
346 | return LeoNode(p2) | |
314 |
|
347 | |||
315 | rootpos = g.findNodeAnywhere(c,'@ipy-results') |
|
348 | if r is not None: | |
316 | if rootpos: |
|
349 | p2 = r.p.insertAsLastChild() | |
317 | p2 = rootpos.insertAsLastChild() |
|
|||
318 |
|
350 | |||
319 | else: |
|
351 | else: | |
320 | p2 = c.currentPosition().insertAfter() |
|
352 | p2 = c.currentPosition().insertAfter() | |
@@ -387,7 +419,7 b' def push_plain_python(node):' | |||||
387 | def push_cl_node(node): |
|
419 | def push_cl_node(node): | |
388 | """ If node starts with @cl, eval it |
|
420 | """ If node starts with @cl, eval it | |
389 |
|
421 | |||
390 |
The result is put |
|
422 | The result is put as last child of @ipy-results node, if it exists | |
391 | """ |
|
423 | """ | |
392 | if not node.b.startswith('@cl'): |
|
424 | if not node.b.startswith('@cl'): | |
393 | raise TryNext |
|
425 | raise TryNext | |
@@ -539,3 +571,5 b' def run_leo_startup_node():' | |||||
539 | print "Running @ipy-startup nodes" |
|
571 | print "Running @ipy-startup nodes" | |
540 | for n in LeoNode(p): |
|
572 | for n in LeoNode(p): | |
541 | push_from_leo(n) |
|
573 | push_from_leo(n) | |
|
574 | ||||
|
575 |
General Comments 0
You need to be logged in to leave comments.
Login now