From 471dccada3a0c9ad4cd44a581c4b8c460d26af0b Mon Sep 17 00:00:00 2001 From: Tal Einat Date: Tue, 6 Aug 2019 00:02:26 +0300 Subject: [PATCH] bpo-37768: IDLE: show help(object) output in a text viewing window --- Lib/idlelib/pyshell.py | 19 ++++++++++++++----- Lib/idlelib/run.py | 5 ++--- .../2019-08-05-23-58-03.bpo-37768.dM-QL8.rst | 2 ++ 3 files changed, 18 insertions(+), 8 deletions(-) create mode 100644 Misc/NEWS.d/next/IDLE/2019-08-05-23-58-03.bpo-37768.dM-QL8.rst diff --git a/Lib/idlelib/pyshell.py b/Lib/idlelib/pyshell.py index ea9465568bd93f..702ea0c624ee4a 100755 --- a/Lib/idlelib/pyshell.py +++ b/Lib/idlelib/pyshell.py @@ -55,6 +55,7 @@ from idlelib.outwin import OutputWindow from idlelib import rpc from idlelib.run import idle_formatwarning, PseudoInputFile, PseudoOutputFile +from idlelib.textview import view_text from idlelib.undo import UndoDelegator HOST = '127.0.0.1' # python execution server on localhost loopback @@ -906,11 +907,9 @@ def __init__(self, flist=None): sys.stderr = self.stderr sys.stdin = self.stdin try: - # page help() text to shell. - import pydoc # import must be done here to capture i/o rebinding. - # XXX KBK 27Dec07 use text viewer someday, but must work w/o subproc - pydoc.pager = pydoc.plainpager - except: + import pydoc # import must be done here to capture i/o rebinding. + pydoc.pager = self.pager + except Exception: sys.stderr = sys.__stderr__ raise # @@ -918,6 +917,16 @@ def __init__(self, flist=None): # self.pollinterval = 50 # millisec + def pager(self, text): + """pydoc.pager compatible callback for showing help() output.""" + import pydoc # Import here to avoid i/o binding issues. + text = pydoc.plain(text) # Remove fancy pydoc formatting. + try: + title, text = text.split(':\n\n', 1) + except ValueError: + title = "Help" + view_text(self.text, title, text, modal=False) + def get_standard_extension_names(self): return idleConf.GetExtensions(shell_only=True) diff --git a/Lib/idlelib/run.py b/Lib/idlelib/run.py index 41e0ded4402937..de33ecbca6dd91 100644 --- a/Lib/idlelib/run.py +++ b/Lib/idlelib/run.py @@ -503,9 +503,8 @@ def handle(self): iomenu.encoding) sys.displayhook = rpc.displayhook - # page help() text to shell. - import pydoc # import must be done here to capture i/o binding - pydoc.pager = pydoc.plainpager + import pydoc # import must be done here to capture i/o binding + pydoc.pager = self.console.pager # Keep a reference to stdin so that it won't try to exit IDLE if # sys.stdin gets changed from within IDLE's shell. See issue17838. diff --git a/Misc/NEWS.d/next/IDLE/2019-08-05-23-58-03.bpo-37768.dM-QL8.rst b/Misc/NEWS.d/next/IDLE/2019-08-05-23-58-03.bpo-37768.dM-QL8.rst new file mode 100644 index 00000000000000..9d7ef892fe0961 --- /dev/null +++ b/Misc/NEWS.d/next/IDLE/2019-08-05-23-58-03.bpo-37768.dM-QL8.rst @@ -0,0 +1,2 @@ +``help(object)`` now shows the help text in a separate text viewing window +rather than in the shell output.