Skip to content

Commit f7c26ed

Browse files
[3.15] gh-66331: Set correct WM_CLASS on X11 for IDLE windows (GH-152733) (#152794)
gh-66331: Set correct WM_CLASS on X11 for IDLE windows (GH-152733) Set the WM_CLASS of IDLE's long-lived windows (window-list windows and the stack viewers) to "Idle" instead of the default "Toplevel", so that window managers group and label them correctly. (cherry picked from commit 4e16b8d) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
1 parent 63da6c8 commit f7c26ed

6 files changed

Lines changed: 16 additions & 2 deletions

File tree

Lib/idlelib/idle_test/test_stackviewer.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ def test_init(self):
3535
isi(stackviewer.sc, ScrolledCanvas)
3636
isi(stackviewer.item, stackviewer.StackTreeItem)
3737
isi(stackviewer.node, TreeNode)
38+
top = stackviewer.sc.frame.winfo_toplevel()
39+
self.assertEqual(top.winfo_class(), 'Idle')
3840

3941

4042
if __name__ == '__main__':

Lib/idlelib/idle_test/test_window.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ def test_init(self):
3939
win = window.ListedToplevel(self.root)
4040
self.assertIn(win, window.registry)
4141
self.assertEqual(win.focused_widget, win)
42+
self.assertEqual(win.winfo_class(), 'Idle')
43+
44+
def test_init_class_override(self):
45+
win = window.ListedToplevel(self.root, class_='Other')
46+
self.assertEqual(win.winfo_class(), 'Other')
4247

4348

4449
if __name__ == '__main__':

Lib/idlelib/pyshell.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -644,7 +644,7 @@ def remote_stack_viewer(self):
644644
return
645645
item = debugobj_r.StubObjectTreeItem(self.rpcclt, oid)
646646
from idlelib.tree import ScrolledCanvas, TreeNode
647-
top = Toplevel(self.tkconsole.root)
647+
top = Toplevel(self.tkconsole.root, class_='Idle')
648648
theme = idleConf.CurrentTheme()
649649
background = idleConf.GetHighlight(theme, 'normal')['background']
650650
sc = ScrolledCanvas(top, bg=background, highlightthickness=0)

Lib/idlelib/stackviewer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
def StackBrowser(root, exc, flist=None, top=None):
1212
global sc, item, node # For testing.
1313
if top is None:
14-
top = tk.Toplevel(root)
14+
top = tk.Toplevel(root, class_='Idle')
1515
sc = ScrolledCanvas(top, bg="white", highlightthickness=0)
1616
sc.frame.pack(expand=1, fill="both")
1717
item = StackTreeItem(exc, flist)

Lib/idlelib/window.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ def call_callbacks(self):
6161
class ListedToplevel(Toplevel):
6262

6363
def __init__(self, master, **kw):
64+
# Set the WM_CLASS property so that X11 window managers group and
65+
# label IDLE's windows under 'Idle' instead of the default
66+
# 'Toplevel' (gh-66331). It matches the class name passed to Tk().
67+
kw.setdefault('class_', 'Idle')
6468
Toplevel.__init__(self, master, kw)
6569
registry.add(self)
6670
self.focused_widget = self
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Set the ``WM_CLASS`` window property of IDLE's windows to ``Idle`` on X11,
2+
so that window managers group and label them correctly instead of using the
3+
default ``Toplevel``.

0 commit comments

Comments
 (0)