|
class gtk.FileFilter(gtk.Object): |
This widget is available in PyGTK 2.4 and above.
A gtk.FileFilter
is an object that filters files based on a set of rules that it
contains. The categories of information that gtk.FileFilter
uses to accept or reject the file are given by the GTK FileFilter Flags Constants:
| The full path name of the file. |
| The URI of the file. |
| The simple name of the file as displayed in a file chooser. |
| The MIME type of the file. |
The add_pattern
()
method adds a rule that only uses the display name
(gtk.FILE_FILTER_DISPLAY_NAME
) for filtering. The
add_mime_type
()
method adds a rule that only uses the mime type
(gtk.FILE_FILTER_MIME_TYPE
) for filtering. To use the
file URI (gtk.FILE_FILTER_URI
) or filename
(gtk.FILE_FILTER_FILENAME
) you have to create a
custom filter rule using a callback function that is registered with the
add_custom
()
method.
The pattern rule uses file globbing to match the file display name:
The MIME type requires an exact match (no pattern matching).
gtk.FileFilter()
Returns : | a new
gtk.FileFilter |
This constructor is available in PyGTK 2.4 and above.
Creates a new gtk.FileFilter
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 add_mime_type()
,
add_pattern()
or add_custom()
methods. To create a filter that accepts any file, use:
filter = gtk.FileFilter() filter.add_pattern("*")
def set_name(name
)
| the human-readable-name for the filter. |
This method is available in PyGTK 2.4 and above.
The set_name
() method sets the
human-readable name of the filter to the string in
name
. The string in name
will
be displayed in the file chooser user interface if there is a selectable
list of filters.
def get_name()
Returns : | The human-readable name of the filter,
or None . |
This method is available in PyGTK 2.4 and above.
The get_name
() method returns the
human-readable name for the filter or None
if the name
has not been set. See the set_name()
method.
def add_mime_type(mime_type
)
| the name of a MIME type |
This method is available in PyGTK 2.4 and above.
The add_mime_type
() method adds a rule
allowing the mime type specified by mime_type
to be
matched. Sets the needs value to
gtk.FILE_FILTER_MIME_TYPE
(see the get_needed
()
method for more information).
def add_pattern(pattern
)
| a shell style glob pattern |
This method is available in PyGTK 2.4 and above.
The add_pattern
() method adds a rule
allowing the shell style glob pattern specified by
pattern
to filter file names. Sets the needs value to
gtk.FILE_FILTER_DISPLAY_NAME
(see the get_needed
()
method for more information).
The pattern rule uses file globbing to match the file display name:
def add_custom(needed
, func
, data
)
| a bitfield of flags indicating the information that the custom filter function needs. |
| a callback function; if the function returns
True , then the file will be displayed. |
| the data to pass to
func |
This method is available in PyGTK 2.4 and above.
The add_custom
() method adds a rule to
a filter that allows files to be filtered based on a custom callback
function specified by func
. The bitfield
needed
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. needed
is a combination of:
| The full path name of the file. |
| The URI of the file. |
| The simple name of the file as displayed in a file chooser. |
| The MIME type of the file. |
The signature of func
is:
def filefilterfunction(filter_info, data):
where filter_info
is a 4-tuple where each
item is either a string or None
. 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. data
is the
value passed in as the data
parameter in the
add_custom
() method. Using a custom filter function
is the only way to filter files based on file URIs or full file
pathnames.
def get_needed()
Returns : | a bitfield of flags indicating the needed fields
when calling filter() |
This method is available in PyGTK 2.4 and above.
The get_needed
() method returns the
information that is needed by the gtk.FileFilter
to filter the file info using the filter()
This method is not typically used by applications; it is
intended principally for use in the implementation of gtk.FileChooser
.
def filter(filter_info
)
| a 4-tuple containing the information about a file. |
Returns : | True if the file should be
displayed |
This method is available in PyGTK 2.4 and above.
The filter
() method tests whether a file should be displayed according to the file filter rules.
The 4-tuple filter_info
should include
the fields returned from the get_needed()
method:
gtk.FILE_FILTER_FILENAME
gtk.FILE_FILTER_URI
gtk.FILE_FILTER_DISPLAY_NAME
gtk.FILE_FILTER_MIME_TYPE
This method will not typically be used by applications; it is
intended principally for use in the implementation of gtk.FileChooser
.
def add_pixbuf_formats()
This method is available in PyGTK 2.6 and above.
The add_pixbuf_formats
() method adds a
rule allowing image files in the formats supported by gtk.gdk.Pixbuf
.
© manpagez.com 2000-2024 Individual documents may contain additional copyright information.