Skip to content

Commit 321f28c

Browse files
bpo-1529353: IDLE: squeeze large output in the shell (GH-7626)
(cherry picked from commit 604e7b9) Co-authored-by: Tal Einat <[email protected]>
1 parent db23206 commit 321f28c

11 files changed

+974
-29
lines changed

Lib/idlelib/config-main.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ font-size= 10
6666
font-bold= 0
6767
encoding= none
6868

69+
[PyShell]
70+
auto-squeeze-min-lines= 50
71+
6972
[Indent]
7073
use-spaces= 1
7174
num-spaces= 4

Lib/idlelib/configdialog.py

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,12 @@
3030
from idlelib.codecontext import CodeContext
3131
from idlelib.parenmatch import ParenMatch
3232
from idlelib.paragraph import FormatParagraph
33+
from idlelib.squeezer import Squeezer
3334

3435
changes = ConfigChanges()
3536
# Reload changed options in the following classes.
36-
reloadables = (AutoComplete, CodeContext, ParenMatch, FormatParagraph)
37+
reloadables = (AutoComplete, CodeContext, ParenMatch, FormatParagraph,
38+
Squeezer)
3739

3840

3941
class ConfigDialog(Toplevel):
@@ -1748,9 +1750,9 @@ def delete_custom_keys(self):
17481750
self.customlist.SetMenu(item_list, item_list[0])
17491751
# Revert to default key set.
17501752
self.keyset_source.set(idleConf.defaultCfg['main']
1751-
.Get('Keys', 'default'))
1753+
.Get('Keys', 'default'))
17521754
self.builtin_name.set(idleConf.defaultCfg['main'].Get('Keys', 'name')
1753-
or idleConf.default_keys())
1755+
or idleConf.default_keys())
17541756
# User can't back out of these changes, they must be applied now.
17551757
changes.save_all()
17561758
self.cd.save_all_changed_extensions()
@@ -1817,6 +1819,10 @@ def create_page_general(self):
18171819
frame_context: Frame
18181820
context_title: Label
18191821
(*)context_int: Entry - context_lines
1822+
frame_shell: LabelFrame
1823+
frame_auto_squeeze_min_lines: Frame
1824+
auto_squeeze_min_lines_title: Label
1825+
(*)auto_squeeze_min_lines_int: Entry - auto_squeeze_min_lines
18201826
frame_help: LabelFrame
18211827
frame_helplist: Frame
18221828
frame_helplist_buttons: Frame
@@ -1842,6 +1848,9 @@ def create_page_general(self):
18421848
self.paren_bell = tracers.add(
18431849
BooleanVar(self), ('extensions', 'ParenMatch', 'bell'))
18441850

1851+
self.auto_squeeze_min_lines = tracers.add(
1852+
StringVar(self), ('main', 'PyShell', 'auto-squeeze-min-lines'))
1853+
18451854
self.autosave = tracers.add(
18461855
IntVar(self), ('main', 'General', 'autosave'))
18471856
self.format_width = tracers.add(
@@ -1855,8 +1864,10 @@ def create_page_general(self):
18551864
text=' Window Preferences')
18561865
frame_editor = LabelFrame(self, borderwidth=2, relief=GROOVE,
18571866
text=' Editor Preferences')
1867+
frame_shell = LabelFrame(self, borderwidth=2, relief=GROOVE,
1868+
text=' Shell Preferences')
18581869
frame_help = LabelFrame(self, borderwidth=2, relief=GROOVE,
1859-
text=' Additional Help Sources ')
1870+
text=' Additional Help Sources ')
18601871
# Frame_window.
18611872
frame_run = Frame(frame_window, borderwidth=0)
18621873
startup_title = Label(frame_run, text='At Startup')
@@ -1918,6 +1929,13 @@ def create_page_general(self):
19181929
self.context_int = Entry(
19191930
frame_context, textvariable=self.context_lines, width=3)
19201931

1932+
# Frame_shell.
1933+
frame_auto_squeeze_min_lines = Frame(frame_shell, borderwidth=0)
1934+
auto_squeeze_min_lines_title = Label(frame_auto_squeeze_min_lines,
1935+
text='Auto-Squeeze Min. Lines:')
1936+
self.auto_squeeze_min_lines_int = Entry(
1937+
frame_auto_squeeze_min_lines, width=4,
1938+
textvariable=self.auto_squeeze_min_lines)
19211939

19221940
# frame_help.
19231941
frame_helplist = Frame(frame_help)
@@ -1943,6 +1961,7 @@ def create_page_general(self):
19431961
# Body.
19441962
frame_window.pack(side=TOP, padx=5, pady=5, expand=TRUE, fill=BOTH)
19451963
frame_editor.pack(side=TOP, padx=5, pady=5, expand=TRUE, fill=BOTH)
1964+
frame_shell.pack(side=TOP, padx=5, pady=5, expand=TRUE, fill=BOTH)
19461965
frame_help.pack(side=TOP, padx=5, pady=5, expand=TRUE, fill=BOTH)
19471966
# frame_run.
19481967
frame_run.pack(side=TOP, padx=5, pady=0, fill=X)
@@ -1983,6 +2002,11 @@ def create_page_general(self):
19832002
context_title.pack(side=LEFT, anchor=W, padx=5, pady=5)
19842003
self.context_int.pack(side=TOP, padx=5, pady=5)
19852004

2005+
# frame_auto_squeeze_min_lines
2006+
frame_auto_squeeze_min_lines.pack(side=TOP, padx=5, pady=0, fill=X)
2007+
auto_squeeze_min_lines_title.pack(side=LEFT, anchor=W, padx=5, pady=5)
2008+
self.auto_squeeze_min_lines_int.pack(side=TOP, padx=5, pady=5)
2009+
19862010
# frame_help.
19872011
frame_helplist_buttons.pack(side=RIGHT, padx=5, pady=5, fill=Y)
19882012
frame_helplist.pack(side=TOP, padx=5, pady=5, expand=TRUE, fill=BOTH)
@@ -2018,6 +2042,10 @@ def load_general_cfg(self):
20182042
self.context_lines.set(idleConf.GetOption(
20192043
'extensions', 'CodeContext', 'maxlines', type='int'))
20202044

2045+
# Set variables for shell windows.
2046+
self.auto_squeeze_min_lines.set(idleConf.GetOption(
2047+
'main', 'PyShell', 'auto-squeeze-min-lines', type='int'))
2048+
20212049
# Set additional help sources.
20222050
self.user_helplist = idleConf.GetAllExtraHelpSourcesList()
20232051
self.helplist.delete(0, 'end')
@@ -2211,6 +2239,9 @@ def detach(self):
22112239
22122240
CodeContext: Maxlines is the maximum number of code context lines to
22132241
display when Code Context is turned on for an editor window.
2242+
2243+
Shell Preferences: Auto-Squeeze Min. Lines is the minimum number of lines
2244+
of output to automatically "squeeze".
22142245
'''
22152246
}
22162247

Lib/idlelib/editor.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22
import importlib.util
33
import os
44
import platform
5-
import re
65
import string
7-
import sys
86
import tokenize
97
import traceback
108
import webbrowser
@@ -50,7 +48,6 @@ class EditorWindow(object):
5048
from idlelib.undo import UndoDelegator
5149
from idlelib.iomenu import IOBinding, encoding
5250
from idlelib import mainmenu
53-
from tkinter import Toplevel, EventType
5451
from idlelib.statusbar import MultiStatusBar
5552
from idlelib.autocomplete import AutoComplete
5653
from idlelib.autoexpand import AutoExpand
@@ -59,6 +56,7 @@ class EditorWindow(object):
5956
from idlelib.paragraph import FormatParagraph
6057
from idlelib.parenmatch import ParenMatch
6158
from idlelib.rstrip import Rstrip
59+
from idlelib.squeezer import Squeezer
6260
from idlelib.zoomheight import ZoomHeight
6361

6462
filesystemencoding = sys.getfilesystemencoding() # for file names
@@ -319,6 +317,9 @@ def __init__(self, flist=None, filename=None, key=None, root=None):
319317
text.bind("<<zoom-height>>", self.ZoomHeight(self).zoom_height_event)
320318
text.bind("<<toggle-code-context>>",
321319
self.CodeContext(self).toggle_code_context_event)
320+
squeezer = self.Squeezer(self)
321+
text.bind("<<squeeze-current-text>>",
322+
squeezer.squeeze_current_text_event)
322323

323324
def _filename_to_unicode(self, filename):
324325
"""Return filename as BMP unicode so diplayable in Tk."""

Lib/idlelib/idle_test/htest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ def _wrapper(parent): # htest #
163163
'msg': "Click the 'Show GrepDialog' button.\n"
164164
"Test the various 'Find-in-files' functions.\n"
165165
"The results should be displayed in a new '*Output*' window.\n"
166-
"'Right-click'->'Goto file/line' anywhere in the search results "
166+
"'Right-click'->'Go to file/line' anywhere in the search results "
167167
"should open that file \nin a new EditorWindow."
168168
}
169169

Lib/idlelib/idle_test/test_config.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -356,11 +356,11 @@ def test_get_section_list(self):
356356

357357
self.assertCountEqual(
358358
conf.GetSectionList('default', 'main'),
359-
['General', 'EditorWindow', 'Indent', 'Theme',
359+
['General', 'EditorWindow', 'PyShell', 'Indent', 'Theme',
360360
'Keys', 'History', 'HelpFiles'])
361361
self.assertCountEqual(
362362
conf.GetSectionList('user', 'main'),
363-
['General', 'EditorWindow', 'Indent', 'Theme',
363+
['General', 'EditorWindow', 'PyShell', 'Indent', 'Theme',
364364
'Keys', 'History', 'HelpFiles'])
365365

366366
with self.assertRaises(config.InvalidConfigSet):
@@ -452,7 +452,7 @@ def test_remove_key_bind_names(self):
452452

453453
self.assertCountEqual(
454454
conf.RemoveKeyBindNames(conf.GetSectionList('default', 'extensions')),
455-
['AutoComplete', 'CodeContext', 'FormatParagraph', 'ParenMatch','ZzDummy'])
455+
['AutoComplete', 'CodeContext', 'FormatParagraph', 'ParenMatch', 'ZzDummy'])
456456

457457
def test_get_extn_name_for_event(self):
458458
userextn.read_string('''

0 commit comments

Comments
 (0)