Multiple loaders

A Loader encapsulates a complete resource path and cache. This lets your application cleanly separate resource loading of different modules. Loaders are constructed for a given search path, and exposes the same methods as the global pyglet.resource module functions.

For example, if a module needs to load its own graphics but does not want to interfere with the rest of the application's resource loading, it would create its own Loader with a local search path:

loader = pyglet.resource.Loader(['@' + __name__])
image = loader.image('logo.png')

This is particularly suitable for "plugin" modules.

You can also use a Loader instance to load a set of resources relative to some user-specified document directory. The following example creates a loader for a directory specified on the command line:

import sys
home = sys.argv[1]
loader = pyglet.resource.Loader(script_home=[home])

This is the only way that absolute directories and resources not bundled with an application should be used with pyglet.resource.