-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathSpecialModesComponent.py
More file actions
54 lines (41 loc) · 1.85 KB
/
Copy pathSpecialModesComponent.py
File metadata and controls
54 lines (41 loc) · 1.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#Embedded file name: /Users/versonator/Jenkins/live/output/mac_64_static/Release/midi-remote-scripts/Launchpad_Pro/SpecialModesComponent.py
from _Framework.ModesComponent import ReenterBehaviour, ModesComponent
class SpecialModesComponent(ModesComponent):
def on_enabled_changed(self):
super(SpecialModesComponent, self).on_enabled_changed()
if not self.is_enabled():
self._last_selected_mode = None
class SpecialReenterBehaviour(ReenterBehaviour):
"""
When a mode with this behaviour is reentered, enters on_reenter_mode instead
"""
def __init__(self, mode_name = None, *a, **k):
super(ReenterBehaviour, self).__init__(*a, **k)
self._mode_name = mode_name
def press_immediate(self, component, mode):
was_active = component.selected_mode == mode
super(ReenterBehaviour, self).press_immediate(component, mode)
if was_active:
if self._mode_name is not None and component.get_mode(self._mode_name):
component.push_mode(self._mode_name)
component.pop_unselected_modes()
class CancelingReenterBehaviour(SpecialReenterBehaviour):
def __init__(self, *a, **k):
super(CancelingReenterBehaviour, self).__init__(*a, **k)
self._reenter_mode_active = False
def press_immediate(self, component, mode):
was_active = component.selected_mode == mode
super(CancelingReenterBehaviour, self).press_immediate(component, mode)
if was_active:
self._reenter_mode_active = True
def release_immediate(self, component, mode):
super(CancelingReenterBehaviour, self).release_immediate(component, mode)
self._return(component, mode)
def release_delayed(self, component, mode):
super(CancelingReenterBehaviour, self).release_delayed(component, mode)
self._return(component, mode)
def _return(self, component, mode):
if self._reenter_mode_active:
component.push_mode(mode)
component.pop_unselected_modes()
self._reenter_mode_active = False