summaryrefslogtreecommitdiff
path: root/doc/gladepython.sgml
blob: d8b00a15ce30b2c2cf62c407f5366e15c0f50a8a (plain)
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
<refentry id="pythonsupport" revision="26 Feb 2011">
 <refmeta>
   <refentrytitle>Python Gtk widgets support</refentrytitle>
   <refmiscinfo>Glade UI</refmiscinfo>
 </refmeta>
 <refnamediv>
   <refname>Add python support to your catalog</refname>
   <refpurpose>
How to write and install a catalog for a python widget library
   </refpurpose>
 </refnamediv>

 <refsect1>
   <title>Introduction</title>
   <para>
Glade supports loading widgets coded in python by linking and running the python
interpreter from the gladepython catalog plugin.
   </para>

   <para>
So in order for glade to include your python gtk widgets you will have to:

<varlistentry><listitem>
a) specify gladepython support code as your plugin library.
</listitem></varlistentry>

<varlistentry><listitem>
b) set glade_python_init as you init function.
</listitem></varlistentry>

<varlistentry><listitem>
c) make sure your catalog name is the same as your python import library since
glade_python_init() will use this name to import your widgets into the
interpreter.
</listitem></varlistentry>

pythonplugin.xml
     <programlisting>
<![CDATA[
<glade-catalog name="pythonplugin" library="gladepython"
domain="glade-3" depends="gtk+">
 <init-function>glade_python_init</init-function>

 <glade-widget-classes>
   <glade-widget-class title="MyPythonBox" name="MyPythonBox" generic-name="mypythonbox"/>
 </glade-widget-classes>

 <glade-widget-group name="python" title="Python">
   <glade-widget-class-ref name="MyPythonBox"/>
 </glade-widget-group>
</glade-catalog>]]>
     </programlisting>
   </para>

   <para>
Glade's python interpreter will look up for your widgets in the same
places it looks
for regular catalogs plugins, that is $GLADE_ENV_MODULE_PATH
environment variable
and `pkg-config --variable=moduledir gladeui-2.0`

So the easiest thing would be to make a symlink in one of those directory, just
do not forget that the name should be the one specified in your catalog name.
   </para>

   <para>
pythonplugin.py
     <programlisting>
<![CDATA[
from gi.repository import GLib, Gtk, GObject

class MyPythonBox(Gtk.Box):
  __gtype_name__ = 'MyPythonBox'

  foo = GObject.Property(type=int, nick='An integer')
  bar = GObject.Property(type=str, nick='A String')

  def _update(self, obj, pspec):
    self.label.set_text ('Python Properties\nInteger = ' + str(self.foo) + '\nString = \'' + self.bar + '\'')

  def __init__ (self):
    Gtk.Box.__init__ (self)
    self.label = Gtk.Label (visible = True)
    self.add (self.label)
    self.connect('notify::foo', self._update)
    self.connect('notify::bar', self._update)
    self._update(None, None)
]]>
     </programlisting>
   </para>
 </refsect1>
</refentry>