Re: How to use pixmaps in GTK+ applications?



-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Iago Rubio wrote:
On Sun, 2005-10-16 at 15:03 +0800, åæå wrote:

If I use them as ordinary files, how can I know the path
after users' installation? What should I do in the configure.ac and
Makefile.am?


You should install them in a "known" location defined in one
configure.ac macro.

As example if you've got the files in the "images" directory this code
in the root Makefile.am should do the trick to install them.

[snip: some overcomplicated auto*-foo stuff]

I'd suggest just defining a simple directory under $datadir.  No need to
touch configure.ac at all, and this method is easy to use and relatively
easy to remember.  In the directory in your source tree with the image
file, put this in Makefile.am:

imagedir = $(datadir)/myappname/pixmaps
image_DATA = image.png
EXTRA_DIST = $(image_DATA)

Of course, change 'myappname' to the package name of your app.  You can
add other image files to the image_DATA line, and automake will expand
that out into a set of rules to install the image files to
$datadir/myappname/pixmaps ($datadir is usually $prefix/share, often
/usr/share).  If there's already an EXTRA_DIST line, add it to the
existing one instead of creating a new one.

Then, in the source directory where you want to load image.png from your
program, in Makefile.am, do something like:

myappname_CFLAGS = -DDATADIR=\"$(datadir)\"

(No, the two 'D's is not a typo.) Again, change 'myappname' to the name
of your app's binary as defined in bin_PROGRAMS in that same
Makefile.am.  Note that myappname_CFLAGS will probably already exist and
have something in it; just append it to the line.

Then, in your app, you can load the image like so:

gtk_pixbuf_new_from_file(DATADIR "/myappname/pixmaps/image.png", NULL);

Again, modify 'myappname' as desired.

There are a couple more options:

$datadir/pixmaps/ is generally regarded as a legacy location for app
pixmaps.  You can use it if you want, but it's far better to use the
next option.

If you want to make it possible to theme the icon, you'd want to put
your default icon in the appropriate place under
/usr/share/icons/hicolor/, and then use something like GtkIconTheme to
load it.  That's left as an exercise for the reader, though ^_^.

        -brian

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)

iD8DBQFDUzyu6XyW6VEeAnsRAsShAJ9FRgnp5YQZp6tqjw7SHoICTXSodgCgsDwe
rO098weeIwYl1+56AfK47wY=
=7TNU
-----END PGP SIGNATURE-----



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]