Accessing Widget Resources

Gamma/GTK: Using Gamma™ with GTK, Version 0.9
Prev | Chapter 2. Differences between Gamma and C for GTK | Next

# 2.2. Accessing Widget Resources

There are potentially three ways to access widget resources in Gamma/GTK:

- Resource name syntax uses the standard Gamma ``instance`.`resource`` notation.

- Methods are generally wrappers for the C function of the same name, minus the `gtk_`widgetname`_` part of the name. They use the Gamma ``instance`.`method`()` notation. All methods wrap functions whose name is of the form: `gtk_`widgetname`_*`, and whose first argument is the corresponding widget class.

- Related Functions are generally wrappers for C functions that do not fit the above naming and argument conventions, and thus cannot be wrapped as methods.

GTK programmers who are used to the C function syntax may be more comfortable with using the method and function calls, but since Gamma is an object-oriented language, we often use the resource name syntax for getting and setting resource values. Here is an example of a code snippet that uses resource name syntax:

        frame = new(GtkFrame)
        frame.label = "Test Frame";
        frame.shadow_type = GTK_SHADOW_OUT;

Here it is in method and function syntax:

        frame = gtk_frame_new("Test Frame");
        frame.set_shadow_type(GTK_SHADOW_OUT);

Of course, many methods provide additional functionality beyond setting or getting a resource value, and thus have no equivalent resource syntax. Also, you will find that a few resources have no resource syntax at all, and can only be set with a method. On the other hand, some resources do not have associated methods, and can only be set directly. The reason for this unusual arrangement is that the GTK widgets and functions are not all written in a completely consistent way. To adapt to some small inconsistencies and to provide the full functionality of GTK, Gamma needs to access certain hidden resources and make them available.

In addition to the above functions, there are many more that are not associated with any particular widget. None of these functions are wrapped as methods, but as functions. They always take the same name as the corresponding C functions, and are generally used in the same way. A list of them appears in the List of Functions (Non Widget-Specific) Appendix of this guide.

Prev | Home | Next
Differences between Gamma and C for GTK | Up | GTK_TYPE_`STRUCTURENAME`

Copyright 1995-2002 by Cogent Real-Time Systems, Inc.