cpython: a949956a80cc (original) (raw)
--- a/Lib/idlelib/EditorWindow.py +++ b/Lib/idlelib/EditorWindow.py @@ -63,6 +63,50 @@ def _find_module(fullname, path=None): descr = os.path.splitext(filename)[1], None, imp.PY_SOURCE return file, filename, descr + +class HelpDialog(object): +
- def init(self):
self.parent = None # parent of help window[](#l1.11)
self.dlg = None # the help window iteself[](#l1.12)
parent - parent widget for the help window[](#l1.17)
near - a Toplevel widget (e.g. EditorWindow or PyShell)[](#l1.19)
to use as a reference for placing the help window[](#l1.20)
"""[](#l1.21)
if self.dlg is None:[](#l1.22)
self.show_dialog(parent)[](#l1.23)
if near:[](#l1.24)
self.nearwindow(near)[](#l1.25)
- def show_dialog(self, parent):
self.parent = parent[](#l1.28)
fn=os.path.join(os.path.abspath(os.path.dirname(__file__)),'help.txt')[](#l1.29)
self.dlg = dlg = textView.view_file(parent,'Help',fn, modal=False)[](#l1.30)
dlg.bind('<Destroy>', self.destroy, '+')[](#l1.31)
- def nearwindow(self, near):
# Place the help dialog near the window specified by parent.[](#l1.34)
# Note - this may not reposition the window in Metacity[](#l1.35)
# if "/apps/metacity/general/disable_workarounds" is enabled[](#l1.36)
dlg = self.dlg[](#l1.37)
geom = (near.winfo_rootx() + 10, near.winfo_rooty() + 10)[](#l1.38)
dlg.withdraw()[](#l1.39)
dlg.geometry("=+%d+%d" % geom)[](#l1.40)
dlg.deiconify()[](#l1.41)
dlg.lift()[](#l1.42)
+ +helpDialog = HelpDialog() # singleton instance + + class EditorWindow(object): from idlelib.Percolator import Percolator from idlelib.ColorDelegator import ColorDelegator @@ -453,8 +497,11 @@ class EditorWindow(object): configDialog.ConfigDialog(self.top,'Settings') def help_dialog(self, event=None):
fn=os.path.join(os.path.abspath(os.path.dirname(__file__)),'help.txt')[](#l1.58)
textView.view_file(self.top,'Help',fn)[](#l1.59)
if self.root:[](#l1.60)
parent = self.root[](#l1.61)
else:[](#l1.62)
parent = self.top[](#l1.63)
helpDialog.display(parent, near=self.top)[](#l1.64)
def python_docs(self, event=None): if sys.platform[:3] == 'win':
--- a/Lib/idlelib/textView.py +++ b/Lib/idlelib/textView.py @@ -9,7 +9,7 @@ class TextViewer(Toplevel): """A simple text viewer dialog for IDLE """
- 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)[](#l2.16)
self.grab_set()[](#l2.17) self.protocol("WM_DELETE_WINDOW", self.Ok)[](#l2.18) self.parent = parent[](#l2.19) self.textView.focus_set()[](#l2.20)
@@ -34,7 +32,11 @@ class TextViewer(Toplevel): self.bind('',self.Ok) #dismiss dialog self.textView.insert(0.0, text) self.textView.config(state=DISABLED)
self.wait_window()[](#l2.25)
if modal:[](#l2.27)
self.transient(parent)[](#l2.28)
self.grab_set()[](#l2.29)
self.wait_window()[](#l2.30)
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):
+def view_text(parent, title, text, modal=True):
-def view_file(parent, title, filename, encoding=None): +def view_file(parent, title, filename, encoding=None, modal=True): try: with open(filename, 'r', encoding=encoding) as file: contents = file.read() @@ -70,7 +72,7 @@ def view_file(parent, title, filename, e message='Unable to load file %r .' % filename, parent=parent) else:
return view_text(parent, title, contents)[](#l2.52)
return view_text(parent, title, contents, modal)[](#l2.53)
if name == 'main': @@ -80,11 +82,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))[](#l2.61)
btn1.pack(side=LEFT) btn2 = Button(root, text='view_file', command=lambda:view_file(root, 'view_file', filename)) btn2.pack(side=LEFT)command=lambda:view_text(root, 'view_text', text))[](#l2.62)
- btn3 = Button(root, text='nonmodal view_text',
command=lambda:view_text(root, 'nonmodal view_text', text,[](#l2.68)
modal=False))[](#l2.69)
- btn3.pack(side=LEFT) close = Button(root, text='Close', command=root.destroy) close.pack(side=RIGHT) root.mainloop()
--- a/Misc/NEWS +++ b/Misc/NEWS @@ -113,6 +113,9 @@ Core and Builtins Library ------- +- Issue #964437 Make IDLE help window non-modal.