##// END OF EJS Templates
Paging using payloads now works.
Brian Granger -
Show More
@@ -0,0 +1,50 b''
1 #!/usr/bin/env python
2 # encoding: utf-8
3 """
4 A payload based version of page.
5
6 Authors:
7
8 * Brian Granger
9 * Fernando Perez
10 """
11
12 #-----------------------------------------------------------------------------
13 # Copyright (C) 2008-2010 The IPython Development Team
14 #
15 # Distributed under the terms of the BSD License. The full license is in
16 # the file COPYING, distributed as part of this software.
17 #-----------------------------------------------------------------------------
18
19 #-----------------------------------------------------------------------------
20 # Imports
21 #-----------------------------------------------------------------------------
22
23 from IPython.core.interactiveshell import InteractiveShell
24
25 #-----------------------------------------------------------------------------
26 # Classes and functions
27 #-----------------------------------------------------------------------------
28
29 def page(strng, start=0, screen_lines=0, pager_cmd=None):
30 """Print a string, piping through a pager.
31
32 This version ignores the screen_lines and pager_cmd arguments and uses
33 IPython's payload system instead.
34 """
35
36 # Some routines may auto-compute start offsets incorrectly and pass a
37 # negative value. Offset to 0 for robustness.
38 start = max(0, start)
39 shell = InteractiveShell.instance()
40 payload = dict(
41 source='IPython.zmq.page.page',
42 data=strng,
43 start_line_number=start
44 )
45 shell.payload_manager.write_payload(payload)
46
47 def install_payload_page():
48 """Install this version of page as IPython.core.page.page."""
49 from IPython.core import page as corepage
50 corepage.page = page
@@ -1901,9 +1901,6 b' class InteractiveShell(Configurable, Magic):'
1901 - 1: an error occurred.
1901 - 1: an error occurred.
1902 """
1902 """
1903
1903
1904 # Clear the payload before executing new code.
1905 self.payload_manager.clear_payload()
1906
1907 # Set our own excepthook in case the user code tries to call it
1904 # Set our own excepthook in case the user code tries to call it
1908 # directly, so that the IPython crash handler doesn't get triggered
1905 # directly, so that the IPython crash handler doesn't get triggered
1909 old_excepthook,sys.excepthook = sys.excepthook, self.excepthook
1906 old_excepthook,sys.excepthook = sys.excepthook, self.excepthook
@@ -52,7 +52,7 b' from IPython.core.error import TryNext'
52 from IPython.core.error import UsageError
52 from IPython.core.error import UsageError
53 from IPython.core.fakemodule import FakeModule
53 from IPython.core.fakemodule import FakeModule
54 from IPython.core.macro import Macro
54 from IPython.core.macro import Macro
55 from IPython.core.page import page
55 from IPython.core import page
56 from IPython.core.prefilter import ESC_MAGIC
56 from IPython.core.prefilter import ESC_MAGIC
57 from IPython.lib.pylabtools import mpl_runner
57 from IPython.lib.pylabtools import mpl_runner
58 from IPython.lib.inputhook import enable_gui
58 from IPython.lib.inputhook import enable_gui
@@ -514,7 +514,7 b' Currently the magic system has the following functions:\\n"""'
514 (' '+mesc).join(self.lsmagic()),
514 (' '+mesc).join(self.lsmagic()),
515 Magic.auto_status[self.shell.automagic] ) )
515 Magic.auto_status[self.shell.automagic] ) )
516
516
517 page(outmsg,screen_lines=self.shell.usable_screen_length)
517 page.page(outmsg,screen_lines=self.shell.usable_screen_length)
518
518
519
519
520 def magic_autoindent(self, parameter_s = ''):
520 def magic_autoindent(self, parameter_s = ''):
@@ -656,7 +656,7 b' Currently the magic system has the following functions:\\n"""'
656 info = self._ofind(oname)
656 info = self._ofind(oname)
657 if info['found']:
657 if info['found']:
658 txt = (raw and str or pformat)( info['obj'] )
658 txt = (raw and str or pformat)( info['obj'] )
659 page(txt)
659 page.page(txt)
660 else:
660 else:
661 print 'Object `%s` not found' % oname
661 print 'Object `%s` not found' % oname
662
662
@@ -727,7 +727,7 b' Currently the magic system has the following functions:\\n"""'
727 except IOError,msg:
727 except IOError,msg:
728 print msg
728 print msg
729 return
729 return
730 page(self.shell.inspector.format(file(filename).read()))
730 page.page(self.shell.inspector.format(file(filename).read()))
731
731
732 def _inspect(self,meth,oname,namespaces=None,**kw):
732 def _inspect(self,meth,oname,namespaces=None,**kw):
733 """Generic interface to the inspector system.
733 """Generic interface to the inspector system.
@@ -1520,7 +1520,7 b' Currently the magic system has the following functions:\\n"""'
1520 output = stdout_trap.getvalue()
1520 output = stdout_trap.getvalue()
1521 output = output.rstrip()
1521 output = output.rstrip()
1522
1522
1523 page(output,screen_lines=self.shell.usable_screen_length)
1523 page.page(output,screen_lines=self.shell.usable_screen_length)
1524 print sys_exit,
1524 print sys_exit,
1525
1525
1526 dump_file = opts.D[0]
1526 dump_file = opts.D[0]
@@ -3256,7 +3256,7 b' Defaulting color scheme to \'NoColor\'"""'
3256 print "Error: no such file or variable"
3256 print "Error: no such file or variable"
3257 return
3257 return
3258
3258
3259 page(self.shell.pycolorize(cont),
3259 page.page(self.shell.pycolorize(cont),
3260 screen_lines=self.shell.usable_screen_length)
3260 screen_lines=self.shell.usable_screen_length)
3261
3261
3262 def _rerun_pasted(self):
3262 def _rerun_pasted(self):
@@ -3413,7 +3413,7 b' Defaulting color scheme to \'NoColor\'"""'
3413 import IPython.core.usage
3413 import IPython.core.usage
3414 qr = IPython.core.usage.quick_reference + self.magic_magic('-brief')
3414 qr = IPython.core.usage.quick_reference + self.magic_magic('-brief')
3415
3415
3416 page(qr)
3416 page.page(qr)
3417
3417
3418 def magic_doctest_mode(self,parameter_s=''):
3418 def magic_doctest_mode(self,parameter_s=''):
3419 """Toggle doctest mode on and off.
3419 """Toggle doctest mode on and off.
@@ -27,7 +27,7 b' import sys'
27 import types
27 import types
28
28
29 # IPython's own
29 # IPython's own
30 from IPython.core.page import page
30 from IPython.core import page
31 from IPython.external.Itpl import itpl
31 from IPython.external.Itpl import itpl
32 from IPython.utils import PyColorize
32 from IPython.utils import PyColorize
33 import IPython.utils.io
33 import IPython.utils.io
@@ -281,7 +281,7 b' class Inspector:'
281 if output is None:
281 if output is None:
282 self.noinfo('documentation',oname)
282 self.noinfo('documentation',oname)
283 return
283 return
284 page(output)
284 page.page(output)
285
285
286 def psource(self,obj,oname=''):
286 def psource(self,obj,oname=''):
287 """Print the source code for an object."""
287 """Print the source code for an object."""
@@ -293,7 +293,7 b' class Inspector:'
293 except:
293 except:
294 self.noinfo('source',oname)
294 self.noinfo('source',oname)
295 else:
295 else:
296 page(self.format(src))
296 page.page(self.format(src))
297
297
298 def pfile(self,obj,oname=''):
298 def pfile(self,obj,oname=''):
299 """Show the whole file where an object was defined."""
299 """Show the whole file where an object was defined."""
@@ -325,7 +325,7 b' class Inspector:'
325 # Print only text files, not extension binaries. Note that
325 # Print only text files, not extension binaries. Note that
326 # getsourcelines returns lineno with 1-offset and page() uses
326 # getsourcelines returns lineno with 1-offset and page() uses
327 # 0-offset, so we must adjust.
327 # 0-offset, so we must adjust.
328 page(self.format(open(ofile).read()),lineno-1)
328 page.page(self.format(open(ofile).read()),lineno-1)
329
329
330 def pinfo(self,obj,oname='',formatter=None,info=None,detail_level=0):
330 def pinfo(self,obj,oname='',formatter=None,info=None,detail_level=0):
331 """Show detailed information about an object.
331 """Show detailed information about an object.
@@ -548,7 +548,7 b' class Inspector:'
548 # Finally send to printer/pager
548 # Finally send to printer/pager
549 output = out.getvalue()
549 output = out.getvalue()
550 if output:
550 if output:
551 page(output)
551 page.page(output)
552 # end pinfo
552 # end pinfo
553
553
554 def psearch(self,pattern,ns_table,ns_search=[],
554 def psearch(self,pattern,ns_table,ns_search=[],
@@ -606,4 +606,4 b' class Inspector:'
606 search_result.extend(tmp_res)
606 search_result.extend(tmp_res)
607 search_result.sort()
607 search_result.sort()
608
608
609 page('\n'.join(search_result))
609 page.page('\n'.join(search_result))
@@ -33,7 +33,7 b' from IPython.core.alias import AliasManager'
33 from IPython.core.autocall import IPyAutocall
33 from IPython.core.autocall import IPyAutocall
34 from IPython.config.configurable import Configurable
34 from IPython.config.configurable import Configurable
35 from IPython.core.splitinput import split_user_input
35 from IPython.core.splitinput import split_user_input
36 from IPython.core.page import page
36 from IPython.core import page
37
37
38 from IPython.utils.traitlets import List, Int, Any, Str, CBool, Bool, Instance
38 from IPython.utils.traitlets import List, Int, Any, Str, CBool, Bool, Instance
39 import IPython.utils.io
39 import IPython.utils.io
@@ -960,7 +960,7 b' class HelpHandler(PrefilterHandler):'
960 #print 'line:<%r>' % line # dbg
960 #print 'line:<%r>' % line # dbg
961 self.shell.magic_pinfo(line)
961 self.shell.magic_pinfo(line)
962 else:
962 else:
963 page(self.shell.usage, screen_lines=self.shell.usable_screen_length)
963 page.page(self.shell.usage, screen_lines=self.shell.usable_screen_length)
964 return '' # Empty string is needed here!
964 return '' # Empty string is needed here!
965 except:
965 except:
966 raise
966 raise
@@ -17,7 +17,7 b" __all__ = ['Gnuplot','gp','gp_new','plot','plot2','splot','replot',"
17
17
18 import IPython.GnuplotRuntime as GRun
18 import IPython.GnuplotRuntime as GRun
19 from IPython.utils.genutils import warn
19 from IPython.utils.genutils import warn
20 from IPython.core.page import page
20 from IPython.core import page
21
21
22 # Set global names for interactive use
22 # Set global names for interactive use
23 Gnuplot = GRun.Gnuplot
23 Gnuplot = GRun.Gnuplot
@@ -98,6 +98,10 b' class RichIPythonWidget(IPythonWidget):'
98 else:
98 else:
99 cmd = 'mate -l %s %s' % (line_number, filename)
99 cmd = 'mate -l %s %s' % (line_number, filename)
100 os.system(cmd)
100 os.system(cmd)
101 elif item['source'] == 'IPython.zmq.page.page':
102 # TODO: This is probably a good place to start, but Evan can
103 # add better paging capabilities.
104 self._append_plain_text(item['data'])
101 else:
105 else:
102 # Add other payload types here!
106 # Add other payload types here!
103 pass
107 pass
@@ -13,6 +13,11 b' from IPython.utils.text import StringTypes'
13 from IPython.utils.traitlets import Instance, Type, Dict
13 from IPython.utils.traitlets import Instance, Type, Dict
14 from IPython.utils.warn import warn
14 from IPython.utils.warn import warn
15 from IPython.zmq.session import extract_header
15 from IPython.zmq.session import extract_header
16 from IPython.core.payloadpage import install_payload_page
17
18
19 # Install the payload version of page.
20 install_payload_page()
16
21
17
22
18 class ZMQDisplayHook(DisplayHook):
23 class ZMQDisplayHook(DisplayHook):
General Comments 0
You need to be logged in to leave comments. Login now