MCPcopy Index your code
hub / github.com/python/cpython / ViewWindow

Class ViewWindow

Lib/idlelib/textview.py:105–147  ·  view source on GitHub ↗

A simple text viewer dialog for IDLE.

Source from the content-addressed store, hash-verified

103
104
105class ViewWindow(Toplevel):
106 "A simple text viewer dialog for IDLE."
107
108 def __init__(self, parent, title, contents, modal=True, wrap=WORD,
109 *, _htest=False, _utest=False):
110 """Show the given text in a scrollable window with a 'close' button.
111
112 If modal is left True, users cannot interact with other windows
113 until the textview window is closed.
114
115 parent - parent of this dialog
116 title - string which is title of popup dialog
117 contents - text to display in dialog
118 wrap - type of text wrapping to use ('word', 'char' or 'none')
119 _htest - bool; change box location when running htest.
120 _utest - bool; don't wait_window when running unittest.
121 """
122 super().__init__(parent)
123 self['borderwidth'] = 5
124 # Place dialog below parent if running htest.
125 x = parent.winfo_rootx() + 10
126 y = parent.winfo_rooty() + (10 if not _htest else 100)
127 self.geometry(f'=750x500+{x}+{y}')
128
129 self.title(title)
130 self.viewframe = ViewFrame(self, contents, wrap=wrap)
131 self.protocol("WM_DELETE_WINDOW", self.ok)
132 self.button_ok = Button(self, text='Close',
133 command=self.ok, takefocus=False)
134 self.viewframe.pack(side='top', expand=True, fill='both')
135
136 self.is_modal = modal
137 if self.is_modal:
138 self.transient(parent)
139 self.grab_set()
140 if not _utest:
141 self.wait_window()
142
143 def ok(self, event=None):
144 """Dismiss text viewer dialog."""
145 if self.is_modal:
146 self.grab_release()
147 self.destroy()
148
149
150def view_text(parent, title, contents, modal=True, wrap='word', _utest=False):

Callers 1

view_textFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…