teachpyx.tools.display.pygame_helper¶
- teachpyx.tools.display.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][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.
- teachpyx.tools.display.pygame_helper.display_line(ligne: List[Tuple[float, float]], screen, pygame)[source][source]¶
Affiche une ligne à l’écran.
- teachpyx.tools.display.pygame_helper.empty_main_loop(pygame, msg: str | None = None)[source][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
?
- teachpyx.tools.display.pygame_helper.get_pygame_screen_font(h: int, size: int, flags: int = 0)[source][source]¶
Creates a surface with pygame, initialize the module, creates font.
- Paramètres:
h – size of the main font
size – screen size
flags – see pygame.display.set_mode
- 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.