Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
0aa0a06e
Commit
0aa0a06e
authored
May 28, 2017
by
csabella
Committed by
terryjreedy
May 28, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bpo-30495: IDLE: Modernize textview.py with docstrings and PEP8 names (#1839)
Patch by Cheryl Sabella.
parent
f7ecfac0
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
62 additions
and
42 deletions
+62
-42
Lib/idlelib/idle_test/test_help_about.py
Lib/idlelib/idle_test/test_help_about.py
+6
-5
Lib/idlelib/idle_test/test_textview.py
Lib/idlelib/idle_test/test_textview.py
+10
-10
Lib/idlelib/textview.py
Lib/idlelib/textview.py
+46
-27
No files found.
Lib/idlelib/idle_test/test_help_about.py
View file @
0aa0a06e
...
...
@@ -45,10 +45,10 @@ class LiveDialogTest(unittest.TestCase):
button
.
invoke
()
self
.
assertEqual
(
printer
.
_Printer__lines
[
0
],
dialog
.
_current_textview
.
text
View
.
get
(
'1.0'
,
'1.end'
))
dialog
.
_current_textview
.
text
.
get
(
'1.0'
,
'1.end'
))
self
.
assertEqual
(
printer
.
_Printer__lines
[
1
],
dialog
.
_current_textview
.
text
View
.
get
(
'2.0'
,
'2.end'
))
dialog
.
_current_textview
.
text
.
get
(
'2.0'
,
'2.end'
))
dialog
.
_current_textview
.
destroy
()
def
test_file_buttons
(
self
):
...
...
@@ -64,10 +64,11 @@ class LiveDialogTest(unittest.TestCase):
with
open
(
fn
)
as
f
:
self
.
assertEqual
(
f
.
readline
().
strip
(),
dialog
.
_current_textview
.
text
View
.
get
(
'1.0'
,
'1.end'
))
dialog
.
_current_textview
.
text
.
get
(
'1.0'
,
'1.end'
))
f
.
readline
()
self
.
assertEqual
(
f
.
readline
().
strip
(),
dialog
.
_current_textview
.
textView
.
get
(
'3.0'
,
'3.end'
))
self
.
assertEqual
(
f
.
readline
().
strip
(),
dialog
.
_current_textview
.
text
.
get
(
'3.0'
,
'3.end'
))
dialog
.
_current_textview
.
destroy
()
...
...
Lib/idlelib/idle_test/test_textview.py
View file @
0aa0a06e
...
...
@@ -41,7 +41,7 @@ class TV(tv.TextViewer): # Used in TextViewTest.
# Call wrapper class with mock wait_window.
class
TextViewTest
(
unittest
.
TestCase
):
def
setUp
(
self
):
TV
.
transient
.
__init__
()
TV
.
grab_set
.
__init__
()
...
...
@@ -52,19 +52,19 @@ class TextViewTest(unittest.TestCase):
self
.
assertTrue
(
TV
.
transient
.
called
)
self
.
assertTrue
(
TV
.
grab_set
.
called
)
self
.
assertTrue
(
TV
.
wait_window
.
called
)
view
.
O
k
()
view
.
o
k
()
def
test_init_nonmodal
(
self
):
view
=
TV
(
root
,
'Title'
,
'test text'
,
modal
=
False
)
self
.
assertFalse
(
TV
.
transient
.
called
)
self
.
assertFalse
(
TV
.
grab_set
.
called
)
self
.
assertFalse
(
TV
.
wait_window
.
called
)
view
.
O
k
()
view
.
o
k
()
def
test_ok
(
self
):
view
=
TV
(
root
,
'Title'
,
'test text'
,
modal
=
False
)
view
.
destroy
=
Func
()
view
.
O
k
()
view
.
o
k
()
self
.
assertTrue
(
view
.
destroy
.
called
)
del
view
.
destroy
# Unmask real function.
view
.
destroy
()
...
...
@@ -86,13 +86,13 @@ class ViewFunctionTest(unittest.TestCase):
def
test_view_text
(
self
):
view
=
tv
.
view_text
(
root
,
'Title'
,
'test text'
,
modal
=
False
)
self
.
assertIsInstance
(
view
,
tv
.
TextViewer
)
view
.
O
k
()
view
.
o
k
()
def
test_view_file
(
self
):
view
=
tv
.
view_file
(
root
,
'Title'
,
__file__
,
modal
=
False
)
self
.
assertIsInstance
(
view
,
tv
.
TextViewer
)
self
.
assertIn
(
'Test'
,
view
.
text
View
.
get
(
'1.0'
,
'1.end'
))
view
.
O
k
()
self
.
assertIn
(
'Test'
,
view
.
text
.
get
(
'1.0'
,
'1.end'
))
view
.
o
k
()
def
test_bad_file
(
self
):
# Mock showerror will be used; view_file will return None.
...
...
@@ -131,7 +131,7 @@ class ButtonClickTest(unittest.TestCase):
self
.
assertEqual
(
self
.
called
,
True
)
self
.
assertEqual
(
self
.
view
.
title
(),
'TITLE_TEXT'
)
self
.
assertEqual
(
self
.
view
.
text
View
.
get
(
'1.0'
,
'1.end'
),
'COMMAND'
)
self
.
assertEqual
(
self
.
view
.
text
.
get
(
'1.0'
,
'1.end'
),
'COMMAND'
)
def
test_view_file_bind_with_button
(
self
):
def
_command
():
...
...
@@ -144,10 +144,10 @@ class ButtonClickTest(unittest.TestCase):
self
.
assertEqual
(
self
.
called
,
True
)
self
.
assertEqual
(
self
.
view
.
title
(),
'TITLE_FILE'
)
with
open
(
__file__
)
as
f
:
self
.
assertEqual
(
self
.
view
.
text
View
.
get
(
'1.0'
,
'1.end'
),
self
.
assertEqual
(
self
.
view
.
text
.
get
(
'1.0'
,
'1.end'
),
f
.
readline
().
strip
())
f
.
readline
()
self
.
assertEqual
(
self
.
view
.
text
View
.
get
(
'3.0'
,
'3.end'
),
self
.
assertEqual
(
self
.
view
.
text
.
get
(
'3.0'
,
'3.end'
),
f
.
readline
().
strip
())
...
...
Lib/idlelib/textview.py
View file @
0aa0a06e
"""Simple text browser for IDLE
"""
from
tkinter
import
*
from
tkinter
import
Toplevel
,
Frame
,
Button
,
Text
from
tkinter
import
DISABLED
,
SUNKEN
,
VERTICAL
,
WORD
from
tkinter
import
RIGHT
,
LEFT
,
TOP
,
BOTTOM
,
BOTH
,
X
,
Y
from
tkinter.ttk
import
Scrollbar
from
tkinter.messagebox
import
showerror
...
...
@@ -16,6 +18,9 @@ class TextViewer(Toplevel):
If modal is left True, users cannot interact with other windows
until the textview window is closed.
parent - parent of this dialog
title - string which is title of popup dialog
text - text to display in dialog
_htest - bool; change box location when running htest.
_utest - bool; don't wait_window when running unittest.
"""
...
...
@@ -29,16 +34,16 @@ class TextViewer(Toplevel):
self
.
bg
=
'#ffffff'
self
.
fg
=
'#000000'
self
.
CreateW
idgets
()
self
.
create_w
idgets
()
self
.
title
(
title
)
self
.
protocol
(
"WM_DELETE_WINDOW"
,
self
.
O
k
)
self
.
protocol
(
"WM_DELETE_WINDOW"
,
self
.
o
k
)
self
.
parent
=
parent
self
.
text
View
.
focus_set
()
self
.
text
.
focus_set
()
# Bind keys for closing this dialog.
self
.
bind
(
'<Return>'
,
self
.
O
k
)
self
.
bind
(
'<Escape>'
,
self
.
O
k
)
self
.
text
View
.
insert
(
0.0
,
text
)
self
.
text
View
.
config
(
state
=
DISABLED
)
self
.
bind
(
'<Return>'
,
self
.
o
k
)
self
.
bind
(
'<Escape>'
,
self
.
o
k
)
self
.
text
.
insert
(
0.0
,
text
)
self
.
text
.
config
(
state
=
DISABLED
)
if
modal
:
self
.
transient
(
parent
)
...
...
@@ -46,34 +51,48 @@ class TextViewer(Toplevel):
if
not
_utest
:
self
.
wait_window
()
def
CreateW
idgets
(
self
):
def
create_w
idgets
(
self
):
"Create Frame with Text (with vertical Scrollbar) and Button."
frameText
=
Frame
(
self
,
relief
=
SUNKEN
,
height
=
700
)
frameButtons
=
Frame
(
self
)
self
.
buttonOk
=
Button
(
frameButtons
,
text
=
'Close'
,
command
=
self
.
Ok
,
takefocus
=
FALSE
)
self
.
scrollbarView
=
Scrollbar
(
frameText
,
orient
=
VERTICAL
,
takefocus
=
FALSE
)
self
.
textView
=
Text
(
frameText
,
wrap
=
WORD
,
highlightthickness
=
0
,
frame
=
Frame
(
self
,
relief
=
SUNKEN
,
height
=
700
)
frame_buttons
=
Frame
(
self
)
self
.
button_ok
=
Button
(
frame_buttons
,
text
=
'Close'
,
command
=
self
.
ok
,
takefocus
=
False
)
self
.
scrollbar
=
Scrollbar
(
frame
,
orient
=
VERTICAL
,
takefocus
=
False
)
self
.
text
=
Text
(
frame
,
wrap
=
WORD
,
highlightthickness
=
0
,
fg
=
self
.
fg
,
bg
=
self
.
bg
)
self
.
scrollbarView
.
config
(
command
=
self
.
textView
.
yview
)
self
.
textView
.
config
(
yscrollcommand
=
self
.
scrollbarView
.
set
)
self
.
buttonOk
.
pack
()
self
.
scrollbarView
.
pack
(
side
=
RIGHT
,
fill
=
Y
)
self
.
textView
.
pack
(
side
=
LEFT
,
expand
=
TRUE
,
fill
=
BOTH
)
frameButtons
.
pack
(
side
=
BOTTOM
,
fill
=
X
)
frameText
.
pack
(
side
=
TOP
,
expand
=
TRUE
,
fill
=
BOTH
)
def
Ok
(
self
,
event
=
None
):
self
.
scrollbar
.
config
(
command
=
self
.
text
.
yview
)
self
.
text
.
config
(
yscrollcommand
=
self
.
scrollbar
.
set
)
self
.
button_ok
.
pack
()
self
.
scrollbar
.
pack
(
side
=
RIGHT
,
fill
=
Y
)
self
.
text
.
pack
(
side
=
LEFT
,
expand
=
True
,
fill
=
BOTH
)
frame_buttons
.
pack
(
side
=
BOTTOM
,
fill
=
X
)
frame
.
pack
(
side
=
TOP
,
expand
=
True
,
fill
=
BOTH
)
def
ok
(
self
,
event
=
None
):
"""Dismiss text viewer dialog."""
self
.
destroy
()
def
view_text
(
parent
,
title
,
text
,
modal
=
True
,
_utest
=
False
):
"Display text in a TextViewer."
"""Create TextViewer for given text.
parent - parent of this dialog
title - string which is the title of popup dialog
text - text to display in this dialog
modal - controls if users can interact with other windows while this
dialog is displayed
_utest - bool; controls wait_window on unittest
"""
return
TextViewer
(
parent
,
title
,
text
,
modal
,
_utest
=
_utest
)
def
view_file
(
parent
,
title
,
filename
,
encoding
=
None
,
modal
=
True
,
_utest
=
False
):
"Display file in a TextViever or show error message."
"""Create TextViewer for text in filename.
Return error message if file cannot be read. Otherwise calls view_text
with contents of the file.
"""
try
:
with
open
(
filename
,
'r'
,
encoding
=
encoding
)
as
file
:
contents
=
file
.
read
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment