wx.FileType

Inheritance diagram for wx.FileType:



Description

This class holds information about a given file type. File type is the same as MIME type under Unix, but under Windows it corresponds more to an extension than to MIME type (in fact, several extensions may correspond to a file type). This object may be created in several different ways: the program might know the file extension and wish to find out the corresponding MIME type or, conversely, it might want to find the right extension for the file to which it writes the contents of given MIME type. Depending on how it was created some fields may be unknown so the return value of all the accessors must be checked: False will be returned if the corresponding information couldn’t be found.

The objects of this class are never created by the application code but are returned by wx.MimeTypesManager.GetFileTypeFromMimeType and wx.MimeTypesManager.GetFileTypeFromExtension methods. But it is your responsibility to delete the returned pointer when you’re done with it!

A brief reminder about what the MIME types are (see the RFC 1341 for more information): basically, it is just a pair category/type (for example, “text/plain”) where the category is a basic indication of what a file is. Examples of categories are “application”, “image”, “text”, “binary”, and type is a precise definition of the document format: “plain” in the example above means just ASCII text without any formatting, while “text/html” is the HTML document source.

A MIME type may have one or more associated extensions: “text/plain” will typically correspond to the extension “.txt”, but may as well be associated with “.ini” or “.conf”.

Class API

Methods

__init__(ftInfo)

Constructor.

Parameters:

  • ftInfo (wx.FileTypeInfo)

Returns:

wx.FileType


ExpandCommand(command, filename, mimetype="")

This function is primarily intended for GetOpenCommand and GetPrintCommand usage but may be also used by the application directly if, for example, you want to use some non-default command to open the file.

The function replaces all occurrences of:

Format Specification With
%s the full file name
%t the MIME type
%{param} the value of the parameter param

If there is no “%s” in the command string (and the string is not empty), it is assumed that the command reads the data on stdin and so the effect is the same as “%s” were appended to the string.

Unlike all other functions of this class, there is no error return for this function.

Parameters:

  • command (string)
  • filename (string)
  • mimetype (string)

Returns:

string


GetAllCommands(filename, mimetype="")

Parameters:

  • filename (string)
  • mimetype (string)

Returns:

PyObject


GetDescription()

Returns a string filled with a brief description for this file type: for example, “text document” for the “text/plain” MIME type.


Returns:

PyObject


GetExtensions()

Returns an array filled with all extensions associated with this file type: for example, it may contain the following two elements for the MIME type “text/html” (notice the absence of the leading dot): “html” and “htm”.


Returns:

list of strings

Note

On Windows, this function is currently not implemented: there is no (efficient) way to retrieve associated extensions from the given MIME type on this platform, so it will only return True if the wx.FileType object was created by GetFileTypeFromExtension function in the first place.


GetIcon()

Returns the location of the icon for this MIME type. A wx.Icon may be created from this icon later.


Returns:

wx.Icon

Note

Windows: The function returns the icon shown by Explorer for the files of the specified type. Mac: This function is not implemented and always returns False. Unix: MIME manager gathers information about icons from GNOME and KDE settings and thus GetIcon success depends on availability of these desktop environments.


GetIconInfo()
No docstrings available for this method.

GetMimeType()

Returns a string filled with full MIME type specification for this file type: for example, “text/plain”.


Returns:

string


GetMimeTypes()

Same as GetMimeType but returns array of MIME types. This array will contain only one item in most cases but sometimes, notably under Unix with KDE, may contain more MIME types. This happens when one file extension is mapped to different MIME types by KDE, mailcap and mime.types.


Returns:

list of strings


GetOpenCommand(filename, mimetype="")

If True is returned, the string pointed to by filename is filled with the command which must be executed (see wx.Execute) in order to open the file of the given type.

Parameters:

  • filename (string)
  • mimetype (string)

Returns:

PyObject

See also

wx.Execute


GetPrintCommand(filename, mimetype="")

If the function returns True, the string pointed to by filename is filled with the command which must be executed (see wx.Execute) in order to print the file of the given type.

Parameters:

  • filename (string)
  • mimetype (string)

Returns:

PyObject

See also

wx.Execute


SetCommand(cmd, verb, overwriteprompt=True)

Parameters:

  • cmd (string)
  • verb (string)
  • overwriteprompt (bool)

Returns:

bool


SetDefaultIcon(cmd="", index=0)

Parameters:

  • cmd (string)
  • index (int)

Returns:

bool


Unassociate()
No docstrings available for this method.

Properties

AllCommands
See GetAllCommands
Description
See GetDescription
Extensions
See GetExtensions
Icon
See GetIcon
IconInfo
See GetIconInfo
MimeType
See GetMimeType
MimeTypes
See GetMimeTypes
OpenCommand
See GetOpenCommand
PrintCommand
See GetPrintCommand