simplegui_lib_loader — class to load images and sounds¶
(Version saved in CodeSkulptor https://py3.codeskulptor.org/#user305_SZPJfNxJlVTjbAy.py .)
Examples of use in :
- example/loader.py: https://py3.codeskulptor.org/#user305_vyR7lzNAMOV0BbV.py
- test/test_image.py: https://py3.codeskulptor.org/#user306_Z5qiKFLrvKnOV1i.py
- example/Spaceship_prototype.py: https://py3.codeskulptor.org/#user305_oBWI7SgNVos3Lgx.py
- example/RiceRocks_Asteroids.py: https://py3.codeskulptor.org/#user305_XNvcqTxIBngtHPu.py
simplegui_lib_loader module.
A class to help load images and sounds in SimpleGUI of CodeSkulptor.
Piece of SimpleGUICS2Pygame. https://bitbucket.org/OPiMedia/simpleguics2pygame
license: | GPLv3 — Copyright (C) 2013-2015, 2020 Olivier Pirson |
---|---|
author: | Olivier Pirson — http://www.opimedia.be/ |
version: | May 19, 2020 |
-
class
SimpleGUICS2Pygame.simplegui_lib_loader.
Loader
(frame, progression_bar_width, after_function, max_waiting=5000)[source]¶ Help to load images and sounds from Internet and wait finished.
With SimpleGUICS2Pygame, SimpleGUICS2Pygame.load_image() and SimpleGUICS2Pygame.load_sound() wait automatically until loading is completed.
But in CodeSkulptor, the browser load images and sounds asynchronously. (With SimpleGUI it is impossible to verify that the sounds are loaded. So Loader begin load sounds, and next begin load images. It wait each image is loaded, and considers that all downloads are completed.)
-
__SIMPLEGUICS2PYGAME
= None¶ True if SimpleGUICS2Pygame are used, else False.
-
__init__
(frame, progression_bar_width, after_function, max_waiting=5000)[source]¶ Set an empty loader.
Parameters: - frame – simplegui.Frame
- progression_bar_width – (int or float) >= 0
- after_function – function () -> *
- max_waiting – (int or float) >= 0
-
__weakref__
¶ list of weak references to the object (if defined)
-
_draw_loading
(canvas)[source]¶ Draw waiting message on the canvas when images and sounds loading.
Parameters: canvas – simplegui.Canvas
-
_interval
= 100¶ Interval in ms betweed two check.
-
add_image
(url, name=None)[source]¶ Add an image from url and give it a name.
Execute `Loader.load()` before use images.
If name == None then “filename” of url is used.
Example: If url == ‘http://commondatastorage.googleapis.com/codeskulptor-assets/lathrop/asteroid_blue.png’ and name == None then ‘asteroid_blue.png’ is used.
Parameters: - url – str
- name – None or str
-
add_sound
(url, name=None)[source]¶ Add a sound from url and give it a name.
Execute `Loader.load()` before use sounds.
If name == None then “filename” of url is used.
Example: If url == ‘http://commondatastorage.googleapis.com/codeskulptor-assets/Epoq-Lepidoptera.ogg’ and name == None then ‘Epoq-Lepidoptera.ogg’ is used.
Parameters: - url – str
- name – None or str
-
cache_clear
()[source]¶ - In standard Python with SimpleGUICS2Pygame: Empty the cache of Pygame surfaces used by each image of this Loader. See Image._pygamesurfaces_cached_clear .
- In SimpleGUI of CodeSkulptor: do nothing.
-
get_image
(name)[source]¶ If an image named name exist then return it, else return None
Parameters: name – str Raise: Exception if Loader.load() was not executed since the addition of this image. Returns: None or simplegui.Image
-
get_nb_images_loaded
()[source]¶ Return the number of loaded images.
It is the number of begin loading by Loader.load() and fully completed.
Returns: int >= 0
-
get_nb_sounds_loaded
()[source]¶ Return the number of loaded sounds.
It is the number of begin loading by Loader.load(), but not necessarily completed. Because with SimpleGUI of CodeSkulptor it is impossible to verify that the sounds are loaded.
Returns: int >= 0
-
get_sound
(name)[source]¶ If a sound named name exist then return it, else return None
Parameters: name – str Raise: Exception if load() was not executed since the addition of this sound. Returns: None or simplegui.Sound
-
load
()[source]¶ Start loading of all images and sounds added since last Loader.load() execution.
- In standard Python with SimpleGUICS2Pygame: draw a progression bar on canvas and wait until the loading is finished.
- In SimpleGUI of CodeSkulptor: don’t wait.
-
print_stats_cache
()[source]¶ - In standard Python with SimpleGUICS2Pygame: Print to stderr some statistics of cached Pygame surfaces used by each image of this Loader. See Image._print_stats_cache .
- In SimpleGUI of CodeSkulptor: do nothing.
-
[source]