##// END OF EJS Templates
Workbook.current & match_h...
Ville M. Vainio -
Show More
@@ -96,6 +96,11 b' class LeoNode(object, UserDict.DictMixin):'
96 def __init__(self,p):
96 def __init__(self,p):
97 self.p = p.copy()
97 self.p = p.copy()
98
98
99 def __str__(self):
100 return "<LeoNode %s>" % str(self.p)
101
102 __repr__ = __str__
103
99 def __get_h(self): return self.p.headString()
104 def __get_h(self): return self.p.headString()
100 def __set_h(self,val):
105 def __set_h(self,val):
101 print "set head",val
106 print "set head",val
@@ -182,11 +187,11 b' class LeoNode(object, UserDict.DictMixin):'
182 head = '@k ' + key
187 head = '@k ' + key
183 p = c.createLastChildNode(self.p, head, '')
188 p = c.createLastChildNode(self.p, head, '')
184 LeoNode(p).v = val
189 LeoNode(p).v = val
185 def __delitem__(self,key):
190
186 pass
187 def ipush(self):
191 def ipush(self):
188 """ Does push-to-ipython on the node """
192 """ Does push-to-ipython on the node """
189 push_from_leo(self)
193 push_from_leo(self)
194
190 def go(self):
195 def go(self):
191 """ Set node as current node (to quickly see it in Outline) """
196 """ Set node as current node (to quickly see it in Outline) """
192 c.beginUpdate()
197 c.beginUpdate()
@@ -195,6 +200,13 b' class LeoNode(object, UserDict.DictMixin):'
195 finally:
200 finally:
196 c.endUpdate()
201 c.endUpdate()
197
202
203 def script(self):
204 """ Method to get the 'tangled' contents of the node
205
206 (parse @others, << section >> references etc.)
207 """
208 return g.getScript(c,self.p,useSelectedText=False,useSentinels=False)
209
198 def __get_uA(self):
210 def __get_uA(self):
199 p = self.p
211 p = self.p
200 # Create the uA if necessary.
212 # Create the uA if necessary.
@@ -203,6 +215,7 b' class LeoNode(object, UserDict.DictMixin):'
203
215
204 d = p.v.t.unknownAttributes.setdefault('ipython', {})
216 d = p.v.t.unknownAttributes.setdefault('ipython', {})
205 return d
217 return d
218
206 uA = property(__get_uA, doc = "Access persistent unknownAttributes of node")
219 uA = property(__get_uA, doc = "Access persistent unknownAttributes of node")
207
220
208
221
@@ -238,13 +251,22 b' class LeoWorkbook:'
238 cells = all_cells()
251 cells = all_cells()
239 return (LeoNode(p) for p in c.allNodes_iter())
252 return (LeoNode(p) for p in c.allNodes_iter())
240
253
254 current = property(lambda self: LeoNode(c.currentPosition()), doc = "Currently selected node")
255
256 def match_h(self, regex):
257 cmp = re.compile(regex)
258 for node in self:
259 if re.match(cmp, node.h, re.IGNORECASE):
260 yield node
261 return
262
241 ip.user_ns['wb'] = LeoWorkbook()
263 ip.user_ns['wb'] = LeoWorkbook()
242
264
243
265
244
266
245 @IPython.generics.complete_object.when_type(LeoWorkbook)
267 @IPython.generics.complete_object.when_type(LeoWorkbook)
246 def workbook_complete(obj, prev):
268 def workbook_complete(obj, prev):
247 return all_cells().keys()
269 return all_cells().keys() + [s for s in prev if not s.startswith('_')]
248
270
249
271
250 def add_var(varname):
272 def add_var(varname):
@@ -277,7 +299,7 b' def push_ipython_script(node):'
277 try:
299 try:
278 ohist = ip.IP.output_hist
300 ohist = ip.IP.output_hist
279 hstart = len(ip.IP.input_hist)
301 hstart = len(ip.IP.input_hist)
280 script = g.getScript(c,node.p,useSelectedText=False,forcePythonSentinels=False,useSentinels=False)
302 script = node.script()
281
303
282 script = g.splitLines(script + '\n')
304 script = g.splitLines(script + '\n')
283
305
@@ -314,7 +336,7 b' def eval_body(body):'
314 def push_plain_python(node):
336 def push_plain_python(node):
315 if not node.h.endswith('P'):
337 if not node.h.endswith('P'):
316 raise TryNext
338 raise TryNext
317 script = g.getScript(c,node.p,useSelectedText=False,forcePythonSentinels=False,useSentinels=False)
339 script = node.script()
318 lines = script.count('\n')
340 lines = script.count('\n')
319 try:
341 try:
320 exec script in ip.user_ns
342 exec script in ip.user_ns
General Comments 0
You need to be logged in to leave comments. Login now