GObject.Class
const GObject = imports.gi.GObject; const MyClass = new GObject.Class({ Name: 'MyClass', Extends: Some.GObjectClass, Signals: { 'my-signal': { param_types: [ GObject.TYPE_INT ] }, Properties: { 'frobby': GObject.ParamSpec.bool('frobby', 'Frobby', 'Fill a description here', GObject.ParamFlags.READABLE, false) }, _init: function(params) { this.parent(params); ... }, vfunc_virtual_function: function() { // override virtual_function() with something else this.parent(); }, get frobby() { return true; } });
GObject.Class is a metaclass, or a class representing all GObject derived types. It is used to define new custom classes.
The constructor for GObject.Class, like Lang.Class, requires a name for the class and a class to inherit from (which must be another GObject derived type), plus an initializer (_init) and public methods.
In addition to that, GObject.Class allows to define signals and properties for the new type, as well as the implemented interfaces.
"Implements", if provided, must be an array of interfaces which will be implemented by the new class.
"Signals", if provided, must be an object mapping signal names to signal descriptors, which are objects holding at least the parameter types (param_types), but optionally flags (choosing from GObject.SignalFlags), accumulator (of type GObject.AccumulatorType) and return_type.
"Properties", if provided, must be an object mapping property names to GObject.ParamSpecs. You can optionally provide an accessor to handle property gets and sets.