Socket

A Socket object provides an object for embedding a Plug. The Socket is run in a separate process, and the functionality is transparent to the user.

Constructor

The Socket can be constructed using the following:

socket = Gtk.Socket()

Methods

To retrieve the window ID of the Socket call:

id = socket.get_id()

When .get_id() is called, the unique identifier is returned to the id variable.

Signals

The commonly used signals of an Socket are:

"plug-added" (socket)
"plug-removed" (socket)

The "plug-added" and "plug-removed" signals are emitted when the Plug is connected or disconnected from the Socket. In both cases, the Socket on which the Plug was connected is passed.

Example

Below is an example of a Socket:

#!/usr/bin/env python3

from gi.repository import Gtk
import sys

def plug_event(widget):
    print("A plug has been inserted")

window = Gtk.Window()
window.set_default_size(200, 200)
window.connect("destroy", Gtk.main_quit)

socket = Gtk.Socket()
socket.connect("plug-added", plug_event)
window.add(socket)

print("Socket ID:", socket.get_id())

if len(sys.argv) == 2:
    pid = int(sys.argv[1])
    socket.add_id(pid)

window.show_all()

Gtk.main()

Download: Socket