GTK 命名图标:在开发过程中从源代码运行时加载

发布于 2024-11-28 14:14:05 字数 247 浏览 5 评论 0原文

我用 Python 编写了一个 GTK 应用程序(使用 PyGObject)。我对如何处理部署感到困惑,特别是图标。

我知道在大多数情况下,我可以从特定路径加载图像;然而,推荐的方法似乎是将图标注册为系统中的命名图标,这样它们就可以被主题化。在某些情况下,比如 Ubuntu 的应用程序指示器,似乎使用命名图标是唯一受支持的。

我已经完成了所有这些工作;期望我希望我的应用程序在从源目录运行时就可以工作,而不需要在系统范围内安装它。这当然有可能吗?

I have written a GTK app in Python (using PyGObject). I'm confused about how to handle deployment, specifically icons.

I understand that in most cases, I would be able to load my images from a specific path; however, the recommended way seems to be to register icons as named icons with the system, so they can be themed. In some cases, like Ubuntu's app indicators, it seems like using named icons is the only thing that is supported.

I have all this working; expect I'd like my app to work when just run from the source directory, without installing it system-wide. Surely this is possible somehow?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

大海や 2024-12-05 14:14:05

如果您要支持从源目录运行,那么您的可执行文件就必须处理一系列基于路径的问题。修复图标主题查找只是此过程中的另一个步骤。

如果您已经有一个按照图标主题规范要求构建的子目录,那么您需要添加到启动器的是:

icon_path = os.path.abspath('icons')
gtk.IconTheme.append_search_path(icon_path)

其中 icons 包含您的图标主题规范兼容目录(即 hicolor)或目录。

If you're going to support running from the source directory, then your executable is already going to have to deal with a range of path-based issues. Fixing icon theme lookups is just another step in this process.

If you already have a subdirectory structured as required by the icon theme spec, then all you should need to add to your launcher is:

icon_path = os.path.abspath('icons')
gtk.IconTheme.append_search_path(icon_path)

where icons contains your icon-theme-spec compliant directory (i.e., hicolor) or directories.

梦明 2024-12-05 14:14:05

我知道这不是 100% 你正在寻找的东西,但 Gnome 也会识别安装在 ~/.local/share/icons/ 的图标。当程序从源目录运行时,可以将图标复制到那里。

I know this isn't 100% what you're looking for but Gnome will also recognize icons installed at ~/.local/share/icons/. When the program is run from the source directory, the icons could be copied there.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文