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
|
<html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>gtk.TreeSortable</title><meta name="generator" content="DocBook XSL Stylesheets V1.65.1"><link rel="home" href="index.html" title="PyGTK 2.0 Reference Manual"><link rel="up" href="gtk-class-reference.html" title="The gtk Class Reference"><link rel="previous" href="class-gtktreeselection.html" title="gtk.TreeSelection"><link rel="next" href="class-gtktreestore.html" title="gtk.TreeStore"></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">gtk.TreeSortable</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="class-gtktreeselection.html">Prev</a></td><th width="60%" align="center">The gtk Class Reference</th><td width="20%" align="right"><a accesskey="n" href="class-gtktreestore.html">Next</a></td></tr></table><hr></div><div class="refentry" lang="en"><a name="class-gtktreesortable"></a><div class="titlepage"><div></div><div></div></div><div class="refnamediv"><h2>gtk.TreeSortable</h2><p>gtk.TreeSortable — an interface for sorting a <a href="class-gtktreemodel.html" title="gtk.TreeModel"><tt class="classname">gtk.TreeModel</tt></a></p></div><div class="refsect1" lang="en"><a name="id3590838"></a><h2>Synopsis</h2><table bgcolor="#D0E0F0" width="100%"><tr><td><pre class="classsynopsis">class <span class="ooclass"><span class="classname">gtk.TreeSortable</span></span>(<span class="ooclass"><span class="classname">gobject.GInterface</span></span>):
<code class="methodsynopsis"> def <span class="methodname"><a href="class-gtktreesortable.html#method-gtktreesortable--sort-column-changed" title="gtk.TreeSortable.sort_column_changed">sort_column_changed</a></span>(<span class="methodparam"></span>)</code><br><code class="methodsynopsis"> def <span class="methodname"><a href="class-gtktreesortable.html#method-gtktreesortable--get-sort-column-id" title="gtk.TreeSortable.get_sort_column_id">get_sort_column_id</a></span>(<span class="methodparam"></span>)</code><br><code class="methodsynopsis"> def <span class="methodname"><a href="class-gtktreesortable.html#method-gtktreesortable--set-sort-column-id" title="gtk.TreeSortable.set_sort_column_id">set_sort_column_id</a></span>(<span class="methodparam"><span class="parameter"><b class="parameter"><tt>sort_column_id</tt></b></span></span>, <span class="methodparam"><span class="parameter"><b class="parameter"><tt>order</tt></b></span></span>)</code><br><code class="methodsynopsis"> def <span class="methodname"><a href="class-gtktreesortable.html#method-gtktreesortable--set-sort-func" title="gtk.TreeSortable.set_sort_func">set_sort_func</a></span>(<span class="methodparam"><span class="parameter"><i class="parameter"><tt>sort_column_id</tt></i></span></span>, <span class="methodparam"><span class="parameter"><i class="parameter"><tt>sort_func</tt></i></span></span>, <span class="methodparam"><span class="parameter"><i class="parameter"><tt>user_data</tt></i></span><span class="initializer">=None</span></span>)</code><br><code class="methodsynopsis"> def <span class="methodname"><a href="class-gtktreesortable.html#method-gtktreesortable--set-default-sort-func" title="gtk.TreeSortable.set_default_sort_func">set_default_sort_func</a></span>(<span class="methodparam"><span class="parameter"><i class="parameter"><tt>sort_func</tt></i></span></span>, <span class="methodparam"><span class="parameter"><i class="parameter"><tt>user_data</tt></i></span><span class="initializer">=None</span></span>)</code><br><code class="methodsynopsis"> def <span class="methodname"><a href="class-gtktreesortable.html#method-gtktreesortable--has-default-sort-func" title="gtk.TreeSortable.has_default_sort_func">has_default_sort_func</a></span>(<span class="methodparam"></span>)</code><br></pre></td></tr></table></div><div class="refsect1" lang="en"><a name="id3590997"></a><h2>Signal Prototypes</h2><table border="0" width="100%" bgcolor="#FFECCE"><col align="left" valign="top" width="0*"><tbody><tr><td><span class="term">"<a href="class-gtktreesortable.html#signal-gtktreesortable--sort-column-changed" title='The "sort-column-changed" gtk.TreeSortable Signal'>sort-column-changed</a>"</span></td><td><code class="methodsynopsis"> def <span class="methodname">callback</span>(<span class="methodparam"><span class="parameter"><i class="parameter"><tt>treesortable</tt></i></span></span>, <span class="methodparam"><span class="parameter"><i class="parameter"><tt>user_param1</tt></i></span></span>, <span class="methodparam"><span class="parameter"><i class="parameter"><tt>...</tt></i></span></span>)</code></td></tr></tbody></table></div><div class="refsect1" lang="en"><a name="id3591050"></a><h2>Description</h2><p>The <a href="class-gtktreesortable.html" title="gtk.TreeSortable"><tt class="classname">gtk.TreeSortable</tt></a>
interface provide the common methods for a <a href="class-gtktreemodel.html" title="gtk.TreeModel"><tt class="classname">gtk.TreeModel</tt></a> to
implement a sorted model for a <a href="class-gtktreeview.html" title="gtk.TreeView"><tt class="classname">gtk.TreeView</tt></a>. See
the <a href="class-gtktreemodelsort.html" title="gtk.TreeModelSort"><tt class="classname">gtk.TreeModelSort</tt></a>
for an example of a treemodel that implements the <a href="class-gtktreesortable.html" title="gtk.TreeSortable"><tt class="classname">gtk.TreeSortable</tt></a>
interface. The key element of the interface is a "sort column ID" which is
an arbitrary integer value referring to a sort function and associated user
data. A sort column ID must be greater than or equal to zero. A usable sort
column ID is created by using the <a href="class-gtktreesortable.html#method-gtktreesortable--set-sort-func" title="gtk.TreeSortable.set_sort_func"><tt class="methodname">set_sort_func</tt>()</a>
method. The sort column ID can then be used for sorting a <a href="class-gtkliststore.html" title="gtk.ListStore"><tt class="classname">gtk.ListStore</tt></a> or
<a href="class-gtktreestore.html" title="gtk.TreeStore"><tt class="classname">gtk.TreeStore</tt></a>
using the <a href="class-gtktreesortable.html#method-gtktreesortable--set-sort-column-id" title="gtk.TreeSortable.set_sort_column_id"><tt class="methodname">set_sort_column_id</tt>()</a>
method.</p><p>The <a href="class-gtkliststore.html" title="gtk.ListStore"><tt class="classname">gtk.ListStore</tt></a> and
<a href="class-gtktreestore.html" title="gtk.TreeStore"><tt class="classname">gtk.TreeStore</tt></a>
objects automatically setup sort column IDs corresponding to the columns in
the store. These sort column IDs are associated with an internal comparison
function that handles the fundamental types:</p><div class="itemizedlist"><ul type="disc"><li>gboolean</li><li>str</li><li>int</li><li>long</li><li>float</li></ul></div><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p>Once a sort column ID has been set on a <a href="class-gtktreemodel.html" title="gtk.TreeModel"><tt class="classname">gtk.TreeModel</tt></a>
implementing the <a href="class-gtktreesortable.html" title="gtk.TreeSortable"><tt class="classname">gtk.TreeSortable</tt></a>
interface it cannot be returned to the original unsorted state. You can
change the sort function or use a default sort function but you cannot set
the <a href="class-gtktreemodel.html" title="gtk.TreeModel"><tt class="classname">gtk.TreeModel</tt></a> to
have no sort function.</p></div></div><div class="refsect1" lang="en"><a name="id3591233"></a><h2>Methods</h2><div class="refsect2" lang="en"><a name="method-gtktreesortable--sort-column-changed"></a><h3>gtk.TreeSortable.sort_column_changed</h3><table border="0" bgcolor="#E0E0E0" width="100%"><tr><td><pre class="programlisting"><code class="methodsynopsis"> def <span class="methodname">sort_column_changed</span>(<span class="methodparam"></span>)</code></pre></td></tr></table><p>The <tt class="methodname">sort_column_changed</tt>() method emits
the "sort_column_changed" signal on the treesortable object.</p></div><div class="refsect2" lang="en"><a name="method-gtktreesortable--get-sort-column-id"></a><h3>gtk.TreeSortable.get_sort_column_id</h3><table border="0" bgcolor="#E0E0E0" width="100%"><tr><td><pre class="programlisting"><code class="methodsynopsis"> def <span class="methodname">get_sort_column_id</span>(<span class="methodparam"></span>)</code></pre></td></tr></table><table border="0" width="100%" bgcolor="#FFECCE"><col align="left" valign="top" width="0*"><tbody><tr><td><span class="term"><span class="emphasis"><em>Returns</em></span>:</span></td><td>a tuple containing the sort column id and the
sort type: <tt class="literal">gtk.SORT_ASCENDING</tt> or
<tt class="literal">gtk.SORT_DESCENDING</tt></td></tr></tbody></table><p>The <tt class="methodname">get_sort_column_id</tt>() method returns
a tuple containing the current sort column ID and the sort type (either
<tt class="literal">gtk.SORT_ASCENDING</tt> or
<tt class="literal">gtk.SORT_DESCENDING</tt>), if applicable. If the sort column
ID is not set, then the tuple <tt class="literal">(-2, 0)</tt> is returned. If the
sort column ID is set to -1 indicating the default sort function is to be
used this method returns (<tt class="literal">None</tt>,
<tt class="literal">None</tt>)</p></div><div class="refsect2" lang="en"><a name="method-gtktreesortable--set-sort-column-id"></a><h3>gtk.TreeSortable.set_sort_column_id</h3><table border="0" bgcolor="#E0E0E0" width="100%"><tr><td><pre class="programlisting"><code class="methodsynopsis"> def <span class="methodname">set_sort_column_id</span>(<span class="methodparam"><span class="parameter"><b class="parameter"><tt>sort_column_id</tt></b></span></span>, <span class="methodparam"><span class="parameter"><b class="parameter"><tt>order</tt></b></span></span>)</code></pre></td></tr></table><table border="0" width="100%" bgcolor="#FFECCE"><col align="left" valign="top" width="0*"><tbody><tr><td><span class="term"><b class="parameter"><tt>sort_column_id</tt></b>:</span></td><td>the sort column id to set</td></tr><tr><td><span class="term"><b class="parameter"><tt>order</tt></b>:</span></td><td>the sort order:
<tt class="literal">gtk.SORT_ASCENDING</tt> or
<tt class="literal">gtk.SORT_DESCENDING</tt></td></tr></tbody></table><p>The <tt class="methodname">set_sort_column_id</tt>() method sets
the current sort comparison function to that associated with the sort column
ID specified by <i class="parameter"><tt>sort_column_id</tt></i> with the sort order
type specified by <i class="parameter"><tt>order</tt></i>. The value of order must be
either: <tt class="literal">gtk.SORT_ASCENDING</tt> or
<tt class="literal">gtk.SORT_DESCENDING</tt>. The treesortable will resort itself
to reflect this change, after emitting a "sort_column_changed" signal.</p><p>If <i class="parameter"><tt>sort_column_id</tt></i> is -1, then the default
sort function will be used, if it is set. If a default sort function is not
set then the sort column ID is not changed.</p></div><div class="refsect2" lang="en"><a name="method-gtktreesortable--set-sort-func"></a><h3>gtk.TreeSortable.set_sort_func</h3><table border="0" bgcolor="#E0E0E0" width="100%"><tr><td><pre class="programlisting"><code class="methodsynopsis"> def <span class="methodname">set_sort_func</span>(<span class="methodparam"><span class="parameter"><i class="parameter"><tt>sort_column_id</tt></i></span></span>, <span class="methodparam"><span class="parameter"><i class="parameter"><tt>sort_func</tt></i></span></span>, <span class="methodparam"><span class="parameter"><i class="parameter"><tt>user_data</tt></i></span><span class="initializer">=None</span></span>)</code></pre></td></tr></table><table border="0" width="100%" bgcolor="#FFECCE"><col align="left" valign="top" width="0*"><tbody><tr><td><span class="term"><i class="parameter"><tt>sort_column_id</tt></i>:</span></td><td>the sort column id to set the function
for</td></tr><tr><td><span class="term"><i class="parameter"><tt>sort_func</tt></i>:</span></td><td>The sorting function</td></tr><tr><td><span class="term"><i class="parameter"><tt>user_data</tt></i>:</span></td><td>the user data to pass to the sort func, or
<tt class="literal">None</tt></td></tr></tbody></table><p>The <tt class="methodname">set_sort_func</tt>() method sets the
comparison function (or method) used when sorting on the sort column ID
specified by <i class="parameter"><tt>column_id</tt></i> to the value specified by
<i class="parameter"><tt>sort_func</tt></i>. If the current sort column id of the
treesortable is the same as <i class="parameter"><tt>sort_column_id</tt></i>, the model
will be resorted. The signature of the comparison function (or method)
is:</p><table border="0" bgcolor="#E0E0E0" width="100%"><tr><td><pre class="programlisting">
<code class="methodsynopsis"> def <span class="methodname">comparefunction</span>(<span class="methodparam"><span class="parameter"><i class="parameter"><tt>treemodel</tt></i></span></span>, <span class="methodparam"><span class="parameter"><i class="parameter"><tt>iter1</tt></i></span></span>, <span class="methodparam"><span class="parameter"><i class="parameter"><tt>iter2</tt></i></span></span>, <span class="methodparam"><span class="parameter"><i class="parameter"><tt>user_data</tt></i></span></span>)</code><br>
<code class="methodsynopsis"> def <span class="methodname">comparemethod</span>(<span class="methodparam"><span class="parameter"><i class="parameter"><tt>self</tt></i></span></span>, <span class="methodparam"><span class="parameter"><i class="parameter"><tt>treemodel</tt></i></span></span>, <span class="methodparam"><span class="parameter"><i class="parameter"><tt>iter1</tt></i></span></span>, <span class="methodparam"><span class="parameter"><i class="parameter"><tt>iter2</tt></i></span></span>, <span class="methodparam"><span class="parameter"><i class="parameter"><tt>user_data</tt></i></span></span>)</code>
</pre></td></tr></table><p>where <i class="parameter"><tt>treemodel</tt></i> is the tree model
implementing the <a href="class-gtktreesortable.html" title="gtk.TreeSortable"><tt class="classname">gtk.TreeSortable</tt></a>
interface, <i class="parameter"><tt>iter1</tt></i> and <i class="parameter"><tt>iter2</tt></i>
point at the rows to compare and <i class="parameter"><tt>user_data</tt></i> is the
user data specified in <tt class="methodname">set_sort_func</tt>() or
<i class="parameter"><tt>None</tt></i>. If <i class="parameter"><tt>sort_func</tt></i> is a method
then <i class="parameter"><tt>self</tt></i> is the object associated with the
method.</p><p>The comparison callback should return -1 if the
<i class="parameter"><tt>iter1</tt></i> row should come before the
<i class="parameter"><tt>iter2</tt></i> row, 0 if the rows are equal, or 1 if the
<i class="parameter"><tt>iter1</tt></i> row should come after the
<i class="parameter"><tt>iter2</tt></i> row.</p></div><div class="refsect2" lang="en"><a name="method-gtktreesortable--set-default-sort-func"></a><h3>gtk.TreeSortable.set_default_sort_func</h3><table border="0" bgcolor="#E0E0E0" width="100%"><tr><td><pre class="programlisting"><code class="methodsynopsis"> def <span class="methodname">set_default_sort_func</span>(<span class="methodparam"><span class="parameter"><i class="parameter"><tt>sort_func</tt></i></span></span>, <span class="methodparam"><span class="parameter"><i class="parameter"><tt>user_data</tt></i></span><span class="initializer">=None</span></span>)</code></pre></td></tr></table><table border="0" width="100%" bgcolor="#FFECCE"><col align="left" valign="top" width="0*"><tbody><tr><td><span class="term"><i class="parameter"><tt>sort_func</tt></i>:</span></td><td>the sorting function</td></tr><tr><td><span class="term"><i class="parameter"><tt>user_data</tt></i>:</span></td><td>the user data to pass to
<i class="parameter"><tt>sort_func</tt></i>, or
<tt class="literal">None</tt></td></tr></tbody></table><p>The <tt class="methodname">set_default_sort_func</tt>() method sets
the default comparison function (or method) to the value of
<i class="parameter"><tt>sort_func</tt></i>. If the current sort column id of the
treesortable is -1 (the <a href="class-gtktreesortable.html#method-gtktreesortable--get-sort-column-id" title="gtk.TreeSortable.get_sort_column_id"><tt class="methodname">get_sort_column_id</tt>()</a>
method returns (None, None)), then the model will be resorted using the
<i class="parameter"><tt>sort_func</tt></i>. See the <a href="class-gtktreesortable.html#method-gtktreesortable--set-sort-func" title="gtk.TreeSortable.set_sort_func"><tt class="methodname">set_sort_func</tt>()</a>
method for more details on the signature of the comparison function.</p></div><div class="refsect2" lang="en"><a name="method-gtktreesortable--has-default-sort-func"></a><h3>gtk.TreeSortable.has_default_sort_func</h3><table border="0" bgcolor="#E0E0E0" width="100%"><tr><td><pre class="programlisting"><code class="methodsynopsis"> def <span class="methodname">has_default_sort_func</span>(<span class="methodparam"></span>)</code></pre></td></tr></table><table border="0" width="100%" bgcolor="#FFECCE"><col align="left" valign="top" width="0*"><tbody><tr><td><span class="term"><span class="emphasis"><em>Returns</em></span>:</span></td><td><tt class="literal">TRUE</tt>, if the model has a
default sort function</td></tr></tbody></table><p>The <tt class="methodname">has_default_sort_func</tt>() method
returns <tt class="literal">TRUE</tt> if the model has a default sort function.
This is used primarily by <a href="class-gtktreeviewcolumn.html" title="gtk.TreeViewColumn"><tt class="classname">gtk.TreeViewColumn</tt></a>
to determine if a model can go back to the default state, or not.</p></div></div><div class="refsect1" lang="en"><a name="id3591911"></a><h2>Signals</h2><div class="refsect2" lang="en"><a name="signal-gtktreesortable--sort-column-changed"></a><h3>The "sort-column-changed" gtk.TreeSortable Signal</h3><table border="0" bgcolor="#E0E0E0" width="100%"><tr><td><pre class="programlisting"><code class="methodsynopsis"> def <span class="methodname">callback</span>(<span class="methodparam"><span class="parameter"><i class="parameter"><tt>treesortable</tt></i></span></span>, <span class="methodparam"><span class="parameter"><i class="parameter"><tt>user_param1</tt></i></span></span>, <span class="methodparam"><span class="parameter"><i class="parameter"><tt>...</tt></i></span></span>)</code></pre></td></tr></table><table border="0" width="100%" bgcolor="#FFECCE"><col align="left" valign="top" width="0*"><tbody><tr><td><span class="term"><i class="parameter"><tt>treesortable</tt></i>:</span></td><td>the treesortable that received the
signal</td></tr><tr><td><span class="term"><i class="parameter"><tt>user_param1</tt></i>:</span></td><td>the first user parameter (if any) specified
with the <a href="class-gobject.html#method-gobject--connect" title="gobject.GObject.connect"><tt class="methodname">connect</tt>()</a>
method</td></tr><tr><td><span class="term"><i class="parameter"><tt>...</tt></i>:</span></td><td>additional user parameters (if
any)</td></tr></tbody></table><p>The "sort-column-changed" signal is emitted when the <a href="class-gtktreesortable.html#method-gtktreesortable--sort-column-changed" title="gtk.TreeSortable.sort_column_changed"><tt class="methodname">sort_column_changed</tt>()</a>
method is called or the sort column is changed using the <a href="class-gtktreesortable.html#method-gtktreesortable--set-sort-column-id" title="gtk.TreeSortable.set_sort_column_id"><tt class="methodname">set_sort_column_id</tt>()</a>
method.</p></div></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="class-gtktreeselection.html">Prev</a></td><td width="20%" align="center"><a accesskey="u" href="gtk-class-reference.html">Up</a></td><td width="40%" align="right"><a accesskey="n" href="class-gtktreestore.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">gtk.TreeSelection</td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top">gtk.TreeStore</td></tr></table></div></body></html>
|