-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwidgets.py
64 lines (56 loc) · 1.84 KB
/
widgets.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import text
import typing
import pygame
import constants
class PushButton(text.String):
"""
Push button sprite.
"""
def __init__(self,
left: int, bottom: int,
alphabet: dict,
line: str,
group: pygame.sprite.Group = None,
n: int = 1,
surface_size: typing.Tuple[int, int] = constants.WINDOW_SIZE,
color: pygame.Color = None,
indent: typing.Tuple[int, int] = (0, 0),
*extra: pygame.Surface
) -> None:
"""
Initialization of the push button.
:param left: left x border.
:param bottom: lower border y coordinate.
:param alphabet: alphabet.
:param line: string which to show.
:param group: sprite group where to put the sprite.
:param n: scaling factor.
:param surface_size: surface_size.
:param indent: indent from left border and lower border.
:param extra: some other images.
"""
self.extra = extra
super().__init__(left, bottom, alphabet, line, group, n, surface_size, indent)
self.color = color
def show(self, indent=None) -> None:
"""
Renders the string.
:param indent: indent from left border and lower border.
"""
ix, iy = super().show(indent)
for img in self.extra:
width, height = img.get_rect().size
self.image.blit(img, (ix, self.rect.height - iy - height))
ix += width
def press(self) -> None:
"""
Presses the push button.
"""
self.image.fill(self.color)
self.show()
def release(self) -> None:
"""
Releases the push button.
"""
self.image.fill(constants.TRANSPARENT_COLOR)
self.show()