Utils
Utils Functions
- gallerynpy.or_default(obj, default=None)
Checks if obj is not None and returns it.
- Parameters:
obj – The object to check
default – Default value to return.
- Returns:
obj if it is not None, otherwise default
- gallerynpy.gamepath()
Gets the absolute path to the game game folder.
- gallerynpy.join_path(first: str, *args: str, **kwargs)
Joins the given paths.
- Parameters:
first – The initial path
args – The other paths to joint with.
kwargs – Only the variable keyword from_renpy will be taken. If it is True, the system path separator is replaced by the one used by renpy
- Returns:
The joined path.
- gallerynpy.file(path: str, mode: str = 'r', encoding: str = 'utf-8', from_game: bool = False)
Open a file with the given mode.
- Parameters:
path – The path to the file.
mode – The mode to open the file.
encoding – The encoding of the file.
from_game – If True, the path will be joined to the absolute path of
gamepath()
.
- Returns:
The opened file.
- gallerynpy.get_registered(name: str)
Gets the registered image (simple or animation like) in the game.
See also renpy.get_registered_image in the documentation of renpy
- Parameters:
name – The name given to the image in the statement.
- Returns:
The registered image if exists, else None
- gallerynpy.make_dir(path: str, from_game: bool = False)
Create a leaf directory and all intermediate ones.
See also os.makedirs
- Parameters:
path – The path to create.
from_game – If True, the path will be joined to the absolute path of
gamepath()
.
- gallerynpy.split_folders(path: str)
Splits the given path into their folders.
- Parameters:
path – The path to split.
- Returns:
A tuple containing a list of the split path, and the last folder name.
- gallerynpy.file_extension(path: str)
Gets the file extension of the given path.
See also os.path.splitext
- Parameters:
path – The file path
- Returns:
The file extension of the path.
- gallerynpy.normalize_path(path: str, for_renpy: bool = False)
Normalizes the given path.
See also os.path.normpath
- Parameters:
path – The path to normalize
for_renpy – If True, the system path separator is replaced by the one used by renpy
- Returns:
The normalized path.
- gallerynpy.images_path(first: str, *args, **kwargs)
Join the given paths to the gallerynpy or game images folder.
- Parameters:
first – The first path to append
args – The other paths to append with.
kwargs – Only the variable keyword from_renpy will be taken. If True, the paths will be appended to the images folder of the game, otherwise to the gallerynpy images folder.
- Returns:
The joined path.
- gallerynpy.is_loadable(path: str, extensions: tuple | list[str] | None = None)
Checks if the given path is loadable.
See also renpy.loadable
- Parameters:
path – The path to the file.
extensions – Extensions with which the path should end.
- Returns:
True if the path is loadable and ends with extensions (if present), False otherwise
- gallerynpy.is_image(obj)
Checks if the given object is an image.
Any instance of renpy.display.im.Image (or simply im.Image or Image) or inheriting from it is considered an image.
- Parameters:
obj – The object to check.
- Returns:
True if the object is an image, False otherwise.
- gallerynpy.is_animation(obj)
Checks if the given object is an animation.
Any instance of renpy.display.transform.ATLTransform or inheriting from it is considered an animation.
- Parameters:
obj – The object to check.
- Returns:
True if the object is an animation, False otherwise
- gallerynpy.is_hex_color(color: str)
Checks if the given color is a hexadecimal.
- Parameters:
color – The string to check
- Returns:
True if the string matches the hexadecimal color format, False otherwise
- gallerynpy.normalize_color(hex_color: str) str
Normalizes the given hexadecimal color.
Normalization refers to completing the channels so that they can have the 6 or 8 values of a normal hexadecimal color.
- Parameters:
hex_color – The color to normalize.
- Returns:
The normalized color.
- gallerynpy.width_ratio(ratio: float) int
Calculates the width corresponding to the given ratio with respect to the config.screen_width.
- Parameters:
ratio – The ratio value
- Returns:
The calculated width
- gallerynpy.is_size(obj)
Checks if the given object is instance of
Size
- Parameters:
obj – The object to check.
- gallerynpy.is_item(obj)
Checks if the given object is instance of
Item
- Parameters:
obj – The object to check.
Util Classes
- class gallerynpy.Singleton(*args, **kwargs)
A class to simulate a singleton. Each class that inherits from this one will only have a single instance.
Utils Variables
- gallerynpy.screen_size: Size
The size of the configured game screen. A reassignment is not recommended.
- gallerynpy.custom_names: dict
The dic with the custom names for the slides or sliders. A reassignment or a direct set is not recommended.
- gallerynpy.RENPY_SEP: str
The sep character that renpy use as path separator