phoenix_title wx.StandardPaths

wx.StandardPaths returns the standard locations in the file system and should be used by applications to find their data files in a portable way.

Note that you must not create objects of class wx.StandardPaths directly, but use the global standard paths object returned by wx.StandardPaths.Get (which can be of a type derived from wx.StandardPaths and not of exactly this type) and call the methods you need on it. The object returned by Get may be customized by overriding wx.AppTraits.GetStandardPaths methods.

In the description of the methods below, the example return values are given for the Unix, Windows and macOS systems, however please note that these are just the examples and the actual values may differ. For example, under Windows: the system administrator may change the standard directories locations, e.g. the Windows directory may be named "W:\Win2003" instead of the default "C:\Windows" .

Notice that in the examples below the string appinfo may be either just the application name (as returned by wx.App.GetAppName ) or a combination of the vendor name ( wx.App.GetVendorName ) and the application name, with a path separator between them. By default, only the application name is used, use UseAppInfo to change this.

The other placeholders should be self-explanatory: the string username should be replaced with the value the name of the currently logged in user. and prefix is only used under Unix and is /usr/local by default but may be changed using wx.StandardPaths.SetInstallPrefix .

The directories returned by the methods of this class may or may not exist. If they don’t exist, it’s up to the caller to create them, wx.StandardPaths doesn’t do it.

Finally note that these functions only work with standardly packaged applications. I.e. under Unix you should follow the standard installation conventions and under Mac you should create your application bundle according to the Apple guidelines. Again, this class doesn’t help you to do it.

This class is MT-safe: its methods may be called concurrently from different threads without additional locking.

See also

wx.FileConfig


class_hierarchy Class Hierarchy

Inheritance diagram for class StandardPaths:

method_summary Methods Summary

Get

Returns reference to the unique global standard paths object.

GetAppDocumentsDir

Return the directory for the document files used by this application.

GetConfigDir

Return the directory containing the system config files.

GetDataDir

Return the location of the applications global, i.e. not user-specific, data files.

GetDocumentsDir

Same as calling GetUserDir with Dir_Documents parameter.

GetExecutablePath

Return the directory and the filename for the current executable.

GetFileLayout

Returns the current file layout.

GetInstallPrefix

Return the program installation prefix, e.g. /usr , /opt or /home/zeitlin .

GetLocalDataDir

Return the location for application data files which are host-specific and can’t, or shouldn’t, be shared with the other machines.

GetLocalizedResourcesDir

Return the localized resources directory containing the resource files of the specified category for the given language.

GetPluginsDir

Return the directory where the loadable modules (plugins) live.

GetResourcesDir

Return the directory where the application resource files are located.

GetTempDir

Return the directory for storing temporary files, for the current user.

GetUserConfigDir

Return the directory for the user config files.

GetUserDataDir

Return the directory for the user-dependent application data files

GetUserDir

Return the path of the specified user data directory.

GetUserLocalDataDir

Return the directory for user data files which shouldn’t be shared with the other machines.

MSWGetShellDir

Returns location of Windows shell special folder.

MakeConfigFileName

Return the file name which would be used by wx.FileConfig if it were constructed with basename.

SetFileLayout

Sets the current file layout.

SetInstallPrefix

Lets wx.StandardPaths know about the real program installation prefix on a Unix system.

UseAppInfo

Controls what application information is used when constructing paths that should be unique to this program, such as the application data directory, the plugins directory on Unix, etc.

__init__

Protected default constructor.


property_summary Properties Summary

AppDocumentsDir

See GetAppDocumentsDir

ConfigDir

See GetConfigDir

DataDir

See GetDataDir

DocumentsDir

See GetDocumentsDir

ExecutablePath

See GetExecutablePath

InstallPrefix

See GetInstallPrefix and SetInstallPrefix

LocalDataDir

See GetLocalDataDir

PluginsDir

See GetPluginsDir

ResourcesDir

See GetResourcesDir

TempDir

See GetTempDir

UserConfigDir

See GetUserConfigDir

UserDataDir

See GetUserDataDir

UserLocalDataDir

See GetUserLocalDataDir


api Class API

class wx.StandardPaths(object)

Possible constructors:

StandardPaths()

StandardPaths returns the standard locations in the file system and should be used by applications to find their data files in a portable way.


Methods

static Get()

Returns reference to the unique global standard paths object.

Return type:

wx.StandardPaths



GetAppDocumentsDir(self)

Return the directory for the document files used by this application.

If the application-specific directory doesn’t exist, this function returns GetDocumentsDir .

Example return values:

  • Unix: ~/appinfo

  • Windows: "C:\Users\username\Documents\appinfo" or "C:\Documents and Settings\username\My Documents\appinfo"

  • Mac: ~/Documents/appinfo

Return type:

string

New in version 2.9.0.



GetConfigDir(self)

Return the directory containing the system config files.

Example return values:

  • Unix: /etc

  • Windows: "C:\ProgramData\appinfo" or "C:\Documents and Settings\All Users\Application Data\appinfo"

  • Mac: /Library/Preferences

Return type:

string

Note

Under Windows this includes appinfo which makes it inconsistent with other ports.

See also

wx.FileConfig



GetDataDir(self)

Return the location of the applications global, i.e. not user-specific, data files.

Example return values:

  • Unix: prefix/share/appinfo

  • Windows: the directory where the executable file is located

  • Mac: appinfo.app/Contents/SharedSupport bundle subdirectory

Under Unix (only) it is possible to override the default value returned from this function by setting the value of WX_APPNAME_DATA_DIR environment variable to the directory to use (where APPNAME is the upper-cased value of wx.App.GetAppName ). This is useful in order to be able to run applications using this function without installing them as you can simply set this environment variable to the source directory location to allow the application to find its files there.

Return type:

string

See also

GetLocalDataDir



GetDocumentsDir(self)

Same as calling GetUserDir with Dir_Documents parameter.

Return type:

string

New in version 2.7.0.



GetExecutablePath(self)

Return the directory and the filename for the current executable.

Example return values:

  • Unix: /usr/local/bin/exename

  • Windows: "C:\Programs\AppFolder\exename.exe"

  • Mac: /Applications/exename .app/Contents/MacOS/exename

Return type:

string



GetFileLayout(self)

Returns the current file layout.

Return type:

wx.StandardPaths.FileLayout

New in version 4.1/wxWidgets-3.1.1.

See also

SetFileLayout



GetInstallPrefix(self)

Return the program installation prefix, e.g. /usr , /opt or /home/zeitlin .

If the prefix had been previously by SetInstallPrefix , returns that value, otherwise tries to determine it automatically (Linux only right now) and finally returns the default /usr/local value if it failed.

Return type:

string

Availability

Only available for GTK.

Note

This function is only available under Unix platforms (but not limited to wxGTK mentioned below).



GetLocalDataDir(self)

Return the location for application data files which are host-specific and can’t, or shouldn’t, be shared with the other machines.

This is the same as GetDataDir except under Unix where it returns /etc/appinfo .

Return type:

string



GetLocalizedResourcesDir(self, lang, category=ResourceCat_None)

Return the localized resources directory containing the resource files of the specified category for the given language.

In general this is just the same as lang subdirectory of GetResourcesDir (or lang.lproj under macOS) but is something quite different for message catalog category under Unix where it returns the standard prefix/share/locale/lang/LC_MESSAGES directory.

Parameters:
Return type:

string

New in version 2.7.0.



GetPluginsDir(self)

Return the directory where the loadable modules (plugins) live.

Example return values:

  • Unix: prefix/lib/appinfo

  • Windows: the directory of the executable file

  • Mac: appinfo.app/Contents/PlugIns bundle subdirectory

Return type:

string

See also

DynamicLibrary



GetResourcesDir(self)

Return the directory where the application resource files are located.

The resources are the auxiliary data files needed for the application to run and include, for example, image and sound files it might use.

This function is the same as GetDataDir for all platforms except macOS. Example return values:

  • Unix: prefix/share/appinfo

  • Windows: the directory where the executable file is located

  • Mac: appinfo.app/Contents/Resources bundle subdirectory

Return type:

string

New in version 2.7.0.



GetTempDir(self)

Return the directory for storing temporary files, for the current user.

Same as FileName.GetTempDir . To create unique temporary files, it is best to use FileName.CreateTempFileName for correct behaviour when multiple processes are attempting to create temporary files.

Return type:

string

New in version 2.7.2.



GetUserConfigDir(self)

Return the directory for the user config files.

This directory is:

  • Unix: ~ (the home directory) or XDG_CONFIG_HOME depending on GetFileLayout return value

  • Windows: "C:\Users\username\AppData\Roaming" or "C:\Documents and Settings\username\Application Data"

  • Mac: ~/Library/Preferences

Only use this method if you have a single configuration file to put in this directory, otherwise GetUserDataDir is more appropriate as the latter adds appinfo to the path, unlike this function.

Return type:

string



GetUserDataDir(self)

Return the directory for the user-dependent application data files:

  • Unix: ~/ .appinfo

  • Windows: "C:\Users\username\AppData\Roaming\appinfo" or "C:\Documents and Settings\username\Application Data\appinfo"

  • Mac: "~/Library/Application Support/appinfo"

Return type:

string



GetUserDir(self, userDir)

Return the path of the specified user data directory.

If the value could not be determined the users home directory is returned.

Parameters:

userDir (Dir) –

Return type:

string

New in version 4.1/wxWidgets-3.1.0.

Note

On Unix this (newer) method always respects the XDG base directory specification, even if SetFileLayout with FileLayout_XDG hadn’t been called.



GetUserLocalDataDir(self)

Return the directory for user data files which shouldn’t be shared with the other machines.

This is the same as GetUserDataDir for all platforms except Windows where it returns "C:\Users\username\AppData\Local\appinfo" or "C:\Documents and Settings\username\Local Settings\Application Data\appinfo"

Return type:

string



static MSWGetShellDir(csidl)

Returns location of Windows shell special folder.

This function is, by definition, MSW-specific. It can be used to access pre-defined shell directories not covered by the existing methods of this class, e.g.:

if wx.Platform == '__WXMSW__':
    # get the location of files waiting to be burned on a CD
    cdburnArea = wx.StandardPaths.MSWGetShellDir(CSIDL_CDBURN_AREA)

# endif __WXMSW__
Parameters:

csidl (int) –

Return type:

string

New in version 2.9.1.



MakeConfigFileName(self, basename, conv=ConfigFileConv_Ext)

Return the file name which would be used by wx.FileConfig if it were constructed with basename.

conv is used to construct the name of the file under Unix and only matters when using the class file layout, i.e. if SetFileLayout had not been called with FileLayout_XDG argument. In this case, this argument is used to determine whether to use an extension or a leading dot. When following XDG specification, the function always appends the extension, regardless of conv value. Finally, this argument is not used at all under non-Unix platforms.

Parameters:
Return type:

string

New in version 4.1/wxWidgets-3.1.1.



SetFileLayout(self, layout)

Sets the current file layout.

The default layout is FileLayout_Classic for compatibility, however newer applications are encouraged to set it to FileLayout_XDG on program startup.

Parameters:

layout (FileLayout) –

New in version 4.1/wxWidgets-3.1.1.



SetInstallPrefix(self, prefix)

Lets wx.StandardPaths know about the real program installation prefix on a Unix system.

By default, the value returned by GetInstallPrefix is used.

Although under Linux systems the program prefix may usually be determined automatically, portable programs should call this function. Usually the prefix is set during program configuration if using GNU autotools and so it is enough to pass its value defined in config.h to this function.

Parameters:

prefix (string) –

Availability

Only available for GTK.

Note

This function is only available under Unix platforms (but not limited to wxGTK mentioned below).



UseAppInfo(self, info)

Controls what application information is used when constructing paths that should be unique to this program, such as the application data directory, the plugins directory on Unix, etc.

Valid values for info are:

  • AppInfo_None : use neither application nor vendor name in the paths.

  • AppInfo_AppName : use the application name in the paths.

  • AppInfo_VendorName : use the vendor name in the paths, usually used combined with AppInfo_AppName , i.e. as AppInfo_AppName | AppInfo_VendorName .

By default, only the application name is used.

Parameters:

info (int) –

New in version 2.9.0.



__init__(self)

Protected default constructor.

This constructor is protected in order to prevent creation of objects of this class as Get should be used instead to access the unique global wx.StandardPaths object of the correct type.


Properties

AppDocumentsDir

See GetAppDocumentsDir



ConfigDir

See GetConfigDir



DataDir

See GetDataDir



DocumentsDir

See GetDocumentsDir



ExecutablePath

See GetExecutablePath



InstallPrefix

See GetInstallPrefix and SetInstallPrefix



LocalDataDir

See GetLocalDataDir



PluginsDir

See GetPluginsDir



ResourcesDir

See GetResourcesDir



TempDir

See GetTempDir



UserConfigDir

See GetUserConfigDir



UserDataDir

See GetUserDataDir



UserLocalDataDir

See GetUserLocalDataDir