classification
Title: IDLE: Set correct WM_CLASS on X11
Type: behavior Stage: test needed
Components: IDLE Versions: Python 3.10
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: terry.reedy Nosy List: Saimadhav.Heblikar, jesstess, serhiy.storchaka, terry.reedy
Priority: normal Keywords: patch

Created on 2014-08-04 14:30 by Saimadhav.Heblikar, last changed 2020-06-07 22:15 by terry.reedy.

Files
File name Uploaded Description Edit
idle-x11-class.diff Saimadhav.Heblikar, 2014-08-04 14:30 review
after-before.png Saimadhav.Heblikar, 2014-08-04 14:30
idle_wm_class.diff serhiy.storchaka, 2014-09-23 20:38 review
Messages (12)
msg224728 - (view) Author: Saimadhav Heblikar (Saimadhav.Heblikar) * Date: 2014-08-04 14:30
I found this bug on gnome where IDLE's activity bar entry is named "Toplevel" instead of "IDLE". After digging through the X11 and gnome docs, the WM_CLASS was wrongly being set as "Toplevel". This patch has been verified using xprop, that the correct WM_CLASS value is getting set.

(Does this have any other side effect on KDE, LXDE, XFCE et al?)
msg224788 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2014-08-04 23:41
Serhiy, do you know if the trivial addition of "class_='IDLE'" can have any ill effect on non-gnome systems? It looks sensible to me, and I see no effect on Windows.
-    self.top = top = WindowList.ListedToplevel(root, menu=self.menubar)
+    self.top = top = WindowList.ListedToplevel(root, class_='IDLE',
+                                               menu=self.menubar)
msg224808 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2014-08-05 05:31
I see no effect on KDE.

We should change window class also for other toplevel windows (from stack viewer to calltip). And for turtledemo and other gui demos too.
msg224814 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2014-08-05 09:28
> And for turtledemo and other gui demos too.

No, this is not needed because they are not installed as separate applications and have not specific .desctop file.

As said on https://wiki.gnome.org/Projects/GnomeShell/ApplicationBased:

"""
To ensure the GNOME 3 Shell will track your application, you can also set the WM_CLASS X window property to be the same as your application's .desktop file name, without the .desktop extension (the desktop file should be lower-case).
"""
Is "class_='IDLE'" works when only IDLE for Python 3 (not for Python 2) is installed? Shouldn't it be 'IDLE3'?
msg224823 - (view) Author: Saimadhav Heblikar (Saimadhav.Heblikar) * Date: 2014-08-05 12:58
>>Is "class_='IDLE'" works when only IDLE for Python 3 (not for Python 2) is installed? Shouldn't it be 'IDLE3'?

I tried class_="IDLE"(or any other string)  for python2 repo build, and it works.

Most applications on Gnome set it to just the name of the program, like "Terminal", or "Google Chrome". So that is why I suggested "IDLE". Even though we have 2 versions of IDLE, we have the IDLE title bar to give more information related to the version etc.
IIRC, OSX also has a system wide title bar which displays the program name which currently has focus. Could we use that as a precedence to choose "IDLE" vs {"IDLE2", "IDLE3"}?
msg224833 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2014-08-05 14:29
I think we should use class_="IDLE3" (or class_="Idle3") on Python 3. I did not check, but I suppose this should has following effects on Gnome Shell:

* Gnome Shell should display IDLE icon from desktop file in different places.
* When IDLE is launched, clicking on it in the dock in the overview should brings focus to it.

Saimadhav, please try class_="Idle" (title case). I suppose that IDLE's activity bar entry will be named "IDLE" (upper case), because Gnome Shell will get the name from IDLE's desktop file (/usr/share/applications/idle.desktop).

There is duplicate issue (issue13553) but it doesn't provide good solution.

For the demonstration, folowing code displays on KDE two windows with IDLE icon if IDLE3 is installed.

>>> from tkinter import *
>>> tk = Tk(className='Idle3')
>>> top = Toplevel(tk, class_='Idle3')
msg224855 - (view) Author: Saimadhav Heblikar (Saimadhav.Heblikar) * Date: 2014-08-05 16:30
"Saimadhav, please try class_="Idle" (title case). I suppose that IDLE's activity bar entry will be named "IDLE" (upper case), because Gnome Shell will get the name from IDLE's desktop file (/usr/share/applications/idle.desktop)."

No. It stays "Idle". Also there was no file for me in /usr/share/applications/idle.desktop. An idle.desktop file was found in /usr/share/app-install/desktop/idle.desktop, whose content is
[Desktop Entry]
X-AppInstall-Package=idle
X-AppInstall-Popcon=132
X-AppInstall-Section=main

Name=IDLE
Comment=Integrated Development Environment for Python
Exec=/usr/bin/idle
Icon=/usr/share/pixmaps/idle.xpm
Terminal=false
MultipleArgs=false
Type=Application
Categories=Application;Development;
StartupNotify=true

I don't have any icon file at /usr/share/pixmaps/idle.xpm

After copying the above idle.desktop to /usr/share/applications/, the activity bar becomes "IDLE". There is NO icon.
If I set class_='Idle3', it works as expected with icon and text.

With 2.7, 'Idle2', displays same behavior with proper icon and text.
With 2.7, 'Idle' it displays "IDLE" and no icon.
msg224884 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2014-08-05 20:27
> We should change window class also for other toplevel windows (from stack viewer to calltip).

Grepping idlelib for 'toplevel, there are about 10. Do all of the Toplevels get put on the activity bar?  I would not expect that popups like calltip would.

I expect that all ListedToplevels could be handled at once by adding the following as the first line of ListedToplevel.__init__.
   kw["class"] = 'IDLE'

What is wrong with simply adding classname to the Tk() call, as Roger suggested in #13553. Does KDE display 2 windows without name='Idle' in the toplevel call?  Is this a KDE or tk bug?
msg225810 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2014-08-24 11:06
> Grepping idlelib for 'toplevel, there are about 10. Do all of the Toplevels get put on the activity bar?  I would not expect that popups like calltip would.

I don't know how dialogs and calltip popups behave on Gnome Shell. But I think we should do this at least for more or less long-lived windows such as stack viewer. On KDE when I added ``kw["class"] = 'Idle3'`` to ListedToplevel constructor, console and editor windows are grouped on taskbar, and stack viewer is separated (without this line all three windows are in the same group).

> I expect that all ListedToplevels could be handled at once by adding the following as the first line of ListedToplevel.__init__.

May be, but this is not so simple. To be robust we should handle both 'class' and 'class_' keywords (and may be even '-class').

> What is wrong with simply adding classname to the Tk() call, as Roger suggested in #13553.

This affects only WM_CLASS of root window (which is withdrawn right after creation in IDLE).

> Does KDE display 2 windows without name='Idle' in the toplevel call?  Is this a KDE or tk bug?

``tk = Tk(className='Idle3')`` creates first (root) window and ``top = Toplevel(tk, class_='Idle3')`` creates second window. The className argument affects root window (and some other things) and the class argument affects Toplevel window.

Another example:

>>> from tkinter import *
>>> tk = Tk(className='Firefox')
>>> top = Toplevel(tk, class_='Chromium-browser')

Created two windows: one with title "firefox" and Firefox icon, and other with title "firefox" and Chromium icon.

I argue that we should add className="Idle3" to every Tk constructor and class_="Idle3" to most (iv not every) Toplevel constructor. On Python 2 it should be "Idle2" or "Idle" (not sure).
msg227390 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2014-09-23 20:38
Here is a patch which sets WM_CLASS of all long-lived toplevel windows.
msg227759 - (view) Author: Saimadhav Heblikar (Saimadhav.Heblikar) * Date: 2014-09-28 15:00
>I don't know how dialogs and calltip popups behave on Gnome Shell

Can you reply what behaviour you want to confirm?
If you meant, grouping  - Toplevels like ClassBrowser, PathBrowser etc are always grouped as single unit in the "Activity Bar". But, in the popup which you get for "Alt + Tab", they are displayed as 2 different applications - stress on different. For example, if I have two different windows of Google Chrome open, they are listed as a single application, both windows nested under a single logo. With IDLE, its two different applications.

tkMessageBox and tkFileDialog usage like in "open_class_browser()" and "Save As" change the title of in the Activity Bar and "Alt+Tab" menu to "tkFDialog". I am not sure if there is a way to pass class_ argument in such a situation.

Just a suggestion, can we use sys.version_info to get Python major version to have uniform code?
msg243245 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2015-05-15 05:07
> Just a suggestion, can we use sys.version_info to get Python major version to have uniform code?

Uniform code is too verbose. WM_CLASS should be "Idle" on Python 2 and "Idle3" on Python 3.

    top = Toplevel(self.root, class_='Idle' if sys.version_info[0] <= 2 else 'Idle%s' % sys.version_info[0])

It is easy to write just the constant literal. It is changed only when the major version is changed.
History
Date User Action Args
2020-06-07 22:15:23terry.reedysetversions: + Python 3.10, - Python 3.6, Python 3.7
2017-06-23 06:24:31terry.reedysetassignee: terry.reedy
stage: test needed
type: behavior
versions: + Python 3.6, Python 3.7, - Python 2.7, Python 3.4, Python 3.5
2015-05-15 05:07:58serhiy.storchakasetmessages: + msg243245
2014-09-28 15:00:06Saimadhav.Heblikarsetmessages: + msg227759
2014-09-23 20:38:12serhiy.storchakasetfiles: + idle_wm_class.diff

messages: + msg227390
2014-08-24 11:06:56serhiy.storchakasetmessages: + msg225810
2014-08-05 20:27:11terry.reedysetmessages: + msg224884
2014-08-05 16:30:35Saimadhav.Heblikarsetmessages: + msg224855
2014-08-05 14:29:50serhiy.storchakasetmessages: + msg224833
2014-08-05 12:58:13Saimadhav.Heblikarsetmessages: + msg224823
2014-08-05 09:28:39serhiy.storchakasetmessages: + msg224814
2014-08-05 05:31:34serhiy.storchakasetmessages: + msg224808
2014-08-04 23:41:43terry.reedysetnosy: + serhiy.storchaka
messages: + msg224788
2014-08-04 14:30:54Saimadhav.Heblikarsetfiles: + after-before.png
2014-08-04 14:30:22Saimadhav.Heblikarcreate