simpleguics2pygame — image

simpleguics2pygame/image (April 29, 2016)

Class Image.

Piece of SimpleGUICS2Pygame. https://bitbucket.org/OPiMedia/simpleguics2pygame

GPLv3 — Copyright (C) 2015, 2016 Olivier Pirson http://www.opimedia.be/

class SimpleGUICS2Pygame.simpleguics2pygame.image.Image(url)[source]

Image similar to SimpleGUI Image of CodeSkulptor.

__init__(url)[source]

Set an image.

Don’t use directly, use load_image().

Parameters:url – str
__repr__()[source]

Return ‘<Image object>’.

Returns:str
_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_cached_clear()[source]

Empty the cache of Pygame surfaces used by this image.

(Not available in SimpleGUI of CodeSkulptor.)

get_height()[source]

Return the height ot this image.

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

Returns:int
get_width()[source]

Return the width ot this image.

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

Returns:int
__weakref__

list of weak references to the object (if defined)

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 http://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', 'load_image', '_load_local_image']

list() -> new empty list list(iterable) -> new list initialized from iterable’s items

[source]