-import sys
-import pygame
-
-class Key:
- row_positions = {
- 'first': 0,
- 'second': 50,
- 'third': 100,
- 'fourth': 150,
- 'fifth': 200,
- 'sixth': 250,
- }
-
- default_outer_color = (120, 120, 120)
- lighter_outer_color = (200, 200, 200)
- default_inner_color = (255, 255, 255)
- mapped_inner_color = ( 0, 255, 0)
- mapped_unready_inner_color = ( 0, 255, 0, 100)
-
- def __init__(self, mapping, draw_lock, key_name, key_sym, top, left, width = 48, height = 48, disabled = False):
- self.draw_lock = draw_lock
- self.mapping = mapping
- self.key_name = key_name
- self.key_sym = key_sym
-
- if isinstance(top, str):
- self.top = self.row_positions[top]
+import threading
+from transitions.extensions import HierarchicalMachine as Machine
+
+class Key(ButtonBehavior, Widget):
+ STATES = [
+ 'initial',
+ 'configuring',
+ 'configured',
+ 'loading',
+ 'failed',
+ {
+ 'name': 'loaded',
+ 'children': [
+ 'no_config',
+ 'no_actions',
+ 'running',
+ 'protecting_repeat'
+ ]
+ }
+ ]
+
+ TRANSITIONS = [
+ {
+ 'trigger': 'configure',
+ 'source': 'initial',
+ 'dest': 'configuring'
+ },
+ {
+ 'trigger': 'fail',
+ 'source': 'configuring',
+ 'dest': 'failed',
+ 'after': 'key_loaded_callback'
+ },
+ {
+ 'trigger': 'success',
+ 'source': 'configuring',
+ 'dest': 'configured',
+ 'after': 'load'
+ },
+ {
+ 'trigger': 'no_config',
+ 'source': 'configuring',
+ 'dest': 'loaded_no_config',
+ 'after': 'key_loaded_callback'
+ },
+ {
+ 'trigger': 'load',
+ 'source': 'configured',
+ 'dest': 'loading'
+ },
+ {
+ 'trigger': 'fail',
+ 'source': 'loading',
+ 'dest': 'failed',
+ 'after': 'key_loaded_callback'
+ },
+ {
+ 'trigger': 'success',
+ 'source': 'loading',
+ 'dest': 'loaded',
+ 'after': 'key_loaded_callback'
+ },
+ {
+ 'trigger': 'no_actions',
+ 'source': 'loading',
+ 'dest': 'loaded_no_actions',
+ 'after': 'key_loaded_callback'
+ },
+ {
+ 'trigger': 'reload',
+ 'source': ['loaded','failed'],
+ 'dest': 'configuring',
+ 'after': 'key_loaded_callback'
+ },
+ {
+ 'trigger': 'run',
+ 'source': 'loaded',
+ 'dest': 'loaded_running',
+ 'after': ['run_actions', 'finish'],
+ # if a child, like loaded_no_actions, has no transitions, then it
+ # is bubbled to the parent, and we don't want that.
+ 'conditions': ['is_loaded']
+ },
+ {
+ 'trigger': 'finish',
+ 'source': 'loaded_running',
+ 'dest': 'loaded_protecting_repeat'
+ },
+ {
+ 'trigger': 'repeat_protection_finished',
+ 'source': 'loaded_protecting_repeat',
+ 'dest': 'loaded'
+ },
+ ]
+
+ key_sym = StringProperty(None)
+ custom_color = ListProperty([0, 1, 0])
+ description_title = StringProperty("")
+ description = ListProperty([])
+ state = StringProperty("")
+
+ def get_alias_line_color(self):
+ if self.is_loaded_running():
+ return [0, 0, 0, 1]