Hello guest, if you read this it means you are not registered. Click here to register in a few simple steps, you will enjoy all features of our Forum.
Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Basic] desktop icon for python app
#1
This is a step-by-step tutorial to place an icon on your desktop that enables you to open a python app, run on your terminal, through a picture icon. I decided to set this up because I wanted a way to do this and had a difficult time getting something operational up and running....so others don't go through the same difficulty.

This is based solely on linux (ubuntu, precisely) but should work for other linux os provided the syntax is tweaked accordingly.


**There is considerable redundancy in the procedure** so that it is a 1 size fits all. It's only for teaching purposes lol. (for example ls -lsh commands can be omitted and so can the nano commands). Yes sys admins will find plenty to object, probably but it is 1 size fits all...and on your local machine u'll be fine. Relax! Tongue

(I use ls and nano just to be sure the cp'd (copied) files are in their intended places...technically more advanced users can use mv instead of cp)

You will need a .desktop file...which looks like this:
Save this as .desktop NOT .py
[Desktop Entry]
Type=Application
Encoding=UTF-8
Name=Fishin
Comment=fishin
Exec=~/usr/share/applications/fishgm1.py
Icon=~/usr/share/icons/hicolor/36x36/apps/gonefishin36.png
Terminal=true
'type' is Application, "terminal" must be set to true
Exec and Icon must point to /usr/share
**note** ubuntu (linux in general) by default looks looks to /usr/share/icons/.. for icon images. Icon image file must be placed here
Name, Comment don't really matter.


This is the longform: (depending on your permissions you have to be root to access /usr/..path)
Again, ls and nano commands can be omitted...I used them just to check myself. And mv can be used for cp.
Output:
me@me-ubuntu:~$ sudo -i [sudo] password for me: root@me-ubuntu:~# cp /home/me/Documents/py/cs/fishgm1.py /usr/share/applications root@me-ubuntu:~# cp /home/me/Documents/py/cs/fishgm1.desktop /usr/share/applications root@me-ubuntu:~# cp /home/me/Documents/py/cs/fishgm1.desktop /home/me/Desktop root@me-ubuntu:~# ls -lsh /usr/share/applications/fishgm1.py /usr/share/applications/fishgm1.desktop 4.0K -rwxr-xr-x 1 root root 189 Mar 11 18:17 /usr/share/applications/fishgm1.desktop 4.0K -rwxr-xr-x 1 root root 3.6K Mar 11 18:16 /usr/share/applications/fishgm1.py root@me-ubuntu:~# cp /home/me/Pictures/gonefishin36.png /usr/share/icons/hicolor/36x36/apps root@me-ubuntu:~# ls -lsh /usr/share/icons/hicolor/36x36/apps/gonefishin36.png12K -rw-r--r-- 1 root root 12K Mar 11 18:20 /usr/share/icons/hicolor/36x36/apps/gonefishin36.png root@me-ubuntu:~# exit logout me@me-ubuntu:~$ cd Desktop me@me-ubuntu:~/Desktop$ ls -lsh *.desktop 4.0K -rwxr-xr-x 1 me me 189 Mar 11 18:17 fishgm1.desktop 4.0K -rwxr-xr-x 1 root root 203 Jan 25 23:47 test1.desktop me@me-ubuntu:~/Desktop$ sudo -i root@me-ubuntu:~# sudo chown me:me /home/me/Desktop/fishgm1.desktop -R root@me-ubuntu:~# sudo -i root@me-ubuntu:~# nano /usr/share/applications/fishgm1.desktop root@me-ubuntu:~# nano /home/me/Desktop/fishgm1.desktop root@me-ubuntu:~# ls -lsh /home/me/Desktop/test1.desktop /home/me/Desktop/fishgm1.desktop 4.0K -rwxr-xr-x 1 me me 189 Mar 11 18:17 /home/me/Desktop/fishgm1.desktop 4.0K -rwxr-xr-x 1 root root 203 Jan 25 23:47 /home/me/Desktop/test1.desktop
Simplified form (remember mv instead of cp...although I copied but still...)
Output:
me@me-ubuntu:~$ sudo -i [sudo] password for me: root@me-ubuntu:~# cp /home/me/Documents/py/cs/fishgm1.py /usr/share/applications root@me-ubuntu:~# cp /home/me/Documents/py/cs/fishgm1.desktop /usr/share/applications root@me-ubuntu:~# cp /home/me/Documents/py/cs/fishgm1.desktop /home/me/Desktop root@me-ubuntu:~# cp /home/me/Pictures/gonefishin36.png /usr/share/icons/hicolor/36x36/apps root@me-ubuntu:~$ cd Desktop root@me-ubuntu:~# chown me:me /home/me/Desktop/fishgm1.desktop
There are about 3 main files
1- the python code (fishgm1.py)
2- icon image (some png file in /usr/share/icons/hicolor/either36_or_48_preferably/apps)
2-desktop file (fishgm1.desktop that creates the link between the image and the python code...aka link 1 and 2 together)

sudo chown just gives permission to the specific username (since everything is really done as root) to access the .desktop icon on your desktop.

You will notice the .desktop file is in BOTH the desktop dir AND applications dir.
Quote

Top Page

Forum Jump:


Users browsing this thread: 1 Guest(s)