]>
Commit | Line | Data |
---|---|---|
1 | import sys | |
2 | import pygame | |
3 | import helpers | |
4 | import threading | |
5 | ||
6 | pygame.mixer.pre_init(frequency = 44100) | |
7 | pygame.init() | |
8 | ||
9 | size = width, height = 913, 563 | |
10 | screen = pygame.display.set_mode(size) | |
11 | screen.fill((229, 228, 226)) | |
12 | ||
13 | draw_lock = helpers.Lock("draw") | |
14 | ||
15 | mapping = helpers.Mapping(screen, draw_lock) | |
16 | channel_number, open_files = helpers.parse_config(mapping) | |
17 | pygame.mixer.set_num_channels(channel_number) | |
18 | ||
19 | mapping.draw() | |
20 | ||
21 | draw_lock.acquire() | |
22 | pygame.display.flip() | |
23 | draw_lock.release() | |
24 | ||
25 | contexts = [ | |
26 | 'normal' | |
27 | ] | |
28 | ||
29 | context = 'normal' | |
30 | ||
31 | #### Normal workflow #### | |
32 | while 1: | |
33 | event = pygame.event.wait() | |
34 | ||
35 | if event.type == pygame.QUIT or ( | |
36 | event.type == pygame.KEYDOWN and | |
37 | event.mod == 4160 and | |
38 | event.key == pygame.K_c): | |
39 | for thread in threading.enumerate(): | |
40 | if thread.getName()[0:2] != "MS": | |
41 | continue | |
42 | thread.join() | |
43 | ||
44 | pygame.quit() | |
45 | sys.exit() | |
46 | ||
47 | if context == 'normal': | |
48 | if event.type == pygame.KEYDOWN: | |
49 | key = mapping.find_by_key_num(event.key) | |
50 | if key is not None and not key.disabled: | |
51 | threading.Thread(name = "MSKeyAction", target=key.do_actions, args = [screen]).start() | |
52 | threading.Thread(name = "MSClic", target=key.list_actions, args = [screen]).start() | |
53 | elif event.type == pygame.MOUSEBUTTONUP: | |
54 | key = mapping.find_by_collidepoint(pygame.mouse.get_pos()) | |
55 | if key is not None: | |
56 | threading.Thread(name = "MSClic", target=key.list_actions, args = [screen]).start() | |
57 | ||
58 | draw_lock.acquire() | |
59 | police = helpers.font(14) | |
60 | icon_police = helpers.font(14, font = "Symbola") | |
61 | ||
62 | surface = pygame.Surface((208, 250)).convert() | |
63 | surface.fill((250, 250, 250)) | |
64 | offset = 0 | |
65 | for music_file in open_files.values(): | |
66 | police.set_bold(False) | |
67 | if music_file.is_playing(): | |
68 | if music_file.is_paused(): | |
69 | icon = icon_police.render("⏸", True, (0,0,0)) | |
70 | else: | |
71 | icon = icon_police.render("⏵", True, (0,0,0)) | |
72 | police.set_bold(True) | |
73 | text = police.render(music_file.name, True, (0,0,0)) | |
74 | surface.blit(icon, (0, offset)) | |
75 | surface.blit(text, (20, offset)) | |
76 | offset += police.get_linesize() | |
77 | screen.blit(surface, (700, 308)) | |
78 | ||
79 | pygame.display.flip() | |
80 | draw_lock.release() |