module helpers.pygame_helper

Short summary

module ensae_teaching_cs.helpers.pygame_helper

pygame helpers

The module pygame is not imported in this module but sent to every function as a parameter to avoid importing the module if not needed.

source on GitHub

Functions

function truncated documentation
build_diff_image Builds an image to show a difference between two lists, we assume these list contain distinct items.
empty_main_loop Removes all events in the main loop, a mouse click make the program halt, another click makes it start again.
get_pygame_screen_font Creates a surface with pygame, initialize the module, creates font.
wait_event The function waits for an event, a

Documentation

pygame helpers

The module pygame is not imported in this module but sent to every function as a parameter to avoid importing the module if not needed.

source on GitHub

ensae_teaching_cs.helpers.pygame_helper.build_diff_image(pygame, screen, h, maxw, seq1=None, seq2=None, diff=None, fonts=None, bars=None, colors=None, progress=None, prev_bars=None)[source]

Builds an image to show a difference between two lists, we assume these list contain distinct items.

Paramètres:
  • pygame – module pygame
  • screen – screen (pygame surface)
  • h – height of a line
  • maxw – width of the screen
  • seq1 – list 1 (can be None)
  • seq2 – list 2 (cannot be None)
  • diff – difference (object SequenceMatcher)
  • fonts – dictionary of fonts with keys 'font', 'font_small', 'font_half'
  • bars – each item of sequence 2 can be associated to a width (in [0, 1])
  • colors – dictionary of colors (see below)
  • progress – draws the progress between two list
  • prev_bars – previous width

Colors:

  • black: no change
  • blue: new
  • red: deleted
  • green: vert
  • yellow: bars

When progress is not None, the picture is a kind of average between the previous position and the new one. When a suggestion moves from p1 to p2, it defines a circle. The result looks like this.

source on GitHub

ensae_teaching_cs.helpers.pygame_helper.empty_main_loop(pygame)[source]

Removes all events in the main loop, a mouse click make the program halt, another click makes it start again.

Paramètres:pygame – module pygame
Renvoie:event pygame.QUIT?

source on GitHub

ensae_teaching_cs.helpers.pygame_helper.get_pygame_screen_font(h, size, flags=0)[source]

Creates a surface with pygame, initialize the module, creates font.

Paramètres:
Renvoie:

pygame, screen, dictionary of fonts

The dictionary of fonts contains three fonts of size h, 3h/4, 5h/6.

This function leaves file still opened and generates warnings. Parameter flag can be useful if you run the function just to test that it is working and the result does not need to be seen.

source on GitHub

ensae_teaching_cs.helpers.pygame_helper.wait_event(pygame)[source]

The function waits for an event, a

Paramètres:pygame – module pygame

source on GitHub