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: str)[source]

Image similar to SimpleGUI Image of CodeSkulptor.

__init__(url: str) None[source]

Set an image.

Don’t use directly, use load_image().

Parameters

url – str

__repr__() str[source]

Return ‘<Image object>’.

Returns

str

__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: str = '', short_url: bool = True) None[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() None[source]

Empty the cache of Pygame surfaces used by this image.

(Not available in SimpleGUI of CodeSkulptor.)

get_height() int[source]

Return the height ot this image.

(If initialization of this image was failed then return 0.)

Returns

int

get_width() int[source]

Return the width ot this image.

(If initialization of this image was failed then return 0.)

Returns

int

class SimpleGUICS2Pygame.simpleguics2pygame.image._LocalImage(filename: str)[source]

Child of Image to load local file image.

(Not available in SimpleGUI of CodeSkulptor.)

__init__(filename: str) None[source]

Set an image.

Don’t use directly, use _load_local_image().

Parameters

filename – str

__repr__() str[source]

Return ‘<_LocalImage object>’.

Returns

str

SimpleGUICS2Pygame.simpleguics2pygame.image._load_local_image(filename: str) _LocalImage[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.load_image(url: str) SimpleGUICS2Pygame.simpleguics2pygame.image.Image[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.__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]