Re: Compiled resources



On Thu, Aug 4, 2011 at 5:33 PM, George Brink <siberianowl yahoo com> wrote:
> I'd like to insert some files into my binary. For example application icons,
> glade definitions of primary windows etc...
> In Qt such task is done by utilizing QRC:
> http://doc.qt.nokia.com/latest/resources.html
> Does GLib/GTK have something similar? If not, what external libraries/tools
> do you use for such a task?

For Glade files, you can load them from string constants compiled into
your binary using gtk_builder_add_from_string()[0]. A project can be
pretty simply setup to do this, generally you have a revisioned
'project.glade.in' and use INTLTOOL_XML_NOMERGE_RULE (not
sure if that's the exact macro), but you could then add a rule to
generate a '.h' file from the '.glade' or '.ui' easily enough (just
need to escape the string and declare a string constant, probably
doable with sed or such).

For icons you can go by gdk_pixbuf_new_from_data()[1] or better yet
you can use gdk_pixbuf_new_from_stream() which will detect the data format
appropriately (you just need to be able to create the stream from some constant
data in your program).

Embedding a png into a binary can be done as easy as generating a header file
with contents like:

const unsigned char *image_data = "\030\004\012...";

...and generating that is a script or tiny program that writes out the value of
every byte of the input file... which might be a png file... into the
'image_data'
string constant in the generated header.

If you want to refer to your own icons explicitly from your glade
file, then you should
look into using GtkIconTheme. Just add a routine to your program to
load your binary
icons and use that to populate the icon theme... then you can refer to them as
stock ids (widgets that can display an icon almost always export a
"stock" property).

GtkBuilder and Glade do allow you to define the GtkIconTheme from a glade file
but it does not let you embed binary image data into the glade file...
however that
might very well be an interesting feature idea.

I dont know if there are any external tools that exist to make this
somehow easier,
the approaches above I described are not much work but very hand-on.

Good luck ;-)

Cheers,
          -Tristan

[0]http://developer.gnome.org/gtk3/3.1/GtkBuilder.html#gtk-builder-add-from-string
[1]http://developer.gnome.org/gdk-pixbuf/stable/gdk-pixbuf-creating.html#gdk-pixbuf-new-from-data
[2]http://developer.gnome.org/gdk-pixbuf/stable/gdk-pixbuf-file-loading.html#gdk-pixbuf-new-from-stream


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