4

I have a python script that does some graphing of data in real-time. While it's running, Ubuntu only shows a question mark icon in the launcher. I'd like to display a custom image.

The reasoning for this is that our application spawns a few different applications, and all of them have the question mark icon. This makes it confusing for the user when wanting to switch focus between the applications.

I have tried creating a Desktop Entry file in ~/.local/share/applications

[Desktop Entry]
Version=1.0
Name=My Plot
Comment=Super cool plot
Exec=python /net/users/username/path/to/plot.py
Icon=plot.png
Terminal=false
Type=Application
Categories=Utility;Application;

Where /net/users/username is my $HOME directory. I tried placing the plot.png icon in /net/users/username/.local/share/icons/hicolor/48x48/apps/

Is that the right way to create a custom icon for a running python script?

Note: I have no desire to launch this script via the Ubuntu Launcher. It wouldn't hurt if the solution also did that. I only want an icon to be displayed while the python script is running.

5
  • Your Desktop Entry isn't going to be valid if you're not launching via the Unity launcher. Are you launching via the terminal ? Commented May 12, 2015 at 14:04
  • Ahhh. I do see I had Terminal=false in there. I copied that from another. I am launching it from a terminal. Eventually it will be a system call from a C++ GUI application, but essentially from a terminal. Is there another way to simply have it show an icon instead of the question mark? Maybe something I can do from within the python script? Commented May 12, 2015 at 14:06
  • Terminal=True will mean that when you launch this from the unity launcher, a terminal will open to run the application. You can see the syntax for desktop entries here However, the desktop entry isn't going to help you in this case. I'll take a look to see what I can find, but first thing's first, I wanted to get you off of the trail of that red herring Commented May 12, 2015 at 14:11
  • Can you show some of your code ? The UI toolkit that you use will be important Commented May 12, 2015 at 14:13
  • I'm using pyqtgraph for plotting. pyqtgraph.org If you had that installed on your machine, you can run python -m pyqtgraph.examples and some sample graphs will come up. That also has a question mark icon. Commented May 12, 2015 at 14:18

1 Answer 1

2

I've worked through setting up a new icon for the pyqtgraph examples module. I edited pyqtgraph.examples.__main__.py which is run in the example that you gave python -m pyqtgraph.examples

In order to give the application an icon, you'll want to give your QApplication a window icon. In this case, I placed 'icon.png' within my path and edited the run() function of the module's main.py file

def run():
    app = QtGui.QApplication([])
    loader = ExampleLoader()
    app.setWindowIcon(QtGui.QIcon('icon.png') # This is the only new line
    app.exec_()

Upon launching you'll see the appropriate icon in your ubuntu task bar. If you run into other trouble with the details, i.e. path for finding the icon etc... you can check out the QT 5 docs here

Sign up to request clarification or add additional context in comments.

1 Comment

I can't believe it was that simple. That is exactly what I was looking for. Thank you so much for taking the time to investigate that.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.