From 238f590489e691fff4a16ab48f93f7ceae00ea1f 2008-02-23 11:49:33 From: Ville M. Vainio Date: 2008-02-23 11:49:33 Subject: [PATCH] ipy_leo: improved ipy_leo docs --- diff --git a/doc/examples/leo_bridge_demo.leo b/doc/examples/leo_bridge_demo.leo index a56400c..ee8d410 100644 --- a/doc/examples/leo_bridge_demo.leo +++ b/doc/examples/leo_bridge_demo.leo @@ -3,16 +3,19 @@ - + @chapters +@settings +@enabled-plugins + @ipy-startup b -Some classes P +Some classes P File-like access csv data String list @@ -30,7 +33,18 @@ bar Docs -Quick intro +@nosent ileointro.txt +Quick intro +Introduction +Installation +Accessing IPython from Leo +Accessing Leo nodes from IPython +Cl definitions +Special node types +Custom push +Acknowledgements and history + + test stuff spam @@ -104,8 +118,26 @@ def format_slist(obj): @wrap -@nocolor +@nocolor +1+2 +print "hello" +3+4 +def f(x): + return x.upper() + +f('hello world') + +@cl rfile +hello +world +and whatever + +@others + + +ipython.py + Introduction ============ @@ -126,13 +158,13 @@ Obviously, you can save the Leo document as usual - this is a great advantage of ILeo over using %edit, you can save your experimental scripts all at one time, without having to organize them into script/module files (before you really want to, of course!) - - + + Installation ============ -You need the latest version of Leo, and the development version of IPython (ILeo -will be incorporated to IPython 0.8.3. +You need at least Leo 4.4.7, and the development version of IPython (ILeo +will be incorporated to IPython 0.8.3). You can get IPython from Launchpad by installing bzr and doing @@ -150,8 +182,9 @@ You need to enable the 'ipython.py' plugin in Leo: - Press alt+5 OR alt-x start-ipython to launch IPython in the console that started leo. You can start entering IPython commands normally, and Leo will keep -running in the same time. - +running at the same time. + + Accessing IPython from Leo ========================== @@ -181,7 +214,7 @@ f('hello world') }}} If you press alt+I on that done, you will see the following in Leo log window (IPython tab): - + {{{ In: 1+2 <2> 3 @@ -203,7 +236,8 @@ through IPython translation mechanism but use the direct python 'exec' statement history, and sometimes it is safer (and more efficient) to execute things as plain Python statements. Large class definitions are good candidates for P nodes. - + + Accessing Leo nodes from IPython ================================ @@ -229,7 +263,7 @@ Suppose that we had a node with headline 'spam' and body: ['12',2222+32] we can access it from IPython (or from scripts entered into other Leo nodes!) by doing: - + C:leo/src]|19> wb.spam.v <19> ['12', 2254] @@ -256,7 +290,8 @@ contents as string list (IPython SList) through 'wb.spam.l'. If you do 'wb.foo.v = 12' when node named 'foo' does not exist, the node titled 'foo' will be automatically created and assigned body 12. - + + @cl definitions =============== @@ -301,7 +336,8 @@ Now, on IPython, we can do this: }}} You should declare new @cl types to make ILeo as convenient your problem domain as possible. For example, a "@cl etree" could return the elementtree object for xml content, or - + + Special node types ================== @@ -325,15 +361,16 @@ You can attach these as children of existing nodes to provide a way to access nodes with arbitrary headlines, or to provide aliases to other nodes. If multiple @a nodes are attached as children of a node, all the names can be used to access the same object. - + + Acknowledgements & History ========================== This idea got started when I (Ville) saw this post by Edward Ream (the author of Leo) on IPython developer mailing list: - + http://lists.ipython.scipy.org/pipermail/ipython-dev/2008-January/003551.html - + I was using FreeMind as mind mapping software, and so I had an immediate use case for Leo (which, incidentally, is superior to FreeMind as mind mapper). The wheels started rolling, I got obsessed with the power of this concept @@ -344,20 +381,29 @@ revolutionary technologies (think Python here). The discussion that "built" ILeo is here: http://sourceforge.net/forum/forum.php?thread_id=1911662&forum_id=10226 - -1+2 -print "hello" -3+4 +? + +Declaring custom push-to-ipython handlers +========================================= -def f(x): - return x.upper() +Sometimes, you might want to configure what alt+I on a node does. You can do +that by creating your own push function and expose it using +ipy_leo.expose_ileo_push(f, priority). The function should check whether the +node should by handled by it and raise IPython.ipapi.TryNext if it will not do +the handling. -f('hello world') - -@cl rfile -hello -world -and whatever - +This would print an uppercase version of node body if the node headline ends +with U (yes, this is completely useless!) + +def push_upcase(node): + if not node.h.endswith('U'): + raise TryNext + print node.b.upper() + +expose_ileo_push(push_upcase, 12) + +(the priority should be between 0-100 - typically, you don't need to care about +it and can omit the argument altogether) +