Show More
@@ -1,363 +1,409 b'' | |||||
1 | <?xml version="1.0" encoding="utf-8"?> |
|
1 | <?xml version="1.0" encoding="utf-8"?> | |
2 | <?xml-stylesheet ekr_test?> |
|
2 | <?xml-stylesheet ekr_test?> | |
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=" |
|
6 | <global_window_position top="261" 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/> | |
10 | <find_panel_settings/> |
|
10 | <find_panel_settings/> | |
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.20080223133721" a="E"><vh>@settings</vh> | |||
|
14 | <v t="vivainio.20080223133721.1"><vh>@enabled-plugins</vh></v> | |||
|
15 | </v> | |||
13 | <v t="vivainio.20080218184540" a="E"><vh>@ipy-startup</vh> |
|
16 | <v t="vivainio.20080218184540" a="E"><vh>@ipy-startup</vh> | |
14 | <v t="vivainio.20080218184613.1"><vh>b</vh></v> |
|
17 | <v t="vivainio.20080218184613.1"><vh>b</vh></v> | |
15 | <v t="vivainio.20080218200031"><vh>Some classes P</vh> |
|
18 | <v t="vivainio.20080218200031" a="E"><vh>Some classes P</vh> | |
16 | <v t="vivainio.20080218190816"><vh>File-like access</vh></v> |
|
19 | <v t="vivainio.20080218190816"><vh>File-like access</vh></v> | |
17 | <v t="vivainio.20080218200106"><vh>csv data</vh></v> |
|
20 | <v t="vivainio.20080218200106"><vh>csv data</vh></v> | |
18 | <v t="vivainio.20080219225120"><vh>String list</vh></v> |
|
21 | <v t="vivainio.20080219225120"><vh>String list</vh></v> | |
19 | <v t="vivainio.20080219230342"><vh>slist to leo</vh></v> |
|
22 | <v t="vivainio.20080219230342"><vh>slist to leo</vh></v> | |
20 | </v> |
|
23 | </v> | |
21 | </v> |
|
24 | </v> | |
22 | <v t="vivainio.20080218195413"><vh>Class tests</vh> |
|
25 | <v t="vivainio.20080218195413"><vh>Class tests</vh> | |
23 | <v t="vivainio.20080218200509"><vh>csvr</vh></v> |
|
26 | <v t="vivainio.20080218200509"><vh>csvr</vh></v> | |
24 | <v t="vivainio.20080218191007"><vh>tempfile</vh></v> |
|
27 | <v t="vivainio.20080218191007"><vh>tempfile</vh></v> | |
25 | <v t="vivainio.20080218195413.1"><vh>rfile</vh></v> |
|
28 | <v t="vivainio.20080218195413.1"><vh>rfile</vh></v> | |
26 | <v t="vivainio.20080219225804"><vh>strlist</vh></v> |
|
29 | <v t="vivainio.20080219225804"><vh>strlist</vh></v> | |
27 | </v> |
|
30 | </v> | |
28 | <v t="vivainio.20080218201219"><vh>Direct variables</vh> |
|
31 | <v t="vivainio.20080218201219"><vh>Direct variables</vh> | |
29 | <v t="vivainio.20080222201226"><vh>NewHeadline</vh></v> |
|
32 | <v t="vivainio.20080222201226"><vh>NewHeadline</vh></v> | |
30 | <v t="vivainio.20080218201219.2"><vh>bar</vh></v> |
|
33 | <v t="vivainio.20080218201219.2"><vh>bar</vh></v> | |
31 | </v> |
|
34 | </v> | |
32 | <v t="vivainio.20080222193236" a="E"><vh>Docs</vh> |
|
35 | <v t="vivainio.20080222193236" a="E"><vh>Docs</vh> | |
33 | <v t="vivainio.20080222193236.1" a="TV"><vh>Quick intro</vh></v> |
|
36 | <v t="vivainio.20080223121915" a="E" tnodeList="vivainio.20080223121915,vivainio.20080222193236.1,vivainio.20080223133858,vivainio.20080223133922,vivainio.20080223133947,vivainio.20080223134018,vivainio.20080223134100,vivainio.20080223134118,vivainio.20080223134433,vivainio.20080223134136"><vh>@nosent ileointro.txt</vh> | |
|
37 | <v t="vivainio.20080222193236.1" a="E"><vh>Quick intro</vh> | |||
|
38 | <v t="vivainio.20080223133858"><vh>Introduction</vh></v> | |||
|
39 | <v t="vivainio.20080223133922"><vh>Installation</vh></v> | |||
|
40 | <v t="vivainio.20080223133947"><vh>Accessing IPython from Leo</vh></v> | |||
|
41 | <v t="vivainio.20080223134018"><vh>Accessing Leo nodes from IPython</vh></v> | |||
|
42 | <v t="vivainio.20080223134100"><vh>Cl definitions</vh></v> | |||
|
43 | <v t="vivainio.20080223134118"><vh>Special node types</vh></v> | |||
|
44 | <v t="vivainio.20080223134433" a="TV"><vh>Custom push</vh></v> | |||
|
45 | <v t="vivainio.20080223134136"><vh>Acknowledgements and history</vh></v> | |||
|
46 | </v> | |||
|
47 | </v> | |||
34 | </v> |
|
48 | </v> | |
35 | <v t="vivainio.20080222202211"><vh>test stuff</vh></v> |
|
49 | <v t="vivainio.20080222202211"><vh>test stuff</vh></v> | |
36 | <v t="vivainio.20080222202211.1"><vh>spam</vh></v> |
|
50 | <v t="vivainio.20080222202211.1"><vh>spam</vh></v> | |
37 | <v t="vivainio.20080222202211.2"><vh>NewHeadline</vh></v> |
|
51 | <v t="vivainio.20080222202211.2"><vh>NewHeadline</vh></v> | |
38 | </vnodes> |
|
52 | </vnodes> | |
39 | <tnodes> |
|
53 | <tnodes> | |
40 | <t tx="vivainio.20080218184525">?</t> |
|
54 | <t tx="vivainio.20080218184525">?</t> | |
41 | <t tx="vivainio.20080218184540">?Direct children of this node will be pushed at ipython bridge startup |
|
55 | <t tx="vivainio.20080218184540">?Direct children of this node will be pushed at ipython bridge startup | |
42 |
|
56 | |||
43 | This node itself will *not* be pushed</t> |
|
57 | This node itself will *not* be pushed</t> | |
44 | <t tx="vivainio.20080218184613.1">print "world"</t> |
|
58 | <t tx="vivainio.20080218184613.1">print "world"</t> | |
45 | <t tx="vivainio.20080218190816">def rfile(body,n): |
|
59 | <t tx="vivainio.20080218190816">def rfile(body,n): | |
46 | """ @cl rfile |
|
60 | """ @cl rfile | |
47 |
|
61 | |||
48 | produces a StringIO (file like obj of the rest of the body) """ |
|
62 | produces a StringIO (file like obj of the rest of the body) """ | |
49 |
|
63 | |||
50 | import StringIO |
|
64 | import StringIO | |
51 | return StringIO.StringIO(body) |
|
65 | return StringIO.StringIO(body) | |
52 |
|
66 | |||
53 | def tmpfile(body,n): |
|
67 | def tmpfile(body,n): | |
54 | """ @cl tmpfile |
|
68 | """ @cl tmpfile | |
55 |
|
69 | |||
56 | Produces a temporary file, with node body as contents |
|
70 | Produces a temporary file, with node body as contents | |
57 |
|
71 | |||
58 | """ |
|
72 | """ | |
59 | import tempfile |
|
73 | import tempfile | |
60 | h, fname = tempfile.mkstemp() |
|
74 | h, fname = tempfile.mkstemp() | |
61 | f = open(fname,'w') |
|
75 | f = open(fname,'w') | |
62 | f.write(body) |
|
76 | f.write(body) | |
63 | f.close() |
|
77 | f.close() | |
64 | return fname |
|
78 | return fname | |
65 | </t> |
|
79 | </t> | |
66 | <t tx="vivainio.20080218191007">@cl tmpfile |
|
80 | <t tx="vivainio.20080218191007">@cl tmpfile | |
67 |
|
81 | |||
68 | Hello</t> |
|
82 | Hello</t> | |
69 | <t tx="vivainio.20080218195413">?</t> |
|
83 | <t tx="vivainio.20080218195413">?</t> | |
70 | <t tx="vivainio.20080218195413.1">@cl rfile |
|
84 | <t tx="vivainio.20080218195413.1">@cl rfile | |
71 | These |
|
85 | These | |
72 | lines |
|
86 | lines | |
73 | should |
|
87 | should | |
74 | be |
|
88 | be | |
75 | readable </t> |
|
89 | readable </t> | |
76 | <t tx="vivainio.20080218200031">@others</t> |
|
90 | <t tx="vivainio.20080218200031">@others</t> | |
77 | <t tx="vivainio.20080218200106">def csvdata(body,n): |
|
91 | <t tx="vivainio.20080218200106">def csvdata(body,n): | |
78 | import csv |
|
92 | import csv | |
79 | d = csv.Sniffer().sniff(body) |
|
93 | d = csv.Sniffer().sniff(body) | |
80 | reader = csv.reader(body.splitlines(), dialect = d) |
|
94 | reader = csv.reader(body.splitlines(), dialect = d) | |
81 | return reader</t> |
|
95 | return reader</t> | |
82 | <t tx="vivainio.20080218200509">@cl csvdata |
|
96 | <t tx="vivainio.20080218200509">@cl csvdata | |
83 |
|
97 | |||
84 | a,b,b |
|
98 | a,b,b | |
85 | 1,2,2</t> |
|
99 | 1,2,2</t> | |
86 | <t tx="vivainio.20080218201219"></t> |
|
100 | <t tx="vivainio.20080218201219"></t> | |
87 | <t tx="vivainio.20080218201219.2">@cl |
|
101 | <t tx="vivainio.20080218201219.2">@cl | |
88 | "hello world"</t> |
|
102 | "hello world"</t> | |
89 | <t tx="vivainio.20080219225120">import IPython.genutils |
|
103 | <t tx="vivainio.20080219225120">import IPython.genutils | |
90 | def slist(body,n): |
|
104 | def slist(body,n): | |
91 | return IPython.genutils.SList(body.splitlines()) |
|
105 | return IPython.genutils.SList(body.splitlines()) | |
92 | </t> |
|
106 | </t> | |
93 | <t tx="vivainio.20080219225804">@cl slist |
|
107 | <t tx="vivainio.20080219225804">@cl slist | |
94 | hello |
|
108 | hello | |
95 | world |
|
109 | world | |
96 | on |
|
110 | on | |
97 | many |
|
111 | many | |
98 | lines |
|
112 | lines | |
99 | </t> |
|
113 | </t> | |
100 | <t tx="vivainio.20080219230342">import ipy_leo |
|
114 | <t tx="vivainio.20080219230342">import ipy_leo | |
101 | @ipy_leo.format_for_leo.when_type(IPython.genutils.SList) |
|
115 | @ipy_leo.format_for_leo.when_type(IPython.genutils.SList) | |
102 | def format_slist(obj): |
|
116 | def format_slist(obj): | |
103 | return "@cl slist\n" + obj.n |
|
117 | return "@cl slist\n" + obj.n | |
104 | </t> |
|
118 | </t> | |
105 | <t tx="vivainio.20080222193236"></t> |
|
119 | <t tx="vivainio.20080222193236"></t> | |
106 | <t tx="vivainio.20080222193236.1">@wrap |
|
120 | <t tx="vivainio.20080222193236.1">@wrap | |
107 | @nocolor |
|
121 | @nocolor</t> | |
|
122 | <t tx="vivainio.20080222201226">1+2 | |||
|
123 | print "hello" | |||
|
124 | 3+4 | |||
108 |
|
125 | |||
|
126 | def f(x): | |||
|
127 | return x.upper() | |||
|
128 | ||||
|
129 | f('hello world')</t> | |||
|
130 | <t tx="vivainio.20080222202211"></t> | |||
|
131 | <t tx="vivainio.20080222202211.1">@cl rfile | |||
|
132 | hello | |||
|
133 | world | |||
|
134 | and whatever</t> | |||
|
135 | <t tx="vivainio.20080222202211.2"></t> | |||
|
136 | <t tx="vivainio.20080223121915">@others | |||
|
137 | </t> | |||
|
138 | <t tx="vivainio.20080223133721"></t> | |||
|
139 | <t tx="vivainio.20080223133721.1">ipython.py</t> | |||
|
140 | <t tx="vivainio.20080223133858"> | |||
109 | Introduction |
|
141 | Introduction | |
110 | ============ |
|
142 | ============ | |
111 |
|
143 | |||
112 | The purpose of ILeo, or leo-ipython bridge, is being a two-way communication |
|
144 | The purpose of ILeo, or leo-ipython bridge, is being a two-way communication | |
113 | channel between Leo and IPython. The level of integration is much deeper than |
|
145 | channel between Leo and IPython. The level of integration is much deeper than | |
114 | conventional integration in IDEs; most notably, you are able to store *data* in |
|
146 | conventional integration in IDEs; most notably, you are able to store *data* in | |
115 | Leo nodes, in addition to mere program code. The possibilities of this are |
|
147 | Leo nodes, in addition to mere program code. The possibilities of this are | |
116 | endless, and this degree of integration has not been seen previously in the python |
|
148 | endless, and this degree of integration has not been seen previously in the python | |
117 | world. |
|
149 | world. | |
118 |
|
150 | |||
119 | IPython users are accustomed to using things like %edit to produce non-trivial |
|
151 | IPython users are accustomed to using things like %edit to produce non-trivial | |
120 | functions/classes (i.e. something that they don't want to enter directly on the |
|
152 | functions/classes (i.e. something that they don't want to enter directly on the | |
121 | interactive prompt, but creating a proper script/module involves too much |
|
153 | interactive prompt, but creating a proper script/module involves too much | |
122 | overhead). In ILeo, this task consists just going to the Leo window, creating a node |
|
154 | overhead). In ILeo, this task consists just going to the Leo window, creating a node | |
123 | and writing the code there, and pressing alt+I (push-to-ipython). |
|
155 | and writing the code there, and pressing alt+I (push-to-ipython). | |
124 |
|
156 | |||
125 | Obviously, you can save the Leo document as usual - this is a great advantage |
|
157 | Obviously, you can save the Leo document as usual - this is a great advantage | |
126 | of ILeo over using %edit, you can save your experimental scripts all at one |
|
158 | of ILeo over using %edit, you can save your experimental scripts all at one | |
127 | time, without having to organize them into script/module files (before you |
|
159 | time, without having to organize them into script/module files (before you | |
128 | really want to, of course!) |
|
160 | really want to, of course!) | |
129 |
|
161 | </t> | ||
130 |
|
162 | <t tx="vivainio.20080223133922"> | ||
131 | Installation |
|
163 | Installation | |
132 | ============ |
|
164 | ============ | |
133 |
|
165 | |||
134 |
You need |
|
166 | You need at least Leo 4.4.7, and the development version of IPython (ILeo | |
135 | will be incorporated to IPython 0.8.3. |
|
167 | will be incorporated to IPython 0.8.3). | |
136 |
|
168 | |||
137 | You can get IPython from Launchpad by installing bzr and doing |
|
169 | You can get IPython from Launchpad by installing bzr and doing | |
138 |
|
170 | |||
139 | bzr branch lp:ipython |
|
171 | bzr branch lp:ipython | |
140 |
|
172 | |||
141 | and running "setup.py install". |
|
173 | and running "setup.py install". | |
142 |
|
174 | |||
143 | You need to enable the 'ipython.py' plugin in Leo: |
|
175 | You need to enable the 'ipython.py' plugin in Leo: | |
144 |
|
176 | |||
145 | - Help -> Open LeoSettings.leo |
|
177 | - Help -> Open LeoSettings.leo | |
146 |
|
178 | |||
147 | - Edit @settings-->Plugins-->@enabled-plugins, add/uncomment 'ipython.py' |
|
179 | - Edit @settings-->Plugins-->@enabled-plugins, add/uncomment 'ipython.py' | |
148 |
|
180 | |||
149 | - Restart Leo. Be sure that you have the console window open (start leo.py from console, or double-click leo.py on windows) |
|
181 | - Restart Leo. Be sure that you have the console window open (start leo.py from console, or double-click leo.py on windows) | |
150 |
|
182 | |||
151 | - Press alt+5 OR alt-x start-ipython to launch IPython in the console that |
|
183 | - Press alt+5 OR alt-x start-ipython to launch IPython in the console that | |
152 | started leo. You can start entering IPython commands normally, and Leo will keep |
|
184 | started leo. You can start entering IPython commands normally, and Leo will keep | |
153 |
running |
|
185 | running at the same time. | |
154 |
|
186 | </t> | ||
|
187 | <t tx="vivainio.20080223133947"> | |||
155 | Accessing IPython from Leo |
|
188 | Accessing IPython from Leo | |
156 | ========================== |
|
189 | ========================== | |
157 |
|
190 | |||
158 | IPython code |
|
191 | IPython code | |
159 | ------------ |
|
192 | ------------ | |
160 |
|
193 | |||
161 | Just enter IPython commands on a Leo node and press alt-I to execute |
|
194 | Just enter IPython commands on a Leo node and press alt-I to execute | |
162 | push-to-ipython to execute the script in IPython. 'commands' is interpreted |
|
195 | push-to-ipython to execute the script in IPython. 'commands' is interpreted | |
163 | loosely here - you can enter function and class definitions, in addition to the |
|
196 | loosely here - you can enter function and class definitions, in addition to the | |
164 | things you would usually enter at IPython prompt - calculations, system commands etc. |
|
197 | things you would usually enter at IPython prompt - calculations, system commands etc. | |
165 |
|
198 | |||
166 | Everything that would be legal to enter on IPython prompt is legal to execute |
|
199 | Everything that would be legal to enter on IPython prompt is legal to execute | |
167 | from ILeo. |
|
200 | from ILeo. | |
168 |
|
201 | |||
169 | Results will be shows in Leo log window for convenience, in addition to the console. |
|
202 | Results will be shows in Leo log window for convenience, in addition to the console. | |
170 |
|
203 | |||
171 | Suppose that a node had the following contents: |
|
204 | Suppose that a node had the following contents: | |
172 | {{{ |
|
205 | {{{ | |
173 | 1+2 |
|
206 | 1+2 | |
174 | print "hello" |
|
207 | print "hello" | |
175 | 3+4 |
|
208 | 3+4 | |
176 |
|
209 | |||
177 | def f(x): |
|
210 | def f(x): | |
178 | return x.upper() |
|
211 | return x.upper() | |
179 |
|
212 | |||
180 | f('hello world') |
|
213 | f('hello world') | |
181 | }}} |
|
214 | }}} | |
182 |
|
215 | |||
183 | If you press alt+I on that done, you will see the following in Leo log window (IPython tab): |
|
216 | If you press alt+I on that done, you will see the following in Leo log window (IPython tab): | |
184 |
|
217 | |||
185 | {{{ |
|
218 | {{{ | |
186 | In: 1+2 |
|
219 | In: 1+2 | |
187 | <2> 3 |
|
220 | <2> 3 | |
188 | In: 3+4 |
|
221 | In: 3+4 | |
189 | <4> 7 |
|
222 | <4> 7 | |
190 | In: f('hello world') |
|
223 | In: f('hello world') | |
191 | <6> 'HELLO WORLD' |
|
224 | <6> 'HELLO WORLD' | |
192 | }}} |
|
225 | }}} | |
193 |
|
226 | |||
194 | (numbers like <6> mean IPython output history indices). |
|
227 | (numbers like <6> mean IPython output history indices). | |
195 |
|
228 | |||
196 |
|
229 | |||
197 | Plain Python code |
|
230 | Plain Python code | |
198 | ----------------- |
|
231 | ----------------- | |
199 |
|
232 | |||
200 | If the headline of the node ends with capital P, alt-I will not run the code |
|
233 | If the headline of the node ends with capital P, alt-I will not run the code | |
201 | through IPython translation mechanism but use the direct python 'exec' statement |
|
234 | through IPython translation mechanism but use the direct python 'exec' statement | |
202 | (in IPython user namespace) to execute the code. It wont be shown in IPython |
|
235 | (in IPython user namespace) to execute the code. It wont be shown in IPython | |
203 | history, and sometimes it is safer (and more efficient) to execute things as |
|
236 | history, and sometimes it is safer (and more efficient) to execute things as | |
204 | plain Python statements. Large class definitions are good candidates for P |
|
237 | plain Python statements. Large class definitions are good candidates for P | |
205 | nodes. |
|
238 | nodes. | |
206 |
|
239 | </t> | ||
|
240 | <t tx="vivainio.20080223134018"> | |||
207 | Accessing Leo nodes from IPython |
|
241 | Accessing Leo nodes from IPython | |
208 | ================================ |
|
242 | ================================ | |
209 |
|
243 | |||
210 | The real fun starts when you start entering text to leo nodes, and are using |
|
244 | The real fun starts when you start entering text to leo nodes, and are using | |
211 | that as data (input/output) for your IPython work. |
|
245 | that as data (input/output) for your IPython work. | |
212 |
|
246 | |||
213 | Accessing Leo nodes happens through the variable 'wb' (short for "WorkBook") |
|
247 | Accessing Leo nodes happens through the variable 'wb' (short for "WorkBook") | |
214 | that exist in the IPython user namespace. Nodes that are directly accessible are |
|
248 | that exist in the IPython user namespace. Nodes that are directly accessible are | |
215 | the ones that have simple names which could also be Python variable names; |
|
249 | the ones that have simple names which could also be Python variable names; | |
216 | 'foo_1' will be accessible directly from IPython, whereas 'my scripts' will not. |
|
250 | 'foo_1' will be accessible directly from IPython, whereas 'my scripts' will not. | |
217 | If you want to access a node with arbitrary headline, add a child node '@a foo' |
|
251 | If you want to access a node with arbitrary headline, add a child node '@a foo' | |
218 | (@a stands for 'anchor'). Then, the parent of '@a foo' is accessible through |
|
252 | (@a stands for 'anchor'). Then, the parent of '@a foo' is accessible through | |
219 | 'wb.foo'. |
|
253 | 'wb.foo'. | |
220 |
|
254 | |||
221 | You can see what nodes are accessible be entering (in IPython) wb.<TAB>. Example: |
|
255 | You can see what nodes are accessible be entering (in IPython) wb.<TAB>. Example: | |
222 |
|
256 | |||
223 | [C:leo/src]|12> wb. |
|
257 | [C:leo/src]|12> wb. | |
224 | wb.b wb.tempfile wb.rfile wb.NewHeadline |
|
258 | wb.b wb.tempfile wb.rfile wb.NewHeadline | |
225 | wb.bar wb.Docs wb.strlist wb.csvr |
|
259 | wb.bar wb.Docs wb.strlist wb.csvr | |
226 |
|
260 | |||
227 | Suppose that we had a node with headline 'spam' and body: |
|
261 | Suppose that we had a node with headline 'spam' and body: | |
228 |
|
262 | |||
229 | ['12',2222+32] |
|
263 | ['12',2222+32] | |
230 |
|
264 | |||
231 | we can access it from IPython (or from scripts entered into other Leo nodes!) by doing: |
|
265 | we can access it from IPython (or from scripts entered into other Leo nodes!) by doing: | |
232 |
|
266 | |||
233 | C:leo/src]|19> wb.spam.v |
|
267 | C:leo/src]|19> wb.spam.v | |
234 | <19> ['12', 2254] |
|
268 | <19> ['12', 2254] | |
235 |
|
269 | |||
236 | 'v' attribute stands for 'value', which means the node contents will be run |
|
270 | 'v' attribute stands for 'value', which means the node contents will be run | |
237 | through 'eval' and everything you would be able to enter into IPython prompt |
|
271 | through 'eval' and everything you would be able to enter into IPython prompt | |
238 | will be converted to objects. This mechanism can be extended far beyond direct |
|
272 | will be converted to objects. This mechanism can be extended far beyond direct | |
239 | evaluation (see '@cl definitions'). |
|
273 | evaluation (see '@cl definitions'). | |
240 |
|
274 | |||
241 | 'v' attribute also has a setter, i.e. you can do: |
|
275 | 'v' attribute also has a setter, i.e. you can do: | |
242 |
|
276 | |||
243 | wb.spam.v = "mystring" |
|
277 | wb.spam.v = "mystring" | |
244 |
|
278 | |||
245 | Which will result in the node 'spam' having the following text: |
|
279 | Which will result in the node 'spam' having the following text: | |
246 |
|
280 | |||
247 | 'mystring' |
|
281 | 'mystring' | |
248 |
|
282 | |||
249 | What assignment to 'v' does can be configured through generic functions |
|
283 | What assignment to 'v' does can be configured through generic functions | |
250 | (simplegeneric module, will be explained later). |
|
284 | (simplegeneric module, will be explained later). | |
251 |
|
285 | |||
252 | Besides v, you can set the body text directly through wb.spam.b = |
|
286 | Besides v, you can set the body text directly through wb.spam.b = | |
253 | "some\nstring", headline by wb.spam.h = 'new_headline' (obviously you must |
|
287 | "some\nstring", headline by wb.spam.h = 'new_headline' (obviously you must | |
254 | access the node through wb.new_headline from that point onwards), and access the |
|
288 | access the node through wb.new_headline from that point onwards), and access the | |
255 | contents as string list (IPython SList) through 'wb.spam.l'. |
|
289 | contents as string list (IPython SList) through 'wb.spam.l'. | |
256 |
|
290 | |||
257 | If you do 'wb.foo.v = 12' when node named 'foo' does not exist, the node titled |
|
291 | If you do 'wb.foo.v = 12' when node named 'foo' does not exist, the node titled | |
258 | 'foo' will be automatically created and assigned body 12. |
|
292 | 'foo' will be automatically created and assigned body 12. | |
259 |
|
293 | </t> | ||
|
294 | <t tx="vivainio.20080223134100"> | |||
260 | @cl definitions |
|
295 | @cl definitions | |
261 | =============== |
|
296 | =============== | |
262 |
|
297 | |||
263 | If the first line in the body text is of the form '@cl sometext', IPython will |
|
298 | If the first line in the body text is of the form '@cl sometext', IPython will | |
264 | will evaluate 'sometext' and call the result with the rest of the body when you |
|
299 | will evaluate 'sometext' and call the result with the rest of the body when you | |
265 | do 'wb.foo.v'. An example is in place here. Suppose that we have defined a class |
|
300 | do 'wb.foo.v'. An example is in place here. Suppose that we have defined a class | |
266 | (I use the term class in a non-python sense here) |
|
301 | (I use the term class in a non-python sense here) | |
267 |
|
302 | |||
268 | {{{ |
|
303 | {{{ | |
269 | def rfile(body,n): |
|
304 | def rfile(body,n): | |
270 | """ @cl rfile |
|
305 | """ @cl rfile | |
271 |
|
306 | |||
272 | produces a StringIO (file like obj) of the rest of the body """ |
|
307 | produces a StringIO (file like obj) of the rest of the body """ | |
273 |
|
308 | |||
274 | import StringIO |
|
309 | import StringIO | |
275 | return StringIO.StringIO(body) |
|
310 | return StringIO.StringIO(body) | |
276 | }}} |
|
311 | }}} | |
277 |
|
312 | |||
278 | Now, let's say you node 'spam' with text |
|
313 | Now, let's say you node 'spam' with text | |
279 |
|
314 | |||
280 | {{{ |
|
315 | {{{ | |
281 | @cl rfile |
|
316 | @cl rfile | |
282 | hello |
|
317 | hello | |
283 | world |
|
318 | world | |
284 | and whatever |
|
319 | and whatever | |
285 | }}} |
|
320 | }}} | |
286 |
|
321 | |||
287 | Now, on IPython, we can do this: |
|
322 | Now, on IPython, we can do this: | |
288 |
|
323 | |||
289 | {{{ |
|
324 | {{{ | |
290 | [C:leo/src]|22> f = wb.spam.v |
|
325 | [C:leo/src]|22> f = wb.spam.v | |
291 | [C:leo/src]|23> f |
|
326 | [C:leo/src]|23> f | |
292 | <23> <StringIO.StringIO instance at 0x04E7E490> |
|
327 | <23> <StringIO.StringIO instance at 0x04E7E490> | |
293 | [C:leo/src]|24> f.readline() |
|
328 | [C:leo/src]|24> f.readline() | |
294 | <24> u'hello\n' |
|
329 | <24> u'hello\n' | |
295 | [C:leo/src]|25> f.readline() |
|
330 | [C:leo/src]|25> f.readline() | |
296 | <25> u'world\n' |
|
331 | <25> u'world\n' | |
297 | [C:leo/src]|26> f.readline() |
|
332 | [C:leo/src]|26> f.readline() | |
298 | <26> u'and whatever' |
|
333 | <26> u'and whatever' | |
299 | [C:leo/src]|27> f.readline() |
|
334 | [C:leo/src]|27> f.readline() | |
300 | <27> u'' |
|
335 | <27> u'' | |
301 | }}} |
|
336 | }}} | |
302 |
|
337 | |||
303 | 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 |
|
338 | 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 | |
304 |
|
339 | </t> | ||
|
340 | <t tx="vivainio.20080223134118"> | |||
305 | Special node types |
|
341 | Special node types | |
306 | ================== |
|
342 | ================== | |
307 |
|
343 | |||
308 | @ipy-startup |
|
344 | @ipy-startup | |
309 | ------------ |
|
345 | ------------ | |
310 |
|
346 | |||
311 | If this node exist, the *direct children* of this will be pushed to IPython when |
|
347 | If this node exist, the *direct children* of this will be pushed to IPython when | |
312 | ILeo is started (you press alt+5). Use it to push your own @cl definitions etc. |
|
348 | ILeo is started (you press alt+5). Use it to push your own @cl definitions etc. | |
313 | The contents of of the node itself will be ignored. |
|
349 | The contents of of the node itself will be ignored. | |
314 |
|
350 | |||
315 | @ipy-results |
|
351 | @ipy-results | |
316 | ------------ |
|
352 | ------------ | |
317 |
|
353 | |||
318 | When you create a new node (wb.foo.v = 'stuff'), the node foo will be created as |
|
354 | When you create a new node (wb.foo.v = 'stuff'), the node foo will be created as | |
319 | a child of this node. If @ipy-results does not exist, the new node will be created after the currently selected node. |
|
355 | a child of this node. If @ipy-results does not exist, the new node will be created after the currently selected node. | |
320 |
|
356 | |||
321 | @a nodes |
|
357 | @a nodes | |
322 | -------- |
|
358 | -------- | |
323 |
|
359 | |||
324 | You can attach these as children of existing nodes to provide a way to access |
|
360 | You can attach these as children of existing nodes to provide a way to access | |
325 | nodes with arbitrary headlines, or to provide aliases to other nodes. If |
|
361 | nodes with arbitrary headlines, or to provide aliases to other nodes. If | |
326 | multiple @a nodes are attached as children of a node, all the names can be used |
|
362 | multiple @a nodes are attached as children of a node, all the names can be used | |
327 | to access the same object. |
|
363 | to access the same object. | |
328 |
|
364 | </t> | ||
|
365 | <t tx="vivainio.20080223134136"> | |||
329 | Acknowledgements & History |
|
366 | Acknowledgements & History | |
330 | ========================== |
|
367 | ========================== | |
331 |
|
368 | |||
332 | This idea got started when I (Ville) saw this post by Edward Ream (the author of |
|
369 | This idea got started when I (Ville) saw this post by Edward Ream (the author of | |
333 | Leo) on IPython developer mailing list: |
|
370 | Leo) on IPython developer mailing list: | |
334 |
|
371 | |||
335 | http://lists.ipython.scipy.org/pipermail/ipython-dev/2008-January/003551.html |
|
372 | http://lists.ipython.scipy.org/pipermail/ipython-dev/2008-January/003551.html | |
336 |
|
373 | |||
337 | I was using FreeMind as mind mapping software, and so I had an immediate use |
|
374 | I was using FreeMind as mind mapping software, and so I had an immediate use | |
338 | case for Leo (which, incidentally, is superior to FreeMind as mind mapper). The |
|
375 | case for Leo (which, incidentally, is superior to FreeMind as mind mapper). The | |
339 | wheels started rolling, I got obsessed with the power of this concept |
|
376 | wheels started rolling, I got obsessed with the power of this concept | |
340 | (everything clicked together), and Edwards excitement paralleled mine. |
|
377 | (everything clicked together), and Edwards excitement paralleled mine. | |
341 | Everything was mind-bogglingly easy/trivial, something that is typical of all |
|
378 | Everything was mind-bogglingly easy/trivial, something that is typical of all | |
342 | revolutionary technologies (think Python here). |
|
379 | revolutionary technologies (think Python here). | |
343 |
|
380 | |||
344 | The discussion that "built" ILeo is here: |
|
381 | The discussion that "built" ILeo is here: | |
345 | http://sourceforge.net/forum/forum.php?thread_id=1911662&forum_id=10226 |
|
382 | http://sourceforge.net/forum/forum.php?thread_id=1911662&forum_id=10226 | |
346 |
|
383 | |||
347 | </t> |
|
384 | ?</t> | |
348 |
<t tx="vivainio.2008022 |
|
385 | <t tx="vivainio.20080223134433"> | |
349 | print "hello" |
|
386 | Declaring custom push-to-ipython handlers | |
350 | 3+4 |
|
387 | ========================================= | |
351 |
|
388 | |||
352 | def f(x): |
|
389 | Sometimes, you might want to configure what alt+I on a node does. You can do | |
353 | return x.upper() |
|
390 | that by creating your own push function and expose it using | |
|
391 | ipy_leo.expose_ileo_push(f, priority). The function should check whether the | |||
|
392 | node should by handled by it and raise IPython.ipapi.TryNext if it will not do | |||
|
393 | the handling. | |||
354 |
|
394 | |||
355 | f('hello world')</t> |
|
395 | This would print an uppercase version of node body if the node headline ends | |
356 | <t tx="vivainio.20080222202211"></t> |
|
396 | with U (yes, this is completely useless!) | |
357 | <t tx="vivainio.20080222202211.1">@cl rfile |
|
397 | ||
358 | hello |
|
398 | def push_upcase(node): | |
359 | world |
|
399 | if not node.h.endswith('U'): | |
360 | and whatever</t> |
|
400 | raise TryNext | |
361 | <t tx="vivainio.20080222202211.2"></t> |
|
401 | print node.b.upper() | |
|
402 | ||||
|
403 | expose_ileo_push(push_upcase, 12) | |||
|
404 | ||||
|
405 | (the priority should be between 0-100 - typically, you don't need to care about | |||
|
406 | it and can omit the argument altogether) | |||
|
407 | </t> | |||
362 | </tnodes> |
|
408 | </tnodes> | |
363 | </leo_file> |
|
409 | </leo_file> |
General Comments 0
You need to be logged in to leave comments.
Login now