Skip to content

Commit 471dcca

Browse files
committed
bpo-37768: IDLE: show help(object) output in a text viewing window
1 parent daa82d0 commit 471dcca

File tree

3 files changed

+18
-8
lines changed

3 files changed

+18
-8
lines changed

Lib/idlelib/pyshell.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
from idlelib.outwin import OutputWindow
5656
from idlelib import rpc
5757
from idlelib.run import idle_formatwarning, PseudoInputFile, PseudoOutputFile
58+
from idlelib.textview import view_text
5859
from idlelib.undo import UndoDelegator
5960

6061
HOST = '127.0.0.1' # python execution server on localhost loopback
@@ -906,18 +907,26 @@ def __init__(self, flist=None):
906907
sys.stderr = self.stderr
907908
sys.stdin = self.stdin
908909
try:
909-
# page help() text to shell.
910-
import pydoc # import must be done here to capture i/o rebinding.
911-
# XXX KBK 27Dec07 use text viewer someday, but must work w/o subproc
912-
pydoc.pager = pydoc.plainpager
913-
except:
910+
import pydoc # import must be done here to capture i/o rebinding.
911+
pydoc.pager = self.pager
912+
except Exception:
914913
sys.stderr = sys.__stderr__
915914
raise
916915
#
917916
self.history = self.History(self.text)
918917
#
919918
self.pollinterval = 50 # millisec
920919

920+
def pager(self, text):
921+
"""pydoc.pager compatible callback for showing help() output."""
922+
import pydoc # Import here to avoid i/o binding issues.
923+
text = pydoc.plain(text) # Remove fancy pydoc formatting.
924+
try:
925+
title, text = text.split(':\n\n', 1)
926+
except ValueError:
927+
title = "Help"
928+
view_text(self.text, title, text, modal=False)
929+
921930
def get_standard_extension_names(self):
922931
return idleConf.GetExtensions(shell_only=True)
923932

Lib/idlelib/run.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -503,9 +503,8 @@ def handle(self):
503503
iomenu.encoding)
504504

505505
sys.displayhook = rpc.displayhook
506-
# page help() text to shell.
507-
import pydoc # import must be done here to capture i/o binding
508-
pydoc.pager = pydoc.plainpager
506+
import pydoc # import must be done here to capture i/o binding
507+
pydoc.pager = self.console.pager
509508

510509
# Keep a reference to stdin so that it won't try to exit IDLE if
511510
# sys.stdin gets changed from within IDLE's shell. See issue17838.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
``help(object)`` now shows the help text in a separate text viewing window
2+
rather than in the shell output.

0 commit comments

Comments
 (0)