Resources Classes
- class gallerynpy.resources.Resource(resource, force_check: bool = False)
A helper to trait with resources such as images, videos, animations or displayable.
- Parameters:
resource – The resource
force_check – If true, named resources such as images or animations will throw
ResourceNameNotFoundError
if they are not found, otherwise the self resource will be put in the resource loader.
- composite_to(target: Size)
Creates a Composite object from the current resource, trying to center it according to the given size and the resource size.
- Parameters:
target – The size to composite the resource.
- Returns:
The Composite object.
- force_load_size()
Forces to load the image size of the resource.
- Raises:
ResourceForbiddenOperationError – if the resource type is not
IMAGE
.ResourceNoLoadableError – If the resource filepath is not loadable.
- get_image()
Gets the image object of the resource.
- Raises:
ResourceForbiddenOperationError – if the resource type is not
IMAGE
.ResourceNoLoadableError – If the resource filepath is not loadable.
- load(force_check: bool = False)
Try to load the resource.
- Parameters:
force_check – If true, named resources such as images or animations will force to load, otherwise the self resource will be put in the resource loader.
- Raises:
UnsupportedResourceTypeError – If the resource type is not valid.
ResourceNameNotFoundError – If the resource is force to load and don’t exist the image or animation for the given resource name
ResourceNoLoadableError – If the resource filepath is not loadable.
- scale_to(target: Size)
Creates an im.Scale object from the current resource according to the given size.
- Parameters:
target – The size to scale the resource.
- Returns:
The im.Scale object.
- Raises:
TypeError – If the target size is not a
Size
object.ResourceForbiddenOperationError – if the resource type is not
IMAGE
orDISPLAYABLE
.ResourceNoLoadableError – If the resource filepath is not loadable.
- size_to(target: Size)
Adjusts the current size to match the aspect ratio of the provided target size.
- Parameters:
target – The target size to match.
- Returns:
The adjusted size, or the target size if the resource doesn’t have a size.
- Raises:
TypeError – If the target size is not a Size object.
- property extension: str | None
- Getter:
Gets the extension of the resource asset.
- Returns:
The extension if the loaded resource asset was a filepath, otherwise None
- property is_displayable_type
- Getter:
Checks if the resource type is
DISPLAYABLE
- property is_named
- property resource
- Getter:
Gets the resource.
- Setter:
Sets the resource.
- Parameters:
resource – The new resource.
- property size
- Getter:
Gets the size of the resource.
- Returns:
Size object if the loaded resource was an image and its size was in
db
, otherwise None
- property type
- Getter:
Gets the type of the resource.
- class gallerynpy.resources.Thumbnail(resource: Resource | str, size: Size)
Handles the creation of thumbnails for the different types of
Resource
.- Parameters:
resource – The resource object, or an object for instance the resource.
size – The size of the thumbnail dimensions.
- create()
Create a thumbnail displayable for the current thumbnail resource.
See also
composite_to()
If the resource is not valid, the
not_found
resource will be used.
- set_custom(resource)
Set the given resource as custom.
It will not change the initial resource.
- property resource
- Getter:
Gets the resource of the thumbnail.
- Returns:
The custom resource if was set, otherwise the initial resource.
Resources Functions
- gallerynpy.resources.is_displayable(obj)
Checks if the object is renpy displayable.
- Parameters:
obj – The object to check.
- Returns:
True if the object is a displayable, False otherwise
Resources Enums like Classes
- class gallerynpy.resources.ResourceTypes
Enum class for the types of resources to be found.
- ANIMATION
Represents that the resource is an animation, this means that the saved resource is a str (name) of an atl block or the atl block itself (object).
An atl block is the animation declaration.
- DISPLAYABLE
Represents that the resource is an displayable, this means that the saved resource is instance of renpy displayable.
- IMAGE
Represents that the resource is an image, this means that the saved resource is a str (name) of an image or the image itself (object).
- NONE
Represents that the resource is not valid, and at any moment it will raise an error.
- VIDEO
Represents that the resource is an video, this means that the saved resource is a filepath to the video.
- class gallerynpy.resources.Extensions
Enum class for resource extensions that renpy can load.
- AUDIO = ('.mp3', '.ogg', '.opus', '.mp2')
List of audio extensions that renpy can load.
- IMAGES = ('.png', '.jpg', '.web', '.jpeg', '.webp')
List of image extensions that renpy can load.
- VIDEOS = ('.webm', '.avi', '.mp4', '.wav', '.mkv', '.ogv')
List of video extensions that renpy can load.
Resources Exceptions
- exception gallerynpy.resources.ResourceForbiddenOperationError(rtype)
Raised when a resource does not have the required type for the operation.
- exception gallerynpy.resources.UnsupportedResourceTypeError(obj)
Raised when the object of the resource is not supported.
- exception gallerynpy.resources.ResourceNameNotFoundError(name: str, message: str = None)
Raised when the resource name is not found in the renpy declared images.
- exception gallerynpy.resources.ResourceNoLoadableError(resource)
Raised when the rosource filepath is not loadable by renpy.