The Misc-Module

Contains code that did not make it into an own module.


Displays a pygame.Surface in the window.

in pygame the window is represented through a surface, on which you can draw as on any other pygame.Surface. A refernce to to the screen can be optained via the pygame.display.get_surface() function. To display the contents of the screen surface in the window pygame.display.flip() needs to be called.

display() draws the surface onto the screen surface at the postion (0, 0), and then calls flip().

Parameters:surface (pygame.Surface) – the pygame.Surface to display
pyparadigm.misc.empty_surface(fill_color, size=None, flags=0)[source]

Returns an empty surface filled with fill_color.

  • fill_color (pygame.Color) – color to fill the surface with
  • size (int-2-tuple) – the size of the new surface, if None its created to be the same size as the screen
pyparadigm.misc.init(resolution, pygame_flags=0, display_pos=(0, 0), interactive_mode=False, title='Pygame Window')[source]

Creates a window of given resolution.

  • resolution (tuple) – the resolution of the windows as (width, height) in pixels
  • pygame_flags (int) – modify the creation of the window. For further information see Creating a Window
  • display_pos (tuple) – determines the position on the desktop where the window is created. In a multi monitor system this can be used to position the window on a different monitor. E.g. the monitor to the right of the main-monitor would be at position (1920, 0) if the main monitor has the width 1920.
  • interactive_mode (bool) – Will install a thread, that emptys the event-queue every 100ms. This is neccessary to be able to use the display() function in an interactive console on windows systems. If interactive_mode is set, init() will return a reference to the background thread. This thread has a stop() method which can be used to cancel it. If you use ctrl+d or exit() within ipython, while the thread is still running, ipython will become unusable, but not close.
  • title (str) – the Title of the Window

a reference to the display screen, or a reference to the background thread if interactive_mode was set to true. In the second scenario you can obtain a reference to the display surface via pygame.display.get_surface()

Return type:


pyparadigm.misc.make_transparent_by_colorkey(surf, colorkey, copy=True)[source]

Makes image transparent, and sets all pixel of a certain color transparent

This is useful if images should be scaled and smoothed, as this will change the colors and make colorkeys useless, if surf has no alpha channel a new image is returned, if it does have one the behavior depends on the copy parameter

pyparadigm.misc.make_transparent_by_mask(surf, mask, copy=True)[source]

Sets all voxels that are 1 in the mask to transparent. if surf has no alpha channel a new image is returned, if it does have one the behavior depends on the copy parameter

pyparadigm.misc.process_char(buffer: str, char: str, mappings={'\t': ' ', '\r': '\n'})[source]

This is a convinience method for use with EventListener.wait_for_unicode_char(). In most cases it simply appends char to buffer. Some replacements are done because presing return will produce ‘r’ but for most cases ‘n’ would be desireable. Also backspace cant just be added to a string either, therefore, if char is “u0008” the last character from buffer will be cut off. The replacement from ‘r’ to ‘n’ is done using the mappings argument, the default value for it also contains a mapping from ‘ ‘ to 4 spaces.

  • buffer (str) – the string to be updated
  • char (str) – the unicode character to be processed
  • mappings (dict) – a dict containing mappings

a new string

pyparadigm.misc.rgba(colorcode, alpha=255)[source]

Returns a pygame rgba color object, with the provided alpha value.

pyparadigm.misc.slide_show(slides, continue_handler)[source]

Displays one “slide” after another.

After displaying a slide, continue_handler is called without arguments. When continue_handler returns, the next slide is displayed.

Usage example

           partial(event_listener.wait_for_n_keypresses, pygame.K_RETURN))  

(partial is imported from the functools module.)

  • slides (iterable) – pygame.Surfaces to be displayed.
  • continue_handler (callable with arity 0.) – function, that returns when the next slide should be displayed.