SimpleGUICS2Pygame package’s documentation¶
It is primarily a standard Python (2 and 3) module reimplementing the SimpleGUI particular module of CodeSkulptor2 and CodeSkulptor3 (a Python browser environment). This is in fact a package also with other modules adapted from CodeSkulptor.
Simply change
import simplegui
by
try:
import simplegui
except ImportError:
import SimpleGUICS2Pygame.simpleguics2pygame as simplegui
in your CodeSkulptor program and your program run both in CodeSkulptor and standard Python with this module (and Pygame).
Online HTML documentation on Read The Docs. (You can also see the online SimpleGUI documentation on CodeSkulptor2 or SimpleGUI documentation on CodeSkulptor3.)
If you have some problem¶
First, read this short main documentation page, this Compatibility page and this Tips page.
If you have problem with some command, you can see its documentation in the modules page or by the Index page .
Next, you can search in Stack Overflow. If you don’t find answer, you can ask question like this.
Finally you can email me. I will try to help you with pleasure. (You can write me in French.)
Installation¶
Before the installation of SimpleGUICS2Pygame¶
Obviously you need Python.
If pip (the Python Package Installer) is not installed on your system, then install it with:
$ python -m ensurepip --user
Note that $
represents the prompt and do not be entered by you.
If several Python implementations are installed,
maybe you must use something like python2
or python3
instead python
command.
With the --user
option
the installation is made in the user directory
and doesn’t require administrator rights.
Before installation, as a precaution, upgrade necessary installation packages:
$ python -m pip install pip setuptools wheel --user --upgrade
Installation of SimpleGUICS2Pygame¶
$ python -m pip install SimpleGUICS2Pygame --user --upgrade
Followed requirements are automatically installed.
But if the installation failed, then install them separately and after that try again to install SimpleGUICS2Pygame.
On Arch Linux you can use this package installation script (written by Danny Fajardo): Arch_Linux/PKGBUILD.
Package pygame required¶
Pygame is required to use module simplegui_lib
(and its submodules)
and module simpleguics2pygame
of SimpleGUICS2Pygame
(except for the Timer class).
Warning
Normally Pygame is installed automatically when you install SimpleGUICS2Pygame. But if it is failed then install it like this first.
$ python -m pip install pygame --user --upgrade
If you have some problem, see installation documentation of pygame.
On Window$ you can also directly install a binary from the Unofficial Windows Binaries for Python Extension Packages: Pygame binary.
Package audioread required¶
audioread is required to play MP3 sounds (other sounds are played by Pygame).
Package matplotlib required¶
matplotlib is required to use module simpleplot
of SimpleGUICS2Pygame.
If you have some problem, see installation documentation of matplotlib.
On Window$ you can also directly install matplotlib binary.
Test installation¶
You can run the little script SimpleGUICS2Pygame_check.py
to check if all required modules are installed.
Examples of result with good installation: result in Python 2 and result in Python 3.
You can also test your Pygame installation alone with the other little script pygame_check.py
.
Examples of CodeSkulptor and SimpleGUICS2Pygame use¶
You can see examples in SimpleGUICS2Pygame/example/ subdirectory from the sources archives.
Or online: Python programs running in CodeSkulptor .
On some environments CodeSkulptor2 maybe runs too slow with Firefox. CodeSkulptor3 is better, but maybe too slow too. In these cases, use Chrome.
- Two simple online examples:
- Frame_example.py: very simple canvas example
- presentation.py: little draw images and texts
Message to developers¶
This is a free software, so you can download it, modify it and submit your modifications. You can also redistribute your own version (keeping the GPL license).
Complete sources on Bitbucket: https://bitbucket.org/OPiMedia/simpleguics2pygame
See developers’page.
Author: 🌳 Olivier Pirson — OPi
🇧🇪🇫🇷🇬🇧 🐧 👨💻 👨🔬¶
🌐 Website: http://www.opimedia.be/
💾 Bitbucket: https://bitbucket.org/OPiMedia/
- 📧 olivier.pirson.opi@gmail.com
- Mastodon: https://mamot.fr/@OPiMedia — Twitter: https://twitter.com/OPirson
- 👨💻 LinkedIn: https://www.linkedin.com/in/olivierpirson/ — CV: http://www.opimedia.be/CV/English.html
- other profiles: http://www.opimedia.be/about/
Support me¶
This program is a free software (GPL license). It is completely free (like “free speech” and like “free beer”). However you can support me financially by donating.
Note that¶
SimpleGUI of CodeSkulptor2 (Scott Rixner) is a specific module of CodeSkulptor2, written in JavaScript.
CodeSkulptor is a Python implementation running in a browser. It implements a subset of Python 2. It is the environment used in the course An Introduction to Interactive Programming in Python (Rice University, Coursera).
SimpleGUI of CodeSkulptor3 (Scott Rixner) is the same in the new version CodeSkulptor3 that implements a subset of Python 3.
SimpleGUICS2Pygame (Olivier Pirson) is this package. It is fully compatible with Python 2 and 3.
It contains
codeskulptor
,numeric
,simpleguics2pygame
andsimpleplot
modules that reimplementcodeskulptor
,numeric
,simplegui
andsimpleplot
modules of CodeSkulptor.simplemap
is not implemented.Warning
SimpleGUICS2Pygame was designed to mimic behavior of CodeSkulptor. So load_image() and load_sound() methods can load medias only from URL, not local files. However SimpleGUICS2Pygame can save these medias to a specific local directory. See the Download medias tips.
You can also use specific _load_local_image() and _load_local_sound() methods to load local files. But be careful, each specific method doesn’t exist in CodeSkulptor.
There exist some little differences between SimpleGUICS2Pygame and SimpleGUI of CodeSkulptor. See Compatibility notes.
SimpleGUITk (David Holm) is another implementation of SimpleGUI of CodeSkulptor, using Tkinter and some others packages. It is really less complete and not updated. However it works for some programs.
simplegui2pygamemodule (Jimmy Kumar Ahalpara) seems be another implementation of SimpleGUI of CodeSkulptor, but I have not tested it.
simplequi (Arthur Gordon-Wright) is another implementation of SimpleGUI of CodeSkulptor, using Qt/PySide2. It is a partial implementation that I have not tested.
Warning
- simplegui (Florian Berger) is a Python package which has the same name as SimpleGUI of CodeSkulptor, but it is totally something else.
- PySimpleGUI is also a Python package that is totally something else.
Table of contents¶
Package SimpleGUICS2Pygame¶
SimpleGUICS2Pygame package.
It is primarily a standard Python (2 and 3) module reimplementing the SimpleGUI particular module of CodeSkulptor2 and CodeSkulptor3 (a Python browser environment). This is in fact a package also with other modules adapted from CodeSkulptor.
Require Pygame (except for the Timer class) (and must be installed separately).
Module simpleplot require matplotlib .
Online HTML documentation on Read The Docs.
Piece of SimpleGUICS2Pygame. https://bitbucket.org/OPiMedia/simpleguics2pygame
license: | GPLv3 — Copyright (C) 2013-2016, 2018, 2020-2021 Olivier Pirson |
---|---|
author: | Olivier Pirson — http://www.opimedia.be/ |
version: | May 4, 2021 |
- v.2.1.1 — May 4, 2021
- v.2.1.0 — November 29, 2020
- v.2.0.3 — October 2, 2020
- v.2.0.2 — May 23, 2020
- v.2.0.1 — May 21, 2020
- v.2.0.0 — April 18, 2020
- v.01.09.00 — January 1st, 2015
- v.01.08.01 — October 9, 2014
- v.01.08.00 — October 4, 2014
- v.01.07.00 — September 2, 2014
- v.01.06.03 — July 24, 2014
- v.01.06.02 — July 18, 2014
- v.01.06.01 — July 17, 2014
- v.01.06.00 — June 16, 2014
- v.01.05.00 — May 25, 2014
- v.01.04.00 — December 16, 2013
- v.01.03.00 — December 13, 2013
- v.01.02.00 — November 8, 2013
- v.01.01.00 — November 1st, 2013
- v.01.00.02 — October 31, 2013
- v.01.00.01 — October 9, 2013
- v.01.00.00 — July 13, 2013
- v.00.92.00 — June 27, 2013
- v.00.91.00 — June 23, 2013
- v.00.90.10 — June 19, 2013
- v.00.90.00 — June 13, 2013
- Started on May 21, 2013
-
SimpleGUICS2Pygame.__init__.
_VERSION
= '2.1.1'¶ Version of SimpleGUICS2Pygame package.
-
SimpleGUICS2Pygame.__init__.
_WEBSITE
= 'https://bitbucket.org/OPiMedia/simpleguics2pygame/'¶ Website of the project.
-
SimpleGUICS2Pygame.__init__.
_WEBSITE_DOC
= 'https://simpleguics2pygame.readthedocs.io/'¶ Website of the documentation.
All modules of this package¶
codeskulptor — replace the codeskulptor module of CodeSkulptor¶
codeskulptor module.
Replace the codeskulptor module of CodeSkulptor.
Piece of SimpleGUICS2Pygame. https://bitbucket.org/OPiMedia/simpleguics2pygame
license: | GPLv3 — Copyright (C) 2013-2014, 2020-2021 Olivier Pirson |
---|---|
author: | Olivier Pirson — http://www.opimedia.be/ |
version: | May 4, 2021 |
-
SimpleGUICS2Pygame.codeskulptor.
file2url
(filename)[source]¶ Return a completed CodeSkulptor URL ressource from a short filename.
Example given in the CodeSkulptor2 file2url documentation: file2url(‘assets-Quick_fox.txt’) returns ‘http://codeskulptor-assets.commondatastorage.googleapis.com/assets-Quick_fox.txt’
Example given in the CodeSkulptor3 urllib2-urlopen documentation (there is an error in file2url documentation): file2url(‘assets_sample_text.txt’) returns ‘//codeskulptor-assets.commondatastorage.googleapis.com/assets_sample_text.txt’
Parameters: filename – str Raise: ValueError if filename is in a incorrect format (the good format is ‘^[a-zA-Z][a-zA-Z0-9]*[_-]’) Returns: str
-
SimpleGUICS2Pygame.codeskulptor.
randomize_iteration
(randomize=True)[source]¶ Fake implementation. In CodeSkulptor this function modify the default behaviour of iterations on
dict
andset
. In SimpleGUICS2Pygame this function does nothing.See CodeSkulptor3 randomize_iteration documentation.
(Available in CodeSkulptor but not in CodeSkulptor documentation!)
Randomize bool:
-
SimpleGUICS2Pygame.codeskulptor.
set_timeout
(seconds)[source]¶ Do nothing.
In CodeSkulptor, this function change the timeout imposed on all programs (by default 5 seconds). See CodeSkulptor2 set_timeout documentation.
(Available in CodeSkulptor and CodeSkulptor3 but not in CodeSkulptor3 documentation!)
Parameters: seconds – int >= 0
[source]
codeskulptor_lib — some miscellaneous functions¶
(Version saved in CodeSkulptor https://py3.codeskulptor.org/#user305_SXBsmszNiUxIeoV.py .)
codeskulptor_lib module.
Some miscellaneous functions to help in CodeSkulptor.
Piece of SimpleGUICS2Pygame. https://bitbucket.org/OPiMedia/simpleguics2pygame
license: | GPLv3 — Copyright (C) 2013-2014, 2020 Olivier Pirson |
---|---|
author: | Olivier Pirson — http://www.opimedia.be/ |
version: | May 19, 2020 |
-
SimpleGUICS2Pygame.codeskulptor_lib.
__CODESKULPTOR_IS
= None¶ Used to memoization by codeskulptor_is().
-
SimpleGUICS2Pygame.codeskulptor_lib.
__CODESKULPTOR_VERSION
= None¶ Used to memoization by codeskulptor_version().
-
SimpleGUICS2Pygame.codeskulptor_lib.
assert_position
(position, non_negative=False, non_zero=False)[source]¶ Assertions to check valid position.
If non_negative then each int or float must be >= 0.
If non_zero then each int or float must be != 0.
Parameters: - position – (int or float, int or float) or [int or float, int or float]
- non_negative – bool
-
SimpleGUICS2Pygame.codeskulptor_lib.
codeskulptor_is
()[source]¶ If run in CodeSkulptor environment then return True, else return False.
Returns: bool
-
SimpleGUICS2Pygame.codeskulptor_lib.
codeskulptor_version
()[source]¶ If run in CodeSkulptor environment then return 2 if CodeSkulptor or 3 if CodeSkulptor3 else return False.
Returns: False, 2 or 3
-
SimpleGUICS2Pygame.codeskulptor_lib.
hex2
(n, uppercase=True)[source]¶ Return 2 characters corresponding to the hexadecimal representation of n.
Parameters: - n – 0 <= int < 256
- uppercase – bool
Returns: str (length == 2)
-
SimpleGUICS2Pygame.codeskulptor_lib.
hex_fig
(n, uppercase=True)[source]¶ Return the hexadecimal figure of n.
Parameters: - n – 0 <= int < 16
- uppercase – bool
Returns: str (one character from 0123456789ABCDEF or 0123456789abcdef)
-
SimpleGUICS2Pygame.codeskulptor_lib.
hsl
(hue, saturation, lightness)[source]¶ Return the string HTML representation of the color in ‘hsl(hue, lightness, saturation)’ format.
Parameters: - hue – float or int
- saturation – 0 <= float or int <= 100
- lightness – 0 <= float or int <= 100
Returns: str
-
SimpleGUICS2Pygame.codeskulptor_lib.
hsla
(hue, saturation, lightness, alpha=1)[source]¶ Return the string HTML representation of the color in ‘hsla(hue, lightness, saturation, alpha)’ format.
Parameters: - hue – float or int
- saturation – 0 <= float or int <= 100
- lightness – 0 <= float or int <= 100
- alpha – 0 <= float or int <= 1
Returns: str
-
SimpleGUICS2Pygame.codeskulptor_lib.
rgb
(red, green, blue)[source]¶ Return the string HTML representation of the color in ‘rgb(red, blue, green)’ format.
Parameters: - red – 0 <= int <= 255
- green – 0 <= int <= 255
- blue – 0 <= int <= 255
Returns: str
-
SimpleGUICS2Pygame.codeskulptor_lib.
rgba
(red, green, blue, alpha=1)[source]¶ Return the string HTML representation of the color in ‘rgba(red, blue, green, alpha)’ format.
Parameters: - red – 0 <= int <= 255
- green – 0 <= int <= 255
- blue – 0 <= int <= 255
- alpha – 0 <= float or int <= 1
Returns: str
[source]
numeric — replace the numeric module of CodeSkulptor¶
numeric module.
Replace the numeric module of CodeSkulptor.
Piece of SimpleGUICS2Pygame. https://bitbucket.org/OPiMedia/simpleguics2pygame
license: | GPLv3 — Copyright (C) 2013-2014, 2020-2021 Olivier Pirson |
---|---|
author: | Olivier Pirson — http://www.opimedia.be/ |
version: | May 5, 2021 |
-
class
SimpleGUICS2Pygame.numeric.
Matrix
(data, _copy=True)[source]¶ Matrix (m x n).
See http://en.wikipedia.org/wiki/Matrix_%28mathematics%29 .
-
__add__
(other)[source]¶ To a matrix (m x n) return the matrix plus other.
Parameters: other – Matrix (m x n) Returns: Matrix (m x n)
-
__getitem__
(i_j)[source]¶ Return the value of the (m x n) matrix at row i and column j.
Parameters: i_j – (0 <= int < m, 0 <= int < n) or [0 <= int < m, 0 <= int < n] Returns: float
-
__init__
(data, _copy=True)[source]¶ Create a matrix with the 2-dimensional data.
If not _copy then data is directly used without copy. In this case, data must be a correct list of list of float. (Option not available in SimpleGUI of CodeSkulptor.)
Parameters: - data – (not empty tuple or list) of (same size tuple or list) of (int or float)
- _copy – bool
-
__mul__
(other)[source]¶ To a matrix (m x k) return the matrix multiply by other.
Parameters: other – Matrix (k x n) Returns: Matrix (m x n)
-
__setitem__
(i_j, value)[source]¶ Change the value of the element at row i and column j, to the (m x n) matrix.
Parameters: - i_j – (0 <= int < m, 0 <= int < n) or [0 <= int < m, 0 <= int < n]
- value – int or float
-
__sub__
(other)[source]¶ To a matrix (m x n) return the matrix minus other.
Parameters: other – Matrix (m x n) Returns: Matrix (m x n)
-
__weakref__
¶ list of weak references to the object (if defined)
-
_is_identity
(epsilon=2.220446049250313e-16)[source]¶ If the matrix is an identity matrix then return True, else return False.
(Not available in SimpleGUI of CodeSkulptor.)
Parameters: epsilon – 0 <= (float or int) < 1 Returns: bool
-
_is_zero
(epsilon=2.220446049250313e-16)[source]¶ If the matrix is a zeros matrix then return True, else return False.
(Not available in SimpleGUI of CodeSkulptor.)
Parameters: epsilon – 0 <= (float or int) < 1 Returns: bool
-
_nb_columns
()[source]¶ Return n for a (m x n) matrix.
(Not available in SimpleGUI of CodeSkulptor.)
Returns: int >= 1
-
_nb_lines
()[source]¶ Return m to a (m x n) matrix.
(Not available in SimpleGUI of CodeSkulptor.)
Returns: int >= 1
-
abs
()[source]¶ To a matrix (m x n) return the matrix with each element is the absolute value.
Returns: Matrix (m x n)
-
getcol
(j)[source]¶ Return the (1 x m) matrix that is a copy of column j of the (m x n) matrix.
Parameters: j – 0 <= int < n Returns: Matrix (1 x m)
-
getrow
(i)[source]¶ Return the (1 x n) matrix that is a copy of row i of the (m x n) matrix.
Parameters: i – 0 <= int < m Returns: Matrix (1 x n)
-
inverse
(_epsilon=2.220446049250313e-16)[source]¶ If the square matrix (n x n) is inversible then return the inverse, else raise an ValueError exception.
Algorithm used: Gaussian elimination. See http://en.wikipedia.org/wiki/Gaussian_elimination .
Parameters: _epsilon – 0 <= (float or int) < 1 (Option not available in SimpleGUI of CodeSkulptor.) Returns: Matrix (n x n) Raise: ValueError if the matrix is not inversible
-
-
SimpleGUICS2Pygame.numeric.
_EPSILON
= 2.220446049250313e-16¶ The default epsilon value.
-
SimpleGUICS2Pygame.numeric.
_zero
(m, n)[source]¶ Return a (m x n) zeros matrix.
Parameters: - m – int >= 1
- n – int >= 1
Returns: Matrix (m x n)
-
SimpleGUICS2Pygame.numeric.
identity
(size)[source]¶ Return a (size x size) identity matrix.
Parameters: size – int >= 1 Returns: Matrix (size x size)
[source]
simplegui_lib — simply import the following modules¶
simplegui_lib_draw — draw functions¶
(Version saved in CodeSkulptor https://py3.codeskulptor.org/#user305_SaT1YKoOikl4ax9.py .)
simplegui_lib_draw module.
Draw functions to help 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 |
-
SimpleGUICS2Pygame.simplegui_lib_draw.
draw_rect
(canvas, pos, size, line_width, line_color, fill_color=None)[source]¶ Draw a rectangle.
Parameters: - canvas – simplegui.Canvas
- pos – (int or float, int or float) or [int or float, int or float]
- size – (int or float, int or float) or [int or float, int or float]
- line_width – int >= 0
- line_color – str
- fill_color – str
-
SimpleGUICS2Pygame.simplegui_lib_draw.
draw_text_multi
(canvas, text, point, font_size, font_color, font_face='serif', _font_size_coef=0.75)[source]¶ Draw the text (possibly with several lines) at the position point.
If text is a str, then split it on each end of line.
If text is a tuple or a list of str, then print each str on a separated line.
See simplegui.draw_text() .
Parameters: - canvas – simplegui.Canvas
- text – str or (tuple of str) or (list of str)
- point – (int or float, int or float) or [int or float, int or float]
- font_size – (int or float) >= 0
- font_color – str
- font_face – str == ‘monospace’, ‘sans-serif’, ‘serif’
- _font_size_coef – int or float
Raise: ValueError if text contains unprintable whitespace character
-
SimpleGUICS2Pygame.simplegui_lib_draw.
draw_text_side
(frame, canvas, text, point, font_size, font_color, font_face='serif', font_size_coef=0.75, rectangle_color=None, rectangle_fill_color=None, side_x=-1, side_y=1)[source]¶ Draw the text string at the position point.
See simplegui.draw_text() .
If rectangle_color != None then draw a rectangle around the text.
If rectangle_fill_color != None then draw a filled rectangle under the text.
If side_x< 0 then point[0] is the left of the text,== 0 then point[0] is the center of the text,> 0 then point[0] is the right of the text.If side_y< 0 then point[1] is the top of the text,== 0 then point[1] is the center of the text,> 0 then point[1] is the bottom of the text.Parameters: - frame – simplegui.Frame
- canvas – simplegui.Canvas
- text – str
- point – (int or float, int or float) or [int or float, int or float]
- font_size – (int or float) >= 0
- font_color – str
- font_face – str == ‘monospace’, ‘sans-serif’, ‘serif’
- font_size_coef – int or float
- rectangle_color – None or str
- rectangle_fill_color – None or str
- side_x – int or float
- side_y – int or float
[source]
simplegui_lib_fps — class to calculate and display Frames Per Second¶
(Version saved in CodeSkulptor https://py3.codeskulptor.org/#user305_tXfH4AcbNLtjfHy.py .)
Examples of use in :
- 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_fps module.
A class to calculate and display FPS (Frames Per Second) in SimpleGUI of CodeSkulptor.
Piece of SimpleGUICS2Pygame. https://bitbucket.org/OPiMedia/simpleguics2pygame
license: | GPLv3 — Copyright (C) 2013-2014, 2020 Olivier Pirson |
---|---|
author: | Olivier Pirson — http://www.opimedia.be/ |
version: | May 19, 2020 |
-
class
SimpleGUICS2Pygame.simplegui_lib_fps.
FPS
(x=10, y=10, font_color='Red', font_size=40)[source]¶ Calculate and display FPS (Frames Per Second).
How to use:
- Create an instance of FPS:
fps = FPS()
- Start:
fps.start()
- And put the
draw_fct()
in the end of your canvas’ draw handler:fps.draw_fct(canvas)
-
__init__
(x=10, y=10, font_color='Red', font_size=40)[source]¶ Set an instance to calculate FPS and drawing on position (x, y).
Parameters: - x – int or float
- y – int or float
- font_color – str
- font_size – int > 0
-
__weakref__
¶ list of weak references to the object (if defined)
- Create an instance of FPS:
[source]
simplegui_lib_keys — class to manage keyboard handling¶
(Version saved in CodeSkulptor https://py3.codeskulptor.org/#user305_EtIUDiM87dN1mD2.py .)
Examples of use in :
- example/keys.py: https://py3.codeskulptor.org/#user305_y6XS9Bq5JFD4eOU.py
simplegui_lib_keys module.
A class to help manage keyboard handling in SimpleGUI of CodeSkulptor.
Piece of SimpleGUICS2Pygame. https://bitbucket.org/OPiMedia/simpleguics2pygame
license: | GPLv3 — Copyright (C) 2014, 2020 Olivier Pirson |
---|---|
author: | Olivier Pirson — http://www.opimedia.be/ |
version: | May 19, 2020 |
-
class
SimpleGUICS2Pygame.simplegui_lib_keys.
Keys
(frame, keys=None)[source]¶ Keys handler.
Set and catch keys handlers of SimpleGUICS2Pygame (and CodeSkulptor) to help.
General note: Some keyboards can’t handle more than two or three keys pressed simultaneously. See Keyboard Ghosting Explained! and Keyboard Ghosting Demonstration.
-
__init__
(frame, keys=None)[source]¶ If keys is None then set an empty keys handler, else set a keys handler with key up and key down functions of keys.
active_handlers(), active_keydown_handler() or active_keyup_handler() must be called to activate.
Parameters: - frame – simplegui.Frame
- keys – None or Keys
-
__weakref__
¶ list of weak references to the object (if defined)
-
is_pressed
(key_code)[source]¶ If the key is pressed then return True, else return False.
Parameters: key_code – int >= 0 Returns: bool
-
is_pressed_key_map
(key_str)[source]¶ If the key is pressed then return True, else return False.
Parameters: key_str – str in simplegui.KEY_MAP Returns: bool
-
pressed_keys
()[source]¶ Return a sorted list with code of all pressed keys.
Returns: list of (int >= 0)
-
set_keydown_fct
(key_code, fct=None)[source]¶ If fct is None then erase the function key down handler to the specified key, else set the function key down handler to the specified key.
Parameters: - key_code – int >= 0
- fct – (int) -> *
-
set_keydown_fct_key_map
(key_str, fct=None)[source]¶ If fct is None then erase the function key down handler to the specified key, else set the function key down handler to the specified key.
Parameters: - key_str – str in simplegui.KEY_MAP
- fct – (int) -> *
-
[source]
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]
(Version saved in CodeSkulptor https://py3.codeskulptor.org/#user305_SZNWcbqQHXN4pow.py .)
simplegui_lib module.
Some functions and classes to help in SimpleGUI of CodeSkulptor, from simplegui_lib_draw, simplegui_lib_fps, simplegui_lib_keys and simplegui_lib_loader.
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 21, 2020 |
simpleguics2pygame — the main module, replace the simplegui module of CodeSkulptor¶
simpleguics2pygame — canvas¶
simpleguics2pygame module: simpleguics2pygame/canvas.
Class Canvas.
Piece of SimpleGUICS2Pygame. https://bitbucket.org/OPiMedia/simpleguics2pygame
license: | GPLv3 — Copyright (C) 2015-2016, 2020-2021 Olivier Pirson |
---|---|
author: | Olivier Pirson — http://www.opimedia.be/ |
version: | May 4, 2021 |
-
class
SimpleGUICS2Pygame.simpleguics2pygame.canvas.
Canvas
(frame, canvas_width, canvas_height)[source]¶ Canvas similar to SimpleGUI Canvas of CodeSkulptor.
-
__init__
(frame, canvas_width, canvas_height)[source]¶ Set the canvas.
Don’t use directly, a canvas is created by Frame() and reachable by handler defined by Frame.set_draw_handler().
Parameters: - frame – Frame (or None)
- canvas_width – int >= 0
- canvas_height – int >= 0
-
__weakref__
¶ list of weak references to the object (if defined)
-
_background_pygame_color
¶ Default pygame.Color of the background of the canvas.
-
_bg_pygame_surface_image
= None¶ pygame.surface.Surface default background image replaces _background_pygame_color.
-
_draw
()[source]¶ If self._draw_handler != None then call it and update display of the canvas.
(Not available in SimpleGUI of CodeSkulptor.)
-
_save
(filename)[source]¶ Save the canvas in filename.
Supported formats are supported formats by Pygame to save: TGA, PNG, JPEG or BMP (see https://www.pygame.org/docs/ref/image.html#pygame.image.save ).
If filename extension is not recognized then TGA format is used.
(Not available in SimpleGUI of CodeSkulptor.)
Parameters: filename – str
-
draw_arc
(center_point, radius, start_angle, end_angle, line_width, line_color)[source]¶ Draw an arc of circle, from start_angle to end_angle. Angles given in radians are clockwise and start from 0 at the 3 o’clock position.
(Available in CodeSkulptor3 but not in CodeSkulptor2!)
Parameters: - center_point – (int or float, int or float) or [int or float, int or float]
- radius – (int or float) > 0
- start_angle – int or float
- end_angle – int or float
- line_width – (int or float) > 0
- line_color – str
-
draw_circle
(center_point, radius, line_width, line_color, fill_color=None)[source]¶ Draw a circle.
If fill_color != None then fill with this color.
Parameters: - center_point – (int or float, int or float) or [int or float, int or float]
- radius – (int or float) > 0
- line_width – (int or float) > 0
- line_color – str
- fill_color – None or str
-
draw_image
(image, center_source, width_height_source, center_dest, width_height_dest, rotation=0)[source]¶ Draw image on the canvas.
Specify center position and size of the source (image) and center position and size of the destination (the canvas).
Size of the source allow get a piece of image. If width_height_source is bigger than image then draw nothing.
Size of the destination allow rescale the drawed image.
rotation specify a clockwise rotation in radians.
Each new Pygame surface used is added to image._pygamesurfaces_cached. See Image._pygamesurfaces_cached_clear() .
If number of surfaces in this caches is greater than image._pygamesurfaces_cache_max_size then remove the oldest surface.
Parameters: - image – Image
- center_source – (int or float, int or float) or [int or float, int or float]
- width_height_source – ((int or float) >= 0, (int or float) >= 0) or [(int or float) >= 0, (int or float) >= 0]
- center_dest – (int or float, int or float) or [int or float, int or float]
- width_height_dest – ((int or float) >= 0, (int or float) >= 0) or [(int or float) >= 0, (int or float) >= 0]
- rotation – int or float
-
draw_line
(point1, point2, line_width, line_color)[source]¶ Draw a line segment from point1 to point2.
Parameters: - point1 – (int or float, int or float) or [int or float, int or float]
- point2 – (int or float, int or float) or [int or float, int or float]
- line_width – (int or float) > 0
- line_color – str
-
draw_point
(position, color)[source]¶ Draw a point.
Parameters: - position – (int or float, int or float) or [int or float, int or float]
- color – str
-
draw_polygon
(point_list, line_width, line_color, fill_color=None)[source]¶ Draw a polygon from a list of points. A segment is automatically drawed between the last point and the first point.
If fill color is not None then fill with this color.
If line_width > 1, ends are poorly made!
Parameters: - point_list – not empty (tuple or list) of ((int or float, int or float) or [int or float, int or float])
- line_width – (int or float) > 0
- line_color – str
- fill_color – None or str
-
draw_polyline
(point_list, line_width, line_color)[source]¶ Draw line segments between a list of points.
If line_width > 1, ends are poorly made!
Parameters: - point_list – not empty (tuple or list) of ((int or float, int or float) or [int or float, int or float])
- line_width – (int or float) > 0
- line_color – str
-
draw_text
(text, point, font_size, font_color, font_face='serif', _font_size_coef=0.75)[source]¶ Draw the text string at the position point.
(point[0] is the left of the text, point[1] is the bottom of the text.)
If correponding font in Pygame is not founded, then use the default pygame.font.Font.
_font_size_coef is used to adjust the vertical positioning. (This paramater is not available in SimpleGUI of CodeSkulptor.)
Warning: This method can’t draw multiline text. To draw multiline text, see simplegui_lib_draw.draw_text_multi() .
Parameters: - text – str
- point – (int or float, int or float) or [int or float, int or float]
- font_size – (int or float) >= 0
- font_color – str
- font_face – str == ‘monospace’, ‘sans-serif’, ‘serif’
- _font_size_coef – int or float
Raise: ValueError if text contains unprintable whitespace character
(Alpha color channel don’t work!!!)
-
-
SimpleGUICS2Pygame.simpleguics2pygame.canvas.
create_invisible_canvas
(width, height)[source]¶ NOT IMPLEMENTED! (Return a “weak” Canvas.)
(Available in SimpleGUI of CodeSkulptor but not in CodeSkulptor documentation!)
Parameters: - width – int >= 0
- height – int >= 0
Returns: Canvas
-
SimpleGUICS2Pygame.simpleguics2pygame.canvas.
__all__
= ('Canvas', 'create_invisible_canvas')¶ 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]
simpleguics2pygame — control¶
simpleguics2pygame module: simpleguics2pygame/control.
Classes Control and TextAreaControl.
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.control.
Control
(frame, text, button_handler=None, width=None)[source]¶ Control similar to SimpleGUI Control (button and label) of CodeSkulptor.
-
__init__
(frame, text, button_handler=None, width=None)[source]¶ Set a button (if button_handler is not None) or a label (if button_handler is None) in the control panel.
Don’t use directly, use Frame.add_button() or Frame.add_label().
Parameters: - frame – Frame
- text – str
- button_handler – None or (function () -> *)
- width – None or int
-
__weakref__
¶ list of weak references to the object (if defined)
pygame.Color of the background in the button.
Horizontal padding in the button.
Vertical padding in the button.
pygame.font.Font of text in the button.
pygame.Color of the background in the button when it has pressed.
pygame.Color of text in the button.
-
_draw
()[source]¶ Draw the control object in the control panel.
(Not available in SimpleGUI of CodeSkulptor.)
Draw the the control object as a button.
(Not available in SimpleGUI of CodeSkulptor.)
-
_draw_label
()[source]¶ Draw the the control object as a label.
(Not available in SimpleGUI of CodeSkulptor.)
-
_label_pygame_font
¶ pygame.font.Font of the label.
-
_label_text_pygame_color
¶ pygame.Color of the label.
Deal a click of left mouse button on the zone of this Control.
If pressed then select this Control, else unselect and run the button handler (if exist).
(Not available in SimpleGUI of CodeSkulptor.)
Parameters: pressed – bool
-
-
class
SimpleGUICS2Pygame.simpleguics2pygame.control.
TextAreaControl
(frame, label_text, input_handler, input_width)[source]¶ TextAreaControl similar to SimpleGUI TextAreaControl (input) of CodeSkulptor.
-
__init__
(frame, label_text, input_handler, input_width)[source]¶ Set a input box in the control panel.
Don’t use directly, use Frame.add_input().
Parameters: - frame – Frame
- label_text – str
- input_handler – function (str) -> *
- input_width – int or float
-
__weakref__
¶ list of weak references to the object (if defined)
-
_input_background_pygame_color
¶ pygame.Color of the background in the input box.
-
_input_mark_pygame_color
¶ pygame.Color of the end mark of text in the input box.
-
_input_padding_x
= 5¶ Horizontal padding in the input box.
-
_input_padding_y
= 3¶ Vertical padding in the input box.
-
_input_pygame_color
¶ pygame.Color of the text in the input box.
-
_input_pygame_font
¶ pygame.font.Font of the text in the input box.
-
_input_selected_background_pygame_color
¶ pygame.Color of the background in the input box when it has focus.
-
_key
(pygame_event)[source]¶ Deal key pressed when this TextAreaControl have focus.
(Not available in SimpleGUI of CodeSkulptor.)
Parameters: pygame_event – pygame.Event KEYDOWN or KEYUP
-
_label_pygame_font
¶ pygame.font.Font of the label of the input box.
-
_label_text_pygame_color
¶ pygame.Color of the label of the input box.
Deal a click of left mouse button on the zone of this TextAreaControl.
If pressed then give it the focus.
(Not available in SimpleGUI of CodeSkulptor.)
Parameters: pressed – bool
-
-
SimpleGUICS2Pygame.simpleguics2pygame.control.
__all__
= ('Control', 'TextAreaControl')¶ 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]
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]
simpleguics2pygame — keys¶
simpleguics2pygame module: simpleguics2pygame/keys.
Keys helpers.
Piece of SimpleGUICS2Pygame. https://bitbucket.org/OPiMedia/simpleguics2pygame
license: | GPLv3 — Copyright (C) 2015, 2020 Olivier Pirson |
---|---|
author: | Olivier Pirson — http://www.opimedia.be/ |
version: | November 29, 2020 |
-
SimpleGUICS2Pygame.simpleguics2pygame.keys.
KEY_MAP
= {'0': 48, '1': 49, '2': 50, '3': 51, '4': 52, '5': 53, '6': 54, '7': 55, '8': 56, '9': 57, 'A': 65, 'B': 66, 'C': 67, 'D': 68, 'E': 69, 'F': 70, 'G': 71, 'H': 72, 'I': 73, 'J': 74, 'K': 75, 'L': 76, 'M': 77, 'N': 78, 'O': 79, 'P': 80, 'Q': 81, 'R': 82, 'S': 83, 'T': 84, 'U': 85, 'V': 86, 'W': 87, 'X': 88, 'Y': 89, 'Z': 90, 'a': 65, 'b': 66, 'c': 67, 'd': 68, 'down': 40, 'e': 69, 'f': 70, 'g': 71, 'h': 72, 'i': 73, 'j': 74, 'k': 75, 'l': 76, 'left': 37, 'm': 77, 'n': 78, 'o': 79, 'p': 80, 'q': 81, 'r': 82, 'right': 39, 's': 83, 'space': 32, 't': 84, 'u': 85, 'up': 38, 'v': 86, 'w': 87, 'x': 88, 'y': 89, 'z': 90}¶ SimpleGUI keyboard characters contants.
simpleguics2pygame — sound¶
simpleguics2pygame module: simpleguics2pygame/sound.
Class Sound.
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.sound.
_LocalSound
(filename)[source]¶ Child of Sound to load local file sound.
(Not available in SimpleGUI of CodeSkulptor.)
-
class
SimpleGUICS2Pygame.simpleguics2pygame.sound.
Sound
(url)[source]¶ Sound similar to SimpleGUI Sound of CodeSkulptor.
-
__init__
(url)[source]¶ Set a sound (if not Sound._load_disabled).
Don’t use directly, use load_sound().
Parameters: url – str
-
__weakref__
¶ list of weak references to the object (if defined)
-
_dir_search_first
= '_snd/'¶ load_sound() try first to loading sound from this directory, and next if failed, try to loading from URL.
This local directory is relative to the directory of your program.
-
_get_length
()[source]¶ Return the length of this sound in seconds.
(If initialization of this sound was failed then return 0.)
(Not available in SimpleGUI of CodeSkulptor.)
Returns: int or float
-
_load_disabled
= False¶ If True then load sounds are disabled.
-
-
SimpleGUICS2Pygame.simpleguics2pygame.sound.
create_sound
(sound_data, sample_rate=8000, num_channels=1)[source]¶ NOT YET IMPLEMENTED! (Return an empty Sound.)
(Available in SimpleGUI of CodeSkulptor but not in CodeSkulptor documentation!)
Parameters: - sound_data – (tuple or list) of (0 <= int < 256)
- sample_rate – int >= 0
- num_channels – int >= 0
Returns: Sound
-
SimpleGUICS2Pygame.simpleguics2pygame.sound.
load_sound
(url)[source]¶ Create and return a sound by loading a file from url. Not founded URL and errors are ignored.
SimpleGUICS2Pygame try first to loading sound from Sound._dir_search_first local directory (_snd/ 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_sound('http://commondatastorage.googleapis.com/codeskulptor-assets/jump.ogg')
try first to loading from_snd/commondatastorage.googleapis.com/codeskulptor_assets/jump.ogg
.Supported formats: OGG, WAV and MP3.
If MP3 sound failed on your system read installation of audioread.
(Supported formats by CodeSkulptor are browser dependant.)
(The sound can be started by Sound.play().)
Parameters: url – str (only a valid URL, not local filename) Returns: Sound
-
SimpleGUICS2Pygame.simpleguics2pygame.sound.
_load_local_sound
(filename)[source]¶ Create and return a sound by loading a file from filename. Not founded file and errors are ignored.
I recommend to use only Internet resources with the load_sound() 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 sound with this “private” function.
Supported formats are the same as the load_sound() function.
(Not available in SimpleGUI of CodeSkulptor.)
Parameters: filename – str (only a valid filename, not URL) Returns: _LocalSound
-
SimpleGUICS2Pygame.simpleguics2pygame.sound.
__all__
= ('_LocalSound', 'Sound', 'create_sound', 'load_sound', '_load_local_sound')¶ 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]
simpleguics2pygame — timer¶
simpleguics2pygame module: simpleguics2pygame/timer.
Class Timer.
Don’t require Pygame.
Piece of SimpleGUICS2Pygame. https://bitbucket.org/OPiMedia/simpleguics2pygame
license: | GPLv3 — Copyright (C) 2015, 2020 Olivier Pirson |
---|---|
author: | Olivier Pirson — http://www.opimedia.be/ |
version: | May 20, 2020 |
-
class
SimpleGUICS2Pygame.simpleguics2pygame.timer.
Timer
(interval, timer_handler)[source]¶ Timer similar to SimpleGUI Timer of CodeSkulptor.
Don’t require Pygame.
-
__init__
(interval, timer_handler)[source]¶ Set a time.
Don’t use directly, use create_timer().
Parameters: - interval – int or float > 0
- timer_handler – function () -> *
-
__weakref__
¶ list of weak references to the object (if defined)
-
classmethod
_stop_all
()[source]¶ Stop all timers.
(Not available in SimpleGUI of CodeSkulptor.)
Side effect: Empty Timer._timers_running.
-
_timers_running
= {}¶ Dict {(Timer id): Timer} of all timers are running.
-
get_interval
()[source]¶ Return the interval of this timer.
(Maybe available in SimpleGUI of CodeSkulptor but not in CodeSkulptor documentation!)
Returns: (int or float) > 0
-
start
()[source]¶ Start this timer.
Warning
With SimpleGUICS2Pygame,
Frame.start()
is blocking untilFrame.stop()
execution or closing window. So timers must be started before, and states must be initialized before. (Or maybe after by a handler function.)(Side effect: Add id(self): self in Timer._timers_running.)
-
-
SimpleGUICS2Pygame.simpleguics2pygame.timer.
create_timer
(interval, timer_handler)[source]¶ Create and return a timer that will execute the function timer_handler every interval milliseconds.
The first execution of time_handler will take place after the first period.
(The timer can be started by Timer.start().)
Parameters: - interval – int or float > 0
- timer_handler – function () -> *
Returns: Timer
-
SimpleGUICS2Pygame.simpleguics2pygame.timer.
__all__
= ('Timer', 'create_timer')¶ 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]
Warning
Be careful, the main module simpleguics2pygame is split in several files, but items from these files are available from the simpleguics2pygame module itself, like the simplegui module of CodeSkulptor.
For example, the function SimpleGUICS2Pygame.simpleguics2pygame.frame.create_frame() must be used by simplegui.create_frame() in CodeSkulptor and also with SimpleGUICS2Pygame with import SimpleGUICS2Pygame.simpleguics2pygame as simplegui.
simpleplot — replace the simpleplot module of CodeSkulptor¶
simpleplot module.
Replace the simpleplot module of CodeSkulptor.
Require matplotlib (and must be installed separately).
Warning
With SimpleGUICS2Pygame,
if your program is terminated,
then windows opened by
plot_bars()
, plot_lines()
and plot_scatter()
will be closed automatically.
You can use the specific function _block()
to block the program until closing all windows.
See Tips to run specific code.
Piece of SimpleGUICS2Pygame. https://bitbucket.org/OPiMedia/simpleguics2pygame
license: | GPLv3 — Copyright (C) 2013-2016, 2020 Olivier Pirson |
---|---|
author: | Olivier Pirson — http://www.opimedia.be/ |
version: | May 20, 2020 |
-
SimpleGUICS2Pygame.simpleplot.
_COLORS
= ('#edc240', '#afd8f8', '#cb4b4b', '#4da74d', '#9440ed', '#bd9b33', '#8cacc6', '#a23c3c', '#3d853d', '#7633bd', '#ffe84c', '#d2ffff', '#f35a5a', '#5cc85c', '#b14cff', '#8e7426', '#698194', '#792d2d', '#2e642e', '#58268e', '#ffff59', '#f4ffff', '#ff6969', '#6be96b', '#cf59ff', '#5e4d19', '#455663', '#511d1d', '#1e421e', '#3b195e', '#ffff66', '#ffffff')¶ Color used for each graph.
(Not available in SimpleGUI of CodeSkulptor.)
-
SimpleGUICS2Pygame.simpleplot.
_MATPLOTLIB_AVAILABLE
= True¶ True if matplotlib is available, else False.
-
SimpleGUICS2Pygame.simpleplot.
_MATPLOTLIB_VERSION
¶ matplotlib.__version__ if Pygame is available, else None.
-
SimpleGUICS2Pygame.simpleplot.
_block
()[source]¶ If some plot windows are open then block the program until closing all windows. (Not available in SimpleGUI of CodeSkulptor.)
-
SimpleGUICS2Pygame.simpleplot.
plot_bars
(framename, width, height, xlabel, ylabel, datasets, legends=None, _block=False, _filename=None)[source]¶ Open a window titled framename and plot graphes with datasets data shown as vertical bars.
xlabel and ylabel are labels of x-axis and y-axis.
datasets must be a sequence of data. Each data must be:
- Sequence (not empty) of pair x, y. Each point (x, y) is represented by a vertical bar of height y.
- Or dict (not empty) x: y. Each point (x, y) is represented by a vertical bar of height y.
If legends is not None then it must be a sequence of legend of each graph.
If _block then block the program until closing the window else continue and close the window when program stop. (Option not available in SimpleGUI of CodeSkulptor.)
If _filename is not None then save the image to this file. (Option not available in SimpleGUI of CodeSkulptor.)
Parameters: - framename – str
- width – int > 0
- height – int > 0
- xlabel – str
- ylabel – str
- datasets – (list or tuple) of (((list or tuple) of ([int or float, int or float] or (int or float, int or float))) or (dict (int or float): (int or float)))
- legends – None or ((list or tuple) of same length as datasets)
- _block – False
- _filename – None or str
-
SimpleGUICS2Pygame.simpleplot.
plot_lines
(framename, width, height, xlabel, ylabel, datasets, points=False, legends=None, _block=False, _filename=None)[source]¶ Open a window titled framename and plot graphes with datasets data shown as connected lines.
xlabel and ylabel are labels of x-axis and y-axis.
datasets must be a sequence of data. Each data must be:
- Sequence (not empty) of pair x, y. Each point (x, y) is plotted (in given order) and connected with line to previous and next points.
- Or dict (not empty) x: y. Each point (x, y) is plotted (in ascending order of x value) and connected with line to previous and next points.
If points then each point is highlighted by a small disc (a small circle in CodeSkulptor).
If legends is not None then it must be a sequence of legend of each graph.
If _block then block the program until closing the window else continue and close the window when program stop. (Option not available in SimpleGUI of CodeSkulptor.)
If _filename is not None then save the image to this file. (Option not available in SimpleGUI of CodeSkulptor.)
Parameters: - framename – str
- width – int > 0
- height – int > 0
- xlabel – str
- ylabel – str
- datasets – (list or tuple) of (((list or tuple) of ([int or float, int or float] or (int or float, int or float))) or (dict (int or float): (int or float)))
- points – bool
- legends – None or ((list or tuple) of same length as datasets)
- _block – False
- _filename – None or str
-
SimpleGUICS2Pygame.simpleplot.
plot_scatter
(framename, width, height, xlabel, ylabel, datasets, legends=None, _block=False, _filename=None)[source]¶ Open a window titled framename and plot graphes with datasets data shown as scattered points.
xlabel and ylabel are labels of x-axis and y-axis.
datasets must be a sequence of data. Each data must be:
- Sequence (not empty) of pair x, y. Each point (x, y) is represented by a circle.
- Or dict (not empty) x: y. Each point (x, y) is represented by a circle.
If legends is not None then it must be a sequence of legend of each graph.
If _block then block the program until closing the window else continue and close the window when program stop. (Option not available in SimpleGUI of CodeSkulptor.)
If _filename is not None then save the image to this file. (Option not available in SimpleGUI of CodeSkulptor.)
Parameters: - framename – str
- width – int > 0
- height – int > 0
- xlabel – str
- ylabel – str
- datasets – (list or tuple) of (((list or tuple) of ([int or float, int or float] or (int or float, int or float))) or (dict (int or float): (int or float)))
- legends – None or ((list or tuple) of same length as datasets)
- _block – False
- _filename – None or str
[source]
Warning
Be careful, the main module simpleguics2pygame is split in several files, but items from these files are available from the simpleguics2pygame module itself, like the simplegui module of CodeSkulptor.
For example, the function SimpleGUICS2Pygame.simpleguics2pygame.frame.create_frame() must be used by simplegui.create_frame() in CodeSkulptor and also with SimpleGUICS2Pygame with import SimpleGUICS2Pygame.simpleguics2pygame as simplegui.
Compatibility¶
Compatibility between SimpleGUI of CodeSkulptor and SimpleGUICS2Pygame¶
With SimpleGUI of CodeSkulptor2 or CodeSkulptor3, some things (like fonts, buttons…) are browser dependents. That is to say that there are some differences from one browser to another. Therefore it is normal that these elements are also slightly different with SimpleGUICS2Pygame.
With SimpleGUI of CodeSkulptor2 or CodeSkulptor3, supported sound formats (WAV, OGG, MP3) are also browser dependents.
With SimpleGUICS2Pygame WAV, OGG and MP3 (since version 2.0.0) are supported.
I recommend to always use the OGG format.
Warning
With SimpleGUICS2Pygame,
Frame.start()
is blocking untilFrame.stop()
execution or closing window. So timers must be started before, and states must be initialized before. (Or maybe after by a handler function.)Warning
With SimpleGUICS2Pygame, if your program is terminated, then windows opened by
plot_bars()
,plot_lines()
andplot_scatter()
will be closed automatically. You can use the specific function_block()
to block the program until closing all windows.See Tips to run specific code.
Problems with SimpleGUICS2Pygame¶
If MP3 sound failed on your system read installation of audioread.
Compatibility between Python 2 and Python 3¶
CodeSkulptor2 implements a subset of Python 2.
CodeSkulptor3 implements a subset of Python 3.
You can use SimpleGUICS2Pygame with Python 2 and Python 3.
The division
/
don’t have the same behavior in Python 2 and Python 3: https://docs.python.org/3/whatsnew/3.0.html#integers .- In Python 2 (and CodeSkulptor):
3/2 == 1
and3/2.0 == 1.5
- In Python 3:
3/2 == 3/2.0 == 1.5
3//2 == 1
and3//2.0 == 1.0
everywehre.(You can add
from __future__ import division
on the top of your program, and Python 2 mimic Python 3 division. But then CodeSkulptor failed!)- In Python 2 (and CodeSkulptor):
Rounded behavior is also different: https://docs.python.org/3/whatsnew/3.0.html#builtins .
- In Python 2 (and CodeSkulptor):
round(1.5) == 2.0
andround(2.5) == 3.0
- In Python 3:
round(1.5) == round(2.5) == 2
- In Python 2 (and CodeSkulptor):
print
is a function in Python 3: https://docs.python.org/3/whatsnew/3.0.html#print-is-a-function .- In Python 2 (and CodeSkulptor):
print 'Hello real world!', 42
- In Python 3:
print('Hello real world!', 42)
With only one argument,
print('Hello real world! ' + str(42))
run everywhere.(You can add
from __future__ import print_function
on the top of your program, and Python 2 mimic Python 3 print function. But then CodeSkulptor failed!)- In Python 2 (and CodeSkulptor):
Compatibility between CodeSkulptor and CodeSkulptor3¶
CodeSkulptor2 implements a subset of Python 2.
CodeSkulptor3 implements a subset of Python 3.
There are moreover some other differences.
In
simplegui module
module of CodeSkulptor3 and SimpleGUICS2Pygame, there is aCanvas.draw_arc()
method that doesn’t exist in CodeSkulptor2.In
simplegui module
module of CodeSkulptor3 and SimpleGUICS2Pygame, there is aFrame.download_canvas_image()
method that doesn’t exist in CodeSkulptor2.In
numeric
module of CodeSkulptor2 and SimpleGUICS2Pygame, there is aMatric.scale()
method to multiply the matrix by a scalar and the operator*
multiply two matrices.In CodeSkulptor3, the
Matric.scale()
method doesn’t exist, the operator*
multiply a matrix by a scalar and the operator@
multiply two matrices.
Problem with CodeSkulptor¶
If you have no sound with CodeSkulptor on Chrome/Chromium and GNU/Linux,
maybe you can fix that problem with pavucontrol
.
For example on Debian, install it and set the volume for the application:
$ sudo apt install pavucontrol
$ pavucontrol
Comparison of speeds¶
Due to the execution in browser CodeSkulptor is slower than directly execute Python on your computer. Below a graph of speeds of the execution of the test program example/Stress_Balls/Stress_Balls.py in several environments (all on Intel Xeon W3530 Quad-Core 2.8 GHz 6 Gio), where the canvas is normally displayed 60 times by second (SimpleGUITk seems not very precise). When there is a lot of shapes to draw the execution can no longer finished all drawing during the given time.
-O
indicates that assertions was disabled during the test.
See Python assertions option section.
You can also execute this online program to plot results: example/Stress_Balls/Stress_Balls_results.py.
Tips¶
CodeSkulptor¶
CodeSkulptor2 is a Python implementation (in JavaScript) running in a browser. It implements a subset of Python 2.
CodeSkulptor3 is the same but it implements a subset of Python 3.
It is the environment used in the MOOC An Introduction to Interactive Programming in Python (Rice University, Coursera).
To use a program from CodeSkulptor in standard Python (with this package),
you need to change
import simplegui
by
import SimpleGUICS2Pygame.simpleguics2pygame as simplegui
.
The right way to do is to write this
try:
import simplegui
except ImportError:
import SimpleGUICS2Pygame.simpleguics2pygame as simplegui
and your program runs both in CodeSkulptor and standard Python.
So, if your program runs in CodeSkulptor, it imports simplegui
.
Else, an ImportError
exception will be raised,
and then it will imports SimpleGUICS2Pygame.simpleguics2pygame
and it renamed to simplegui
.
cs2both.py
can help to quickly make this changement on program downloaded from CodeSkulptor.python cs2both.py YOURPROGRAM.py
.YOURPROGRAM.py
is copied to YOURPROGRAM.py.bak
before changing.To use also the other modules, you can write this. But specify only those you use.
try:
import simplegui
import codeskulptor
import numeric
import simpleplot
import user305_SXBsmszNiUxIeoV as codeskulptor_lib
import user305_SZNWcbqQHXN4pow as simplegui_lib
except ImportError:
import SimpleGUICS2Pygame.simpleguics2pygame as simplegui
import SimpleGUICS2Pygame.codeskulptor as codeskulptor
import SimpleGUICS2Pygame.numeric as numeric
import SimpleGUICS2Pygame.simpleplot as simpleplot
import SimpleGUICS2Pygame.codeskulptor_lib as codeskulptor_lib
import SimpleGUICS2Pygame.simplegui_lib as simplegui_lib
Note that import name like user305_SXBsmszNiUxIeoV
in CodeSkulptor
is valid both for CodeSkulptor2 and CodeSkulptor3.
It corresponds to URLs
https://py2.codeskulptor.org/#user305_SXBsmszNiUxIeoV.py
and
https://py3.codeskulptor.org/#user305_SXBsmszNiUxIeoV.py .
Specific code¶
To run specific code on CodeSkulptor2 or with SimpleGUICS2Pygame, you can write this
try:
import simplegui
SIMPLEGUICS2PYGAME = False
except ImportError:
import SimpleGUICS2Pygame.simpleguics2pygame as simplegui
SIMPLEGUICS2PYGAME = True
And then you can run specific code simply by testing value of SIMPLEGUICS2PYGAME
. For example:
# …
def joypad_up(joypad, button):
if joypad == 0:
if button == 0:
# …
if SIMPLEGUICS2PYGAME:
frame._set_joypadup_handler(joypad_up)
Joypads¶
SimpleGUICS2Pygame adds the possibility to use joypads. It is not available in CodeSkulptor. You can make compatible program with the previous tip to separate specific code.
Similarly to set_mouseclick_handler()
and set_mousedrag_handler()
functions,
the class Frame in SimpleGUICS2Pygame defines
_set_joypaddown_handler()
,
_set_joypadup_handler()
,
_set_joypadaxe_handler()
and _set_joypadhat_handler()
.
Two little examples using joypads (but of course only when you run them with SimpleGUICS2Pygame directly on your computer): example/Pong.py and example/RiceRocks_Asteroids.py.
Colors¶
The color parameter used by drawing functions must be in the following formats:
'#rrggbb'
with rr, gg, bb hexadecimal numbers on 2 figures'#rgb'
with r, g, b hexadecimal numbers on 1 figure'rbg(red,blue,green)'
with red, blue, green 0 <= integer <= 255'rgba(red,blue,green,alpha)'
with red, blue, green 0 <= integer <= 255 and alpha between 0 and 1- a constant name in this list https://www.w3schools.com/colors/colors_names.asp .
See the official HTML colors: http://www.opimedia.be/DS/mementos/colors.htm .
Command line arguments¶
When you run a program you can use following arguments:
python YOURPROGRAM.py [SimpleGUICS2Pygame arguments] [application arguments]
--default-font
: Use Pygame default font instead serif, monospace… (this is faster if you display a lot of text).--display-fps
: Display FPS average on the canvas.--fps N
: Set Frame Per Second (default: 60 FPS).--frame-padding N
: Set the padding in pixels found around the canvas (default: 2).--fullscreen
: Fullscreen mode.--help
: Print help message and quit.--keep-timers
: Keep running timers when close frame without asking (default: ask before close). See also--stop-timers
.--last
: Mark this argument as the last SimpleGUICS2Pygame’s argument. (Do nothing else.)--no-border
: Window without border.--no-controlpanel
: Hide the control panel (and status boxes).--no-load-sound
: Don’t load any sound.--no-status
: Hide two status boxes.--overwrite-downloaded-medias
: Download all images and sounds from Web and save in local directory even if they already exist.--print-application-args
: Print remaining arguments transmit to application.--print-args
: Print final configuration from SimpleGUICS2Pygame’s argument.--print-load-medias
: Print URLs or local filenames loaded.--print-stats-cache
: After frame stopped, print some statistics of caches.--save-downloaded-medias
: Save images and sounds downloaded from Web that don’t already exist in local directory.--stop-timers
: Stop all timers when ending program (default: running timers continue, as in CodeSkulptor). See also--keep-timers
.--version
: Print help message and quit.
If an argument is not in this list then it is ignored and all next arguments are ignored by SimpleGUICS2Pygame.
Arguments used by SimpleGUICS2Pygame is deleted to sys.argv
.
Remaining arguments can used by your application.
SimpleGUICS2Pygame arguments are automatically read
when the module simpleguics2pygame
is imported.
- Examples:
python YOURPROGRAM.py --no-controlpanel --stop-timers --foo --fullscreen
RunYOURPROGRAM.py
with the control panel hidden and timers will stoped. But SimpleGUICS2Pygame ignore--foo
and--fullscreen
.YOURPROGRAM.py
application receive--foo --fullscreen
arguments.python YOURPROGRAM.py --no-controlpanel --last --stop-timers --foo --fps 30
RunYOURPROGRAM.py
with the control panel hidden. But SimpleGUICS2Pygame ignore--stop-timers
,--foo
,--fps
and30
.YOURPROGRAM.py
application receive--stop-timers --foo --fps 30
arguments.
Download medias¶
Run python YOURPROGRAM.py --save-downloaded-medias --print-load-medias
once.
Images and sounds used (from URLs) will be saved in local directory (_img/
et _snd/
by default).
Next simply run python YOURPROGRAM.py
and the medias will be loaded from these local directories.
For example,
load_image('http://commondatastorage.googleapis.com/codeskulptor-assets/lathrop/double_ship.png')
save image to
_img/commondatastorage.googleapis.com/codeskulptor_assets/lathrop/double_ship.png
.
SimpleGUICS2Pygame has two additional classes to load directly local files: _LocalImage() and _LocalSound(). But be aware that these functions are not available in CodeSkulptor.
Helper functions¶
This package contains 5 additional modules with several helper functions that you can also import online in CodeSkulptor:
- codeskulptor_lib — some miscellaneous functions
- simplegui_lib_draw — draw functions
- simplegui_lib_fps — class to calculate and display Frames Per Second
- simplegui_lib_keys — class to manage keyboard handling
- simplegui_lib_loader — class to load images and sounds
For example, to draw multiline text you can use draw_text_multi() from the simplegui_lib_draw module by:
try:
import simplegui
import user305_SaT1YKoOikl4ax9 as simplegui_lib_draw
except ImportError:
import SimpleGUICS2Pygame.simpleguics2pygame as simplegui
import SimpleGUICS2Pygame.simplegui_lib as simplegui_lib_draw
def draw(canvas):
# …
draw_text_multi(canvas,
"""line 1
line 2
line 3""", (x, y), size, 'white', 'serif')
# …
Python assertions option¶
Run
python YOURPROGRAM.py
then asserts is enabled and this package is (intentionnaly) very strict.
So maybe “correct” programs in CodeSkulptor fail!
(In fact CodeSkulptor is very permissive.
Some incorrect Python codes are accepted.)
It is a good point to develop and write correct programs.
But if you want just run a program
without annoying assertions
you can disable them with.
python -O YOURPROGRAM.py
.
In some cases run without assertions is faster. See in the Comparison of speeds section, an example where SimpleGUICS2Pygame functions are executed a lot of times.
Ressources: images, sounds and example programs¶
License: GPLv3
¶
Copyright (C) 2013-2016, 2018, 2020-2021 Olivier Pirson
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
Author: 🌳 Olivier Pirson — OPi
🇧🇪🇫🇷🇬🇧 🐧 👨💻 👨🔬¶
🌐 Website: http://www.opimedia.be/
💾 Bitbucket: https://bitbucket.org/OPiMedia/
- 📧 olivier.pirson.opi@gmail.com
- Mastodon: https://mamot.fr/@OPiMedia — Twitter: https://twitter.com/OPirson
- 👨💻 LinkedIn: https://www.linkedin.com/in/olivierpirson/ — CV: http://www.opimedia.be/CV/English.html
- other profiles: http://www.opimedia.be/about/
Support me¶
This program is a free software (GPL license). It is completely free (like “free speech” and like “free beer”). However you can support me financially by donating.
Known bugs¶
Developers¶
This is a free software, so you can download it, modify it and submit your modifications. You can also redistribute your own version (keeping the GPL license).
Complete sources on Bitbucket: https://bitbucket.org/OPiMedia/simpleguics2pygame
Naming convention¶
Usually in Python, prepending a name by underscore _
is a convention for non-public items.
Here intention is to separate additional variables and functions in SimpleGUICS2Pygame
to the standard API of CodeSkulptor.
One goal of SimpleGUICS2Pygame is to mimic as much as possible the behavior of CodeSkulptor.
Additional functionalities are isolated with prepending underscore _
.
Hierarchy of files on Bitbucket¶
- SimpleGUICS2Pygame/: source code
- example/: little example programs and games
- script/
- cs2both.py: Python program to modify automatically your CodeSkulptor programs to run with SimpleGUICS2Pygame
- pygame_check.py: Python program to check Pygame installation
- SimpleGUICS2Pygame_check.py: Python program to check installation
- simpleguics2pygame/: main module (splitted in several files) that reimplementing the
simpleguics2pygame
module of CodeSkulptor - test/: test files, mainly to check compatibility with CodeSkulptor
- codeskulptor.py: module that reimplementing the
codeskulptor
module of CodeSkulptor - numeric.py: module that reimplementing the
numeric
module of CodeSkulptor - simpleplot.py: module that reimplementing the
simpleplot
module of CodeSkulptor - …
- Sphinx/: source documentation
- _static/links/: links of programs, images and sounds
- …
- stuffs/: unimportant stuff
- _dist/: last and previous versions of installation archive files
- _img/: logos
- Makefile: to build documentation, distributions, etc.
- setup.py: Python installation file
- …
Warning
Before the version 2.0.0, the main module simpleguics2pygame
was one file. Now it is splitted in several files in simpleguics2pygame/
subdirectory.
ChangeLog¶
- 2.1.1 — May 4, 2021 (Work in progress)
- Updated links to CodeSkulptor2.
- 2.1.0 — November 29, 2020
- Removed Pygame restriction to version 1.9.6.
- Removed old special cases when Pygame was not installed.
- Cleaned some warnings from mypy.
example/Nostalgic_Basic_Blitz.py
: corrected bug with negative position of bomb.
- 2.0.3 — October 2, 2020
- Corrected reading permission of files in distribution files.
- Added Arch Linux installation script (written by Danny Fajardo).
- 2.0.2 — May 23, 2020
- Documentation:
- Updated image and sound links.
- Tests:
- Completed missing type annotations in simpleguics2pygame/control.
- Documentation:
- 2.0.1 — May 21, 2020
- Documentation:
- Added class diagram generated by Pyreverse.
- Updated image and CodeSkulptor program links.
- Program examples:
- Adapted
example/Memory.py
with images moved to HTTPS.
- Adapted
- Tests:
- Added type annotations (in Python 2 mode) for each function.
- Cleaned some type annotations instead ignore them.
- Documentation:
- 2.0.0 — April 18, 2020
- Converted from Mercurial version control system to Git.
- Corrected files included in MANIFEST.in for distribution building. (Thanks to 7coil.)
- Improved installation. Now all requirements are automatically installed.
- Modules:
- Splitted the big file ``simpleguics2pygame.py``.
- Added alpha possibility on background color.
- Added dealing of joypads.
- Added dealing of MP3 sounds.
Added
draw_arc()
inCanvas
andtest_arc
. - Added
Frame.download_canvas_image()
,Frame._cursor_auto_hide
andFrame._set_cursor_visible()
. - Added
codeskulptor_version()
incodeskulptor_lib
. - Added
draw_text_multi()
insimplegui_lib_draw
. - Added
--frame-padding
(thanks to 7coil),--last
,--help
,--print-application-args
,--print-args
and--version
command line options. - Added
randomize_iteration()
incodeskulptor
. - Added
transparent
“color” name. - Added
ValueError
exception ifdraw_text()
try to draw a text containing unprintable whitespace character. - Corrected
keys
parameter use insimplegui_lib_keys.Keys()
. - Improved dealing of input box.
- Updated
simpleplot
module, to “run” same if matplotlib is not installed.
- Documentation:
- Corrected “Read the Docs” subpackage problem.
- Added a developer’s page.
- Replaced
_WEBSITE
value by documentation link. - Updated. (Thanks to John Gray and Tom Keller.)
- Splitted media links to image links and sound links.
- Updated installation documentation.
- Updated media and CodeSkulptor programs links.
- Program examples:
- Added
example/presentation.py
. - Added
example/stop_example.py
. - Moved from CodeSkulptor to CodeSkulptor3.
- Added
- Scripts:
- Added
script/pygame_check.py
to check Pygame installation alone. - Updated
script/SimpleGUICS2Pygame_check.py
.
- Added
- Tests:
- Added static checking in
Makefile
, and corrected a lot of style warnings. - Corrected and updated
test/test_sound.py
. - Added
test/test_command_line_options.py
. - Added
test/test_input.py
. - Updated
test/test_dir.py
. - Updated
test/test_objects.py
. - Updated
test/test_text.py
.
- Added static checking in
- 01.09.00 — January 1st, 2015
- Added ``_load_local_image()`` and ``_load_local_sound()`` functions.
- Added
test/test_sound.py
. - Updated
test/test_dir.py
. - Updated
test/test_image.py
. - Added
--fps n
option. - Added Donate button in
_draw_about()
panel.
- 01.08.01 — October 9, 2014
- Added information when pygame is not installed.
- Corrected local filename bug in
_load_media()
. (Thanks to Sergey Sorokin.) - Updated documentation.
- 01.08.00 — October 4, 2014
- Added alternative grey colors.
- Added HSL and HSLA colors format.
- Added
test/test_colors_html_hsla.py
. - Updated CodeSkulptor programs links.
- Updated
codeskulptor_lib
. - Updated
test/test_colors_html_rgba.py
. - Updated media links.
- 01.07.00 — September 2, 2014
- Added
plot_scatter()
function insimpleplot
module. - Added
test/test_simpleplot_scatter.py
. - Updated
test/test_dir.py
. - Updated documentation.
- Updated CodeSkulptor programs links.
- Added
- 01.06.03 — July 24, 2014
- Implemented
width
parameter inadd_label()
. - Added
test/test_button_label.py
.
- Implemented
- 01.06.02 — July 18, 2014
- Corrected stupid error in
add_label()
.
- Corrected stupid error in
- 01.06.01 — July 17, 2014
- Added (fake) width parameter in
add_label()
. - Corrected gz archive of HTML offline documentation.
- Added private members in all documentation.
- Added (fake) width parameter in
- 01.06.00 — June 16, 2014
- Updated
numeric
. - Updated
example/Spaceship_prototype.py
andexample/RiceRocks_Asteroids.py
. - Updated
test/test_dir.py
. - Added
Loader.cache_clear()
andLoader.print_stats_cache()
. - Added a cache mechanism to Pygame surfaces used by
Image
(improve speed ofdraw_image()
). - Added
Image._url
attribute. - Moved
_RADIAN_TO_DEGREE
. - Print now to
stderr
insteadstdout
. - Updated
_draw_about()
. - Updated documentation.
- Updated media and CodeSkulptor programs links.
- Updated
- 01.05.00 — May 25, 2014
- Added cache for colors and option
--print-stats-cache
. - First public version of
.hgignore
andMakefile
. - Off the mixer if no sound is loaded.
- Updated
example/RiceRocks_Asteroids.py
. - Updated documentation.
- Updated
example/Spaceship_prototype.py
. - Updated
example/Blackjack.py
. - Updated
example/Memory.py
. - Updated
example/Pong.py
. - Cosmetic changes in some example programs.
- Updated
test/test_all.py
. - Better order Pygame initalization.
- Updated
script/cs2both.py
andscript/SimpleGUICS2Pygame_check.py
. - Updated
simplegui_lib_keys.py
andexample/keys.py
. - Updated
example/Stopwatch.py
. - Changed filename used by
_load_media()
(use now the query part of URLs). - Added precision to Window$ installation.
- Updated media and CodeSkulptor programs links.
- Added cache for colors and option
- 01.04.00 — December 16, 2013
- Customized documentation.
- Splitted changes in a separated file.
- Added
numeric
(Matrix
object) module. - Corrected some typos by Maxim Rybalov. (Thank you.)
- Updated
simplegui_lib_fps.py
. - Updated
example/RiceRocks_Asteroids.py
.
- 01.03.00 — December 13, 2013
- Removed exception to
get_canvas_image()
. - Updated almost all files to add
except ImportError
. - Updated
codeskulptor_lib.codeskulptor_is()
. - Added
simplegui_lib_fps.py
. - Corrected bug in
_load_media()
(issue #1). (Thanks to Sean Flanigan.) - Updated documentation to clarify local use of images and sounds. (Thanks to Ines Simicic.)
- Updated
script/cs2both.py
. - Corrected conversion of
_fps_average
toint
in Python 2. - Corrected mentions of
Frame._fps
in comment. - Updated
example/Blackjack.py
. - Updated
example/Spaceship_prototype.py
. - Updated
example/Memory.py
. - Updated media and CodeSkulptor programs links.
- Removed exception to
- 01.02.00 — November 8, 2013
- Splitted
simplegui_lib.py
insimplegui_lib.py
,simplegui_lib_draw.py
andsimplegui_lib_loader.py
. - Added
simplegui_lib_keys.py
. - Added
example/keys.py
andexample/loader.py
. - Updated
example/RiceRocks_Asteroids.py
andexample/Spaceship_prototype.py
. - Updated
script/SimpleGUICS2Pygame_check.py
. - Updated
test/test_image.py
andtest/test_text.py
. - Updated media and CodeSkulptor programs links.
- Corrected installation documentation.
- Splitted
- 01.01.00 — November 1st, 2013
- Added
_block
and_filename
parameters insimpleplot.plot_lines()
function. - Added
plot_bars()
function insimpleplot
module. - Added
test/test_simpleplot_bars.py
andtest/test_simpleplot_lines.py
. - Updated
test/test_all.py
. - Updated media links.
- Corrected minor errors in documentation.
- Added
set_timeout()
function incodeskulptor
module. - Updated
example/Mandelbrot_Set.py
(usedset_timeout()
). - Updated CodeSkulptor programs links.
- Added
- 01.00.02 — October 31, 2013
- Corrected bug in
TextAreaControl.set_text()
: the label text was also modified. - Updated documentation.
- Updated
cs2both.py
. - Updated
example/Mandelbrot_Set.py
(optimized draw). - Updated media and CodeSkulptor programs links.
- Corrected bug in
- 01.00.01 — October 9, 2013
- Adapted documentation and
cs2both.py
to changes of CodeSkulptor (int
andfloat
are now separate).
- Adapted documentation and
- 01.00.00 — July 13, 2013
- Moved documentation to Read The Docs.
- Added
simpleplot
module. - Updated
example/Mandelbrot_Set.py
(used vertical symetry). - Updated media and CodeSkulptor programs links.
- 00.92.00 — June 27, 2013
- Changed
simplegui_lib.Loader
class to display progression loading in SimpleGUICS2Pygame (moved arguments fromwait_loaded()
function to__init__()
). - Replaced
Frame._already_frame
byFrame._frame_instance
. - Updated
example/RiceRocks_Asteroids.py
(collisions of asteroids and little asteroids). - Added
Frame._set_canvas_background_image()
function. - Memoization of downloaded images and sounds.
- Changed save in local directory to avoid conflict.
- Added
test/test_image.py
. - Added
--overwrite-downloaded-medias
and--save-downloaded-medias
options. - Display versions in
script/SimpleGUICS2Pygame_check.py
.
- Changed
- 00.91.00 — June 23, 2013
- Changed installation program to build distributions (now
setuptools
is used). - Added
--print-load-medias
option. - Added
script/SimpleGUICS2Pygame_check.py
and moved and updatedcs2both.py
. - Now,
_set_option_from_argv()
deleted SimpleGUICS2Pygame options after use. - Memoization of Pygame fonts.
- Added
--default-font
option. - Many cosmetic changes to respect PEP 8.
- Updated media and CodeSkulptor programs links.
- Some precisions and English corrections in the documentation.
- Added some CodeSkulptor programs links.
example/Memory.py
: moved image locations.example/Nostalgic_Basic_Blitz.py
: added spacebar information.
- Changed installation program to build distributions (now
- 00.90.10 — June 19, 2013
- Adapted button, label and input to display multine text.
- Simplified handler functions transmitted to
add_button()
in some programs. - Added
example/Nostalgic_Basic_Blitz.py
. - Changed
default_pygame_color
param of_simpleguicolor_to_pygamecolor()
function (now installation is ok even if Pygame not installed). - Moved
_VERSION
and_WEBSITE
constants fromsimpleguics2pygame.py
to__init__.py
. - Removed
enumerate()
function fromcodeskulptor_lib
(now implemented natively by CodeSkulptor). - Added
--display-fps
option. - Added
example/RiceRocks_Asteroids.py
. - Updated some CodeSkulptor programs links.
- Added some new media links.
- Added some details in documentations.
- Some cosmetic changes.
- 00.90.00 — June 13, 2013
- First public version.