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
|
<html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>gtk.FileFilter</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-gtkfilechooserwidget.html" title="gtk.FileChooserWidget"><link rel="next" href="class-gtkfileselection.html" title="gtk.FileSelection"></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.FileFilter</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="class-gtkfilechooserwidget.html">Prev</a></td><th width="60%" align="center">The gtk Class Reference</th><td width="20%" align="right"><a accesskey="n" href="class-gtkfileselection.html">Next</a></td></tr></table><hr></div><div class="refentry" lang="en"><a name="class-gtkfilefilter"></a><div class="titlepage"><div></div><div></div></div><div class="refnamediv"><h2>gtk.FileFilter</h2><p>gtk.FileFilter — a filter for selecting a
file subset (new in PyGTK 2.4)</p></div><div class="refsect1" lang="en"><a name="id3420670"></a><h2>Synopsis</h2><table bgcolor="#D0E0F0" width="100%"><tr><td><pre class="classsynopsis">class <span class="ooclass"><span class="classname">gtk.FileFilter</span></span>(<span class="ooclass"><span class="classname"><a href="class-gtkobject.html" title="gtk.Object">gtk.Object</a></span></span>):
<code class="constructorsynopsis"> <span class="methodname"><a href="class-gtkfilefilter.html#constructor-gtkfilefilter" title="Constructor">gtk.FileFilter</a></span>(<span class="methodparam"></span>)</code><br><code class="methodsynopsis"> def <span class="methodname"><a href="class-gtkfilefilter.html#method-gtkfilefilter--set-name" title="gtk.FileFilter.set_name">set_name</a></span>(<span class="methodparam"><span class="parameter"><b class="parameter"><tt>name</tt></b></span></span>)</code><br><code class="methodsynopsis"> def <span class="methodname"><a href="class-gtkfilefilter.html#method-gtkfilefilter--get-name" title="gtk.FileFilter.get_name">get_name</a></span>(<span class="methodparam"></span>)</code><br><code class="methodsynopsis"> def <span class="methodname"><a href="class-gtkfilefilter.html#method-gtkfilefilter--add-mime-type" title="gtk.FileFilter.add_mime_type">add_mime_type</a></span>(<span class="methodparam"><span class="parameter"><b class="parameter"><tt>mime_type</tt></b></span></span>)</code><br><code class="methodsynopsis"> def <span class="methodname"><a href="class-gtkfilefilter.html#method-gtkfilefilter--add-pattern" title="gtk.FileFilter.add_pattern">add_pattern</a></span>(<span class="methodparam"><span class="parameter"><b class="parameter"><tt>pattern</tt></b></span></span>)</code><br><code class="methodsynopsis"> def <span class="methodname"><a href="class-gtkfilefilter.html#method-gtkfilefilter--add-custom" title="gtk.FileFilter.add_custom">add_custom</a></span>(<span class="methodparam"><span class="parameter"><i class="parameter"><tt>needed</tt></i></span></span>, <span class="methodparam"><span class="parameter"><i class="parameter"><tt>func</tt></i></span></span>, <span class="methodparam"><span class="parameter"><i class="parameter"><tt>data</tt></i></span></span>)</code><br><code class="methodsynopsis"> def <span class="methodname"><a href="class-gtkfilefilter.html#method-gtkfilefilter--get-needed" title="gtk.FileFilter.get_needed">get_needed</a></span>(<span class="methodparam"></span>)</code><br><code class="methodsynopsis"> def <span class="methodname"><a href="class-gtkfilefilter.html#method-gtkfilefilter--filter" title="gtk.FileFilter.filter">filter</a></span>(<span class="methodparam"><span class="parameter"><b class="parameter"><tt>filter_info</tt></b></span></span>)</code><br></pre></td></tr></table></div><div class="refsect1" lang="en"><a name="id3420829"></a><h2>Ancestry</h2><table border="0" bgcolor="#E0E0E0" width="100%"><tr><td><pre class="synopsis">+-- <a href="class-gobject.html" title="gobject.GObject">gobject.GObject</a>
+-- <a href="class-gtkobject.html" title="gtk.Object">gtk.Object</a>
+-- <a href="class-gtkfilefilter.html" title="gtk.FileFilter">gtk.FileFilter</a>
</pre></td></tr></table></div><div class="refsect1" lang="en"><a name="id3420854"></a><h2>Description</h2><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p>This widget is available in PyGTK 2.4 and above.</p></div><p>A <a href="class-gtkfilefilter.html" title="gtk.FileFilter"><tt class="classname">gtk.FileFilter</tt></a>
is an object that filters files based on a set of rules that it
contains. The categories of information that <a href="class-gtkfilefilter.html" title="gtk.FileFilter"><tt class="classname">gtk.FileFilter</tt></a>
uses to accept or reject the file are:</p><table border="0" width="100%" bgcolor="#FFECCE"><col align="left" valign="top" width="0*"><tbody><tr><td><span class="term"><tt class="literal">gtk.FILE_FILTER_FILENAME</tt></span></td><td>The full path name of the file.</td></tr><tr><td><span class="term"><tt class="literal">gtk.FILE_FILTER_URI</tt></span></td><td>The URI of the file.</td></tr><tr><td><span class="term"><tt class="literal">gtk.FILE_FILTER_DISPLAY_NAME</tt></span></td><td>The simple name of the file as displayed in a file
chooser.</td></tr><tr><td><span class="term"><tt class="literal">gtk.FILE_FILTER_MIME_TYPE</tt></span></td><td>The MIME type of the file.</td></tr></tbody></table><p>The <a href="class-gtkfilefilter.html#method-gtkfilefilter--add-pattern" title="gtk.FileFilter.add_pattern"><tt class="methodname">add_pattern</tt>()</a>
method adds a rule that only uses the display name
(<tt class="literal">gtk.FILE_FILTER_DISPLAY_NAME</tt>) for filtering. The <a href="class-gtkfilefilter.html#method-gtkfilefilter--add-mime-type" title="gtk.FileFilter.add_mime_type"><tt class="methodname">add_mime_type</tt>()</a>
method adds a rule that only uses the mime type
(<tt class="literal">gtk.FILE_FILTER_MIME_TYPE</tt>) for filtering. To use the
file URI (<tt class="literal">gtk.FILE_FILTER_URI</tt>) or filename
(<tt class="literal">gtk.FILE_FILTER_FILENAME</tt>) you have to create a custom
filter rule using a callback function that is registered with the <a href="class-gtkfilefilter.html#method-gtkfilefilter--add-custom" title="gtk.FileFilter.add_custom"><tt class="methodname">add_custom</tt>()</a>
method.</p><p>The pattern rule uses file globbing to match the file display
name:</p><div class="itemizedlist"><ul type="disc"><li>'*' matches any combination of characters e.g.. "a*c" matches
"abc", "a bridge tic", "aaabbbc" and so on.</li><li>'?' matches any single character e.g. "a?c" matches "abc",
aZc" and so on but not "abbc".</li><li>'[' and ']' enclose a set of characters that can be matched; ranges
of characters can be included by separating the start and end with a dash
(e.g. "a-z" include all the lowercase letters). e.g. "a[0-9]c" matches "a3c"
and "a9c" but not "a28c" or "abc".</li><li>'\' escapes the next character to allow "*", "?", "[" and "]"
to be matched literally.</li></ul></div><p>The MIME type requires an exact match (no pattern matching).</p></div><div class="refsect1" lang="en"><a name="constructor-gtkfilefilter"></a><h2>Constructor</h2><table border="0" bgcolor="#E0E0E0" width="100%"><tr><td><pre class="programlisting"><code class="constructorsynopsis"> <span class="methodname">gtk.FileFilter</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 new
<a href="class-gtkfilefilter.html" title="gtk.FileFilter"><tt class="classname">gtk.FileFilter</tt></a></td></tr></tbody></table><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p>This constructor is available in PyGTK 2.4 and above.</p></div><p>Creates a new <a href="class-gtkfilefilter.html" title="gtk.FileFilter"><tt class="classname">gtk.FileFilter</tt></a>
with no rules added to it. Such a filter doesn't pass any files, so it's not
particularly useful until you add rules with the <a href="class-gtkfilefilter.html#method-gtkfilefilter--add-mime-type" title="gtk.FileFilter.add_mime_type"><tt class="methodname">add_mime_type()</tt></a>,
<a href="class-gtkfilefilter.html#method-gtkfilefilter--add-pattern" title="gtk.FileFilter.add_pattern"><tt class="methodname">add_pattern()</tt></a>
or <a href="class-gtkfilefilter.html#method-gtkfilefilter--add-custom" title="gtk.FileFilter.add_custom"><tt class="methodname">add_custom()</tt></a>
methods. To create a filter that accepts any file, use:</p><table border="0" bgcolor="#E0E0E0" width="100%"><tr><td><pre class="programlisting">
filter = gtk.FileFilter()
filter.add_pattern("*")
</pre></td></tr></table><p></p></div><div class="refsect1" lang="en"><a name="id3421121"></a><h2>Methods</h2><div class="refsect2" lang="en"><a name="method-gtkfilefilter--set-name"></a><h3>gtk.FileFilter.set_name</h3><table border="0" bgcolor="#E0E0E0" width="100%"><tr><td><pre class="programlisting"><code class="methodsynopsis"> def <span class="methodname">set_name</span>(<span class="methodparam"><span class="parameter"><b class="parameter"><tt>name</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>name</tt></b>:</span></td><td>the human-readable-name for the
filter.</td></tr></tbody></table><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p>This method is available in PyGTK 2.4 and above.</p></div><p>The <tt class="methodname">set_name</tt>() method sets the
human-readable name of the filter to the string in
<i class="parameter"><tt>name</tt></i>. The string in <i class="parameter"><tt>name</tt></i> will
be displayed in the file chooser user interface if there is a selectable
list of filters.</p></div><div class="refsect2" lang="en"><a name="method-gtkfilefilter--get-name"></a><h3>gtk.FileFilter.get_name</h3><table border="0" bgcolor="#E0E0E0" width="100%"><tr><td><pre class="programlisting"><code class="methodsynopsis"> def <span class="methodname">get_name</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>The human-readable name of the filter,
or <tt class="literal">None</tt>.</td></tr></tbody></table><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p>This method is available in PyGTK 2.4 and above.</p></div><p>The <tt class="methodname">get_name</tt>() method returns the
human-readable name for the filter or <tt class="literal">None</tt> if the name
has not been set. See the <a href="class-gtkfilefilter.html#method-gtkfilefilter--set-name" title="gtk.FileFilter.set_name"><tt class="methodname">set_name()</tt></a>
method.</p></div><div class="refsect2" lang="en"><a name="method-gtkfilefilter--add-mime-type"></a><h3>gtk.FileFilter.add_mime_type</h3><table border="0" bgcolor="#E0E0E0" width="100%"><tr><td><pre class="programlisting"><code class="methodsynopsis"> def <span class="methodname">add_mime_type</span>(<span class="methodparam"><span class="parameter"><b class="parameter"><tt>mime_type</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>mime_type</tt></b>:</span></td><td>the name of a MIME type</td></tr></tbody></table><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p>This method is available in PyGTK 2.4 and above.</p></div><p>The <tt class="methodname">add_mime_type</tt>() method adds a rule
allowing the mime type specified by <i class="parameter"><tt>mime_type</tt></i> to be
matched. Sets the needs value to
<tt class="literal">gtk.FILE_FILTER_MIME_TYPE</tt> (see the <a href="class-gtkfilefilter.html#method-gtkfilefilter--get-needed" title="gtk.FileFilter.get_needed"><tt class="methodname">get_needed</tt>()</a>
method for more information).</p></div><div class="refsect2" lang="en"><a name="method-gtkfilefilter--add-pattern"></a><h3>gtk.FileFilter.add_pattern</h3><table border="0" bgcolor="#E0E0E0" width="100%"><tr><td><pre class="programlisting"><code class="methodsynopsis"> def <span class="methodname">add_pattern</span>(<span class="methodparam"><span class="parameter"><b class="parameter"><tt>pattern</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>pattern</tt></b>:</span></td><td>a shell style glob pattern</td></tr></tbody></table><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p>This method is available in PyGTK 2.4 and above.</p></div><p>The <tt class="methodname">add_pattern</tt>() method adds a rule
allowing the shell style glob pattern specified by
<i class="parameter"><tt>pattern</tt></i> to filter file names. Sets the needs value to
<tt class="literal">gtk.FILE_FILTER_DISPLAY_NAME</tt> (see the <a href="class-gtkfilefilter.html#method-gtkfilefilter--get-needed" title="gtk.FileFilter.get_needed"><tt class="methodname">get_needed</tt>()</a>
method for more information).</p><p>The pattern rule uses file globbing to match the file display
name:</p><div class="itemizedlist"><ul type="disc"><li>'*' matches any combination of characters e.g.. "a*c" matches
"abc", "a bridge tic", "aaabbbc" and so on.</li><li>'?' matches any single character e.g. "a?c" matches "abc",
aZc" and so on but not "abbc".</li><li>'[' and ']' enclose a set of characters that can be matched; ranges
of characters can be included by separating the start and end with a dash
(e.g. "a-z" include all the lowercase letters). e.g. "a[0-9]c" matches "a3c"
and "a9c" but not "a28c" or "abc".</li><li>'\' escapes the next character to allow "*", "?", "[" and "]"
to be matched literally.</li></ul></div></div><div class="refsect2" lang="en"><a name="method-gtkfilefilter--add-custom"></a><h3>gtk.FileFilter.add_custom</h3><table border="0" bgcolor="#E0E0E0" width="100%"><tr><td><pre class="programlisting"><code class="methodsynopsis"> def <span class="methodname">add_custom</span>(<span class="methodparam"><span class="parameter"><i class="parameter"><tt>needed</tt></i></span></span>, <span class="methodparam"><span class="parameter"><i class="parameter"><tt>func</tt></i></span></span>, <span class="methodparam"><span class="parameter"><i class="parameter"><tt>data</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>needed</tt></i>:</span></td><td>a bitfield of flags indicating the information
that the custom filter function needs.</td></tr><tr><td><span class="term"><i class="parameter"><tt>func</tt></i>:</span></td><td>a callback function; if the function returns
<tt class="literal">TRUE</tt>, then the file will be displayed.</td></tr><tr><td><span class="term"><i class="parameter"><tt>data</tt></i>:</span></td><td>the data to pass to
<i class="parameter"><tt>func</tt></i></td></tr></tbody></table><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p>This method is available in PyGTK 2.4 and above.</p></div><p>The <tt class="methodname">add_custom</tt>() method adds a rule to
a filter that allows files to be filtered based on a custom callback
function specified by <i class="parameter"><tt>func</tt></i>. The bitfield
<i class="parameter"><tt>needed</tt></i> provides information about what sorts of
information that the filter function needs; this allows GTK+ to avoid
retrieving expensive information when it isn't needed by the
filter. <i class="parameter"><tt>needed</tt></i> is a combination of:</p><table border="0" width="100%" bgcolor="#FFECCE"><col align="left" valign="top" width="0*"><tbody><tr><td><span class="term"><tt class="literal">gtk.FILE_FILTER_FILENAME</tt></span></td><td>The full path name of the file.</td></tr><tr><td><span class="term"><tt class="literal">gtk.FILE_FILTER_URI</tt></span></td><td>The URI of the file.</td></tr><tr><td><span class="term"><tt class="literal">gtk.FILE_FILTER_DISPLAY_NAME</tt></span></td><td>The simple name of the file as displayed in a file
chooser.</td></tr><tr><td><span class="term"><tt class="literal">gtk.FILE_FILTER_MIME_TYPE</tt></span></td><td>The MIME type of the file.</td></tr></tbody></table><p>The signature of <i class="parameter"><tt>func</tt></i> is:</p><table border="0" bgcolor="#E0E0E0" width="100%"><tr><td><pre class="programlisting">
def filefilterfunction(filter_info, data):
</pre></td></tr></table><p>where <i class="parameter"><tt>filter_info</tt></i> is a 4-tuple where each
item is either a string or <tt class="literal">None</tt>. The strings correspond
to: the full pathname of the file, the URI of the file, the display name of
the file and the MIME type of the file. <i class="parameter"><tt>data</tt></i> is the
value passed in as the <i class="parameter"><tt>data</tt></i> parameter in the
<tt class="methodname">add_custom</tt>() method. Using a custom filter function
is the only way to filter files based on file URIs or full file
pathnames.</p></div><div class="refsect2" lang="en"><a name="method-gtkfilefilter--get-needed"></a><h3>gtk.FileFilter.get_needed</h3><table border="0" bgcolor="#E0E0E0" width="100%"><tr><td><pre class="programlisting"><code class="methodsynopsis"> def <span class="methodname">get_needed</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 bitfield of flags indicating the needed fields
when calling <a href="class-gtkfilefilter.html#method-gtkfilefilter--filter" title="gtk.FileFilter.filter"><tt class="methodname">filter()</tt></a></td></tr></tbody></table><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p>This method is available in PyGTK 2.4 and above.</p></div><p>The <tt class="methodname">get_needed</tt>() method returns the
information that is needed by the <a href="class-gtkfilefilter.html" title="gtk.FileFilter"><tt class="classname">gtk.FileFilter</tt></a>
to filter the file info using the <a href="class-gtkfilefilter.html#method-gtkfilefilter--filter" title="gtk.FileFilter.filter"><tt class="methodname">filter()</tt></a></p><p>This method is not typically used by applications; it is
intended principally for use in the implementation of <a href="class-gtkfilechooser.html" title="gtk.FileChooser"><tt class="classname">gtk.FileChooser</tt></a>.</p></div><div class="refsect2" lang="en"><a name="method-gtkfilefilter--filter"></a><h3>gtk.FileFilter.filter</h3><table border="0" bgcolor="#E0E0E0" width="100%"><tr><td><pre class="programlisting"><code class="methodsynopsis"> def <span class="methodname">filter</span>(<span class="methodparam"><span class="parameter"><b class="parameter"><tt>filter_info</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>filter_info</tt></b>:</span></td><td>a 4-tuple containing the information
about a file.</td></tr><tr><td><span class="term"><span class="emphasis"><em>Returns</em></span>:</span></td><td><tt class="literal">TRUE</tt> if the file should be
displayed</td></tr></tbody></table><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p>This method is available in PyGTK 2.4 and above.</p></div><p>The <tt class="methodname">filter</tt>() method tests whether a file should be displayed according to the file filter rules.
The 4-tuple <i class="parameter"><tt>filter_info</tt></i> should include
the fields returned from the <a href="class-gtkfilefilter.html#method-gtkfilefilter--get-needed" title="gtk.FileFilter.get_needed"><tt class="methodname">get_needed()</tt></a> method:</p><div class="itemizedlist"><ul type="disc"><li>the full pathname of the file if needs includes
<tt class="literal">gtk.FILE_FILTER_FILENAME</tt></li><li>the URI of the file is needs includes
<tt class="literal">gtk.FILE_FILTER_URI</tt></li><li>the display name (without the path) if the file if needs
includes <tt class="literal">gtk.FILE_FILTER_DISPLAY_NAME</tt></li><li>the MIME type of the file if needs includes
<tt class="literal">gtk.FILE_FILTER_MIME_TYPE</tt></li></ul></div><p>This method will not typically be used by applications; it is
intended principally for use in the implementation of <a href="class-gtkfilechooser.html" title="gtk.FileChooser"><tt class="classname">gtk.FileChooser</tt></a>.</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-gtkfilechooserwidget.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-gtkfileselection.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">gtk.FileChooserWidget</td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top">gtk.FileSelection</td></tr></table></div></body></html>
|