summaryrefslogtreecommitdiff
path: root/docs/reference/pygtk-gtktooltip.xml
blob: 1b2f47cb4262145e612b9d614a975c6f07517533 (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
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
<?xml version="1.0" standalone="no"?>
<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN"
    "http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd">

<refentry id="class-gtktooltip">
    <refnamediv>
        <refname>gtk.Tooltip</refname>
        <refpurpose>Add tips to your widgets (new in PyGTK 2.12)</refpurpose>
    </refnamediv>

    <refsect1>
        <title>Synopsis</title>

    <classsynopsis language="python">
        <ooclass><classname>gtk.Tooltip</classname></ooclass>
        <ooclass><classname><link linkend="class-gobject">gobject.GObject</link></classname></ooclass>
    
    <methodsynopsis language="python">
        <methodname><link linkend="method-gtktooltip--set-custom">set_custom</link></methodname>
        <methodparam><parameter role="keyword">widget</parameter></methodparam>
    </methodsynopsis>
    <methodsynopsis language="python">
        <methodname><link linkend="method-gtktooltip--set-icon">set_icon</link></methodname>
        <methodparam><parameter role="keyword">pixbuf</parameter></methodparam>
    </methodsynopsis>
    <methodsynopsis language="python">
        <methodname><link linkend="method-gtktooltip--set-icon-from-stock">set_icon_from_icon_name</link></methodname>
        <methodparam><parameter role="keyword">icon_name</parameter></methodparam>
        <methodparam><parameter role="keyword">size</parameter></methodparam>
    </methodsynopsis>
    <methodsynopsis language="python">
        <methodname><link linkend="method-gtktooltip--set-icon-from-stock">set_icon_from_stock</link></methodname>
        <methodparam><parameter role="keyword">stock_id</parameter></methodparam>
        <methodparam><parameter role="keyword">size</parameter></methodparam>
    </methodsynopsis>
    <methodsynopsis language="python">
        <methodname><link linkend="method-gtktooltip--set-markup">set_markup</link></methodname>
        <methodparam><parameter role="keyword">markup</parameter></methodparam>
    </methodsynopsis>
    <methodsynopsis language="python">
        <methodname><link linkend="method-gtktooltip--set-text">set_text</link></methodname>
        <methodparam><parameter role="keyword">text</parameter></methodparam>
    </methodsynopsis>

    </classsynopsis>

<programlisting>
<emphasis role="bold">Functions</emphasis>
 
<methodsynopsis language="python">
    <methodname><link linkend="function-gtk--tooltip-trigger-tooltip-query">gtk.tooltip_trigger_tooltip_query</link></methodname>
    <methodparam><parameter role="keyword">display</parameter></methodparam>
  </methodsynopsis></programlisting>

    </refsect1>

    <refsect1>
        <title>Ancestry</title>

<synopsis>+-- <link linkend="class-gobject">gobject.GObject</link>
  +-- <link linkend="class-gtktooltip">gtk.Tooltip</link>
</synopsis>

    </refsect1>

    <refsect1>
        <title>Description</title>
            <para>
                <link linkend="class-gtktooltip"><classname>gtk.Tooltip</classname></link>
                belongs to the new tooltips API that was introduced in GTK+ 2.12 and which
                deprecates the old <link linkend="class-gtktooltips"><classname>gtk.Tooltips</classname></link> API.
            </para>
            <para>
                Basic tooltips can be realized simply by using
                <methodname><link linkend="method-gtkwidget--set-tooltip-text">gtk.Widget.set_tooltip_text</link></methodname>() or
                <methodname><link linkend="method-gtkwidget--set-tooltip-markup">gtk.Widget.set_tooltip_markup</link></methodname>()
                without any explicit tooltip object.
            </para>
            <para>
                When you need a tooltip with a little more fancy contents, like adding an image,
                or you want the tooltip to have different contents per
                <link linkend="class-gtktreeview"><classname>gtk.TreeView</classname></link> row or cell,
                you will have to do a little more work:
            </para>
            <itemizedlist>
                <listitem>
                    <simpara>
                        Set the GtkWidget:has-tooltip property to <literal>True</literal>,
                        this will make GTK+ monitor the widget for motion and related events
                        which are needed to determine when and where to show a tooltip.
                    </simpara>
                </listitem>
                <listitem>
                    <simpara>
                        Connect to the <link linkend="signal-gtkwidget--query-tooltip">GtkWidget::query-tooltip</link>
                        signal. This signal will be emitted
                        when a tooltip is supposed to be shown. One of the arguments passed to the
                        signal handler is a
                        <link linkend="class-gtktooltip"><classname>gtk.Tooltip</classname></link>
                        object. This is the object that we are about
                        to display as a tooltip, and can be manipulated in your callback using functions
                        like <methodname><link linkend="method-gtktooltip--set-icon">set_icon</link></methodname>.
                        There are functions for setting the tooltip's markup,
                        setting an image from a stock icon, or even putting in a custom widget.
                    </simpara>
                </listitem>
                <listitem>
                    <simpara>
                        Return <literal>True</literal> from your query-tooltip handler. This causes the
                        tooltip to be show. If you return <literal>False</literal>, it will not be shown.
                    </simpara>
                </listitem>
            </itemizedlist>
            <para>
                In the probably rare case where you want to have even more control over the tooltip that
                is about to be shown, you can set your own
                <link linkend="class-gtkwindow"><classname>gtk.Window</classname></link> which will be used as tooltip window.
                This works as follows:
            </para>
            <itemizedlist>
                <listitem>
                    <simpara>
                        Set GtkWidget:has-tooltip and connect to
                        <link linkend="signal-gtkwidget--query-tooltip">GtkWidget::query-tooltip</link>
                        as before.
                    </simpara>
                </listitem>
                <listitem>
                    <simpara>
                        Use <methodname><link linkend="method-gtkwidget--set-tooltip-window">gtk.Widget.set_tooltip_window</link></methodname>()
                        to set a <link linkend="class-gtkwindow"><classname>gtk.Window</classname></link> created by you as tooltip window.
                    </simpara>
                </listitem>
                <listitem>
                    <simpara>
                        In the ::query-tooltip callback you can access your window using
                        <methodname><link linkend="method-gtkwidget--get-tooltip-window">gtk.Widget.get_tooltip_window</link></methodname>()
                        and manipulate as you wish. The semantics of the return value are exactly as before,
                        return <literal>True</literal> to show the window, <literal>False</literal> to not show it.
                    </simpara>
                </listitem>
            </itemizedlist>
    </refsect1>

    <refsect1>
        <title>Methods</title>

        <refsect2 id="method-gtktooltip--set-custom">
            <title>gtk.Tooltip.set_custom</title>

            <programlisting><methodsynopsis language="python">
                <methodname>set_custom</methodname>
                <methodparam><parameter>widget</parameter></methodparam>
            </methodsynopsis></programlisting>
            
            <variablelist>
                <varlistentry>
                    <term><parameter role="keyword">widget</parameter>&nbsp;:</term>
                        <listitem><simpara>A
                        <link linkend="class-gtkwidget"><classname>gtk.Widget</classname></link>
                        </simpara></listitem>
                </varlistentry>
            </variablelist>

            <note>
                <para>This method is available in PyGTK 2.12 and above.</para>
            </note>

            <para>
                The <methodname>set_custom</methodname>() method replaces the widget packed into
                the tooltip with custom_widget. By default a box with a
                <link linkend="class-gtkimage"><classname>gtk.Image</classname></link> and
                <link linkend="class-gtklabel"><classname>gtk.Label</classname></link> is
                embedded in the tooltip, which can be configured using
                <methodname><link linkend="method-gtktooltip--set-markup">set_markup</link></methodname> and
                <methodname><link linkend="method-gtktooltip--set-icon">set_icon</link></methodname>.
            </para>
        </refsect2>

        <refsect2 id="method-gtktooltip--set-icon">
            <title>gtk.Tooltip.set_icon</title>

            <programlisting><methodsynopsis language="python">
                <methodname>get_value</methodname>
                <methodparam><parameter>pixbuf</parameter></methodparam>
            </methodsynopsis></programlisting>
            
            <variablelist>
                <varlistentry>
                    <term><parameter role="keyword">pixbuf</parameter>&nbsp;:</term>
                        <listitem><simpara>A
                        <link linkend="class-gdkpixbuf"><classname>gtk.gdk.Pixbuf</classname></link>
                        or <literal>None</literal>.</simpara></listitem>
                </varlistentry>
            </variablelist>

            <note>
                <para>This method is available in PyGTK 2.12 and above.</para>
            </note>

            <para>
                The <methodname>set_icon</methodname>() method sets the icon of the tooltip
                (which is in front of the text) to be pixbuf.
                If <parameter>pixbuf</parameter> is <literal>None</literal>, the image will be hidden.
            </para>
        </refsect2>

        <refsect2 id="method-gtktooltip--set-icon-from-icon-name">
            <title>gtk.Tooltip.set_icon_from_icon_name</title>

            <programlisting><methodsynopsis language="python">
                <methodname>set_icon_from_icon_name</methodname>
                <methodparam><parameter>icon_name</parameter></methodparam>
                <methodparam><parameter>size</parameter></methodparam>
            </methodsynopsis></programlisting>
            
            <variablelist>
                <varlistentry>
                    <term><parameter role="keyword">icon_name</parameter>&nbsp;:</term>
                        <listitem><simpara>an icon name, or <literal>None</literal>.</simpara></listitem>
                </varlistentry>
                <varlistentry>
                    <term><parameter role="keyword">size</parameter>&nbsp;:</term>
                        <listitem><simpara>A stock icon size.</simpara></listitem>
                </varlistentry>
            </variablelist>

            <note>
                <para>This method is available in PyGTK 2.14 and above.</para>
            </note>

            <para>
                The <methodname>set_icon_from_icon_name</methodname>() method sets
                the icon of the tooltip (which is in front of the text) to be the
                icon indicated by icon_name with the size indicated by size. If icon_name
                is <literal>None</literal>, the image will be hidden.
            </para>
        </refsect2>

        <refsect2 id="method-gtktooltip--set-icon-from-stock">
            <title>gtk.Tooltip.set_icon_from_stock</title>

            <programlisting><methodsynopsis language="python">
                <methodname>set_icon_from_stock</methodname>
                <methodparam><parameter>stock_id</parameter></methodparam>
                <methodparam><parameter>size</parameter></methodparam>
            </methodsynopsis></programlisting>
            
            <variablelist>
                <varlistentry>
                    <term><parameter role="keyword">stock_id</parameter>&nbsp;:</term>
                        <listitem><simpara>A stock icon name, or <literal>None</literal>.</simpara></listitem>
                </varlistentry>
                <varlistentry>
                    <term><parameter role="keyword">size</parameter>&nbsp;:</term>
                        <listitem><simpara>A stock icon size.</simpara></listitem>
                </varlistentry>
            </variablelist>

            <note>
                <para>This method is available in PyGTK 2.12 and above.</para>
            </note>

            <para>
                The <methodname>set_icon_from_stock</methodname>() method sets the icon of the tooltip
                (which is in front of the text) to be the stock item indicated by stock_id with the size
                indicated by size. If stock_id is <literal>None</literal>, the image will be hidden.
            </para>
        </refsect2>

        <refsect2 id="method-gtktooltip--set-markup">
            <title>gtk.Tooltip.set_markup</title>

            <programlisting><methodsynopsis language="python">
                <methodname>set_markup</methodname>
                <methodparam><parameter>markup</parameter></methodparam>
            </methodsynopsis></programlisting>
            
            <variablelist>
                <varlistentry>
                    <term><parameter role="keyword">markup</parameter>&nbsp;:</term>
                        <listitem><simpara>A markup string (see Pango markup format)
                        or <literal>None</literal>.</simpara></listitem>
                </varlistentry>
            </variablelist>

            <note>
                <para>This method is available in PyGTK 2.12 and above.</para>
            </note>

            <para>
                The <methodname>set_markup</methodname>() method sets the text of the tooltip to be
                <parameter>markup</parameter>, which is marked up with the Pango text markup language.
                If <parameter>markup</parameter> is <literal>None</literal>, the label will be hidden.
            </para>
        </refsect2>

        <refsect2 id="method-gtktooltip--set-text">
            <title>gtk.Tooltip.set_text</title>

            <programlisting><methodsynopsis language="python">
                <methodname>set_text</methodname>
                <methodparam><parameter>text</parameter></methodparam>
            </methodsynopsis></programlisting>
            
            <variablelist>
                <varlistentry>
                    <term><parameter role="keyword">text</parameter>&nbsp;:</term>
                        <listitem><simpara>A text string or <literal>None</literal>.</simpara></listitem>
                </varlistentry>
            </variablelist>

            <note>
                <para>This method is available in PyGTK 2.12 and above.</para>
            </note>

            <para>
                The <methodname>set_text</methodname>() method sets the text of the tooltip to be text.
                If text is <literal>None</literal>, the label will be hidden. See also
                <methodname><link linkend="method-gtktooltip--set-markup">set_markup</link></methodname>.
            </para>
        </refsect2>
    </refsect1>
    
    <refsect1>
        <title>Functions</title>

        <refsect2 id="function-gtk--tooltip-trigger-tooltip-query">
            <title>gtk.tooltip_trigger_tooltip_query</title>

            <programlisting><methodsynopsis language="python">
                <methodname>tooltip_trigger_tooltip_query</methodname>
                <methodparam><parameter>display</parameter></methodparam>
            </methodsynopsis></programlisting>
            
            <variablelist>
                <varlistentry>
                    <term><parameter role="keyword">display</parameter>&nbsp;:</term>
                        <listitem><simpara>A
                            <link linkend="class-gdkdisplay"><classname>gtk.gdk.Display</classname></link>
                        </simpara></listitem>
                </varlistentry>
            </variablelist>

            <note>
                <para>This function is available in PyGTK 2.12 and above.</para>
            </note>

            <para>
                The <methodname>tooltip_trigger_tooltip_query</methodname>() function triggers a
                new tooltip query on display, in order to update the current visible tooltip,
                or to show/hide the current tooltip. This function is useful to call when, for example,
                the state of the widget changed by a key press.
            </para>
        </refsect2>
    </refsect1>
</refentry>