99class TextViewer (Toplevel ):
1010 "A simple text viewer dialog for IDLE."
1111
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.
1415
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.
1818
1919 _htest - bool; change box location when running htest.
20+ _utest - bool; don't wait_window when running unittest.
2021 """
2122 Toplevel .__init__ (self , parent )
2223 self .configure (borderwidth = 5 )
@@ -42,9 +43,11 @@ def __init__(self, parent, title, text, modal=True, _htest=False):
4243 if modal :
4344 self .transient (parent )
4445 self .grab_set ()
45- self .wait_window ()
46+ if not _utest :
47+ self .wait_window ()
4648
4749 def CreateWidgets (self ):
50+ "Create Frame with Text (with vertical Scrollbar) and Button."
4851 frameText = Frame (self , relief = SUNKEN , height = 700 )
4952 frameButtons = Frame (self )
5053 self .buttonOk = Button (frameButtons , text = 'Close' ,
@@ -65,10 +68,12 @@ def Ok(self, event=None):
6568 self .destroy ()
6669
6770
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 )
7074
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."
7277 try :
7378 with open (filename , 'r' , encoding = encoding ) as file :
7479 contents = file .read ()
@@ -81,7 +86,8 @@ def view_file(parent, title, filename, encoding=None, modal=True):
8186 message = str (err ),
8287 parent = parent )
8388 else :
84- return view_text (parent , title , contents , modal )
89+ return view_text (parent , title , contents , modal , _utest = _utest )
90+
8591
8692if __name__ == '__main__' :
8793 import unittest
0 commit comments