summaryrefslogtreecommitdiff
path: root/docs/reference/pygtk-pygtkgenerictreemodel.xml
blob: 455a28e9d2d55b0fd459420e60cf0869a7caedb3 (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
<?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-pygtkgenerictreemodel">
  <refnamediv>
    <refname>gtk.GenericTreeModel</refname>
    <refpurpose>a TreeView model that helps create tree models in
Python</refpurpose>
  </refnamediv>

  <refsect1>
    <title>Synopsis</title>

    <classsynopsis language="python">
      <ooclass><classname>gtk.GenericTreeModel</classname></ooclass>
      <ooclass><classname><link
linkend="class-gobject">gobject.GObject</link></classname></ooclass>
      <ooclass><classname><link
linkend="class-gtktreemodel">gtk.TreeModel</link></classname></ooclass>
      <constructorsynopsis language="python">
	<methodname><link
linkend="constructor-gtkgenerictreemodel">gtk.GenericTreeModel</link></methodname>
	<methodparam></methodparam>  </constructorsynopsis>
      <methodsynopsis language="python">
        <methodname><link linkend="method-gtkgenerictreemodel--invalidate-iters">invalidate_iters</link></methodname>
        <methodparam></methodparam>
      </methodsynopsis>
      <methodsynopsis language="python">
        <methodname><link linkend="method-gtkgenerictreemodel--iter-is-valid">iter_is_valid</link></methodname>
        <methodparam><parameter role="keyword">iter</parameter></methodparam>
      </methodsynopsis>
      <methodsynopsis language="python">
        <methodname><link linkend="method-gtkgenerictreemodel--get-user-data">get_user_data</link></methodname>
        <methodparam><parameter role="keyword">iter</parameter></methodparam>
      </methodsynopsis>
      <methodsynopsis language="python">
        <methodname><link linkend="method-gtkgenerictreemodel--create-tree-iter">create_tree_iter</link></methodname>
        <methodparam><parameter role="keyword">user_data</parameter></methodparam>
      </methodsynopsis>
    </classsynopsis>

  </refsect1>

  <refsect1>
    <title>Ancestry</title>

<synopsis>+-- <link linkend="class-gobject">gobject.GObject</link>
  +-- <link linkend="class-pygtkgenerictreemodel">gtk.GenericTreeModel</link> (implements <link linkend="class-gtktreemodel">gtk.TreeModel</link>)
</synopsis>

  </refsect1>

  <refsect1>
    <title>Properties</title>

    <blockquote role="properties">
      <informaltable pgwide="1" frame="none">
	<tgroup cols="3">
	  <colspec column="1" colwidth="1in"/>
	  <colspec column="2" colwidth="1in"/>
	  <colspec column="3" colwidth="4in"/>
	  <tbody>

	    <row valign="top">
	      <entry>"leak-references"</entry>
              <entry>Read-Write</entry>

	      <entry>If <literal>True</literal>, creating a <link
linkend="class-gtktreeiter"><classname>gtk.TreeIter</classname></link> will
bump the reference count of the object used as the internal row
reference. This may cause a memory leak but will prevent problems with
objects being destroyed while still in use in a <link
linkend="class-gtktreeiter"><classname>gtk.TreeIter</classname></link>. Set
this to <literal>False</literal> only if the model saves the objects used in
tree iters.</entry>
	    </row>

	  </tbody>
	</tgroup>
      </informaltable>
    </blockquote>

  </refsect1>

  <refsect1>
    <title>Description</title>

    <para>The <link
linkend="class-pygtkgenerictreemodel"><classname>gtk.GenericTreeModel</classname></link> 
helps in the creation of <link
linkend="class-gtktreeview"><classname>gtk.TreeView</classname></link> tree
models in Python. The <link
linkend="class-pygtkgenerictreemodel"><classname>gtk.GenericTreeModel</classname></link> 
is subclassed to provide a new tree model that provides the tree model
behavior using methods with predefined names that are called by the <link
linkend="class-pygtkgenerictreemodel"><classname>gtk.GenericTreeModel</classname></link> 
methods as required to provide the various tree model operations. The
methods that need to be defined by the programmer in Python are:</para>

    <methodsynopsis language="python">
      <methodname>on_get_flags</methodname>
      <methodparam><parameter>self</parameter></methodparam>
    </methodsynopsis>
    <methodsynopsis language="python">
      <methodname>on_get_n_columns</methodname>
      <methodparam><parameter>self</parameter></methodparam>
    </methodsynopsis>
    <methodsynopsis language="python">
      <methodname>on_get_column_type</methodname>
      <methodparam><parameter>self</parameter></methodparam>
      <methodparam><parameter>index</parameter></methodparam>
    </methodsynopsis>
    <methodsynopsis language="python">
      <methodname>on_get_iter</methodname>
      <methodparam><parameter>self</parameter></methodparam>
      <methodparam><parameter>path</parameter></methodparam>
    </methodsynopsis>
    <methodsynopsis language="python">
      <methodname>on_get_path</methodname>
      <methodparam><parameter>self</parameter></methodparam>
      <methodparam><parameter>rowref</parameter></methodparam>
    </methodsynopsis>
    <methodsynopsis language="python">
      <methodname>on_get_value</methodname>
      <methodparam><parameter>self</parameter></methodparam>
      <methodparam><parameter>rowref</parameter></methodparam>
      <methodparam><parameter>column</parameter></methodparam>
    </methodsynopsis>
    <methodsynopsis language="python">
      <methodname>on_iter_next</methodname>
      <methodparam><parameter>self</parameter></methodparam>
      <methodparam><parameter>rowref</parameter></methodparam>
    </methodsynopsis>
    <methodsynopsis language="python">
      <methodname>on_iter_children</methodname>
      <methodparam><parameter>self</parameter></methodparam>
      <methodparam><parameter>parent</parameter></methodparam>
    </methodsynopsis>
    <methodsynopsis language="python">
      <methodname>on_iter_has_child</methodname>
      <methodparam><parameter>self</parameter></methodparam>
      <methodparam><parameter>rowref</parameter></methodparam>
    </methodsynopsis>
    <methodsynopsis language="python">
      <methodname>on_iter_n_children</methodname>
      <methodparam><parameter>self</parameter></methodparam>
      <methodparam><parameter>rowref</parameter></methodparam>
    </methodsynopsis>
    <methodsynopsis language="python">
      <methodname>on_iter_nth_child</methodname>
      <methodparam><parameter>self</parameter></methodparam>
      <methodparam><parameter>parent</parameter></methodparam>
      <methodparam><parameter>n</parameter></methodparam>
    </methodsynopsis>
    <methodsynopsis language="python">
      <methodname>on_iter_parent</methodname>
      <methodparam><parameter>self</parameter></methodparam>
      <methodparam><parameter>child</parameter></methodparam>
    </methodsynopsis>

    <para>See the <link
linkend="class-gtktreemodel"><classname>gtk.TreeModel</classname></link>
description for details of the above methods.</para>

    <para>In PyGTK 2.4 and above the <link
linkend="method-gtkgenerictreemodel--invalidate-iters"><methodname>invalidate_iters</methodname>()</link>
and <link
linkend="method-gtkgenerictreemodel--iter-is-valid"><methodname>iter_is_valid</methodname>()</link>
methods are available to help manage the <link
linkend="class-gtktreeiter"><classname>gtk.TreeIter</classname></link>
objects and their Python object references. These are particularly useful
when the "leak-references" property is set to
<literal>False</literal>.</para>

    <para>The tree models derived from <link
linkend="class-pygtkgenerictreemodel"><classname>gtk.GenericTreeModel</classname></link>
are protected from problems with out of date <link
linkend="class-gtktreeiter"><classname>gtk.TreeIter</classname></link>
objects because <link
linkend="class-gtktreeiter"><classname>gtk.TreeIter</classname></link>
objects are automatically checked for validity with the tree model.</para>

    <para>If a custom tree model doesn't support persistent iters
(i.e. <literal>gtk.TREE_MODEL_ITERS_PERSIST</literal> is not set in the
return from the <link
linkend="method-gtktreemodel--get-flags"><methodname>gtk.TreeModel.get_flags</methodname>()</link>
method), it can call the <link
linkend="method-gtkgenerictreemodel--invalidate-iters"><methodname>invalidate_iters</methodname>()</link>
method to invalidate all its outstanding <link
linkend="class-gtktreeiter"><classname>gtk.TreeIter</classname></link>
objects when it changes the model (e.g. after inserting a new row). The tree
model can also dispose of any Python objects that it passed references to
<link linkend="class-gtktreeiter"><classname>gtk.TreeIter</classname></link>
objects after calling the <link
linkend="method-gtkgenerictreemodel--invalidate-iters"><methodname>invalidate_iters</methodname>()</link>
method.</para>

    <para>Applications can use the <link
linkend="method-gtkgenerictreemodel--iter-is-valid"><methodname>iter_is_valid</methodname>()</link>
method to determine if a <link
linkend="class-gtktreeiter"><classname>gtk.TreeIter</classname></link> is
still valid for the custom tree model.</para>

  </refsect1>

  <refsect1 id="constructor-gtkgenerictreemodel">
    <title>Constructor</title>

    <programlisting><constructorsynopsis language="python">
	<methodname>gtk.GenericTreeModel</methodname>
	<methodparam></methodparam>  </constructorsynopsis></programlisting>
    <variablelist>
      <varlistentry>
	<term><emphasis>Returns</emphasis>&nbsp;:</term>
	<listitem><simpara>a new <link
linkend="class-pygtkgenerictreemodel"><classname>gtk.GenericTreeModel</classname></link> 
object</simpara></listitem>
      </varlistentry>
    </variablelist>

    <para>Creates a new <link
linkend="class-pygtkgenerictreemodel"><classname>gtk.GenericTreeModel</classname></link> 
object</para>

  </refsect1>

  <refsect1>
    <title>Methods</title>

    <refsect2 id="method-gtkgenerictreemodel--invalidate-iters">
      <title>gtk.GenericTreeModel.invalidate_iters</title>

      <programlisting><methodsynopsis language="python">
	  <methodname>invalidate_iters</methodname>
	  <methodparam></methodparam>
	</methodsynopsis></programlisting>

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

      <para>The <methodname>invalidate_iters</methodname>() method
invalidates all the <link
linkend="class-gtktreeiter"><classname>gtk.TreeIter</classname></link>
objects for the custom tree model.</para>

    </refsect2>

    <refsect2 id="method-gtkgenerictreemodel--iter-is-valid">
      <title>gtk.GenericTreeModel.iter_is_valid</title>

      <programlisting><methodsynopsis language="python">
	  <methodname>iter_is_valid</methodname>
	  <methodparam><parameter
			 role="keyword">iter</parameter></methodparam>
	</methodsynopsis></programlisting>
      <variablelist>
	<varlistentry>
	  <term><parameter role="keyword">iter</parameter>&nbsp;:</term>
	  <listitem><simpara>a <link
	  linkend="class-gtktreeiter"><classname>gtk.TreeIter</classname></link></simpara></listitem>
	</varlistentry>
	<varlistentry>
	<term><emphasis>Returns</emphasis>&nbsp;:</term>
	  <listitem><simpara><literal>True</literal> if
	  <parameter>iter</parameter> is valid for the tree model;
	  otherwise, <literal>False</literal> is
	  returned.</simpara></listitem>
	</varlistentry>
      </variablelist>

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

      <para>The <methodname>iter_is_valid</methodname>() method returns
<literal>True</literal> if the <link
linkend="class-gtktreeiter"><classname>gtk.TreeIter</classname></link>
specified by <parameter>iter</parameter> is valid for the custom tree
model.</para>

    </refsect2>

    <refsect2 id="method-gtkgenerictreemodel--get-user-data">
      <title>gtk.GenericTreeModel.get_user_data</title>

      <programlisting><methodsynopsis language="python">
	  <methodname>get_user_data</methodname>
	  <methodparam><parameter
			 role="keyword">iter</parameter></methodparam>
	</methodsynopsis></programlisting>
      <variablelist>
	<varlistentry>
	  <term><parameter role="keyword">iter</parameter>&nbsp;:</term>
	  <listitem><simpara>a <link
	  linkend="class-gtktreeiter"><classname>gtk.TreeIter</classname></link>
	  created by this tree model.</simpara></listitem>
	</varlistentry>
	<varlistentry>
	<term><emphasis>Returns</emphasis>&nbsp;:</term>
	  <listitem><simpara>Python object reference that is wrapped by this
	      <classname>gtk.TreeIter</classname>.</simpara></listitem>
	</varlistentry>
      </variablelist>

      <warning>
        <para>This method should be treated as protected.  It should only
        be used by derived classes.</para>
      </warning>

      <para><classname>gtk.GenericTreeModel</classname> transparently wraps arbitrary Python objects to instances of <link linkend="class-gtktreeiter"><classname>gtk.TreeIter</classname></link>. E.g. you return anything from <methodname>on_get_iter</methodname> and the model wraps the value, so <methodname>get_iter</methodname> method returns a <classname>gtk.TreeIter</classname>. This method allows to retrieve the Python object used to construct given iterator.</para>

    </refsect2>

    <refsect2 id="method-gtkgenerictreemodel--create-tree-iter">
      <title>gtk.GenericTreeModel.create_tree_iter</title>

      <programlisting><methodsynopsis language="python">
	  <methodname>create_tree_iter</methodname>
	  <methodparam><parameter
			 role="keyword">user_data</parameter></methodparam>
	</methodsynopsis></programlisting>
      <variablelist>
	<varlistentry>
	  <term><parameter role="keyword">user_data</parameter>&nbsp;:</term>
	  <listitem><simpara>a Python object, the same you would return from
	      e.g. <methodname>on_get_iter</methodname>.</simpara></listitem>
	</varlistentry>
	<varlistentry>
	<term><emphasis>Returns</emphasis>&nbsp;:</term>
	  <listitem><simpara>a <link
	  linkend="class-gtktreeiter"><classname>gtk.TreeIter</classname></link>.</simpara></listitem>
	</varlistentry>
      </variablelist>

      <warning>
        <para>This method should be treated as protected.  It should only
        be used by derived classes.</para>
      </warning>

      <para><classname>gtk.GenericTreeModel</classname> transparently wraps arbitrary Python objects to instances of <link linkend="class-gtktreeiter"><classname>gtk.TreeIter</classname></link>. E.g. you return anything from <methodname>on_get_iter</methodname> and the model wraps the value, so <methodname>get_iter</methodname> method returns a <classname>gtk.TreeIter</classname>. This method allows you to perform this wrapping explicitly, not just from a predefined set of methods.</para>

    </refsect2>

  </refsect1>

</refentry>