diff options
author | Louie Lu <me@louie.lu> | 2017-05-17 21:51:31 (GMT) |
---|---|---|
committer | terryjreedy <tjreedy@udel.edu> | 2017-05-17 21:51:31 (GMT) |
commit | ba365da9cee8901fad08ab0b61c7489c110e5c97 (patch) | |
tree | fa52c68a6f1b574454639de635c59dff36cda42b /Lib/idlelib/textview.py | |
parent | ab4413a7e9bda95b6fcd517073e2a51dafaa1624 (diff) | |
download | cpython-ba365da9cee8901fad08ab0b61c7489c110e5c97.zip cpython-ba365da9cee8901fad08ab0b61c7489c110e5c97.tar.gz cpython-ba365da9cee8901fad08ab0b61c7489c110e5c97.tar.bz2 |
bpo-30303: IDLE: Add _utest argument to textview (#1499)
Diffstat (limited to 'Lib/idlelib/textview.py')
-rw-r--r-- | Lib/idlelib/textview.py | 26 |
1 files changed, 16 insertions, 10 deletions
diff --git a/Lib/idlelib/textview.py b/Lib/idlelib/textview.py index adee326..f33ac32 100644 --- a/Lib/idlelib/textview.py +++ b/Lib/idlelib/textview.py @@ -9,14 +9,15 @@ from tkinter.messagebox import showerror class TextViewer(Toplevel): "A simple text viewer dialog for IDLE." - def __init__(self, parent, title, text, modal=True, _htest=False): - """Show the given text in a scrollable window with a 'close' button + def __init__(self, parent, title, text, modal=True, + _htest=False, _utest=False): + """Show the given text in a scrollable window with a 'close' button. - If modal option set to False, user can interact with other windows, - otherwise they will be unable to interact with other windows until - the textview window is closed. + If modal is left True, users cannot interact with other windows + until the textview window is closed. _htest - bool; change box location when running htest. + _utest - bool; don't wait_window when running unittest. """ Toplevel.__init__(self, parent) self.configure(borderwidth=5) @@ -42,9 +43,11 @@ class TextViewer(Toplevel): if modal: self.transient(parent) self.grab_set() - self.wait_window() + if not _utest: + self.wait_window() def CreateWidgets(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', @@ -65,10 +68,12 @@ class TextViewer(Toplevel): self.destroy() -def view_text(parent, title, text, modal=True): - return TextViewer(parent, title, text, modal) +def view_text(parent, title, text, modal=True, _utest=False): + "Display text in a TextViewer." + return TextViewer(parent, title, text, modal, _utest=_utest) -def view_file(parent, title, filename, encoding=None, modal=True): +def view_file(parent, title, filename, encoding=None, modal=True, _utest=False): + "Display file in a TextViever or show error message." try: with open(filename, 'r', encoding=encoding) as file: contents = file.read() @@ -81,7 +86,8 @@ def view_file(parent, title, filename, encoding=None, modal=True): message=str(err), parent=parent) else: - return view_text(parent, title, contents, modal) + return view_text(parent, title, contents, modal, _utest=_utest) + if __name__ == '__main__': import unittest |