Skip to content

GObject.SignalGroup

class — extends Object

GSignalGroup manages a collection of signals on a GObject.

GSignalGroup simplifies the process of connecting many signals to a GObject as a group. As such there is no API to disconnect a signal from the group.

In particular, this allows you to:

  • Change the target instance, which automatically causes disconnection of the signals from the old instance and connecting to the new instance.
  • Block and unblock signals as a group
  • Ensuring that blocked state transfers across target instances.

One place you might want to use such a structure is with GtkTextView and GtkTextBuffer. Often times, you'll need to connect to many signals on GtkTextBuffer from a GtkTextView subclass. This allows you to create a signal group during instance construction, simply bind the GtkTextView:buffer property to GSignalGroup:target and connect all the signals you need. When the GtkTextView:buffer property changes all of the signals will be transitioned correctly.

Constructors

new

@classmethod
def new(cls, target_type: type | Type) -> SignalGroup

Creates a new SignalGroup for target instances of target_type.

Parameters:

  • target_type — the GType of the target instance.

Methods

block

def block(self) -> None

Blocks all signal handlers managed by self so they will not be called during any signal emissions. Must be unblocked exactly the same number of times it has been blocked to become active again.

This blocked state will be kept across changes of the target instance.

connect_closure

def connect_closure(self, detailed_signal: str, closure: Closure, after: bool) -> None

Connects closure to the signal detailed_signal on SignalGroup:target.

You cannot connect a signal handler after SignalGroup:target has been set.

Parameters:

  • detailed_signal — a string of the form signal-name with optional ::signal-detail
  • closure — the closure to connect.
  • after — whether the handler should be called before or after the default handler of the signal.

connect_data

def connect_data(self, detailed_signal: str, c_handler: Callback, flags: ConnectFlags | int) -> None

Connects c_handler to the signal detailed_signal on the target instance of self.

You cannot connect a signal handler after SignalGroup:target has been set.

Parameters:

  • detailed_signal — a string of the form "signal-name::detail"
  • c_handler — the GCallback to connect
  • flags — the flags used to create the signal connection

connect_swapped

def connect_swapped(self, detailed_signal: str, c_handler: Callback) -> None

Connects c_handler to the signal detailed_signal on the target instance of self.

The instance on which the signal is emitted and data will be swapped when calling c_handler.

You cannot connect a signal handler after SignalGroup:target has been set.

Parameters:

  • detailed_signal — a string of the form "signal-name::detail"
  • c_handler — the GCallback to connect

dup_target

def dup_target(self) -> Object | None

Gets the target instance used when connecting signals.

set_target

def set_target(self, target: Object | None = ...) -> None

Sets the target instance used when connecting signals. Any signal that has been registered with g_signal_group_connect_object() or similar functions will be connected to this object.

If the target instance was previously set, signals will be disconnected from that object prior to connecting to target.

Parameters:

  • target — The target instance used when connecting signals.

unblock

def unblock(self) -> None

Unblocks all signal handlers managed by self so they will be called again during any signal emissions unless it is blocked again. Must be unblocked exactly the same number of times it has been blocked to become active again.

Properties

target

target: Object  # read/write

The target instance used when connecting signals.

target_type

target_type: type | Type  # read/write

The GType of the target property.

Signals

bind

def on_bind(self, instance: Object) -> None: ...

This signal is emitted when SignalGroup:target is set to a new value other than None. It is similar to Object::notify on target except it will not emit when SignalGroup:target is None and also allows for receiving the Object without a data-race.

unbind

def on_unbind(self) -> None: ...

This signal is emitted when the target instance of self is set to a new Object.

This signal will only be emitted if the previous target of self is non-None.