-
Notifications
You must be signed in to change notification settings - Fork 43
/
using_ui_form.py
78 lines (62 loc) · 2.29 KB
/
using_ui_form.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import pygame
import pygame_gui
from pygame_gui import UI_FORM_SUBMITTED
from pygame_gui.elements import UIButton, UIForm, UIDropDownMenu
pygame.init()
pygame.display.set_caption("UI Form Example")
window_surface = pygame.display.set_mode((800, 600))
background = pygame.Surface((800, 600))
background.fill(pygame.Color("#000000"))
manager = pygame_gui.UIManager((800, 600))
test_rect = pygame.Rect(40, 50, 700, 500)
questionnaire = {
"Just enter one character:": "character",
"Perhaps some more text:": "short_text",
"Or go wild!": "long_text",
"how about a section?": {
"do you like it?": "boolean",
"well, here, section-ception": {
"do you like it?": "boolean",
"well, here, section-ception": {"finally...": "integer"},
},
},
"Enter a float:": "decimal(default=0.01)",
"You *must* enter something here:": "short_text('here', True)",
"Let's make this form longer:": "long_text",
"let's try a button": UIButton(pygame.Rect(100, 100, 100, 100), "button"),
"Try entering a password!:": "password",
"A dropdown appeared!": UIDropDownMenu(
["foo", "foo", "foo", "foo", "foo", "foo", "foo", "foo", "foo", "foo"],
"foo",
pygame.Rect(100, 100, 100, 100),
),
}
form_test = UIForm(test_rect, questionnaire, manager)
print(form_test.combined_element_ids)
print(form_test.get_container().combined_element_ids)
print(form_test.parsed_questionnaire["how about a section?"].combined_element_ids)
print(
form_test.parsed_questionnaire["how about a section?"]
.parsed_questionnaire["well, here, section-ception"]
.combined_element_ids
)
clock = pygame.time.Clock()
is_running = True
pressed = False
element = None
while is_running:
time_delta = clock.tick(30) / 1000.0
for event in pygame.event.get():
if event.type == pygame.QUIT:
is_running = False
elif event.type == pygame_gui.UI_BUTTON_PRESSED:
print(event.ui_element.most_specific_combined_id)
pressed = False
element = None
elif event.type == UI_FORM_SUBMITTED:
print(event.form_values)
manager.process_events(event)
manager.update(time_delta)
window_surface.blit(background, (0, 0))
manager.draw_ui(window_surface)
pygame.display.update()