simpleguics2pygame — image¶
simpleguics2pygame module: simpleguics2pygame/image.
Class Image.
Piece of SimpleGUICS2Pygame. https://bitbucket.org/OPiMedia/simpleguics2pygame
license: | GPLv3 — Copyright (C) 2015-2016, 2020 Olivier Pirson |
---|---|
author: | Olivier Pirson — http://www.opimedia.be/ |
version: | November 29, 2020 |
-
class
SimpleGUICS2Pygame.simpleguics2pygame.image.
Image
(url)[source]¶ Image similar to SimpleGUI Image of CodeSkulptor.
-
__weakref__
¶ list of weak references to the object (if defined)
-
_dir_search_first
= '_img/'¶ load_image() try first to loading image from this directory, and next if failed, try to loading from URL.
This local directory is relative to the directory of your program.
-
_print_stats_cache
(text='', short_url=True)[source]¶ Print to stderr some statistics of cached Pygame surfaces used by this image.
(Not available in SimpleGUI of CodeSkulptor.)
Parameters: - text – str
- short_url – bool
-
_pygamesurfaces_cache_default_max_size
= 1000¶ Default maximum number of Pygame surfaces in the self._pygamesurfaces_cached.
-
_pygamesurfaces_cached_clear
()[source]¶ Empty the cache of Pygame surfaces used by this image.
(Not available in SimpleGUI of CodeSkulptor.)
-
-
class
SimpleGUICS2Pygame.simpleguics2pygame.image.
_LocalImage
(filename)[source]¶ Child of Image to load local file image.
(Not available in SimpleGUI of CodeSkulptor.)
-
SimpleGUICS2Pygame.simpleguics2pygame.image.
load_image
(url)[source]¶ Create and return an image by loading a file from url. Not founded URL and errors are ignored.
SimpleGUICS2Pygame try first to loading image from Image._dir_search_first local directory (_img/ by default), and next if failed, try to loading from url.
This local directory is relative to the directory of your program.
For example,
load_image('http://commondatastorage.googleapis.com/codeskulptor-assets/lathrop/double_ship.png')
try first to loading from_img/commondatastorage.googleapis.com/codeskulptor_assets/lathrop/double_ship.png
.Supported formats are supported formats by Pygame to load: PNG, JPG, GIF (not animated)… (see https://www.pygame.org/docs/ref/image.html ).
(CodeSkulptor may supported other formats, dependant on browser support.)
I recommend PNG and JPG format.
CodeSkulptor loads images asynchronously (the program continues without waiting for the images to be loaded). To handle this problem, you can use
simplegui_lib_loader.Loader
class.Parameters: url – str (only a valid URL, not local filename) Returns: Image
-
SimpleGUICS2Pygame.simpleguics2pygame.image.
_load_local_image
(filename)[source]¶ Create and return an image by loading a file from filename. Not founded file and errors are ignored.
I recommend to use only Internet resources with the load_image() function. Then you can use your program both in standard Python and in CodeSkulptor. (See Tips.html#download-medias .)
But if it is necessary, you can load local image with this “private” function.
Supported formats are the same as the load_image() function.
(Not available in SimpleGUI of CodeSkulptor.)
Parameters: filename – str (only a valid filename, not URL) Returns: _LocalImage
-
SimpleGUICS2Pygame.simpleguics2pygame.image.
__all__
= ('Image', '_LocalImage', 'load_image', '_load_local_image')¶ Built-in immutable sequence.
If no argument is given, the constructor returns an empty tuple. If iterable is specified the tuple is initialized from iterable’s items.
If the argument is a tuple, the return value is the same object.
[source]