9
9
class TextViewer (Toplevel ):
10
10
"A simple text viewer dialog for IDLE."
11
11
12
- def __init__ (self , parent , title , text , modal = True , _htest = False ):
13
- """Show the given text in a scrollable window with a 'close' button
12
+ def __init__ (self , parent , title , text , modal = True ,
13
+ _htest = False , _utest = False ):
14
+ """Show the given text in a scrollable window with a 'close' button.
14
15
15
- If modal option set to False, user can interact with other windows,
16
- otherwise they will be unable to interact with other windows until
17
- the textview window is closed.
16
+ If modal is left True, users cannot interact with other windows
17
+ until the textview window is closed.
18
18
19
19
_htest - bool; change box location when running htest.
20
+ _utest - bool; don't wait_window when running unittest.
20
21
"""
21
22
Toplevel .__init__ (self , parent )
22
23
self .configure (borderwidth = 5 )
@@ -42,9 +43,11 @@ def __init__(self, parent, title, text, modal=True, _htest=False):
42
43
if modal :
43
44
self .transient (parent )
44
45
self .grab_set ()
45
- self .wait_window ()
46
+ if not _utest :
47
+ self .wait_window ()
46
48
47
49
def CreateWidgets (self ):
50
+ "Create Frame with Text (with vertical Scrollbar) and Button."
48
51
frameText = Frame (self , relief = SUNKEN , height = 700 )
49
52
frameButtons = Frame (self )
50
53
self .buttonOk = Button (frameButtons , text = 'Close' ,
@@ -65,10 +68,12 @@ def Ok(self, event=None):
65
68
self .destroy ()
66
69
67
70
68
- def view_text (parent , title , text , modal = True ):
69
- return TextViewer (parent , title , text , modal )
71
+ def view_text (parent , title , text , modal = True , _utest = False ):
72
+ "Display text in a TextViewer."
73
+ return TextViewer (parent , title , text , modal , _utest = _utest )
70
74
71
- def view_file (parent , title , filename , encoding = None , modal = True ):
75
+ def view_file (parent , title , filename , encoding = None , modal = True , _utest = False ):
76
+ "Display file in a TextViever or show error message."
72
77
try :
73
78
with open (filename , 'r' , encoding = encoding ) as file :
74
79
contents = file .read ()
@@ -81,7 +86,8 @@ def view_file(parent, title, filename, encoding=None, modal=True):
81
86
message = str (err ),
82
87
parent = parent )
83
88
else :
84
- return view_text (parent , title , contents , modal )
89
+ return view_text (parent , title , contents , modal , _utest = _utest )
90
+
85
91
86
92
if __name__ == '__main__' :
87
93
import unittest
0 commit comments