Gtk.Socket

g Atk.ImplementorIface Atk.ImplementorIface Gtk.Widget Gtk.Widget Atk.ImplementorIface->Gtk.Widget GObject.GInterface GObject.GInterface GObject.GInterface->Atk.ImplementorIface Gtk.Buildable Gtk.Buildable GObject.GInterface->Gtk.Buildable GObject.InitiallyUnowned GObject.InitiallyUnowned GObject.InitiallyUnowned->Gtk.Widget GObject.Object GObject.Object GObject.Object->GObject.InitiallyUnowned Gtk.Buildable->Gtk.Widget Gtk.Container Gtk.Container Gtk.Socket Gtk.Socket Gtk.Container->Gtk.Socket Gtk.Widget->Gtk.Container

Subclasses:

None

Methods

Inherited:

Gtk.Container (35), Gtk.Widget (278), GObject.Object (37), Gtk.Buildable (10)

Structs:

Gtk.ContainerClass (5), Gtk.WidgetClass (12), GObject.ObjectClass (5)

class

new ()

add_id (window)

get_id ()

get_plug_window ()

Virtual Methods

Inherited:

Gtk.Container (10), Gtk.Widget (82), GObject.Object (7), Gtk.Buildable (10)

do_plug_added ()

do_plug_removed ()

Properties

Inherited:

Gtk.Container (3), Gtk.Widget (39)

Style Properties

Inherited:

Gtk.Widget (17)

Signals

Inherited:

Gtk.Container (4), Gtk.Widget (69), GObject.Object (1)

Name

Short Description

plug-added

This signal is emitted when a client is successfully added to the socket.

plug-removed

This signal is emitted when a client is removed from the socket.

Fields

Inherited:

Gtk.Container (4), Gtk.Widget (69), GObject.Object (1)

Name

Type

Access

Description

container

Gtk.Container

r

Class Details

class Gtk.Socket(**kwargs)
Bases:

Gtk.Container

Abstract:

No

Structure:

Gtk.SocketClass

Together with Gtk.Plug, Gtk.Socket provides the ability to embed widgets from one process into another process in a fashion that is transparent to the user. One process creates a Gtk.Socket widget and passes that widget’s window ID to the other process, which then creates a Gtk.Plug with that window ID. Any widgets contained in the Gtk.Plug then will appear inside the first application’s window.

The socket’s window ID is obtained by using Gtk.Socket.get_id(). Before using this function, the socket must have been realized, and for hence, have been added to its parent.

Obtaining the window ID of a socket.
GtkWidget *socket = gtk_socket_new ();
gtk_widget_show (socket);
gtk_container_add (GTK_CONTAINER (parent), socket);

// The following call is only necessary if one of
// the ancestors of the socket is not yet visible.
gtk_widget_realize (socket);
g_print ("The ID of the sockets window is %#x\n",
         gtk_socket_get_id (socket));

Note that if you pass the window ID of the socket to another process that will create a plug in the socket, you must make sure that the socket widget is not destroyed until that plug is created. Violating this rule will cause unpredictable consequences, the most likely consequence being that the plug will appear as a separate toplevel window. You can check if the plug has been created by using Gtk.Socket.get_plug_window(). If it returns a non-None value, then the plug has been successfully created inside of the socket.

When GTK+ is notified that the embedded window has been destroyed, then it will destroy the socket as well. You should always, therefore, be prepared for your sockets to be destroyed at any time when the main event loop is running. To prevent this from happening, you can connect to the Gtk.Socket ::plug-removed signal.

The communication between a Gtk.Socket and a Gtk.Plug follows the XEmbed Protocol. This protocol has also been implemented in other toolkits, e.g. Qt, allowing the same level of integration when embedding a Qt widget in GTK or vice versa.

The Gtk.Plug and Gtk.Socket widgets are only available when GTK+ is compiled for the X11 platform and %GDK_WINDOWING_X11 is defined. They can only be used on a #GdkX11Display. To use Gtk.Plug and Gtk.Socket, you need to include the gtk/gtkx.h header.

classmethod new()[source]
Returns:

the new Gtk.Socket.

Return type:

Gtk.Widget

Create a new empty Gtk.Socket.

add_id(window)[source]
Parameters:

window (int) – the Window of a client participating in the XEMBED protocol.

Adds an XEMBED client, such as a Gtk.Plug, to the Gtk.Socket. The client may be in the same process or in a different process.

To embed a Gtk.Plug in a Gtk.Socket, you can either create the Gtk.Plug with gtk_plug_new (0), call Gtk.Plug.get_id() to get the window ID of the plug, and then pass that to the Gtk.Socket.add_id(), or you can call Gtk.Socket.get_id() to get the window ID for the socket, and call Gtk.Plug.new() passing in that ID.

The Gtk.Socket must have already be added into a toplevel window before you can make this call.

get_id()[source]
Returns:

the window ID for the socket

Return type:

int

Gets the window ID of a Gtk.Socket widget, which can then be used to create a client embedded inside the socket, for instance with Gtk.Plug.new().

The Gtk.Socket must have already be added into a toplevel window before you can make this call.

get_plug_window()[source]
Returns:

the window of the plug if available, or None

Return type:

Gdk.Window or None

Retrieves the window of the plug. Use this to check if the plug has been created inside of the socket.

New in version 2.14.

do_plug_added() virtual
do_plug_removed() virtual
Return type:

bool

Signal Details

Gtk.Socket.signals.plug_added(socket)
Signal Name:

plug-added

Flags:

RUN_LAST

Parameters:

socket (Gtk.Socket) – The object which received the signal

This signal is emitted when a client is successfully added to the socket.

Gtk.Socket.signals.plug_removed(socket)
Signal Name:

plug-removed

Flags:

RUN_LAST

Parameters:

socket (Gtk.Socket) – The object which received the signal

Returns:

True to stop other handlers from being invoked.

Return type:

bool

This signal is emitted when a client is removed from the socket. The default action is to destroy the Gtk.Socket widget, so if you want to reuse it you must add a signal handler that returns True.