mirror of
https://github.com/python/cpython.git
synced 2025-08-03 00:23:06 +00:00
Issue 964437 Make IDLE help window non-modal.
Patch by Guilherme Polo and Roger Serwy.
This commit is contained in:
parent
d76c1bf599
commit
adb87e2677
3 changed files with 67 additions and 11 deletions
|
@ -9,7 +9,7 @@ class TextViewer(Toplevel):
|
|||
"""A simple text viewer dialog for IDLE
|
||||
|
||||
"""
|
||||
def __init__(self, parent, title, text):
|
||||
def __init__(self, parent, title, text, modal=True):
|
||||
"""Show the given text in a scrollable window with a 'close' button
|
||||
|
||||
"""
|
||||
|
@ -24,8 +24,6 @@ class TextViewer(Toplevel):
|
|||
|
||||
self.CreateWidgets()
|
||||
self.title(title)
|
||||
self.transient(parent)
|
||||
self.grab_set()
|
||||
self.protocol("WM_DELETE_WINDOW", self.Ok)
|
||||
self.parent = parent
|
||||
self.textView.focus_set()
|
||||
|
@ -34,7 +32,11 @@ class TextViewer(Toplevel):
|
|||
self.bind('<Escape>',self.Ok) #dismiss dialog
|
||||
self.textView.insert(0.0, text)
|
||||
self.textView.config(state=DISABLED)
|
||||
self.wait_window()
|
||||
|
||||
if modal:
|
||||
self.transient(parent)
|
||||
self.grab_set()
|
||||
self.wait_window()
|
||||
|
||||
def CreateWidgets(self):
|
||||
frameText = Frame(self, relief=SUNKEN, height=700)
|
||||
|
@ -57,10 +59,10 @@ class TextViewer(Toplevel):
|
|||
self.destroy()
|
||||
|
||||
|
||||
def view_text(parent, title, text):
|
||||
TextViewer(parent, title, text)
|
||||
def view_text(parent, title, text, modal=True):
|
||||
return TextViewer(parent, title, text, modal)
|
||||
|
||||
def view_file(parent, title, filename, encoding=None):
|
||||
def view_file(parent, title, filename, encoding=None, modal=True):
|
||||
try:
|
||||
if encoding:
|
||||
import codecs
|
||||
|
@ -73,7 +75,7 @@ def view_file(parent, title, filename, encoding=None):
|
|||
message='Unable to load file %r .' % filename,
|
||||
parent=parent)
|
||||
else:
|
||||
return view_text(parent, title, textFile.read())
|
||||
return view_text(parent, title, textFile.read(), modal)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
@ -83,11 +85,15 @@ if __name__ == '__main__':
|
|||
filename = './textView.py'
|
||||
text = file(filename, 'r').read()
|
||||
btn1 = Button(root, text='view_text',
|
||||
command=lambda:view_text(root, 'view_text', text))
|
||||
command=lambda:view_text(root, 'view_text', text))
|
||||
btn1.pack(side=LEFT)
|
||||
btn2 = Button(root, text='view_file',
|
||||
command=lambda:view_file(root, 'view_file', filename))
|
||||
btn2.pack(side=LEFT)
|
||||
btn3 = Button(root, text='nonmodal view_text',
|
||||
command=lambda:view_text(root, 'nonmodal view_text', text,
|
||||
modal=False))
|
||||
btn3.pack(side=LEFT)
|
||||
close = Button(root, text='Close', command=root.destroy)
|
||||
close.pack(side=RIGHT)
|
||||
root.mainloop()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue