Gtk.WidgetClass

Fields

Name

Type

Access

Description

compute_expand

object

r

Computes whether a container should give this widget extra space when possible.

contains

object

r

Vfunc for Gtk.Widget.contains().

css_changed

object

r

Vfunc called when the CSS used by widget was changed. Widgets should then discard their caches that depend on CSS and queue resizes or redraws accordingly. The default implementation will take care of this for all the default CSS properties, so implementations must chain up.

direction_changed

object

r

Signal emitted when the text direction of a widget changes.

focus

object

r

Vfunc for Gtk.Widget.child_focus()

get_request_mode

object

r

Called to get the request mode, if the widget does not have a layout manager. This allows a widget to tell its parent container whether it prefers to be allocated in Gtk.SizeRequestMode.HEIGHT_FOR_WIDTH or Gtk.SizeRequestMode.WIDTH_FOR_HEIGHT mode. Gtk.SizeRequestMode.HEIGHT_FOR_WIDTH means the widget prefers to have GtkWidgetClass.measure() called first to get the default width (passing a for_size of -1), then again to get the height for said default width. Gtk.SizeRequestMode.CONSTANT_SIZE disables any height-for-width or width-for-height geometry management for said widget and is the default return. It’s important to note that any widget which trades height-for-width or width-for-height must respond properly to a for_size value >= -1 passed to GtkWidgetClass.measure, for both possible orientations.

grab_focus

object

r

Causes widget to have the keyboard focus for the GtkWindow it’s inside.

hide

object

r

Signal emitted when widget is hidden.

keynav_failed

object

r

Signal emitted if keyboard navigation fails.

map

object

r

Signal emitted when widget is going to be mapped, that is when the widget is visible (which is controlled with Gtk.Widget.set_visible()) and all its parents up to the toplevel widget are also visible.

measure

object

r

Called to obtain the minimum and natural size of the widget, if the widget does not have a layout manager. Depending on the orientation parameter, the passed for_size can be interpreted as width or height. A widget will never be allocated less than its minimum size.

mnemonic_activate

object

r

Activates the widget if group_cycling is False, and just grabs the focus if group_cycling is True.

move_focus

object

r

Signal emitted when a change of focus is requested

padding

[object]

r

parent_class

GObject.InitiallyUnownedClass

r

The object class structure needs to be the first element in the widget class structure in order for the class mechanism to work correctly. This allows a Gtk.WidgetClass pointer to be cast to a GObject.ObjectClass pointer.

query_tooltip

object

r

Signal emitted when “has-tooltip” is True and the hover timeout has expired with the cursor hovering “above” widget; or emitted when widget got focus in keyboard mode.

realize

object

r

Signal emitted when widget is associated with a GdkSurface, which means that Gtk.Widget.realize() has been called or the widget has been mapped (that is, it is going to be drawn).

root

object

r

Called when the widget gets added to a GtkRoot widget. Must chain up

set_focus_child

object

r

Sets the focused child of a widget. Must chain up

show

object

r

Signal emitted when widget is shown

size_allocate

object

r

Called to set the allocation, if the widget does not have a layout manager.

snapshot

object

r

Vfunc called when a new snapshot of the widget has to be taken.

state_flags_changed

object

r

Signal emitted when the widget state changes, see Gtk.Widget.get_state_flags().

system_setting_changed

object

r

Emitted when a system setting was changed. Must chain up.

unmap

object

r

Signal emitted when widget is going to be unmapped, which means that either it or any of its parents up to the toplevel widget have been set as hidden.

unrealize

object

r

Signal emitted when the Gdk.Surface associated with widget is destroyed, which means that Gtk.Widget.unrealize() has been called or the widget has been unmapped (that is, it is going to be hidden).

unroot

object

r

Called when the widget is about to be removed from its GtkRoot widget. Must chain up

Methods

add_shortcut (shortcut)

bind_template_callback_full (callback_name, callback_symbol)

bind_template_child_full (name, internal_child, struct_offset)

get_accessible_role ()

get_activate_signal ()

get_css_name ()

get_layout_manager_type ()

install_action (action_name, parameter_type, activate)

install_property_action (action_name, property_name)

query_action (index_)

set_accessible_role (accessible_role)

set_activate_signal (signal_id)

set_activate_signal_from_name (signal_name)

set_css_name (name)

set_layout_manager_type (type)

set_template (template_bytes)

set_template_from_resource (resource_name)

set_template_scope (scope)

Details

class Gtk.WidgetClass
add_shortcut(shortcut)[source]
Parameters:

shortcut (Gtk.Shortcut) – the GtkShortcut to add

Installs a shortcut in self.

Every instance created for self or its subclasses will inherit this shortcut and trigger it.

Shortcuts added this way will be triggered in the Gtk.PropagationPhase.BUBBLE phase, which means they may also trigger if child widgets have focus.

This function must only be used in class initialization functions otherwise it is not guaranteed that the shortcut will be installed.

bind_template_callback_full(callback_name, callback_symbol)[source]
Parameters:
  • callback_name (str) – The name of the callback as expected in the template XML

  • callback_symbol (GObject.Callback) – The callback symbol

Declares a callback_symbol to handle callback_name from the template XML defined for widget_type.

This function is not supported after [method`Gtk`.WidgetClass.set_template_scope] has been used on self. See [method`Gtk`.BuilderCScope.add_callback_symbol].

Note that this must be called from a composite widget classes class initializer after calling [method`Gtk`.WidgetClass.set_template].

bind_template_child_full(name, internal_child, struct_offset)[source]
Parameters:
  • name (str) – The “id” of the child defined in the template XML

  • internal_child (bool) – Whether the child should be accessible as an “internal-child” when this class is used in Gtk.Builder XML

  • struct_offset (int) – The structure offset into the composite widget’s instance public or private structure where the automated child pointer should be set, or 0 to not assign the pointer.

Automatically assign an object declared in the class template XML to be set to a location on a freshly built instance’s private data, or alternatively accessible via [method`Gtk`.Widget.get_template_child].

The struct can point either into the public instance, then you should use G_STRUCT_OFFSET(WidgetType, member) for struct_offset, or in the private struct, then you should use G_PRIVATE_OFFSET(WidgetType, member).

An explicit strong reference will be held automatically for the duration of your instance’s life cycle, it will be released automatically when GObjectClass.dispose() runs on your instance and if a struct_offset that is != 0 is specified, then the automatic location in your instance public or private data will be set to None. You can however access an automated child pointer the first time your classes GObjectClass.dispose() runs, or alternatively in [signal`Gtk`.Widget::destroy].

If internal_child is specified, [vfunc`Gtk`.Buildable.get_internal_child] will be automatically implemented by the GtkWidget class so there is no need to implement it manually.

The wrapper macros [func`Gtk`.widget_class_bind_template_child], [func`Gtk`.widget_class_bind_template_child_internal], [func`Gtk`.widget_class_bind_template_child_private] and [func`Gtk`.widget_class_bind_template_child_internal_private] might be more convenient to use.

Note that this must be called from a composite widget classes class initializer after calling [method`Gtk`.WidgetClass.set_template].

get_accessible_role()[source]
Returns:

the accessible role for the widget class

Return type:

Gtk.AccessibleRole

Retrieves the accessible role used by the given GtkWidget class.

Different accessible roles have different states, and are rendered differently by assistive technologies.

See also: [method`Gtk`.Accessible.get_accessible_role].

get_activate_signal()[source]
Returns:

a signal id, or 0 if the widget class does not specify an activation signal

Return type:

int

Retrieves the signal id for the activation signal.

the activation signal is set using [method`Gtk`.WidgetClass.set_activate_signal].

get_css_name()[source]
Returns:

the CSS name of the given class

Return type:

str

Gets the name used by this class for matching in CSS code.

See [method`Gtk`.WidgetClass.set_css_name] for details.

get_layout_manager_type()[source]
Returns:

type of a GtkLayoutManager subclass, or GObject.TYPE_INVALID

Return type:

GObject.GType

Retrieves the type of the [class`Gtk`.LayoutManager] used by widgets of class self.

See also: [method`Gtk`.WidgetClass.set_layout_manager_type].

install_action(action_name, parameter_type, activate)[source]
Parameters:
  • action_name (str) – a prefixed action name, such as “clipboard.paste”

  • parameter_type (str or None) – the parameter type

  • activate (Gtk.WidgetActionActivateFunc) – callback to use when the action is activated

This should be called at class initialization time to specify actions to be added for all instances of this class.

Actions installed by this function are stateless. The only state they have is whether they are enabled or not (which can be changed with [method`Gtk`.Widget.action_set_enabled]).

install_property_action(action_name, property_name)[source]
Parameters:
  • action_name (str) – name of the action

  • property_name (str) – name of the property in instances of self or any parent class.

Installs an action called action_name on self and binds its state to the value of the property_name property.

This function will perform a few sanity checks on the property selected via property_name. Namely, the property must exist, must be readable, writable and must not be construct-only. There are also restrictions on the type of the given property, it must be boolean, int, unsigned int, double or string. If any of these conditions are not met, a critical warning will be printed and no action will be added.

The state type of the action matches the property type.

If the property is boolean, the action will have no parameter and toggle the property value. Otherwise, the action will have a parameter of the same type as the property.

query_action(index_)[source]
Parameters:

index (int) – position of the action to query

Returns:

True if the action was found, False if index_ is out of range

owner:

return location for the type where the action was defined

action_name:

return location for the action name

parameter_type:

return location for the parameter type

property_name:

return location for the property name

Return type:

(bool, owner: GObject.GType, action_name: str, parameter_type: GLib.VariantType or None, property_name: str or None)

Returns details about the index_-th action that has been installed for self during class initialization.

See [method`Gtk`.WidgetClass.install_action] for details on how to install actions.

Note that this function will also return actions defined by parent classes. You can identify those by looking at owner.

set_accessible_role(accessible_role)[source]
Parameters:

accessible_role (Gtk.AccessibleRole) – the GtkAccessibleRole used by the self

Sets the accessible role used by the given GtkWidget class.

Different accessible roles have different states, and are rendered differently by assistive technologies.

set_activate_signal(signal_id)[source]
Parameters:

signal_id (int) – the id for the activate signal

Sets the GtkWidgetClass.activate_signal field with the given signal_id.

The signal will be emitted when calling [method`Gtk`.Widget.activate].

The signal_id must have been registered with g_signal_new() or GObject.signal_newv() before calling this function.

set_activate_signal_from_name(signal_name)[source]
Parameters:

signal_name (str) – the name of the activate signal of widget_type

Sets the GtkWidgetClass.activate_signal field with the signal id for the given signal_name.

The signal will be emitted when calling [method`Gtk`.Widget.activate].

The signal_name of widget_type must have been registered with GObject.signal_new() or GObject.signal_newv() before calling this function.

set_css_name(name)[source]
Parameters:

name (str) – name to use

Sets the name to be used for CSS matching of widgets.

If this function is not called for a given class, the name set on the parent class is used. By default, GtkWidget uses the name “widget”.

set_layout_manager_type(type)[source]
Parameters:

type (GObject.GType) – The object type that implements the GtkLayoutManager for self

Sets the type to be used for creating layout managers for widgets of self.

The given type must be a subtype of [class`Gtk`.LayoutManager].

This function should only be called from class init functions of widgets.

set_template(template_bytes)[source]
Parameters:

template_bytes (GLib.Bytes) – A GBytes holding the GtkBuilder XML

This should be called at class initialization time to specify the GtkBuilder XML to be used to extend a widget.

For convenience, [method`Gtk`.WidgetClass.set_template_from_resource] is also provided.

Note that any class that installs templates must call [method`Gtk`.Widget.init_template] in the widget’s instance initializer.

set_template_from_resource(resource_name)[source]
Parameters:

resource_name (str) – The name of the resource to load the template from

A convenience function that calls [method`Gtk`.WidgetClass.set_template] with the contents of a GResource.

Note that any class that installs templates must call [method`Gtk`.Widget.init_template] in the widget’s instance initializer.

set_template_scope(scope)[source]
Parameters:

scope (Gtk.BuilderScope) – The GtkBuilderScope to use when loading the class template

For use in language bindings, this will override the default GtkBuilderScope to be used when parsing Gtk.Builder XML from this class’s template data.

Note that this must be called from a composite widget classes class initializer after calling [method`Gtk`.WidgetClass.set_template].