GObject.ObjectClass

Fields

Name

Type

Access

Description

construct_properties

[object]

r

constructed

object

r

the constructed function is called by g_object_new() as the final step of the object creation process. At the point of the call, all construction properties have been set on the object. The purpose of this call is to allow for object initialisation steps that can only be performed after construction properties have been set. constructed implementors should chain up to the constructed call of their parent class to allow it to complete its initialisation.

constructor

object

r

the constructor function is called by g_object_new () to complete the object initialization after all the construction properties are set. The first thing a constructor implementation must do is chain up to the constructor of the parent class. Overriding constructor should be rarely needed, e.g. to handle construct properties, or to implement singletons.

dispatch_properties_changed

object

r

emits property change notification for a bunch of properties. Overriding dispatch_properties_changed should be rarely needed.

dispose

object

r

the dispose function is supposed to drop all references to other objects, but keep the instance otherwise intact, so that client method invocations still work. It may be run multiple times (due to reference loops). Before returning, dispose should chain up to the dispose method of the parent class.

finalize

object

r

instance finalization function, should finish the finalization of the instance begun in dispose and chain up to the finalize method of the parent class.

flags

int

r

g_type_class

GObject.TypeClass

r

the parent class

get_property

object

r

the generic getter for all properties of this type. Should be overridden for every type with properties.

n_construct_properties

int

r

n_pspecs

int

r

notify

object

r

the class closure for the notify signal

pdummy

[object]

r

pspecs

object

r

set_property

object

r

the generic setter for all properties of this type. Should be overridden for every type with properties. If implementations of set_property don’t emit property change notification explicitly, this will be done implicitly by the type system. However, if the notify signal is emitted explicitly, the type system will not emit it a second time.

Methods

find_property (property_name)

install_properties (pspecs)

install_property (property_id, pspec)

list_properties ()

override_property (property_id, name)

Details

class GObject.ObjectClass

The class structure for the GObject.Object type.

// Example of implementing a singleton using a constructor.
static MySingleton *the_singleton = NULL;

static GObject*
my_singleton_constructor (GType                  type,
                          guint                  n_construct_params,
                          GObjectConstructParam *construct_params)
{
  GObject *object;

  if (!the_singleton)
    {
      object = G_OBJECT_CLASS (parent_class)->constructor (type,
                                                           n_construct_params,
                                                           construct_params);
      the_singleton = MY_SINGLETON (object);
    }
  else
    object = g_object_ref (G_OBJECT (the_singleton));

  return object;
}
find_property(property_name)[source]
Parameters:

property_name (str) – the name of the property to look up

Returns:

the GObject.ParamSpec for the property, or None if the class doesn’t have a property of that name

Return type:

GObject.ParamSpec

Looks up the GObject.ParamSpec for a property of a class.

install_properties(pspecs)[source]
Parameters:

pspecs ([GObject.ParamSpec]) – the GObject.ParamSpecs array defining the new properties

Installs new properties from an array of GObject.ParamSpecs.

All properties should be installed during the class initializer. It is possible to install properties after that, but doing so is not recommend, and specifically, is not guaranteed to be thread-safe vs. use of properties on the same type on other threads.

The property id of each property is the index of each GObject.ParamSpec in the pspecs array.

The property id of 0 is treated specially by GObject.Object and it should not be used to store a GObject.ParamSpec.

This function should be used if you plan to use a static array of GObject.ParamSpecs and GObject.Object.notify_by_pspec(). For instance, this class initialization:

typedef enum {
  PROP_FOO = 1,
  PROP_BAR,
  N_PROPERTIES
} MyObjectProperty;

static GParamSpec *obj_properties[N_PROPERTIES] = { NULL, };

static void
my_object_class_init (MyObjectClass *klass)
{
  GObjectClass *gobject_class = G_OBJECT_CLASS (klass);

  obj_properties[PROP_FOO] =
    g_param_spec_int ("foo", NULL, NULL,
                      -1, G_MAXINT,
                      0,
                      G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);

  obj_properties[PROP_BAR] =
    g_param_spec_string ("bar", NULL, NULL,
                         NULL,
                         G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);

  gobject_class->set_property = my_object_set_property;
  gobject_class->get_property = my_object_get_property;
  g_object_class_install_properties (gobject_class,
                                     G_N_ELEMENTS (obj_properties),
                                     obj_properties);
}

allows calling GObject.Object.notify_by_pspec() to notify of property changes:

void
my_object_set_foo (MyObject *self, gint foo)
{
  if (self->foo != foo)
    {
      self->foo = foo;
      g_object_notify_by_pspec (G_OBJECT (self), obj_properties[PROP_FOO]);
    }
 }

New in version 2.26.

install_property(property_id, pspec)[source]
Parameters:

Installs a new property.

All properties should be installed during the class initializer. It is possible to install properties after that, but doing so is not recommend, and specifically, is not guaranteed to be thread-safe vs. use of properties on the same type on other threads.

Note that it is possible to redefine a property in a derived class, by installing a property with the same name. This can be useful at times, e.g. to change the range of allowed values or the default value.

list_properties()[source]
Returns:

an array of GObject.ParamSpec which should be freed after use

Return type:

[GObject.ParamSpec]

Get an array of GObject.ParamSpec for all properties of a class.

override_property(property_id, name)[source]
Parameters:
  • property_id (int) – the new property ID

  • name (str) – the name of a property registered in a parent class or in an interface of this class.

Registers property_id as referring to a property with the name name in a parent class or in an interface implemented by self. This allows this class to “override” a property implementation in a parent class or to provide the implementation of a property from an interface.

Internally, overriding is implemented by creating a property of type GObject.ParamSpecOverride; generally operations that query the properties of the object class, such as GObject.ObjectClass.find_property() or GObject.ObjectClass.list_properties() will return the overridden property. However, in one case, the construct_properties argument of the constructor virtual function, the GObject.ParamSpecOverride is passed instead, so that the param_id field of the GObject.ParamSpec will be correct. For virtually all uses, this makes no difference. If you need to get the overridden property, you can call GObject.ParamSpec.get_redirect_target().

New in version 2.4.