[Python-checkins] bpo-43655: Tkinter and IDLE dialog windows are now recognized as dialogs by window managers on macOS and X Window (#25187)

serhiy-storchaka webhook-mailer at python.org
Sun Apr 25 06:08:02 EDT 2021


https://github.com/python/cpython/commit/3bb3fb3be09d472a43cdc3d9d9578bd49f3dfb8c
commit: 3bb3fb3be09d472a43cdc3d9d9578bd49f3dfb8c
branch: master
author: Serhiy Storchaka <storchaka at gmail.com>
committer: serhiy-storchaka <storchaka at gmail.com>
date: 2021-04-25T13:07:58+03:00
summary:

bpo-43655: Tkinter and IDLE dialog windows are now recognized as dialogs by window managers on macOS and X Window (#25187)

files:
A Misc/NEWS.d/next/IDLE/2021-04-04-20-52-07.bpo-43655.HSyaKH.rst
A Misc/NEWS.d/next/Library/2021-04-04-20-51-19.bpo-43655.LwGy8R.rst
M Lib/idlelib/config_key.py
M Lib/idlelib/query.py
M Lib/idlelib/searchbase.py
M Lib/tkinter/filedialog.py
M Lib/tkinter/simpledialog.py

diff --git a/Lib/idlelib/config_key.py b/Lib/idlelib/config_key.py
index 7510aa9f3d878..9ca3a156f4b97 100644
--- a/Lib/idlelib/config_key.py
+++ b/Lib/idlelib/config_key.py
@@ -4,6 +4,7 @@
 from tkinter import Toplevel, Listbox, StringVar, TclError
 from tkinter.ttk import Frame, Button, Checkbutton, Entry, Label, Scrollbar
 from tkinter import messagebox
+from tkinter.simpledialog import _setup_dialog
 import string
 import sys
 
@@ -63,6 +64,7 @@ def __init__(self, parent, title, action, current_key_sequences,
         self.resizable(height=False, width=False)
         self.title(title)
         self.transient(parent)
+        _setup_dialog(self)
         self.grab_set()
         self.protocol("WM_DELETE_WINDOW", self.cancel)
         self.parent = parent
diff --git a/Lib/idlelib/query.py b/Lib/idlelib/query.py
index 015fc7ade459d..fefa5aac1b7f5 100644
--- a/Lib/idlelib/query.py
+++ b/Lib/idlelib/query.py
@@ -28,6 +28,7 @@
 from tkinter.ttk import Frame, Button, Entry, Label, Checkbutton
 from tkinter import filedialog
 from tkinter.font import Font
+from tkinter.simpledialog import _setup_dialog
 
 class Query(Toplevel):
     """Base class for getting verified answer from a user.
@@ -60,13 +61,8 @@ def __init__(self, parent, title, message, *, text0='', used_names={},
         if not _utest:  # Otherwise fail when directly run unittest.
             self.grab_set()
 
-        windowingsystem = self.tk.call('tk', 'windowingsystem')
-        if windowingsystem == 'aqua':
-            try:
-                self.tk.call('::tk::unsupported::MacWindowStyle', 'style',
-                             self._w, 'moveableModal', '')
-            except:
-                pass
+        _setup_dialog(self)
+        if self._windowingsystem == 'aqua':
             self.bind("<Command-.>", self.cancel)
         self.bind('<Key-Escape>', self.cancel)
         self.protocol("WM_DELETE_WINDOW", self.cancel)
diff --git a/Lib/idlelib/searchbase.py b/Lib/idlelib/searchbase.py
index fbef87aa2d3d0..64ed50c7364be 100644
--- a/Lib/idlelib/searchbase.py
+++ b/Lib/idlelib/searchbase.py
@@ -2,6 +2,7 @@
 
 from tkinter import Toplevel
 from tkinter.ttk import Frame, Entry, Label, Button, Checkbutton, Radiobutton
+from tkinter.simpledialog import _setup_dialog
 
 
 class SearchDialogBase:
@@ -83,6 +84,7 @@ def create_widgets(self):
         top.protocol("WM_DELETE_WINDOW", self.close)
         top.wm_title(self.title)
         top.wm_iconname(self.icon)
+        _setup_dialog(top)
         self.top = top
         self.frame = Frame(top, padding="5px")
         self.frame.grid(sticky="nwes")
diff --git a/Lib/tkinter/filedialog.py b/Lib/tkinter/filedialog.py
index 3ed93eb8c163a..600d0bd49fe2c 100644
--- a/Lib/tkinter/filedialog.py
+++ b/Lib/tkinter/filedialog.py
@@ -24,6 +24,7 @@
 )
 from tkinter.dialog import Dialog
 from tkinter import commondialog
+from tkinter.simpledialog import _setup_dialog
 
 
 dialogstates = {}
@@ -62,6 +63,7 @@ def __init__(self, master, title=None):
         self.top = Toplevel(master)
         self.top.title(title)
         self.top.iconname(title)
+        _setup_dialog(self.top)
 
         self.botframe = Frame(self.top)
         self.botframe.pack(side=BOTTOM, fill=X)
diff --git a/Lib/tkinter/simpledialog.py b/Lib/tkinter/simpledialog.py
index a66fbd6cb9885..538bbfc318d70 100644
--- a/Lib/tkinter/simpledialog.py
+++ b/Lib/tkinter/simpledialog.py
@@ -40,6 +40,9 @@ def __init__(self, master,
         if title:
             self.root.title(title)
             self.root.iconname(title)
+
+        _setup_dialog(self.root)
+
         self.message = Message(self.root, text=text, aspect=400)
         self.message.pack(expand=1, fill=BOTH)
         self.frame = Frame(self.root)
@@ -115,6 +118,8 @@ def __init__(self, parent, title = None):
         if title:
             self.title(title)
 
+        _setup_dialog(self)
+
         self.parent = parent
 
         self.result = None
@@ -252,6 +257,13 @@ def _place_window(w, parent=None):
     w.wm_deiconify() # Become visible at the desired location
 
 
+def _setup_dialog(w):
+    if w._windowingsystem == "aqua":
+        w.tk.call("::tk::unsupported::MacWindowStyle", "style",
+                  w, "moveableModal", "")
+    elif w._windowingsystem == "x11":
+        w.wm_attributes("-type", "dialog")
+
 # --------------------------------------------------------------------
 # convenience dialogues
 
diff --git a/Misc/NEWS.d/next/IDLE/2021-04-04-20-52-07.bpo-43655.HSyaKH.rst b/Misc/NEWS.d/next/IDLE/2021-04-04-20-52-07.bpo-43655.HSyaKH.rst
new file mode 100644
index 0000000000000..105ec9281f005
--- /dev/null
+++ b/Misc/NEWS.d/next/IDLE/2021-04-04-20-52-07.bpo-43655.HSyaKH.rst
@@ -0,0 +1,2 @@
+IDLE dialog windows are now recognized as dialogs by window managers on
+macOS and X Window.
diff --git a/Misc/NEWS.d/next/Library/2021-04-04-20-51-19.bpo-43655.LwGy8R.rst b/Misc/NEWS.d/next/Library/2021-04-04-20-51-19.bpo-43655.LwGy8R.rst
new file mode 100644
index 0000000000000..7916d2248b231
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2021-04-04-20-51-19.bpo-43655.LwGy8R.rst
@@ -0,0 +1,2 @@
+:mod:`tkinter` dialog windows are now recognized as dialogs by window
+managers on macOS and X Window.



More information about the Python-checkins mailing list