glooey.themes.helpers.ResourceLoader¶
- class glooey.themes.helpers.ResourceLoader(paths=None)[source]¶
Bases:
pyglet.resource.LoaderPublic Methods:
__init__([paths])Create a loader for the given path.
yaml(name)Inherited from
Loader__init__([paths])Create a loader for the given path.
reindex()Refresh the file index.
file(name[, mode])Load a resource.
location(name)Get the location of a resource.
add_font(name)Add a font resource to the application.
image(name[, flip_x, flip_y, rotate, atlas, ...])Load an image with optional transformation.
animation(name[, flip_x, flip_y, rotate, border])Load an animation with optional transformation.
Get a list of image filenames that have been cached.
Get a list of animation filenames that have been cached.
Get a list of texture bins in use.
media(name[, streaming])Load a sound or video resource.
texture(name)Load a texture.
model(name[, batch])Load a 3D model.
html(name)Load an HTML document.
attributed(name)Load an attributed text document.
text(name)Load a plain text document.
Get the names of textures currently cached.
Private Methods:
Inherited from
Loader_get_stream(path)_index_file(name, location)_alloc_image(name, atlas, border)_get_texture_atlas_bin(width, height, border)A heuristic for determining the atlas bin to use for a given image size.
- __dict__ = mappingproxy({'__module__': 'glooey.themes.helpers', '__init__': <function ResourceLoader.__init__>, 'yaml': <function ResourceLoader.yaml>, '__doc__': None, '__annotations__': {}})¶
- __init__(paths=None)[source]¶
Create a loader for the given path.
If no path is specified it defaults to
['.']; that is, just the program directory.See the module documentation for details on the path format.
- Parameters
pathlist of strList of locations to search for resources.
script_homestrBase location of relative files. Defaults to the result of
get_script_home.
- __module__ = 'glooey.themes.helpers'¶
- __weakref__¶
list of weak references to the object (if defined)
- _alloc_image(name, atlas, border)¶
- _get_stream(path)¶
- _get_texture_atlas_bin(width, height, border)¶
A heuristic for determining the atlas bin to use for a given image size. Returns None if the image should not be placed in an atlas (too big), otherwise the bin (a list of TextureAtlas).
- _index_file(name, location)¶
- _require_index()¶
- add_font(name)¶
Add a font resource to the application.
Fonts not installed on the system must be added to pyglet before they can be used with
font.load. Although the font is added with its filename using this function, it is loaded by specifying its family name. For example:resource.add_font('action_man.ttf') action_man = font.load('Action Man')
- Parameters
namestrFilename of the font resource to add.
- animation(name, flip_x=False, flip_y=False, rotate=0, border=1)¶
Load an animation with optional transformation.
Animations loaded from the same source but with different transformations will use the same textures.
- Parameters
namestrFilename of the animation source to load.
flip_xboolIf True, the returned image will be flipped horizontally.
flip_yboolIf True, the returned image will be flipped vertically.
rotateintThe returned image will be rotated clockwise by the given number of degrees (a multiple of 90).
borderintLeaves specified pixels of blank space around each image in an atlas, which may help reduce texture bleeding.
- Return type
Animation
- attributed(name)¶
Load an attributed text document.
See
pyglet.text.formats.attributedfor details on this format.- Parameters
namestrFilename of the attribute text resource to load.
- Return type
FormattedDocument
- file(name, mode='rb')¶
Load a resource.
- Parameters
namestrFilename of the resource to load.
modestrCombination of
r,w,a,bandtcharacters with the meaning as for the builtinopenfunction.
- Return type
file object
- get_cached_animation_names()¶
Get a list of animation filenames that have been cached.
This is useful for debugging and profiling only.
- Return type
list
- Returns
List of str
- get_cached_image_names()¶
Get a list of image filenames that have been cached.
This is useful for debugging and profiling only.
- Return type
list
- Returns
List of str
- get_cached_texture_names()¶
Get the names of textures currently cached.
- Return type
list of str
- get_texture_bins()¶
Get a list of texture bins in use.
This is useful for debugging and profiling only.
- Return type
list
- Returns
List of
TextureBin
- html(name)¶
Load an HTML document.
- Parameters
namestrFilename of the HTML resource to load.
- Return type
FormattedDocument
- image(name, flip_x=False, flip_y=False, rotate=0, atlas=True, border=1)¶
Load an image with optional transformation.
This is similar to
texture, except the resulting image will be packed into aTextureBinif it is an appropriate size for packing. This is more efficient than loading images into separate textures.- Parameters
namestrFilename of the image source to load.
flip_xboolIf True, the returned image will be flipped horizontally.
flip_yboolIf True, the returned image will be flipped vertically.
rotateintThe returned image will be rotated clockwise by the given number of degrees (a multiple of 90).
atlasboolIf True, the image will be loaded into an atlas managed by pyglet. If atlas loading is not appropriate for specific texturing reasons (e.g. border control is required) then set this argument to False.
borderintLeaves specified pixels of blank space around each image in an atlas, which may help reduce texture bleeding.
- Return type
Texture- Returns
A complete texture if the image is large or not in an atlas, otherwise a
TextureRegionof a texture atlas.
- location(name)¶
Get the location of a resource.
This method is useful for opening files referenced from a resource. For example, an HTML file loaded as a resource might reference some images. These images should be located relative to the HTML file, not looked up individually in the loader’s path.
- Parameters
namestrFilename of the resource to locate.
- Return type
Location
- media(name, streaming=True)¶
Load a sound or video resource.
The meaning of
streamingis as formedia.load. Compressed sources cannot be streamed (that is, video and compressed audio cannot be streamed from a ZIP archive).- Parameters
namestrFilename of the media source to load.
streamingboolTrue if the source should be streamed from disk, False if it should be entirely decoded into memory immediately.
- Return type
media.Source
- model(name, batch=None)¶
Load a 3D model.
- Parameters
namestrFilename of the 3D model to load.
batchBatch or NoneAn optional Batch instance to add this model to.
- Return type
Model
- reindex()¶
Refresh the file index.
You must call this method if
pathis changed or the filesystem layout changes.
- text(name)¶
Load a plain text document.
- Parameters
namestrFilename of the plain text resource to load.
- Return type
UnformattedDocument
- texture(name)¶
Load a texture.
The named image will be loaded as a single OpenGL texture. If the dimensions of the image are not powers of 2 a
TextureRegionwill be returned.- Parameters
namestrFilename of the image resource to load.
- Return type
Texture