Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
a7e130a
bpo-1529353: update the Squeezer extension and its tests
taleinat Jun 11, 2018
0af6a62
bpo-1529353: use idlelib.textview for previewing squeezed output
taleinat Aug 12, 2018
71fb2c1
Merge branch 'master' into bpo-1529353
taleinat Aug 12, 2018
bda6572
Refactor Squeezer from an extension to an integral part of IDLE.
taleinat Aug 13, 2018
53e74d9
Merge branch 'master' into bpo-1529353
taleinat Aug 27, 2018
902091e
Update Squeezer's tests given the latest changes
taleinat Aug 27, 2018
6d7035b
add ability to control text wrapping in IDLE's text viewer
taleinat Aug 28, 2018
45fb1a6
ask for user confirmation before expanding huge squeezed outputs
taleinat Aug 28, 2018
18106e8
increase Squeezer's default auto-squeeze-min-lines from 30 to 50
taleinat Aug 28, 2018
2c795e3
move 'copy' and 'preview' squeezed output actions to a context menu
taleinat Aug 28, 2018
1a1288a
Squeezer: rename "preview" to "view"
taleinat Aug 28, 2018
f753b37
Squeezer: remove tooltip configuration options (delay set to 80ms)
taleinat Aug 30, 2018
6087d3f
Squeezer: remove expand/view-last-squeezed events
taleinat Aug 30, 2018
b7d27cb
Squeezer: make view window non-modal and add horizontal scrollbar
taleinat Aug 30, 2018
ce07987
Merge remote-tracking branch 'origin/master' into pr_7626.
terryjreedy Sep 25, 2018
9676991
Correct error in merge resolution.
terryjreedy Sep 25, 2018
e768e0f
Make test_squeezer runnable.
terryjreedy Sep 25, 2018
fcc9084
bpo-1529353: explicitly create root Tk() objects in tests
taleinat Sep 25, 2018
468d9ec
bpo-1529353: reformat doc-strings as PEP8 and rename test classes
taleinat Sep 25, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Squeezer: rename "preview" to "view"
  • Loading branch information
taleinat committed Aug 28, 2018
commit 1a1288a7019c8b12055e6014d32ae29a30f901b1
41 changes: 20 additions & 21 deletions Lib/idlelib/idle_test/test_squeezer.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import os
from collections import namedtuple
from tkinter import Text
import unittest
Expand Down Expand Up @@ -250,22 +249,22 @@ def test_expand_last_squeezed_event(self):
self.assertEqual(retval, "break")
self.assertEqual(squeezer.text.bell.call_count, 1)

def test_preview_last_squeezed_event_no_squeezed(self):
"""test the preview_last_squeezed event"""
def test_view_last_squeezed_event_no_squeezed(self):
"""test the view_last_squeezed event"""
# The tested scenario: There are no squeezed texts, therefore there
# are no ExpandingButton instances. The preview_last_squeezed event
# are no ExpandingButton instances. The view_last_squeezed event
# is called and should fail (i.e. call squeezer.text.bell()).
editwin = self.make_mock_editor_window()
squeezer = self.make_squeezer_instance(editwin)

retval = squeezer.preview_last_squeezed_event(event=Mock())
retval = squeezer.view_last_squeezed_event(event=Mock())
self.assertEqual(retval, "break")

def test_preview_last_squeezed_event(self):
"""test the preview_last_squeezed event"""
def test_view_last_squeezed_event(self):
"""test the view_last_squeezed event"""
# The tested scenario: There are two squeezed texts, therefore there
# are two ExpandingButton instances. The preview_last_squeezed event
# is called twice. Both times should call the preview() method of the
# are two ExpandingButton instances. The view_last_squeezed event
# is called twice. Both times should call the view() method of the
# second ExpandingButton.
editwin = self.make_mock_editor_window()
squeezer = self.make_squeezer_instance(editwin)
Expand All @@ -274,17 +273,17 @@ def test_preview_last_squeezed_event(self):
squeezer.expandingbuttons = [mock_expandingbutton1,
mock_expandingbutton2]

# check that the second expanding button is previewed
retval = squeezer.preview_last_squeezed_event(event=SENTINEL_VALUE)
# check that the second expanding button is viewed
retval = squeezer.view_last_squeezed_event(event=SENTINEL_VALUE)
self.assertEqual(retval, "break")
self.assertEqual(squeezer.text.bell.call_count, 0)
self.assertEqual(mock_expandingbutton1.preview.call_count, 0)
self.assertEqual(mock_expandingbutton2.preview.call_count, 1)
mock_expandingbutton2.preview.assert_called_with(SENTINEL_VALUE)
self.assertEqual(mock_expandingbutton1.view.call_count, 0)
self.assertEqual(mock_expandingbutton2.view.call_count, 1)
mock_expandingbutton2.view.assert_called_with(SENTINEL_VALUE)

squeezer.preview_last_squeezed_event(event=SENTINEL_VALUE)
self.assertEqual(mock_expandingbutton1.preview.call_count, 0)
self.assertEqual(mock_expandingbutton2.preview.call_count, 2)
squeezer.view_last_squeezed_event(event=SENTINEL_VALUE)
self.assertEqual(mock_expandingbutton1.view.call_count, 0)
self.assertEqual(mock_expandingbutton2.view.call_count, 2)

def test_auto_squeeze(self):
"""test that the auto-squeezing creates an ExpandingButton properly"""
Expand Down Expand Up @@ -565,16 +564,16 @@ def test_copy(self):
self.assertEqual(expandingbutton.clipboard_append.call_count, 1)
expandingbutton.clipboard_append.assert_called_with('TEXT')

def test_preview(self):
"""test the preview event"""
def test_view(self):
"""test the view event"""
squeezer = self.make_mock_squeezer()
expandingbutton = ExpandingButton('TEXT', 'TAGS', 50, squeezer)
expandingbutton.selection_own = Mock()

with patch('idlelib.squeezer.view_text', autospec=view_text)\
as mock_view_text:
# trigger the preview event
expandingbutton.preview(event=Mock())
# trigger the view event
expandingbutton.view(event=Mock())

# check that the expanding button called view_text
self.assertEqual(mock_view_text.call_count, 1)
Expand Down
18 changes: 9 additions & 9 deletions Lib/idlelib/squeezer.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ class ExpandingButton(tk.Button):

These buttons are displayed inside a Tk Text widget in place of text. A
user can then use the button to replace it with the original text, copy
the original text to the clipboard or preview the original text in a
separate window.
the original text to the clipboard or view the original text in a separate
window.

Each button is tied to a Squeezer instance, and it knows to update the
Squeezer instance when it is expanded (and therefore removed).
Expand Down Expand Up @@ -168,7 +168,7 @@ def expand(self, event=None):
message="\n\n".join([
"The squeezed output is very long: %d lines, %d chars.",
"Expanding it could make IDLE slow or unresponsive.",
"It is recommended to preview or copy the output instead.",
"It is recommended to view or copy the output instead.",
"Really expand?"
]) % (self.numoflines, len(self.s)),
default=tkMessageBox.CANCEL,
Expand All @@ -188,8 +188,8 @@ def copy(self, event=None):
self.clipboard_clear()
self.clipboard_append(self.s)

def preview(self, event=None):
"""preview event handler
def view(self, event=None):
"""view event handler

View the original text in a separate text viewer window.
"""
Expand All @@ -198,7 +198,7 @@ def preview(self, event=None):
rmenu_specs = (
# item structure: (label, method_name)
('copy', 'copy'),
('preview', 'preview'),
('view', 'view'),
)

def context_menu_event(self, event):
Expand Down Expand Up @@ -329,16 +329,16 @@ def expand_last_squeezed_event(self, event):
self.text.bell()
return "break"

def preview_last_squeezed_event(self, event):
"""preview-last-squeezed event handler
def view_last_squeezed_event(self, event):
"""view-last-squeezed event handler

Preview the last squeezed text in the Text widget.

If there is no such squeezed text, give the user a small warning and
do nothing.
"""
if len(self.expandingbuttons) > 0:
self.expandingbuttons[-1].preview(event)
self.expandingbuttons[-1].view(event)
else:
self.text.bell()
return "break"
Expand Down