Package _Framework :: Module SwitchModeSelectorComponent
[hide private]
[frames] | no frames]

Source Code for Module _Framework.SwitchModeSelectorComponent

 1  #Embedded file name: /Users/versonator/Hudson/live/Projects/AppLive/Resources/MIDI Remote Scripts/_Framework/SwitchModeSelectorComponent.py 
 2  from ModeSelectorComponent import ModeSelectorComponent 
 3  from ControlSurfaceComponent import ControlSurfaceComponent 
 4  from ButtonElement import ButtonElement 
 5   
6 -class SwitchModeSelectorComponent(ModeSelectorComponent):
7 """ Class that handles modes by enabling and disabling components """ 8
9 - def __init__(self):
10 ModeSelectorComponent.__init__(self) 11 self._components_per_mode = []
12
13 - def disconnect(self):
14 ModeSelectorComponent.disconnect(self) 15 self._components_per_mode = None
16
17 - def add_mode(self, components, button):
18 if not components != None: 19 raise AssertionError 20 if not isinstance(components, tuple): 21 raise AssertionError 22 raise button == None or isinstance(button, ButtonElement) or AssertionError 23 self._mode_index = len(self._modes_buttons) == 0 and 0 24 for component in components: 25 raise isinstance(component, ControlSurfaceComponent) or AssertionError 26 27 identify_sender = button != None and True 28 button.add_value_listener(self._mode_value, identify_sender) 29 self._modes_buttons.append(button) 30 self._components_per_mode.append(components) 31 self.update()
32
33 - def number_of_modes(self):
34 return len(self._components_per_mode)
35
36 - def update(self):
37 if not (len(self._modes_buttons) == 0 or len(self._modes_buttons) == len(self._components_per_mode)): 38 raise AssertionError 39 if not len(self._components_per_mode) > self._mode_index: 40 raise AssertionError 41 index = 0 42 active_components = None 43 active_components = self.is_enabled() and self._components_per_mode[self._mode_index] 44 for index in range(len(self._components_per_mode)): 45 if self._components_per_mode[index] != active_components: 46 if len(self._modes_buttons) == len(self._components_per_mode): 47 self._modes_buttons[index].turn_off() 48 for component in self._components_per_mode[index]: 49 component.set_enabled(False) 50 51 if active_components != None: 52 for component in active_components: 53 component.set_enabled(True) 54 55 len(self._modes_buttons) == len(self._components_per_mode) and self._modes_buttons[self._mode_index].turn_on()
56