]>
Commit | Line | Data |
---|---|---|
d8ab67c7 | 1 | import sys |
189bf90c | 2 | import pygame |
189bf90c | 3 | import helpers |
e7f8dab4 | 4 | import threading |
189bf90c | 5 | |
8f88a3e4 | 6 | pygame.mixer.pre_init(frequency = 44100) |
189bf90c IB |
7 | pygame.init() |
8 | ||
9 | size = width, height = 1024, 600 | |
189bf90c | 10 | screen = pygame.display.set_mode(size) |
ba9ea93a IB |
11 | screen.fill((250, 250, 250)) |
12 | ||
13 | draw_lock = helpers.Lock("draw") | |
189bf90c | 14 | |
ba9ea93a | 15 | mapping = helpers.Mapping(screen, draw_lock) |
e7f8dab4 | 16 | helpers.parse_config(mapping) |
8f88a3e4 | 17 | |
e7f8dab4 | 18 | mapping.draw() |
189bf90c | 19 | |
ba9ea93a | 20 | draw_lock.acquire() |
189bf90c | 21 | pygame.display.flip() |
ba9ea93a | 22 | draw_lock.release() |
189bf90c IB |
23 | |
24 | contexts = [ | |
25 | 'normal' | |
26 | ] | |
27 | ||
28 | context = 'normal' | |
29 | ||
23b7e0e5 | 30 | #### Normal workflow #### |
189bf90c IB |
31 | while 1: |
32 | event = pygame.event.wait() | |
e7f8dab4 | 33 | |
189bf90c IB |
34 | if event.type == pygame.QUIT or ( |
35 | event.type == pygame.KEYDOWN and | |
36 | event.mod == 4160 and | |
37 | event.key == pygame.K_c): | |
be27763f | 38 | for thread in threading.enumerate(): |
23b7e0e5 | 39 | if thread.getName()[0:2] != "MS": |
be27763f IB |
40 | continue |
41 | thread.join() | |
42 | ||
189bf90c IB |
43 | pygame.quit() |
44 | sys.exit() | |
45 | ||
46 | if context == 'normal': | |
d8ab67c7 | 47 | if event.type == pygame.KEYDOWN: |
e7f8dab4 | 48 | key = mapping.find_by_key_num(event.key) |
d8ab67c7 | 49 | if key is not None: |
23b7e0e5 | 50 | threading.Thread(name = "MSKeyAction", target=key.do_actions).start() |
d8ab67c7 | 51 | elif event.type == pygame.MOUSEBUTTONUP: |
e7f8dab4 | 52 | key = mapping.find_by_collidepoint(pygame.mouse.get_pos()) |
d8ab67c7 | 53 | if key is not None: |
23b7e0e5 | 54 | threading.Thread(name = "MSClic", target=key.list_actions, args = [screen]).start() |
189bf90c | 55 | |
ba9ea93a | 56 | draw_lock.acquire() |
189bf90c | 57 | pygame.display.flip() |
ba9ea93a | 58 | draw_lock.release() |
189bf90c | 59 | |
23b7e0e5 IB |
60 | #### In Ipython #### |
61 | # for thread in threading.enumerate(): | |
62 | # if thread.getName()[0:2] != "MS": | |
63 | # continue | |
64 | # thread.join() |