[Python-checkins] cpython (merge 3.2 -> default): Merge with 3.2 #964437

terry.reedy python-checkins at python.org
Sun Feb 5 21:25:59 CET 2012


http://hg.python.org/cpython/rev/2b841adbae81
changeset:   74801:2b841adbae81
parent:      74798:60beb14636b7
parent:      74800:a949956a80cc
user:        Terry Jan Reedy <tjreedy at udel.edu>
date:        Sun Feb 05 15:24:39 2012 -0500
summary:
  Merge with 3.2 #964437

files:
  Lib/idlelib/EditorWindow.py |  51 ++++++++++++++++++++++++-
  Lib/idlelib/textView.py     |  24 +++++++----
  Misc/NEWS                   |   3 +
  3 files changed, 67 insertions(+), 11 deletions(-)


diff --git a/Lib/idlelib/EditorWindow.py b/Lib/idlelib/EditorWindow.py
--- a/Lib/idlelib/EditorWindow.py
+++ b/Lib/idlelib/EditorWindow.py
@@ -63,6 +63,50 @@
             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
+        self.dlg = None         # the help window iteself
+
+    def display(self, parent, near=None):
+        """ Display the help dialog.
+
+            parent - parent widget for the help window
+
+            near - a Toplevel widget (e.g. EditorWindow or PyShell)
+                   to use as a reference for placing the help window
+        """
+        if self.dlg is None:
+            self.show_dialog(parent)
+        if near:
+            self.nearwindow(near)
+
+    def show_dialog(self, parent):
+        self.parent = parent
+        fn=os.path.join(os.path.abspath(os.path.dirname(__file__)),'help.txt')
+        self.dlg = dlg = textView.view_file(parent,'Help',fn, modal=False)
+        dlg.bind('<Destroy>', self.destroy, '+')
+
+    def nearwindow(self, near):
+        # Place the help dialog near the window specified by parent.
+        # Note - this may not reposition the window in Metacity
+        #  if "/apps/metacity/general/disable_workarounds" is enabled
+        dlg = self.dlg
+        geom = (near.winfo_rootx() + 10, near.winfo_rooty() + 10)
+        dlg.withdraw()
+        dlg.geometry("=+%d+%d" % geom)
+        dlg.deiconify()
+        dlg.lift()
+
+    def destroy(self, ev=None):
+        self.dlg = None
+        self.parent = None
+
+helpDialog = HelpDialog()  # singleton instance
+
+
 class EditorWindow(object):
     from idlelib.Percolator import Percolator
     from idlelib.ColorDelegator import ColorDelegator
@@ -453,8 +497,11 @@
         configDialog.ConfigDialog(self.top,'Settings')
 
     def help_dialog(self, event=None):
-        fn=os.path.join(os.path.abspath(os.path.dirname(__file__)),'help.txt')
-        textView.view_file(self.top,'Help',fn)
+        if self.root:
+            parent = self.root
+        else:
+            parent = self.top
+        helpDialog.display(parent, near=self.top)
 
     def python_docs(self, event=None):
         if sys.platform[:3] == 'win':
diff --git a/Lib/idlelib/textView.py b/Lib/idlelib/textView.py
--- a/Lib/idlelib/textView.py
+++ b/Lib/idlelib/textView.py
@@ -9,7 +9,7 @@
     """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 @@
 
         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 @@
         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 @@
         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:
         with open(filename, 'r', encoding=encoding) as file:
             contents = file.read()
@@ -70,7 +72,7 @@
                                message='Unable to load file %r .' % filename,
                                parent=parent)
     else:
-        return view_text(parent, title, contents)
+        return view_text(parent, title, contents, modal)
 
 
 if __name__ == '__main__':
@@ -80,11 +82,15 @@
     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()
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -466,6 +466,9 @@
 Library
 -------
 
+- Issue #964437 Make IDLE help window non-modal.
+  Patch by Guilherme Polo and Roger Serwy.
+
 - Issue #13734: Add os.fwalk(), a directory walking function yielding file
   descriptors.
 

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list