如何将图标添加到Ubuntu应用程序

如何将图标添加到Ubuntu应用程序

问题描述:

我已经开发了一款应用程序,可以快速使用python中的ubuntu。
我打包了它,并且工作完美,但我无法找到如何将图标添加到我的应用程序中,它现在就像一个空白图标。

I have developed an App for ubuntu in python using quickly. I packaged it and is working perfectly but i could not find how to add an icon to my App currently its like a blank icon.

我已经使用了Glade和gtk。

I have used Glade and gtk.

最好的方法是安装一个命名图标。为此,您的安装脚本会将文件复制到依赖于用户系统的特定位置,但通常< datadir> / icons / hicolor /< size> / app /< app-name.png | svg> 其中 datadir 类似于 / usr / local / share 。建议的最小图标大小通常是一个带SVG格式的可缩放图标和一个48x48像素的PNG图标。

The best way is to install a "named icon". To do this, your installation script will copy the file to a specific location which is dependent up on the user's system, but typically <datadir>/icons/hicolor/<size>/app/<app-name.png|svg> where datadir is something like /usr/local/share. The minimum suggested icon sizes are typically a scalable icon with SVG format and a PNG icon that is 48x48 pixels.

将图标复制到正确的位置后,您可以使用gtk - update-icon-cache 命令更新GTK的缓存。

Once you've copied the icons to the right place, you can update GTK's cache using the gtk-update-icon-cache command.

当您安装了命名图标,您的应用程序可以通过名称引用它:

When you've installed a "named icon", your application can refer to it by name:

window = Gtk.Window
window.set_icon_name("myapp")

现在,您需要做的另一件事是安装destop入口文件。这些告诉Ubuntu(或GNOME或KDE或Xfce)关于您的应用程序,以便它可以启动,也是它的图标。您可以根据桌面条目规范创建该文件并将其复制到< datadir> / share / applicaions / 与一个 .desktop 文件扩展名。您可以在系统上安装的应用程序中看到 / usr / share / applications / 中的示例。您也可以使用桌面条目编辑器创建 .desktop 文件。在桌面文件中,图标也会设置为您的命名图标。

Now, one other thing you'll need to do, is install a "destop entry" file. These tell Ubuntu (or GNOME or KDE or Xfce) about your application so that it can be launched and also what it's icon is. You create the file according to the Desktop Entry Specification and copy it to <datadir>/share/applicaions/ with a .desktop file extension. You can see examples in /usr/share/applications/ from applications installed on your system. You could also use Desktop Entry Editor to create the .desktop file. In the desktop file, the icon would be set to your "named icon" too.

因此,总而言之,要安装指定图标和桌面条目,再看一下这样的东西:

So all in all, to install a named icon and a desktop entry, you're looking at something like:

/usr/local/share/applications/myapp.desktop
/usr/local/share/icons/hicolor/scalable/apps/myapp.svg
/usr/local/share/icons/hicolor/48x48/apps/myapp.png