module Resources

A resource is a file containing information used by the application that is bundled with the application. PyGUI provides some functions for locating resources by looking in certain standard places for them.

A resource is specified by a resource name. This is a relative pathname using '/' as a directory separator on all platforms. A resource specification may also include a type, which is a filename suffix (excluding the dot) to be appended to the resource name.

The standard locations searched for resources are as follows:

Search Order
MacOSX applications created with Py2App
Other platforms
1. Application resources
The Resources directory in the application bundle.
A directory called Resources in the same directory as the application's main Python code file or its parent directory.
2. PyGUI standard resources
A platform-dependent location within the PyGUI installation.

Global Functions

find_resource(name, type = None)
Searches for the named resource and returns the full pathname of the first matching file found on the search path. If type is specified, it is appended to the name with a dot between, after removing any existing dot-suffix from the name. The type itself should not contain a dot. If no matching file is found,  ResourceNotFoundError is raised.

lookup_resource(name, type = None)
Searches for a resource as per find_resource, but if the resource is not found, None is returned instead of raising an exception.

get_resource(loader, name, type = None, default = None, **kwds)
Finds a resource and loads it using the specified loader function. The loader is called as loader(path, **kwds) where path is the full pathname of the resource. The loaded resource is cached, and subsequent calls referencing the same resource will return the cached value. If the resource is not found, the specified default is returned if any, otherwise ResourceNotFoundError is raised.

Global Variables

A list of directory names to search for resources. This is initialised on startup to include the standard locations for PyGUI application resources. You can insert additional directories in this list to customise the search path.


Raised by find_resource when a resource cannot be found.