Skip to content

Commit

Permalink
bpo-1529353: IDLE: squeeze large output in the shell (GH-7626)
Browse files Browse the repository at this point in the history
(cherry picked from commit 604e7b9)

Co-authored-by: Tal Einat <taleinat+github@gmail.com>
  • Loading branch information
miss-islington and taleinat committed Sep 25, 2018
1 parent 936d740 commit 0b3e120
Show file tree
Hide file tree
Showing 11 changed files with 974 additions and 29 deletions.
3 changes: 3 additions & 0 deletions Lib/idlelib/config-main.def
Expand Up @@ -66,6 +66,9 @@ font-size= 10
font-bold= 0
encoding= none

[PyShell]
auto-squeeze-min-lines= 50

[Indent]
use-spaces= 1
num-spaces= 4
Expand Down
39 changes: 35 additions & 4 deletions Lib/idlelib/configdialog.py
Expand Up @@ -30,10 +30,12 @@
from idlelib.codecontext import CodeContext
from idlelib.parenmatch import ParenMatch
from idlelib.paragraph import FormatParagraph
from idlelib.squeezer import Squeezer

changes = ConfigChanges()
# Reload changed options in the following classes.
reloadables = (AutoComplete, CodeContext, ParenMatch, FormatParagraph)
reloadables = (AutoComplete, CodeContext, ParenMatch, FormatParagraph,
Squeezer)


class ConfigDialog(Toplevel):
Expand Down Expand Up @@ -1748,9 +1750,9 @@ def delete_custom_keys(self):
self.customlist.SetMenu(item_list, item_list[0])
# Revert to default key set.
self.keyset_source.set(idleConf.defaultCfg['main']
.Get('Keys', 'default'))
.Get('Keys', 'default'))
self.builtin_name.set(idleConf.defaultCfg['main'].Get('Keys', 'name')
or idleConf.default_keys())
or idleConf.default_keys())
# User can't back out of these changes, they must be applied now.
changes.save_all()
self.cd.save_all_changed_extensions()
Expand Down Expand Up @@ -1817,6 +1819,10 @@ def create_page_general(self):
frame_context: Frame
context_title: Label
(*)context_int: Entry - context_lines
frame_shell: LabelFrame
frame_auto_squeeze_min_lines: Frame
auto_squeeze_min_lines_title: Label
(*)auto_squeeze_min_lines_int: Entry - auto_squeeze_min_lines
frame_help: LabelFrame
frame_helplist: Frame
frame_helplist_buttons: Frame
Expand All @@ -1842,6 +1848,9 @@ def create_page_general(self):
self.paren_bell = tracers.add(
BooleanVar(self), ('extensions', 'ParenMatch', 'bell'))

self.auto_squeeze_min_lines = tracers.add(
StringVar(self), ('main', 'PyShell', 'auto-squeeze-min-lines'))

self.autosave = tracers.add(
IntVar(self), ('main', 'General', 'autosave'))
self.format_width = tracers.add(
Expand All @@ -1855,8 +1864,10 @@ def create_page_general(self):
text=' Window Preferences')
frame_editor = LabelFrame(self, borderwidth=2, relief=GROOVE,
text=' Editor Preferences')
frame_shell = LabelFrame(self, borderwidth=2, relief=GROOVE,
text=' Shell Preferences')
frame_help = LabelFrame(self, borderwidth=2, relief=GROOVE,
text=' Additional Help Sources ')
text=' Additional Help Sources ')
# Frame_window.
frame_run = Frame(frame_window, borderwidth=0)
startup_title = Label(frame_run, text='At Startup')
Expand Down Expand Up @@ -1918,6 +1929,13 @@ def create_page_general(self):
self.context_int = Entry(
frame_context, textvariable=self.context_lines, width=3)

# Frame_shell.
frame_auto_squeeze_min_lines = Frame(frame_shell, borderwidth=0)
auto_squeeze_min_lines_title = Label(frame_auto_squeeze_min_lines,
text='Auto-Squeeze Min. Lines:')
self.auto_squeeze_min_lines_int = Entry(
frame_auto_squeeze_min_lines, width=4,
textvariable=self.auto_squeeze_min_lines)

# frame_help.
frame_helplist = Frame(frame_help)
Expand All @@ -1943,6 +1961,7 @@ def create_page_general(self):
# Body.
frame_window.pack(side=TOP, padx=5, pady=5, expand=TRUE, fill=BOTH)
frame_editor.pack(side=TOP, padx=5, pady=5, expand=TRUE, fill=BOTH)
frame_shell.pack(side=TOP, padx=5, pady=5, expand=TRUE, fill=BOTH)
frame_help.pack(side=TOP, padx=5, pady=5, expand=TRUE, fill=BOTH)
# frame_run.
frame_run.pack(side=TOP, padx=5, pady=0, fill=X)
Expand Down Expand Up @@ -1983,6 +2002,11 @@ def create_page_general(self):
context_title.pack(side=LEFT, anchor=W, padx=5, pady=5)
self.context_int.pack(side=TOP, padx=5, pady=5)

# frame_auto_squeeze_min_lines
frame_auto_squeeze_min_lines.pack(side=TOP, padx=5, pady=0, fill=X)
auto_squeeze_min_lines_title.pack(side=LEFT, anchor=W, padx=5, pady=5)
self.auto_squeeze_min_lines_int.pack(side=TOP, padx=5, pady=5)

# frame_help.
frame_helplist_buttons.pack(side=RIGHT, padx=5, pady=5, fill=Y)
frame_helplist.pack(side=TOP, padx=5, pady=5, expand=TRUE, fill=BOTH)
Expand Down Expand Up @@ -2018,6 +2042,10 @@ def load_general_cfg(self):
self.context_lines.set(idleConf.GetOption(
'extensions', 'CodeContext', 'maxlines', type='int'))

# Set variables for shell windows.
self.auto_squeeze_min_lines.set(idleConf.GetOption(
'main', 'PyShell', 'auto-squeeze-min-lines', type='int'))

# Set additional help sources.
self.user_helplist = idleConf.GetAllExtraHelpSourcesList()
self.helplist.delete(0, 'end')
Expand Down Expand Up @@ -2211,6 +2239,9 @@ def detach(self):
CodeContext: Maxlines is the maximum number of code context lines to
display when Code Context is turned on for an editor window.
Shell Preferences: Auto-Squeeze Min. Lines is the minimum number of lines
of output to automatically "squeeze".
'''
}

Expand Down
7 changes: 4 additions & 3 deletions Lib/idlelib/editor.py
Expand Up @@ -2,9 +2,7 @@
import importlib.util
import os
import platform
import re
import string
import sys
import tokenize
import traceback
import webbrowser
Expand Down Expand Up @@ -50,7 +48,6 @@ class EditorWindow(object):
from idlelib.undo import UndoDelegator
from idlelib.iomenu import IOBinding, encoding
from idlelib import mainmenu
from tkinter import Toplevel, EventType
from idlelib.statusbar import MultiStatusBar
from idlelib.autocomplete import AutoComplete
from idlelib.autoexpand import AutoExpand
Expand All @@ -59,6 +56,7 @@ class EditorWindow(object):
from idlelib.paragraph import FormatParagraph
from idlelib.parenmatch import ParenMatch
from idlelib.rstrip import Rstrip
from idlelib.squeezer import Squeezer
from idlelib.zoomheight import ZoomHeight

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

def _filename_to_unicode(self, filename):
"""Return filename as BMP unicode so diplayable in Tk."""
Expand Down
2 changes: 1 addition & 1 deletion Lib/idlelib/idle_test/htest.py
Expand Up @@ -163,7 +163,7 @@ def _wrapper(parent): # htest #
'msg': "Click the 'Show GrepDialog' button.\n"
"Test the various 'Find-in-files' functions.\n"
"The results should be displayed in a new '*Output*' window.\n"
"'Right-click'->'Goto file/line' anywhere in the search results "
"'Right-click'->'Go to file/line' anywhere in the search results "
"should open that file \nin a new EditorWindow."
}

Expand Down
6 changes: 3 additions & 3 deletions Lib/idlelib/idle_test/test_config.py
Expand Up @@ -356,11 +356,11 @@ def test_get_section_list(self):

self.assertCountEqual(
conf.GetSectionList('default', 'main'),
['General', 'EditorWindow', 'Indent', 'Theme',
['General', 'EditorWindow', 'PyShell', 'Indent', 'Theme',
'Keys', 'History', 'HelpFiles'])
self.assertCountEqual(
conf.GetSectionList('user', 'main'),
['General', 'EditorWindow', 'Indent', 'Theme',
['General', 'EditorWindow', 'PyShell', 'Indent', 'Theme',
'Keys', 'History', 'HelpFiles'])

with self.assertRaises(config.InvalidConfigSet):
Expand Down Expand Up @@ -452,7 +452,7 @@ def test_remove_key_bind_names(self):

self.assertCountEqual(
conf.RemoveKeyBindNames(conf.GetSectionList('default', 'extensions')),
['AutoComplete', 'CodeContext', 'FormatParagraph', 'ParenMatch','ZzDummy'])
['AutoComplete', 'CodeContext', 'FormatParagraph', 'ParenMatch', 'ZzDummy'])

def test_get_extn_name_for_event(self):
userextn.read_string('''
Expand Down

0 comments on commit 0b3e120

Please sign in to comment.