Gtk.WidgetClass¶
record (struct)
Methods¶
add_shortcut¶
Installs a shortcut in widget_class.
Every instance created for widget_class or its subclasses will
inherit this shortcut and trigger it.
Shortcuts added this way will be triggered in the 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.
Parameters:
shortcut— the shortcut to add
bind_template_callback_full¶
def bind_template_callback_full(self, callback_name: str, callback_symbol: GObject.Callback) -> None
Associates a name to be used in GtkBuilder XML with a symbol.
This function is not supported after WidgetClass.set_template_scope
has been used on widget_class.
See BuilderCScope.add_callback_symbol.
Note that this must be called from a composite widget classes
class initializer after calling WidgetClass.set_template.
Parameters:
callback_name— name of the callback as expected in the template XMLcallback_symbol— the callback symbol
bind_template_child_full¶
Assigns 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 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 nonzero struct_offset
is specified, then the automatic location in your instance public or private
data will be set to NULL. You can however access an automated child pointer
the first time your classes GObjectClass.dispose() runs, or alternatively
in Widget.destroy.
If internal_child is specified, Buildable.get_internal_child
will be automatically implemented by the widget class so there is no
need to implement it manually.
The wrapper macros Gtk.widget_class_bind_template_child,
Gtk.widget_class_bind_template_child_internal,
Gtk.widget_class_bind_template_child_private and
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 WidgetClass.set_template.
Parameters:
name— ID of the child defined in the template XMLinternal_child— whether the child should be accessible as an “internal-child” when this class is used in GtkBuilder XMLstruct_offset— The 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
get_accessible_role¶
Retrieves the accessible role used by the given widget class.
Different accessible roles have different states, and are rendered differently by assistive technologies.
See also: Accessible.get_accessible_role.
get_activate_signal¶
Retrieves the signal id for the activation signal.
The activation signal is set using
WidgetClass.set_activate_signal.
get_css_name¶
Gets the name used by this class for matching in CSS code.
See WidgetClass.set_css_name for details.
get_layout_manager_type¶
Retrieves the type of the LayoutManager
used by widgets of class widget_class.
See also: WidgetClass.set_layout_manager_type.
install_action¶
def install_action(self, action_name: str, parameter_type: str | None, activate: WidgetActionActivateFunc) -> None
Adds an action for all instances of a widget class.
This function should be called at class initialization time.
Actions installed by this function are stateless. The only state
they have is whether they are enabled or not (which can be changed
with Widget.action_set_enabled).
Parameters:
action_name— a prefixed action name, such as "clipboard.paste"parameter_type— the parameter typeactivate— callback to use when the action is activated
install_property_action¶
Installs an action called action_name on widget_class 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.
Parameters:
action_name— name of the actionproperty_name— name of a property in instances ofwidget_classor any parent class
query_action¶
Returns details about an action that has been
installed for widget_class.
See 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.
Parameters:
index_— position of the action to query
set_accessible_role¶
Sets the accessible role used by the given widget class.
Different accessible roles have different states, and are rendered differently by assistive technologies.
Parameters:
accessible_role— the accessible role to use
set_activate_signal¶
Sets the activation signal for a widget class.
The signal will be emitted when calling Widget.activate.
The signal_id must have been registered with [function.GObject.signal_new]
or GObject.signal_newv before calling this function.
Parameters:
signal_id— the id for the activate signal
set_activate_signal_from_name¶
Sets the activation signal for a widget class.
The signal id will by looked up by signal_name.
The signal will be emitted when calling Widget.activate.
The signal_name must have been registered with [function.GObject.signal_new]
or GObject.signal_newv before calling this function.
Parameters:
signal_name— the name of the activate signal ofwidget_type
set_css_name¶
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".
Parameters:
name— name to use
set_layout_manager_type¶
Sets the type to be used for creating layout managers for
widgets of widget_class.
The given type must be a subtype of LayoutManager.
This function should only be called from class init functions of widgets.
Parameters:
type— the object type that implements theGtkLayoutManagerforwidget_class
set_template¶
This should be called at class initialization time to specify
the GtkBuilder XML to be used to extend a widget.
For convenience, WidgetClass.set_template_from_resource
is also provided.
Note that any class that installs templates must call
Widget.init_template in the widget’s instance initializer.
Parameters:
template_bytes—GBytesholding theGtkBuilderXML
set_template_from_resource¶
A convenience function that calls WidgetClass.set_template
with the contents of a resource.
Note that any class that installs templates must call
Widget.init_template in the widget’s instance
initializer.
Parameters:
resource_name— resource path to load the template from
set_template_scope¶
Overrides the default scope to be used when parsing the class template.
This function is intended for language bindings.
Note that this must be called from a composite widget classes class
initializer after calling WidgetClass.set_template.
Parameters:
scope—GtkBuilderScopeto use when loading the class template