mne-tools / mne-python

MNE: Magnetoencephalography (MEG) and Electroencephalography (EEG) in Python
https://mne.tools
BSD 3-Clause "New" or "Revised" License
2.7k stars 1.31k forks source link

MNE-Python application icon broken in Ubuntu 24.04 #12899

Open larsoner opened 6 days ago

larsoner commented 6 days ago

... I think due to the use of Gnome3 newer Ubuntu seems to by default now require a .desktop file to use something other than this in the dock:

image

I tried a bunch of Qt stuff and none of it worked. At some point I stumbled upon a post that mentioned .desktop with StartupWMClass could fix it and indeed this seems to work:

~/.local/share/applications/mne-python.desktop ``` [Desktop Entry] Type=Application Version=1.5 Name=MNE-Python StartupWMClass=MNE-Python Icon=/home/larsoner/python/mne-python/mne/icons/mne_default_icon.png SingleMainWindow=true NoDisplay=true ```

image

@hoechenberger our installers currently add files like mne-python-180_prompt-mne.desktop but I'm not sure if it's possible to have them create a separate linux-only file, do you?

Either way, we could consider adding a note about this to our install docs somewhere as well.

hoechenberger commented 5 days ago

@larsoner The installer creates .desktop files via menuinst; this is why we ship all those icons etc:

https://github.com/conda-forge/mne-feedstock/tree/main/recipe/menu

See the respective config file: https://github.com/conda-forge/mne-feedstock/blob/ac4cd905e3e5ac5e667fd707dfff498a60ade511/recipe/menu/menu.json

I don't fully understand your issue report – are you saying you didn't end up with a .desktop file after using the installer?

larsoner commented 5 days ago

are you saying you didn't end up with a .desktop file after using the installer?

No, there are several .desktop files as expected.

The issue is that on latest Ubuntu -- regardless of whether or not the installer is used -- when you open Python, init a Qt app, and show a window, you get the generic gear icon that shows up in the taskbar (first image pasted above). No runtime Qt calls could be used to set it. This is different from previous versions of Ubuntu, where our app.setWindowIcon(...) worked to set this icon.

The workaround is to have a .desktop file with the StartupWMClass=MNE-Python and Icon=... fields populated appropriately, creating an association between windows of the MNE-Python class (which ours have when we use _init_qt_app) and a given icon. In contrast to what gets installed by the installer, this .desktop file I pasted above is not meant to be a launcher of a program, but rather a sign to Gnome that "hey, windows of this class should use this icon instead of the generic one". That's why it has fields like NoDisplay=true that prevent it from showing up as a program you can launch (e.g., when pressing the Windows key), but once it's launched from the Python terminal (by creating a Qt app and showing a window) the application shows up in the dock with the correct icon.

So the question is really how do should we suggest to people (in install docs) or add to our installer a custom .desktop file for people with the contents I pasted above? For the installer, I'm guessing menuinst would not be the correct way to do it, since we're actually not trying to install a new menu launcher, just a specific .desktop file having to do with a window-class-to-icon association. So maybe the easiest thing would be to add it in the post-install scripts. I'll try a PR for this. Then we just need to decide where this suggestion should live in our install docs.

larsoner commented 5 days ago

... looking at https://conda.github.io/menuinst/reference/ I don't see an option for StartupWMClass which is what we'd need to set. I'll open in issue over there since maybe we could add a Linux specific shortcut for it if we could set this.

larsoner commented 5 days ago

Okay, opened https://github.com/conda-forge/mne-feedstock/pull/139, https://github.com/conda/menuinst/pull/265, and https://github.com/mne-tools/mne-python/pull/12900

hoechenberger commented 4 days ago

Hello, just to clarify, no veto against this PR from my side! I only think that maybe we can come up with an additional / a better solution that requires less user interaction 👍

cbrnr commented 17 hours ago

Hi @larsoner! I have the same problem with MNELAB, but adding the .desktop file doesn't work for me.

I've created ~/.local/share/applications/mnelab.desktop with the following content:

[Desktop Entry]
Type=Application
Version=0.9.2
Name=MNELAB
StartupWMClass=MNELAB
Icon=/home/clemens/mnelab.png
SingleMainWindow=true
NoDisplay=true

Do I have to do anything else? Or is it a problem that the "executable" is really running Python with a specific module (or uvx mnelab)?

larsoner commented 8 hours ago

You need to know the StartupWMClass so start Looking Glass (e.g., alt-F2 then lg) and inspect the window. For example for import matplotlib.pyplot as plt; plt.figure() (which now also has the same problem as us) in the Windows tab I can see:

image

So if I then create:

~/.local/share/applications/matplotlib.desktop ```ini [Desktop Entry] Type=Application Version=1.5 Name=matplotlib StartupWMClass=matplotlib Icon=/home/larsoner/python/matplotlib/lib/matplotlib/mpl-data/images/matplotlib_large.png SingleMainWindow=true NoDisplay=true ```

It updates to use the matplotlib a few seconds later:

image