Show More
@@ -28,7 +28,9 b' def init_ipython(ipy):' | |||||
28 | expose_ileo_push(push_ipython_script, 1000) |
|
28 | expose_ileo_push(push_ipython_script, 1000) | |
29 | expose_ileo_push(push_plain_python, 100) |
|
29 | expose_ileo_push(push_plain_python, 100) | |
30 | expose_ileo_push(push_ev_node, 100) |
|
30 | expose_ileo_push(push_ev_node, 100) | |
31 | ip.user_ns['wb'] = LeoWorkbook() |
|
31 | global wb | |
|
32 | wb = LeoWorkbook() | |||
|
33 | ip.user_ns['wb'] = wb | |||
32 |
|
34 | |||
33 | show_welcome() |
|
35 | show_welcome() | |
34 |
|
36 | |||
@@ -311,9 +313,12 b' def add_var(varname):' | |||||
311 | return LeoNode(p2) |
|
313 | return LeoNode(p2) | |
312 |
|
314 | |||
313 | rootpos = g.findNodeAnywhere(c,'@ipy-results') |
|
315 | rootpos = g.findNodeAnywhere(c,'@ipy-results') | |
314 |
if |
|
316 | if rootpos: | |
315 |
|
|
317 | p2 = rootpos.insertAsLastChild() | |
316 | p2 = rootpos.insertAsLastChild() |
|
318 | ||
|
319 | else: | |||
|
320 | p2 = c.currentPosition().insertAfter() | |||
|
321 | ||||
317 | c.setHeadString(p2,varname) |
|
322 | c.setHeadString(p2,varname) | |
318 | return LeoNode(p2) |
|
323 | return LeoNode(p2) | |
319 | finally: |
|
324 | finally: | |
@@ -411,7 +416,10 b' def push_position_from_leo(p):' | |||||
411 | def edit_object_in_leo(obj, varname): |
|
416 | def edit_object_in_leo(obj, varname): | |
412 | """ Make it @cl node so it can be pushed back directly by alt+I """ |
|
417 | """ Make it @cl node so it can be pushed back directly by alt+I """ | |
413 | node = add_var(varname) |
|
418 | node = add_var(varname) | |
414 |
|
|
419 | formatted = format_for_leo(obj) | |
|
420 | if not formatted.startswith('@cl'): | |||
|
421 | formatted = '@cl\n' + formatted | |||
|
422 | node.b = formatted | |||
415 | node.go() |
|
423 | node.go() | |
416 |
|
424 | |||
417 | @edit_object_in_leo.when_type(IPython.macro.Macro) |
|
425 | @edit_object_in_leo.when_type(IPython.macro.Macro) | |
@@ -420,17 +428,41 b' def edit_macro(obj,varname):' | |||||
420 | node = add_var('Macro_' + varname) |
|
428 | node = add_var('Macro_' + varname) | |
421 | node.b = bod |
|
429 | node.b = bod | |
422 | node.go() |
|
430 | node.go() | |
|
431 | ||||
|
432 | def get_history(hstart = 0): | |||
|
433 | res = [] | |||
|
434 | ohist = ip.IP.output_hist | |||
|
435 | ||||
|
436 | for idx in range(hstart, len(ip.IP.input_hist)): | |||
|
437 | val = ohist.get(idx,None) | |||
|
438 | has_output = True | |||
|
439 | inp = ip.IP.input_hist_raw[idx] | |||
|
440 | if inp.strip(): | |||
|
441 | res.append('In [%d]: %s' % (idx, inp)) | |||
|
442 | if val: | |||
|
443 | res.append(pprint.pformat(val)) | |||
|
444 | res.append('\n') | |||
|
445 | return ''.join(res) | |||
|
446 | ||||
423 |
|
447 | |||
424 | def lee_f(self,s): |
|
448 | def lee_f(self,s): | |
425 | """ Open file(s)/objects in Leo |
|
449 | """ Open file(s)/objects in Leo | |
426 |
|
450 | |||
427 | Takes an mglob pattern, e.g. '%lee *.cpp' or %leo 'rec:*.cpp' |
|
451 | - %lee hist -> open full session history in leo | |
|
452 | - Takes an object | |||
|
453 | - Takes an mglob pattern, e.g. '%lee *.cpp' or %leo 'rec:*.cpp' | |||
428 | """ |
|
454 | """ | |
429 | import os |
|
455 | import os | |
430 |
|
456 | |||
431 | c.beginUpdate() |
|
457 | c.beginUpdate() | |
432 | try: |
|
458 | try: | |
433 |
|
459 | if s == 'hist': | ||
|
460 | wb.ipython_history.b = get_history() | |||
|
461 | wb.ipython_history.go() | |||
|
462 | return | |||
|
463 | ||||
|
464 | ||||
|
465 | ||||
434 | # try editing the object directly |
|
466 | # try editing the object directly | |
435 | obj = ip.user_ns.get(s, None) |
|
467 | obj = ip.user_ns.get(s, None) | |
436 | if obj is not None: |
|
468 | if obj is not None: | |
@@ -440,7 +472,7 b' def lee_f(self,s):' | |||||
440 | # if it's not object, it's a file name / mglob pattern |
|
472 | # if it's not object, it's a file name / mglob pattern | |
441 | from IPython.external import mglob |
|
473 | from IPython.external import mglob | |
442 |
|
474 | |||
443 | files = mglob.expand(s) |
|
475 | files = (os.path.abspath(f) for f in mglob.expand(s)) | |
444 | for fname in files: |
|
476 | for fname in files: | |
445 | p = g.findNodeAnywhere(c,'@auto ' + fname) |
|
477 | p = g.findNodeAnywhere(c,'@auto ' + fname) | |
446 | if not p: |
|
478 | if not p: | |
@@ -450,6 +482,7 b' def lee_f(self,s):' | |||||
450 | if os.path.isfile(fname): |
|
482 | if os.path.isfile(fname): | |
451 | c.setBodyString(p,open(fname).read()) |
|
483 | c.setBodyString(p,open(fname).read()) | |
452 | c.selectPosition(p) |
|
484 | c.selectPosition(p) | |
|
485 | print "Editing file(s), press ctrl+shift+w in Leo to write @auto nodes" | |||
453 | finally: |
|
486 | finally: | |
454 | c.endUpdate() |
|
487 | c.endUpdate() | |
455 |
|
488 |
General Comments 0
You need to be logged in to leave comments.
Login now