/usr/share/doc/python-gtk2-tutorial/html/sec-PlugsAndSockets.html is in python-gtk2-tutorial 2.4-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 | <html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>10.13. Plugs and Sockets</title><meta name="generator" content="DocBook XSL Stylesheets V1.65.1"><link rel="home" href="index.html" title="PyGTK 2.0 Tutorial"><link rel="up" href="ch-ContainerWidgets.html" title="Chapter 10. Container Widgets"><link rel="previous" href="sec-Notebooks.html" title="10.12. Notebooks"><link rel="next" href="ch-MenuWidget.html" title="Chapter 11. Menu Widget"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">10.13. Plugs and Sockets</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="sec-Notebooks.html">Prev</a> </td><th width="60%" align="center">Chapter 10. Container Widgets</th><td width="20%" align="right"> <a accesskey="n" href="ch-MenuWidget.html">Next</a></td></tr></table><hr></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="sec-PlugsAndSockets"></a>10.13. Plugs and Sockets</h2></div></div><div></div></div><p><tt class="classname">Plugs</tt> and <tt class="classname">Sockets</tt>
cooperate to embed the user interface from one process into another process.
This can also be accomplished using Bonobo.</p><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id3114722"></a>10.13.1. Plugs</h3></div></div><div></div></div><p>A <tt class="classname">Plug</tt> encapsulates a user interface
provided by one application so that it can be embedded in another
application's user interface. The "embedded" signal alerts the plug
application that the plug has been embedded in the other application's user
interface.</p><p>A <tt class="classname">Plug</tt> is created using the following
function:</p><table border="0" bgcolor="#E0E0E0" width="100%"><tr><td><pre class="programlisting">
plug = gtk.Plug(socket_id)
</pre></td></tr></table><p>which creates a new <tt class="classname">Plug</tt> and embeds it in
the <tt class="classname">Socket</tt> identified by
<i class="parameter"><tt>socket_id</tt></i>. If <i class="parameter"><tt>socket_id</tt></i> is 0L,
the plug is left "unplugged" and can later be plugged into a
<tt class="classname">Socket</tt> using the <tt class="classname">Socket</tt>
<tt class="methodname">add_id</tt>() method.</p><p>The <tt class="classname">Plug</tt> method:</p><table border="0" bgcolor="#E0E0E0" width="100%"><tr><td><pre class="programlisting">
id = plug.get_id()
</pre></td></tr></table><p>returns the window ID of a <tt class="classname">Plug</tt>, that can
be used to embed it inside a <tt class="classname">Socket</tt> using the
<tt class="classname">Socket</tt> <tt class="methodname">add_id</tt>()
method.</p><p>The <a href="examples/plug.py" target="_top"><span><b class="command">plug.py</b></span></a> example
program illustrates the use of a Plug:</p><table border="0" bgcolor="#E0E0E0" width="100%"><tr><td><pre class="programlisting">
1 #!/usr/bin/python
2
3 import pygtk
4 pygtk.require('2.0')
5 import gtk,sys
6
7 Wid = 0L
8 if len(sys.argv) == 2:
9 Wid = long(sys.argv[1])
10
11 plug = gtk.Plug(Wid)
12 print "Plug ID=", plug.get_id()
13
14 def embed_event(widget):
15 print "I (",widget,") have just been embedded!"
16
17 plug.connect("embedded", embed_event)
18
19 entry = gtk.Entry()
20 entry.set_text("hello")
21 def entry_point(widget):
22 print "You've changed my text to '%s'" % widget.get_text()
23
24 entry.connect("changed", entry_point)
25 plug.connect("destroy", gtk.mainquit)
26
27 plug.add(entry)
28 plug.show_all()
29
30
31 gtk.mainloop()
</pre></td></tr></table><p>The program is invoked like:</p><table border="0" bgcolor="#E0E0E0" width="100%"><tr><td><pre class="programlisting">
plug.py [windowID]
</pre></td></tr></table><p>where <i class="parameter"><tt>windowID</tt></i> is the ID of a
<tt class="classname">Socket</tt> to connect the <tt class="classname">Plug</tt>
to.</p></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id3114847"></a>10.13.2. Sockets</h3></div></div><div></div></div><p>A <tt class="classname">Socket</tt> provides the widget to embed a
<tt class="classname">Plug</tt> widget from another application into your GUI
transparently. An application creates a <tt class="classname">Socket</tt> widget
and, passes that widget's window ID to another application, which then
creates a <tt class="classname">Plug</tt> using that window ID as a
parameter. Any widgets contained in the <tt class="classname">Plug</tt> appear
inside the first application's window.</p><p>The <tt class="classname">Socket</tt> window ID is obtained by using
the <tt class="classname">Socket</tt> method <tt class="methodname">get_id</tt>().
Before using this method, the <tt class="classname">Socket</tt> must be
realized, and added to its parent.</p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p>If you pass the window ID of the <tt class="classname">Socket</tt>
to another process that will create a <tt class="classname">Plug</tt> in the
<tt class="classname">Socket</tt>, you must make sure that the
<tt class="classname">Socket</tt> widget is not destroyed until that
<tt class="classname">Plug</tt> is created.</p></div><p>When GTK+ is notified that the embedded window has been
destroyed, then it will destroy the <tt class="classname">Socket</tt> as well.
You should always, therefore, be prepared for your sockets to be destroyed
at any time when the main event loop is running. Destroying a
<tt class="classname">Socket</tt> will cause an embedded
<tt class="classname">Plug</tt> to be destroyed as well.</p><p>The communication between a <tt class="classname">Socket</tt> and a
<tt class="classname">Plug</tt> 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.</p><p>Create a new empty <tt class="classname">Socket</tt>:</p><table border="0" bgcolor="#E0E0E0" width="100%"><tr><td><pre class="programlisting">
socket = gtk.Socket()
</pre></td></tr></table><p>The <tt class="classname">Socket</tt> must be contained in a
toplevel window before you invoke the <tt class="methodname">add_id</tt>()
method:</p><table border="0" bgcolor="#E0E0E0" width="100%"><tr><td><pre class="programlisting">
socket.add_id(window_id)
</pre></td></tr></table><p>which adds an XEMBED client, such as a
<tt class="classname">Plug</tt>, to the <tt class="classname">Socket</tt>. The
client may be in the same process or in a different process.</p><p>To embed a <tt class="classname">Plug</tt> in a
<tt class="classname">Socket</tt>, you can either create the
<tt class="classname">Plug</tt> with:</p><table border="0" bgcolor="#E0E0E0" width="100%"><tr><td><pre class="programlisting">
plug = gtk.Plug(0L)
</pre></td></tr></table><p>and then pass the number returned by the
<tt class="classname">Plug</tt> <tt class="methodname">get_id</tt>() method to the
<tt class="classname">Socket</tt> <tt class="methodname">add_id</tt>()
method:</p><table border="0" bgcolor="#E0E0E0" width="100%"><tr><td><pre class="programlisting">
socket.add_id(plug)
</pre></td></tr></table><p>or you can invoke the <tt class="classname">Socket</tt>
<tt class="methodname">get_id</tt>() method:</p><table border="0" bgcolor="#E0E0E0" width="100%"><tr><td><pre class="programlisting">
window_id = socket.get_id()
</pre></td></tr></table><p>to get the window ID for the socket, and then create the plug
with:</p><table border="0" bgcolor="#E0E0E0" width="100%"><tr><td><pre class="programlisting">
plug = gtk.Plug(window_id)
</pre></td></tr></table><p>The <tt class="classname">Socket</tt> must have already be added
into a toplevel window before you can make this call.</p><p>The <a href="examples/socket.py" target="_top"><span><b class="command">socket.py</b></span></a> example
program illustrates the use of a <tt class="classname">Socket</tt>:</p><table border="0" bgcolor="#E0E0E0" width="100%"><tr><td><pre class="programlisting">
1 #!/usr/bin/python
2
3 import string
4
5 import pygtk
6 pygtk.require('2.0')
7 import gtk,sys
8
9 window = gtk.Window()
10 window.show()
11
12 socket = gtk.Socket()
13 socket.show()
14 window.add(socket)
15
16 print "Socket ID=", socket.get_id()
17 window.connect("destroy", gtk.mainquit)
18
19 def plugged_event(widget):
20 print "I (",widget,") have just had a plug inserted!"
21
22 socket.connect("plug-added", plugged_event)
23
24 if len(sys.argv) == 2:
25 socket.add_id(long(sys.argv[1]))
26
27 gtk.mainloop()
</pre></td></tr></table><p>To run the example you can either run <a href="examples/plug.py" target="_top"><span><b class="command">plug.py</b></span></a> first:</p><table border="0" bgcolor="#E0E0E0" width="100%"><tr><td><pre class="programlisting">
$ python plug.py
Plug ID= 20971522
</pre></td></tr></table><p>and copy the output ID to the first arg of <a href="examples/socket.py" target="_top"><span><b class="command">socket.py</b></span></a>:</p><table border="0" bgcolor="#E0E0E0" width="100%"><tr><td><pre class="programlisting">
$ python socket.py 20971522
Socket ID= 48234523
I ( <gtk.Plug object (GtkPlug) at 0x3008dd78> ) have just been embedded!
I ( <gtk.Socket object (GtkSocket) at 0x3008ddf0> ) have just had a plug inserted!
</pre></td></tr></table><p>Or you can run <a href="examples/socket.py" target="_top"><span><b class="command">socket.py</b></span></a>:</p><table border="0" bgcolor="#E0E0E0" width="100%"><tr><td><pre class="programlisting">
$ python socket.py
Socket ID= 20971547
</pre></td></tr></table><p>and then run <a href="examples/plug.py" target="_top"><span><b class="command">plug.py</b></span></a>, copying across
the window ID:</p><table border="0" bgcolor="#E0E0E0" width="100%"><tr><td><pre class="programlisting">
$ python plug.py
20971547
I ( <gtk.Socket object (GtkSocket) at 0x3008ddf0> ) have just had a plug inserted!
Plug ID= 48234498
</pre></td></tr></table></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="sec-Notebooks.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="ch-ContainerWidgets.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="ch-MenuWidget.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">10.12. Notebooks </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> Chapter 11. Menu Widget</td></tr></table></div></body></html>
|