Chapter 22. GTK's rc Files

Table of Contents
23.1. Functions For rc Files
23.2. GTK's rc File Format
23.3. Example rc file
GTK has its own way of dealing with application defaults, by using rc files. These can be used to set the colors of just about any widget, and can also be used to tile pixmaps onto the background of some widgets.

22.1. Functions For rc Files

When your application starts, you should include a call to:
 
rc_parse(filename)

Passing in the filename of your rc file. This will cause GTK to parse this file, and use the style settings for the widget types defined there.

If you wish to have a special set of widgets that can take on a different style from others, or any other logical division of widgets, use a call to:
 
widget.set_name(name)

Your newly created widget will be assigned the name you give. This will allow you to change the attributes of this widget by name through the rc file.

If we use a call something like this:
 
button = GtkButton("Special Button")
button.set_name("special button")

Then this button is given the name "special button" and may be addressed by name in the rc file as "special button.GtkButton". [<--- Verify ME!]

The example rc file below, sets the properties of the main window, and lets all children of that main window inherit the style described by the "main button" style. The code used in the application is:
 
window = GtkWindow(WINDOW_TOPLEVEL)
window.set_name("main window")

And then the style is defined in the rc file using:
 
widget "main window.*GtkButton*" style "main_button"

Which sets all the Button widgets in the "main window" to the "main_buttons" style as defined in the rc file.

As you can see, this is a fairly powerful and flexible system. Use your imagination as to how best to take advantage of this.