GTK can construct images by name of the \"icon from current icon theme\". For example:
#!/usr/bin/env python
import gtk; wnd=gtk.Window(); img=gtk.Image();
img.s
Developing on Debian but wanting cross-platform support, I've recently installed gtkmm
and co on both Windows and OS X, via MSYS2 and Homebrew respectively. As an aside, gtkmm
, MSYS2, and Homebrew are excellent projects and well worth a look (I have no affiliation blah blah).
In that time, I think I've gained a decent understanding of why this happens and how to 'fix' it.
This is not a bug in GTK+, as the accepted answer suggests. It's a fact of life when using a library tailored to Linux on another platform, via an environment that creates a Linux-like picture.
On Linux, you have a single environment with a standardised filesystem - via the FHS and FreeDesktop specs - with icons always in /usr/share/icons
.
In contrast, on other platforms, you install Linux-like environments for compilation and sometimes runtime, each with its own virtual filesystem - which is difficult to track by other programs, without doing dangerous things to the end-user's PATH
, especially if you're trying multiple such environments... You get the idea. The end result is that your program, by default, doesn't necessary have any awareness of where your environment's virtual root resides.
The solution, I've found, is to copy all required resources to the same folder as your executable - i.e. the directory you'll eventually redistribute, or if you're writing OSS, do this in your makefile
or such. This is because, as far as I can tell, a program - looking for GTK+ resources, DLLs, etc. - checks its own directory before the (probably not helpful) PATH
. A little opposite to how shells do things, but handy!
So, you copy the relevant icon themes, as installed by your package manager, into a new folder within said directory. At a minimum, do this for the standard theme: copy it to $YOURDIR/share/icons/Adwaita
. Then restart your program. If you're anything like me, now all the icons work perfectly.
The same applies for pretty much any other resource that you need to redistribute with your application.
Notably, I'd suggest doing the same thing with all DLLs needed by your binary. These may or may not work for you out-of-the-box and depending on how you invoke your binary - but you really can't afford to speculate about whether your end-users already have the right set of DLLs installed somewhere in their PATH
, of the right version compiled by the right compiler.