1 from .rounded_rect
import *
17 default_outer_color
= (120, 120, 120)
18 lighter_outer_color
= (200, 200, 200)
19 default_inner_color
= (255, 255, 255)
20 mapped_inner_color
= ( 0, 255, 0)
21 mapped_unready_inner_color
= (255, 165, 0)
23 def __init__(self
, mapping
, draw_lock
, key_name
, key_sym
, top
, left
, width
= 48, height
= 48, disabled
= False):
24 self
.draw_lock
= draw_lock
25 self
.mapping
= mapping
26 self
.key_name
= key_name
27 self
.key_sym
= key_sym
29 if isinstance(top
, str):
30 self
.top
= self
.row_positions
[top
]
38 self
.bottom
= self
.top
+ self
.height
39 self
.right
= self
.left
+ self
.width
41 self
.rect
= (self
.left
, self
.top
, self
.right
, self
.bottom
)
42 self
.position
= (self
.left
, self
.top
)
45 self
.outer_color
= self
.lighter_outer_color
48 self
.outer_color
= self
.default_outer_color
51 self
.inner_color
= self
.default_inner_color
54 def square(self
, all_actions_ready
):
55 if self
.has_actions():
57 self
.inner_color
= self
.mapped_inner_color
59 self
.inner_color
= self
.mapped_unready_inner_color
61 return RoundedRect((0, 0, self
.width
, self
.height
),
62 self
.outer_color
, self
.inner_color
, self
.linewidth
)
64 def collidepoint(self
, position
):
65 return self
.surface
.get_rect().collidepoint(
66 position
[0] - self
.position
[0],
67 position
[1] - self
.position
[1]
70 def draw(self
, background_surface
):
71 self
.draw_lock
.acquire()
72 all_actions_ready
= self
.all_actions_ready()
74 self
.surface
= self
.square(all_actions_ready
).surface()
76 if getattr(sys
, 'frozen', False):
77 police
= pygame
.font
.Font(sys
._MEIPASS
+ "/Ubuntu-Regular.ttf", 14)
79 police
= pygame
.font
.Font("Ubuntu-Regular.ttf", 14)
81 text
= police
.render(self
.key_sym
, True, (0,0,0))
82 self
.surface
.blit(text
, (5,5))
83 background_surface
.blit(self
.surface
, self
.position
)
84 self
.draw_lock
.release()
86 return not all_actions_ready
88 def poll_redraw(self
, background
):
91 if self
.all_actions_ready():
96 def has_actions(self
):
97 return len(self
.actions
) > 0
99 def all_actions_ready(self
):
100 return all(action
.ready() for action
in self
.actions
)
102 def add_action(self
, action_name
, **arguments
):
103 self
.actions
.append(Action(action_name
, self
, **arguments
))
105 def do_actions(self
):
106 print("running actions for {}".format(self
.key_sym
))
107 start_time
= time
.time()
108 self
.mapping
.start_running(self
, start_time
)
109 for action
in self
.actions
:
110 if self
.mapping
.keep_running(self
, start_time
):
113 self
.mapping
.finished_running(self
, start_time
)
115 def list_actions(self
, surface
):
117 print("bouh", self
.key_sym
)
118 surface
.fill((255, 0, 0))