##// END OF EJS Templates
pager payload is a mime-bundle
MinRK -
Show More
@@ -152,6 +152,10 b' def page(strng, start=0, screen_lines=0, pager_cmd=None):'
152 152 If no system pager works, the string is sent through a 'dumb pager'
153 153 written in python, very simplistic.
154 154 """
155
156 # for compatibility with mime-bundle form:
157 if isinstance(strng, dict):
158 strng = strng['text/plain']
155 159
156 160 # Some routines may auto-compute start offsets incorrectly and pass a
157 161 # negative value. Offset to 0 for robustness.
@@ -1,41 +1,16 b''
1 1 # encoding: utf-8
2 """
3 A payload based version of page.
2 """A payload based version of page."""
4 3
5 Authors:
4 # Copyright (c) IPython Development Team.
5 # Distributed under the terms of the Modified BSD License.
6 6
7 * Brian Granger
8 * Fernando Perez
9 """
10
11 #-----------------------------------------------------------------------------
12 # Copyright (C) 2008-2011 The IPython Development Team
13 #
14 # Distributed under the terms of the BSD License. The full license is in
15 # the file COPYING, distributed as part of this software.
16 #-----------------------------------------------------------------------------
17
18 #-----------------------------------------------------------------------------
19 # Imports
20 #-----------------------------------------------------------------------------
21
22 # Third-party
23 try:
24 from docutils.core import publish_string
25 except ImportError:
26 # html paging won't be available, but we don't raise any errors. It's a
27 # purely optional feature.
28 pass
29
30 # Our own
31 from IPython.core.interactiveshell import InteractiveShell
7 from IPython.core.getipython import get_ipython
32 8
33 9 #-----------------------------------------------------------------------------
34 10 # Classes and functions
35 11 #-----------------------------------------------------------------------------
36 12
37 def page(strng, start=0, screen_lines=0, pager_cmd=None,
38 html=None, auto_html=False):
13 def page(strng, start=0, screen_lines=0, pager_cmd=None):
39 14 """Print a string, piping through a pager.
40 15
41 16 This version ignores the screen_lines and pager_cmd arguments and uses
@@ -43,49 +18,28 b' def page(strng, start=0, screen_lines=0, pager_cmd=None,'
43 18
44 19 Parameters
45 20 ----------
46 strng : str
47 Text to page.
21 strng : str or mime-dict
22 Text to page, or a mime-type keyed dict of already formatted data.
48 23
49 24 start : int
50 25 Starting line at which to place the display.
51
52 html : str, optional
53 If given, an html string to send as well.
54
55 auto_html : bool, optional
56 If true, the input string is assumed to be valid reStructuredText and is
57 converted to HTML with docutils. Note that if docutils is not found,
58 this option is silently ignored.
59
60 Notes
61 -----
62
63 Only one of the ``html`` and ``auto_html`` options can be given, not
64 both.
65 26 """
66 27
67 28 # Some routines may auto-compute start offsets incorrectly and pass a
68 29 # negative value. Offset to 0 for robustness.
69 30 start = max(0, start)
70 shell = InteractiveShell.instance()
71
72 if auto_html:
73 try:
74 # These defaults ensure user configuration variables for docutils
75 # are not loaded, only our config is used here.
76 defaults = {'file_insertion_enabled': 0,
77 'raw_enabled': 0,
78 '_disable_config': 1}
79 html = publish_string(strng, writer_name='html',
80 settings_overrides=defaults)
81 except:
82 pass
83
31 shell = get_ipython()
32
33 if isinstance(strng, dict):
34 data = strng
35 else:
36 data = {'text/plain' : strng}
84 37 payload = dict(
85 38 source='page',
39 data=data,
86 40 text=strng,
87 html=html,
88 start_line_number=start
41 start=start,
42 screen_lines=screen_lines,
89 43 )
90 44 shell.payload_manager.write_payload(payload)
91 45
@@ -1,9 +1,5 b''
1 //----------------------------------------------------------------------------
2 // Copyright (C) 2008-2011 The IPython Development Team
3 //
4 // Distributed under the terms of the BSD License. The full license is in
5 // the file COPYING, distributed as part of this software.
6 //----------------------------------------------------------------------------
1 // Copyright (c) IPython Development Team.
2 // Distributed under the terms of the Modified BSD License.
7 3
8 4 //============================================================================
9 5 // Pager
@@ -81,12 +77,18 b' var IPython = (function (IPython) {'
81 77 var that = this;
82 78
83 79 this.pager_element.bind('collapse_pager', function (event, extrap) {
84 var time = (extrap != undefined) ? ((extrap.duration != undefined ) ? extrap.duration : 'fast') : 'fast';
80 var time = 'fast';
81 if (extrap && extrap.duration) {
82 time = extrap.duration;
83 }
85 84 that.pager_element.hide(time);
86 85 });
87 86
88 87 this.pager_element.bind('expand_pager', function (event, extrap) {
89 var time = (extrap != undefined) ? ((extrap.duration != undefined ) ? extrap.duration : 'fast') : 'fast';
88 var time = 'fast';
89 if (extrap && extrap.duration) {
90 time = extrap.duration;
91 }
90 92 that.pager_element.show(time);
91 93 });
92 94
@@ -103,12 +105,13 b' var IPython = (function (IPython) {'
103 105 that.toggle();
104 106 });
105 107
106 $([IPython.events]).on('open_with_text.Pager', function (event, data) {
107 if (data.text.trim() !== '') {
108 $([IPython.events]).on('open_with_text.Pager', function (event, payload) {
109 // FIXME: support other mime types
110 if (payload.data['text/plain'] && payload.data['text/plain'] !== "") {
108 111 that.clear();
109 112 that.expand();
110 that.append_text(data.text);
111 };
113 that.append_text(payload.data['text/plain']);
114 }
112 115 });
113 116 };
114 117
@@ -117,7 +120,7 b' var IPython = (function (IPython) {'
117 120 if (this.expanded === true) {
118 121 this.expanded = false;
119 122 this.pager_element.add($('div#notebook')).trigger('collapse_pager', extrap);
120 };
123 }
121 124 };
122 125
123 126
@@ -125,7 +128,7 b' var IPython = (function (IPython) {'
125 128 if (this.expanded !== true) {
126 129 this.expanded = true;
127 130 this.pager_element.add($('div#notebook')).trigger('expand_pager', extrap);
128 };
131 }
129 132 };
130 133
131 134
@@ -134,7 +137,7 b' var IPython = (function (IPython) {'
134 137 this.collapse();
135 138 } else {
136 139 this.expand();
137 };
140 }
138 141 };
139 142
140 143
@@ -160,8 +163,7 b' var IPython = (function (IPython) {'
160 163 pager_body.append(this.pager_element.clone().children());
161 164 w.document.close();
162 165 this.collapse();
163
164 }
166 };
165 167
166 168 Pager.prototype.append_text = function (text) {
167 169 // The only user content injected with this HTML call is escaped by
@@ -532,10 +532,11 b' class IPythonWidget(FrontendWidget):'
532 532 # Since the plain text widget supports only a very small subset of HTML
533 533 # and we have no control over the HTML source, we only page HTML
534 534 # payloads in the rich text widget.
535 if item['html'] and self.kind == 'rich':
536 self._page(item['html'], html=True)
535 data = item['data']
536 if 'text/html' in data and self.kind == 'rich':
537 self._page(data['text/html'], html=True)
537 538 else:
538 self._page(item['text'], html=False)
539 self._page(data['text/plain'], html=False)
539 540
540 541 #------ Trait change handlers --------------------------------------------
541 542
@@ -206,11 +206,13 b' class ZMQTerminalInteractiveShell(TerminalInteractiveShell):'
206 206 self.write('Aborted\n')
207 207 return
208 208 elif status == 'ok':
209 # print execution payloads as well:
209 # handle payloads
210 210 for item in content["payload"]:
211 text = item.get('text', None)
212 if text:
213 page.page(text)
211 source = item['source']
212 if source == 'page':
213 page.page(item['data']['text/plain'])
214 elif source == 'set_next_input':
215 self.set_next_input(item['text'])
214 216
215 217 elif status == 'error':
216 218 for frame in content["traceback"]:
General Comments 0
You need to be logged in to leave comments. Login now