##// END OF EJS Templates
Pulling in content and rewriting from ipython-in-depth.
Brian E. Granger -
Show More
1 NO CONTENT: new file 100644, binary diff hidden
1 NO CONTENT: new file 100644, binary diff hidden
@@ -1,9 +1,149 b''
1 1 {
2 2 "metadata": {
3 "name": "",
4 "signature": "sha256:0abf067a20ebda26a671db997ac954770350d292dff7b7d6a4ace8808f70aca1"
3 "name": ""
5 4 },
6 5 "nbformat": 3,
7 6 "nbformat_minor": 0,
8 "worksheets": []
7 "worksheets": [
8 {
9 "cells": [
10 {
11 "cell_type": "heading",
12 "level": 1,
13 "metadata": {},
14 "source": [
15 "Keyboard Shortcut Customization"
16 ]
17 },
18 {
19 "cell_type": "markdown",
20 "metadata": {},
21 "source": [
22 "Starting with IPython 2.0 keyboard shortcuts in command and edit mode are fully customizable. These customizations are made using the IPython JavaScript API. Here is an example that makes the `r` key available for running a cell:"
23 ]
24 },
25 {
26 "cell_type": "code",
27 "collapsed": false,
28 "input": [
29 "%%javascript\n",
30 "\n",
31 "IPython.keyboard_manager.command_shortcuts.add_shortcut('r', {\n",
32 " help : 'run cell',\n",
33 " help_index : 'zz',\n",
34 " handler : function (event) {\n",
35 " IPython.notebook.execute_cell();\n",
36 " return false;\n",
37 " }}\n",
38 ");"
39 ],
40 "language": "python",
41 "metadata": {},
42 "outputs": [
43 {
44 "javascript": [
45 "\n",
46 "IPython.keyboard_manager.command_shortcuts.add_shortcut('r', {\n",
47 " help : 'run cell',\n",
48 " help_index : 'zz',\n",
49 " handler : function (event) {\n",
50 " IPython.notebook.execute_cell();\n",
51 " return false;\n",
52 " }}\n",
53 ");"
54 ],
55 "metadata": {},
56 "output_type": "display_data",
57 "text": [
58 "<IPython.core.display.Javascript at 0x10e8d1890>"
59 ]
60 }
61 ],
62 "prompt_number": 7
63 },
64 {
65 "cell_type": "markdown",
66 "metadata": {},
67 "source": [
68 "There are a couple of points to mention about this API:\n",
69 "\n",
70 "* The `help_index` field is used to sort the shortcuts in the Keyboard Shortcuts help dialog. It defaults to `zz`.\n",
71 "* When a handler returns `false` it indicates that the event should stop propagating and the default action should not be performed. For further details about the `event` object or event handling, see the jQuery docs.\n",
72 "* If you don't need a `help` or `help_index` field, you can simply pass a function as the second argument to `add_shortcut`."
73 ]
74 },
75 {
76 "cell_type": "code",
77 "collapsed": false,
78 "input": [
79 "%%javascript\n",
80 "\n",
81 "IPython.keyboard_manager.command_shortcuts.add_shortcut('r', function (event) {\n",
82 " IPython.notebook.execute_cell();\n",
83 " return false;\n",
84 "});"
85 ],
86 "language": "python",
87 "metadata": {},
88 "outputs": [
89 {
90 "javascript": [
91 "\n",
92 "IPython.keyboard_manager.command_shortcuts.add_shortcut('r', function (event) {\n",
93 " IPython.notebook.execute_cell();\n",
94 " return false;\n",
95 "});"
96 ],
97 "metadata": {},
98 "output_type": "display_data",
99 "text": [
100 "<IPython.core.display.Javascript at 0x1019baf90>"
101 ]
102 }
103 ],
104 "prompt_number": 11
105 },
106 {
107 "cell_type": "markdown",
108 "metadata": {},
109 "source": [
110 "Likewise, to remove a shortcut, use `remove_shortcut`:"
111 ]
112 },
113 {
114 "cell_type": "code",
115 "collapsed": false,
116 "input": [
117 "%%javascript\n",
118 "\n",
119 "IPython.keyboard_manager.command_shortcuts.remove_shortcut('r');"
120 ],
121 "language": "python",
122 "metadata": {},
123 "outputs": [
124 {
125 "javascript": [
126 "\n",
127 "IPython.keyboard_manager.command_shortcuts.remove_shortcut('r');"
128 ],
129 "metadata": {},
130 "output_type": "display_data",
131 "text": [
132 "<IPython.core.display.Javascript at 0x10e8d1950>"
133 ]
134 }
135 ],
136 "prompt_number": 8
137 },
138 {
139 "cell_type": "markdown",
140 "metadata": {},
141 "source": [
142 "If you want your keyboard shortcuts to be active for all of your notebooks, put the above API calls into your `<profile>/static/custom/custom.js` file."
143 ]
144 }
145 ],
146 "metadata": {}
147 }
148 ]
9 149 } No newline at end of file
@@ -1,7 +1,7 b''
1 1 {
2 2 "metadata": {
3 3 "name": "",
4 "signature": "sha256:f3479d16d8a60d0aa82e5fbffd52552e5649074a7a660730ddca9d5b286692b2"
4 "signature": "sha256:33a14f36e4dad22b2fc23c59ce0e0ed96719007a09f616f240ed5f665e1b871f"
5 5 },
6 6 "nbformat": 3,
7 7 "nbformat_minor": 0,
@@ -53,9 +53,11 b''
53 53 "* [Running the Notebook Server](Running the Notebook Server.ipynb)\n",
54 54 "* [Notebook Dashboard](Notebook Dashboard.ipynb)\n",
55 55 "* [Notebook User Interface](Notebook User Interface.ipynb)\n",
56 "* [Notebook Cell Types](Notebook Cell Types.ipynb)\n",
56 "* [Custom Keyboard Shortcuts](Custom Keyboard Shortcuts.ipynb)\n",
57 57 "* [Working With Code Cells](Working With Code Cells.ipynb)\n",
58 "* [Basic Output](Basic Output.ipynb)\n",
58 59 "* [Working With Markdown Cells](Working With Markdown Cells.ipynb)\n",
60 "* [JavaScript Notebook Extensions](JavaScript Notebook Extensions.ipynb)\n",
59 61 "* [Notebook Security](Notebook Security.ipynb)"
60 62 ]
61 63 },
@@ -71,19 +73,10 b''
71 73 "cell_type": "markdown",
72 74 "metadata": {},
73 75 "source": [
74 "* [Custom Keyboard Shortcuts](Custom Keyboard Shortcuts.ipynb)\n",
75 76 "* [Importing Notebooks](Importing Notebooks.ipynb)\n",
76 77 "* [Connecting with the Qt Console](Connecting with the Qt Console.ipynb)\n",
77 78 "* [Typesetting Equations](Typesetting Equations.ipynb)"
78 79 ]
79 },
80 {
81 "cell_type": "code",
82 "collapsed": false,
83 "input": [],
84 "language": "python",
85 "metadata": {},
86 "outputs": []
87 80 }
88 81 ],
89 82 "metadata": {}
@@ -1,6 +1,7 b''
1 1 {
2 2 "metadata": {
3 "name": ""
3 "name": "",
4 "signature": "sha256:fdeb47a733910a12406e6a2e4f13c2c76fe50b19428feb6ba77c06652fb1d6af"
4 5 },
5 6 "nbformat": 3,
6 7 "nbformat_minor": 0,
@@ -12,16 +13,21 b''
12 13 "level": 1,
13 14 "metadata": {},
14 15 "source": [
15 "User Interface"
16 "Notebook User Interface"
16 17 ]
17 18 },
18 19 {
19 20 "cell_type": "markdown",
20 21 "metadata": {},
21 22 "source": [
22 "This notebook describes the user interface of the IPython Notebook. This includes both mouse and keyboard based navigation and interaction.\n",
23 "\n",
24 "<div class=\"alert\" style=\"margin: 10px\">\n",
23 "This notebook describes the user interface of the IPython Notebook. This includes both mouse and keyboard based navigation and interaction."
24 ]
25 },
26 {
27 "cell_type": "markdown",
28 "metadata": {},
29 "source": [
30 "<div class=\"alert\">\n",
25 31 "As of IPython 2.0, the user interface has changed significantly. Because of this we highly recommend existing users to review this information after upgrading to IPython 2.0. All new users of IPython should review this information as well.\n",
26 32 "</div>"
27 33 ]
@@ -31,6 +37,27 b''
31 37 "level": 2,
32 38 "metadata": {},
33 39 "source": [
40 "Overview of the UI"
41 ]
42 },
43 {
44 "cell_type": "markdown",
45 "metadata": {},
46 "source": [
47 "The notebook UI has the following main areas:\n",
48 "\n",
49 "* Menu\n",
50 "* Toolbar\n",
51 "* Notebook area and cells\n",
52 "\n",
53 "IPython 2.0 has an interactive tour of these elements that can be started in the \"Help:User Interface Tour\" menu item."
54 ]
55 },
56 {
57 "cell_type": "heading",
58 "level": 2,
59 "metadata": {},
60 "source": [
34 61 "Modal editor"
35 62 ]
36 63 },
@@ -57,10 +84,15 b''
57 84 "\n",
58 85 "<img src=\"images/edit_mode.png\">\n",
59 86 "\n",
60 "When a cell is in edit mode, you can type into the cell, like a normal text editor.\n",
61 "\n",
62 "<div class=\"alert alert-success\" style=\"margin: 10px\">\n",
63 "Enter edit mode by pressing `enter` or using the mouse to click on a cell's editor area.\n",
87 "When a cell is in edit mode, you can type into the cell, like a normal text editor."
88 ]
89 },
90 {
91 "cell_type": "markdown",
92 "metadata": {},
93 "source": [
94 "<div class=\"alert alert-success\">\n",
95 "Enter edit mode by pressing `Enter` or using the mouse to click on a cell's editor area.\n",
64 96 "</div>"
65 97 ]
66 98 },
@@ -80,14 +112,24 b''
80 112 "\n",
81 113 "<img src=\"images/command_mode.png\">\n",
82 114 "\n",
83 "When you are in command mode, you are able to edit the notebook as a whole, but not type into individual cells. Most importantly, in command mode, the keyboard is mapped to a set of shortcuts that let you perform notebook and cell actions efficiently. For example, if you are in command mode and you press `c`, you will copy the current cell - no modifier is needed.\n",
84 "\n",
85 "<div class=\"alert alert-error\" style=\"margin: 10px\">\n",
115 "When you are in command mode, you are able to edit the notebook as a whole, but not type into individual cells. Most importantly, in command mode, the keyboard is mapped to a set of shortcuts that let you perform notebook and cell actions efficiently. For example, if you are in command mode and you press `c`, you will copy the current cell - no modifier is needed."
116 ]
117 },
118 {
119 "cell_type": "markdown",
120 "metadata": {},
121 "source": [
122 "<div class=\"alert alert-error\">\n",
86 123 "Don't try to type into a cell in command mode; unexpected things will happen!\n",
87 "</div>\n",
88 "\n",
89 "<div class=\"alert alert-success\" style=\"margin: 10px\">\n",
90 "Enter command mode by pressing `esc` or using the mouse to click *outside* a cell's editor area.\n",
124 "</div>"
125 ]
126 },
127 {
128 "cell_type": "markdown",
129 "metadata": {},
130 "source": [
131 "<div class=\"alert alert-success\">\n",
132 "Enter command mode by pressing `Esc` or using the mouse to click *outside* a cell's editor area.\n",
91 133 "</div>"
92 134 ]
93 135 },
@@ -121,9 +163,9 b''
121 163 "cell_type": "markdown",
122 164 "metadata": {},
123 165 "source": [
124 "The second idea of mouse based navigation is that **cell actions usually apply to the currently selected cell**. Thus if you want to run the code in a cell, you would select it and click the \"Play\" button in the toolbar or the \"Cell:Run\" menu item. Similarly, to copy a cell you would select it and click the \"Copy\" button in the toolbar or the \"Edit:Copy\" menu item. With this simple pattern, you should be able to do most everything you need with the mouse.\n",
166 "The second idea of mouse based navigation is that **cell actions usually apply to the currently selected cell**. Thus if you want to run the code in a cell, you would select it and click the <button><i class=\"icon-play\"></i></button> button in the toolbar or the \"Cell:Run\" menu item. Similarly, to copy a cell you would select it and click the <button><i class=\"icon-copy\"></i></button> button in the toolbar or the \"Edit:Copy\" menu item. With this simple pattern, you should be able to do most everything you need with the mouse.\n",
125 167 "\n",
126 "Markdown and heading cells have one other state that can be modified with the mouse. These cells can either be rendered or unrendered. When they are rendered, you will see a nice formatted representation of the cell's contents. When they are unrendered, you will see the raw text source of the cell. To render the selected cell with the mouse, click the \"Play\" button in the toolbar or the \"Cell:Run\" menu item. To unrender the selected cell, double click on the cell."
168 "Markdown and heading cells have one other state that can be modified with the mouse. These cells can either be rendered or unrendered. When they are rendered, you will see a nice formatted representation of the cell's contents. When they are unrendered, you will see the raw text source of the cell. To render the selected cell with the mouse, click the <button><i class=\"icon-play\"></i></button> button in the toolbar or the \"Cell:Run\" menu item. To unrender the selected cell, double click on the cell."
127 169 ]
128 170 },
129 171 {
@@ -140,100 +182,27 b''
140 182 "source": [
141 183 "The modal user interface of the IPython Notebook has been optimized for efficient keyboard usage. This is made possible by having two different sets of keyboard shortcuts: one set that is active in edit mode and another in command mode.\n",
142 184 "\n",
143 "The most important keyboard shortcuts are `enter`, which enters edit mode, and `esc`, which enters command mode.\n",
185 "The most important keyboard shortcuts are `Enter`, which enters edit mode, and `Esc`, which enters command mode.\n",
144 186 "\n",
145 "In edit mode, most of the keyboard is dedicated to typing into the cell's editor. Thus, in edit mode there are relatively few shortcuts:"
146 ]
147 },
148 {
149 "cell_type": "markdown",
150 "metadata": {},
151 "source": [
152 "The `display_edit_shortcuts()` function used here is defined in the [Utilities section](#Utilities) at the bottom of this notebook."
153 ]
154 },
155 {
156 "cell_type": "code",
157 "collapsed": false,
158 "input": [
159 "display_edit_shortcuts()"
160 ],
161 "language": "python",
162 "metadata": {},
163 "outputs": [
164 {
165 "html": [
166 "<div class=\"hbox\"><div class=\"box-flex0\"><div class=\"quickhelp\"><span class=\"shortcut_key\">esc</span><span class=\"shortcut_descr\"> : command mode</span></div><div class=\"quickhelp\"><span class=\"shortcut_key\">ctrl+m</span><span class=\"shortcut_descr\"> : command mode</span></div><div class=\"quickhelp\"><span class=\"shortcut_key\">shift+enter</span><span class=\"shortcut_descr\"> : run cell</span></div><div class=\"quickhelp\"><span class=\"shortcut_key\">ctrl+enter</span><span class=\"shortcut_descr\"> : run cell, select below</span></div></div><div class=\"box-flex0\"><div class=\"quickhelp\"><span class=\"shortcut_key\">alt+enter</span><span class=\"shortcut_descr\"> : run cell, insert below</span></div><div class=\"quickhelp\"><span class=\"shortcut_key\">alt+-</span><span class=\"shortcut_descr\"> : split cell</span></div><div class=\"quickhelp\"><span class=\"shortcut_key\">meta+s</span><span class=\"shortcut_descr\"> : save notebook</span></div><div class=\"quickhelp\"><span class=\"shortcut_key\">ctrl+s</span><span class=\"shortcut_descr\"> : save notebook</span></div></div></div>"
167 ],
168 "output_type": "display_data"
169 },
170 {
171 "javascript": [
172 "var help = IPython.quick_help.build_edit_help();\n",
173 "help.children().first().remove();\n",
174 "this.append_output({output_type: 'display_data', html: help.html()});"
175 ],
176 "metadata": {},
177 "output_type": "display_data",
178 "text": [
179 "<IPython.core.display.Javascript at 0x10e8d1a50>"
180 ]
181 }
182 ],
183 "prompt_number": 17
184 },
185 {
186 "cell_type": "markdown",
187 "metadata": {},
188 "source": [
189 "There are two other keyboard shortcuts in edit mode that are not listed here:\n",
187 "In edit mode, most of the keyboard is dedicated to typing into the cell's editor. Thus, in edit mode there are relatively few shortcuts:\n",
190 188 "\n",
191 "* `tab`: trigger \"tab\" completion\n",
192 "* `shift+tab`: open the tooltip"
189 "<img src=\"images/edit_shortcuts.png\">"
193 190 ]
194 191 },
195 192 {
196 193 "cell_type": "markdown",
197 194 "metadata": {},
198 195 "source": [
199 "In command mode, the entire keyboard is available for shortcuts:"
196 "In command mode, the entire keyboard is available for shortcuts, so there are many more:\n",
197 "\n",
198 "<img src=\"images/command_shortcuts.png\">"
200 199 ]
201 200 },
202 201 {
203 "cell_type": "code",
204 "collapsed": false,
205 "input": [
206 "display_command_shortcuts()"
207 ],
208 "language": "python",
209 "metadata": {},
210 "outputs": [
211 {
212 "html": [
213 "<div class=\"hbox\"><div class=\"box-flex0\"><div class=\"quickhelp\"><span class=\"shortcut_key\">enter</span><span class=\"shortcut_descr\"> : edit mode</span></div><div class=\"quickhelp\"><span class=\"shortcut_key\">shift+enter</span><span class=\"shortcut_descr\"> : run cell</span></div><div class=\"quickhelp\"><span class=\"shortcut_key\">ctrl+enter</span><span class=\"shortcut_descr\"> : run cell, select below</span></div><div class=\"quickhelp\"><span class=\"shortcut_key\">alt+enter</span><span class=\"shortcut_descr\"> : run cell, insert below</span></div><div class=\"quickhelp\"><span class=\"shortcut_key\">y</span><span class=\"shortcut_descr\"> : to code</span></div><div class=\"quickhelp\"><span class=\"shortcut_key\">m</span><span class=\"shortcut_descr\"> : to markdown</span></div><div class=\"quickhelp\"><span class=\"shortcut_key\">t</span><span class=\"shortcut_descr\"> : to raw</span></div><div class=\"quickhelp\"><span class=\"shortcut_key\">1</span><span class=\"shortcut_descr\"> : to heading 1</span></div><div class=\"quickhelp\"><span class=\"shortcut_key\">2</span><span class=\"shortcut_descr\"> : to heading 2</span></div><div class=\"quickhelp\"><span class=\"shortcut_key\">3</span><span class=\"shortcut_descr\"> : to heading 3</span></div><div class=\"quickhelp\"><span class=\"shortcut_key\">4</span><span class=\"shortcut_descr\"> : to heading 4</span></div><div class=\"quickhelp\"><span class=\"shortcut_key\">5</span><span class=\"shortcut_descr\"> : to heading 5</span></div><div class=\"quickhelp\"><span class=\"shortcut_key\">6</span><span class=\"shortcut_descr\"> : to heading 6</span></div><div class=\"quickhelp\"><span class=\"shortcut_key\">up</span><span class=\"shortcut_descr\"> : select previous cell</span></div><div class=\"quickhelp\"><span class=\"shortcut_key\">down</span><span class=\"shortcut_descr\"> : select next cell</span></div><div class=\"quickhelp\"><span class=\"shortcut_key\">k</span><span class=\"shortcut_descr\"> : select previous cell</span></div><div class=\"quickhelp\"><span class=\"shortcut_key\">j</span><span class=\"shortcut_descr\"> : select next cell</span></div><div class=\"quickhelp\"><span class=\"shortcut_key\">ctrl+k</span><span class=\"shortcut_descr\"> : move cell up</span></div></div><div class=\"box-flex0\"><div class=\"quickhelp\"><span class=\"shortcut_key\">ctrl+j</span><span class=\"shortcut_descr\"> : move cell down</span></div><div class=\"quickhelp\"><span class=\"shortcut_key\">a</span><span class=\"shortcut_descr\"> : insert cell above</span></div><div class=\"quickhelp\"><span class=\"shortcut_key\">b</span><span class=\"shortcut_descr\"> : insert cell below</span></div><div class=\"quickhelp\"><span class=\"shortcut_key\">x</span><span class=\"shortcut_descr\"> : cut cell</span></div><div class=\"quickhelp\"><span class=\"shortcut_key\">c</span><span class=\"shortcut_descr\"> : copy cell</span></div><div class=\"quickhelp\"><span class=\"shortcut_key\">v</span><span class=\"shortcut_descr\"> : paste cell below</span></div><div class=\"quickhelp\"><span class=\"shortcut_key\">z</span><span class=\"shortcut_descr\"> : undo last delete</span></div><div class=\"quickhelp\"><span class=\"shortcut_key\">d</span><span class=\"shortcut_descr\"> : delete cell (press twice)</span></div><div class=\"quickhelp\"><span class=\"shortcut_key\">shift+=</span><span class=\"shortcut_descr\"> : merge cell below</span></div><div class=\"quickhelp\"><span class=\"shortcut_key\">s</span><span class=\"shortcut_descr\"> : save notebook</span></div><div class=\"quickhelp\"><span class=\"shortcut_key\">meta+s</span><span class=\"shortcut_descr\"> : save notebook</span></div><div class=\"quickhelp\"><span class=\"shortcut_key\">ctrl+s</span><span class=\"shortcut_descr\"> : save notebook</span></div><div class=\"quickhelp\"><span class=\"shortcut_key\">l</span><span class=\"shortcut_descr\"> : toggle line numbers</span></div><div class=\"quickhelp\"><span class=\"shortcut_key\">o</span><span class=\"shortcut_descr\"> : toggle output</span></div><div class=\"quickhelp\"><span class=\"shortcut_key\">shift+o</span><span class=\"shortcut_descr\"> : toggle output</span></div><div class=\"quickhelp\"><span class=\"shortcut_key\">h</span><span class=\"shortcut_descr\"> : keyboard shortcuts</span></div><div class=\"quickhelp\"><span class=\"shortcut_key\">i</span><span class=\"shortcut_descr\"> : interrupt kernel</span></div><div class=\"quickhelp\"><span class=\"shortcut_key\">.</span><span class=\"shortcut_descr\"> : restart kernel</span></div></div></div>"
214 ],
215 "output_type": "display_data"
216 },
217 {
218 "javascript": [
219 "var help = IPython.quick_help.build_command_help();\n",
220 "help.children().first().remove();\n",
221 "this.append_output({output_type: 'display_data', html: help.html()});"
222 ],
223 "metadata": {},
224 "output_type": "display_data",
225 "text": [
226 "<IPython.core.display.Javascript at 0x10e8d1650>"
227 ]
228 }
229 ],
230 "prompt_number": 18
231 },
232 {
233 202 "cell_type": "markdown",
234 203 "metadata": {},
235 204 "source": [
236 "Here the rough order in which we recommend learning the command mode shortcuts:\n",
205 "We recommend learning the command mode shortcuts in the following rough order:\n",
237 206 "\n",
238 207 "1. Basic navigation: `enter`, `shift-enter`, `up/k`, `down/j`\n",
239 208 "2. Saving the notebook: `s`\n",
@@ -248,195 +217,25 b''
248 217 "level": 2,
249 218 "metadata": {},
250 219 "source": [
251 "Keyboard shortcut customization"
220 "Cell types"
252 221 ]
253 222 },
254 223 {
255 224 "cell_type": "markdown",
256 225 "metadata": {},
257 226 "source": [
258 "Starting with IPython 2.0 keyboard shortcuts in command and edit mode are fully customizable. These customizations are made using the IPython JavaScript API. Here is an example that makes the `r` key available for running a cell:"
259 ]
260 },
261 {
262 "cell_type": "code",
263 "collapsed": false,
264 "input": [
265 "%%javascript\n",
227 "The notebook UI and notebook documents are a linear sequence of cells. There are four cell types:\n",
266 228 "\n",
267 "IPython.keyboard_manager.command_shortcuts.add_shortcut('r', {\n",
268 " help : 'run cell',\n",
269 " help_index : 'zz',\n",
270 " handler : function (event) {\n",
271 " IPython.notebook.execute_cell();\n",
272 " return false;\n",
273 " }}\n",
274 ");"
275 ],
276 "language": "python",
277 "metadata": {},
278 "outputs": [
279 {
280 "javascript": [
281 "\n",
282 "IPython.keyboard_manager.command_shortcuts.add_shortcut('r', {\n",
283 " help : 'run cell',\n",
284 " help_index : 'zz',\n",
285 " handler : function (event) {\n",
286 " IPython.notebook.execute_cell();\n",
287 " return false;\n",
288 " }}\n",
289 ");"
290 ],
291 "metadata": {},
292 "output_type": "display_data",
293 "text": [
294 "<IPython.core.display.Javascript at 0x10e8d1890>"
295 ]
296 }
297 ],
298 "prompt_number": 7
299 },
300 {
301 "cell_type": "markdown",
302 "metadata": {},
303 "source": [
304 "There are a couple of points to mention about this API:\n",
229 "* **Code cells:** Input and output of live code that is run in the kernel\n",
230 "* **Markdown cells:** Narrative text with embedded LaTeX equations\n",
231 "* **Heading cells:** 6 levels of hierarchical organization and formatting\n",
232 "* **Raw cells:** Unformatted text that is included, without modification, when notebooks are converted to different formats using nbconvert\n",
305 233 "\n",
306 "* The `help_index` field is used to sort the shortcuts in the Keyboard Shortcuts help dialog. It defaults to `zz`.\n",
307 "* When a handler returns `false` it indicates that the event should stop propagating and the default action should not be performed. For further details about the `event` object or event handling, see the jQuery docs.\n",
308 "* If you don't need a `help` or `help_index` field, you can simply pass a function as the second argument to `add_shortcut`."
309 ]
310 },
311 {
312 "cell_type": "code",
313 "collapsed": false,
314 "input": [
315 "%%javascript\n",
234 "More information about code and Markdown cell can be found in these tutorials:\n",
316 235 "\n",
317 "IPython.keyboard_manager.command_shortcuts.add_shortcut('r', function (event) {\n",
318 " IPython.notebook.execute_cell();\n",
319 " return false;\n",
320 "});"
321 ],
322 "language": "python",
323 "metadata": {},
324 "outputs": [
325 {
326 "javascript": [
327 "\n",
328 "IPython.keyboard_manager.command_shortcuts.add_shortcut('r', function (event) {\n",
329 " IPython.notebook.execute_cell();\n",
330 " return false;\n",
331 "});"
332 ],
333 "metadata": {},
334 "output_type": "display_data",
335 "text": [
336 "<IPython.core.display.Javascript at 0x1019baf90>"
337 ]
338 }
339 ],
340 "prompt_number": 11
341 },
342 {
343 "cell_type": "markdown",
344 "metadata": {},
345 "source": [
346 "Likewise, to remove a shortcut, use `remove_shortcut`:"
236 "* [Working With Code Cells](Working With Code Cells.ipynb)\n",
237 "* [Working With Markdown Cells](Working With Markdown Cells.ipynb)"
347 238 ]
348 },
349 {
350 "cell_type": "code",
351 "collapsed": false,
352 "input": [
353 "%%javascript\n",
354 "\n",
355 "IPython.keyboard_manager.command_shortcuts.remove_shortcut('r');"
356 ],
357 "language": "python",
358 "metadata": {},
359 "outputs": [
360 {
361 "javascript": [
362 "\n",
363 "IPython.keyboard_manager.command_shortcuts.remove_shortcut('r');"
364 ],
365 "metadata": {},
366 "output_type": "display_data",
367 "text": [
368 "<IPython.core.display.Javascript at 0x10e8d1950>"
369 ]
370 }
371 ],
372 "prompt_number": 8
373 },
374 {
375 "cell_type": "markdown",
376 "metadata": {},
377 "source": [
378 "If you want your keyboard shortcuts to be active for all of your notebooks, put the above API calls into your `<profile>/static/custom/custom.js` file."
379 ]
380 },
381 {
382 "cell_type": "heading",
383 "level": 2,
384 "metadata": {},
385 "source": [
386 "Utilities"
387 ]
388 },
389 {
390 "cell_type": "markdown",
391 "metadata": {},
392 "source": [
393 "We use the following functions to generate the keyboard shortcut listings above."
394 ]
395 },
396 {
397 "cell_type": "code",
398 "collapsed": false,
399 "input": [
400 "from IPython.display import Javascript, display, HTML\n",
401 "\n",
402 "t = \"\"\"var help = IPython.quick_help.build_{0}_help();\n",
403 "help.children().first().remove();\n",
404 "this.append_output({{output_type: 'display_data', html: help.html()}});\"\"\"\n",
405 "\n",
406 "def display_command_shortcuts():\n",
407 " display(Javascript(t.format('command')))\n",
408 "\n",
409 "def display_edit_shortcuts():\n",
410 " display(Javascript(t.format('edit')))\n",
411 "\n",
412 "display(HTML(\"\"\"\n",
413 "<style>\n",
414 ".shortcut_key {display: inline-block; width: 15ex; text-align: right; font-family: monospace;}\n",
415 ".shortcut_descr {display: inline-block;}\n",
416 "div.quickhelp {float: none; width: 100%;}\n",
417 "</style>\n",
418 "\"\"\"))"
419 ],
420 "language": "python",
421 "metadata": {},
422 "outputs": [
423 {
424 "html": [
425 "\n",
426 "<style>\n",
427 ".shortcut_key {display: inline-block; width: 15ex; text-align: right; font-family: monospace;}\n",
428 ".shortcut_descr {display: inline-block;}\n",
429 "div.quickhelp {float: none; width: 100%;}\n",
430 "</style>\n"
431 ],
432 "metadata": {},
433 "output_type": "display_data",
434 "text": [
435 "<IPython.core.display.HTML at 0x10e8b0710>"
436 ]
437 }
438 ],
439 "prompt_number": 16
440 239 }
441 240 ],
442 241 "metadata": {}
@@ -1,7 +1,7 b''
1 1 {
2 2 "metadata": {
3 3 "name": "",
4 "signature": "sha256:3676a017d63581291cf2d61ea56d09cb3e5480a4f222184d8216e3e829eb4871"
4 "signature": "sha256:1fd1c67d342de34c5edf43789ce56f80963eda3662752e7d9cbc97ac54848be8"
5 5 },
6 6 "nbformat": 3,
7 7 "nbformat_minor": 0,
@@ -112,7 +112,7 b''
112 112 "\n",
113 113 "* **Code cells:** Input and output of live code that is run in the kernel\n",
114 114 "* **Markdown cells:** Narrative text with embedded LaTeX equations\n",
115 "* **Heading cells:** 6 levels of hierarchical organization\n",
115 "* **Heading cells:** 6 levels of hierarchical organization and formatting\n",
116 116 "* **Raw cells:** Unformatted text that is included, without modification, when notebooks are converted to different formats using nbconvert\n",
117 117 "\n",
118 118 "Internally, notebook documents are [JSON](http://en.wikipedia.org/wiki/JSO) data with binary values [base64](http://en.wikipedia.org/wiki/Base64) encoded. This allows them to be read and manipulated programmatically by any programming language. Because JSON is a text format, notebook documents are version control friendly.\n",
1 NO CONTENT: file was removed
General Comments 0
You need to be logged in to leave comments. Login now