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

Source Code for Module _Framework.ScrollComponent

  1  #Embedded file name: /Users/versonator/Hudson/live/Projects/AppLive/Resources/MIDI Remote Scripts/_Framework/ScrollComponent.py 
  2  from _Framework.ControlSurfaceComponent import ControlSurfaceComponent 
  3  from _Framework.SubjectSlot import subject_slot 
  4  from _Framework import Task 
  5  from _Framework import Defaults 
6 7 -class Scrollable(object):
8 """ 9 Abstract interface for an object that can be scrolled in discreet 10 steps in one dimension. 11 """ 12
13 - def can_scroll_up(self):
14 return False
15
16 - def can_scroll_down(self):
17 return False
18
19 - def scroll_up(self):
20 pass
21
22 - def scroll_down(self):
23 pass
24
25 26 -class ScrollComponent(ControlSurfaceComponent, Scrollable):
27 """ 28 A component that handles scrolling behavior over a Scrollable 29 with a pair of buttons. 30 """ 31 is_private = True 32 scrolling_delay = Defaults.MOMENTARY_DELAY 33 scrolling_step_delay = 0.1 34 default_scrollable = Scrollable() 35 _scrollable = default_scrollable 36
37 - def __init__(self, scrollable = None, *a, **k):
38 super(ScrollComponent, self).__init__(*a, **k) 39 self._scroll_task_up = self._make_scroll_task(self._do_scroll_up) 40 self._scroll_task_down = self._make_scroll_task(self._do_scroll_down) 41 if scrollable != None: 42 self.scrollable = scrollable
43
44 - def _make_scroll_task(self, scroll_step):
45 task = self._tasks.add(Task.sequence(Task.wait(self.scrolling_delay), Task.loop(Task.wait(self.scrolling_step_delay), Task.run(scroll_step)))) 46 task.kill() 47 return task
48
49 - def _get_scrollable(self):
50 return self._scrollable
51
52 - def _set_scrollable(self, scrollable):
53 self._scrollable = scrollable 54 self.update()
55 56 scrollable = property(_get_scrollable, _set_scrollable) 57
58 - def can_scroll_up(self):
59 return self._scrollable.can_scroll_up()
60
61 - def can_scroll_down(self):
62 return self._scrollable.can_scroll_down()
63
64 - def scroll_up(self):
65 return self._scrollable.scroll_up()
66
67 - def scroll_down(self):
68 return self._scrollable.scroll_down()
69
70 - def set_scroll_up_button(self, button):
73
74 - def set_scroll_down_button(self, button):
77
78 - def update(self):
81
82 - def _update_scroll_up_button(self):
83 button = self._on_scroll_up_value.subject 84 if self.is_enabled() and button: 85 if button.is_momentary(): 86 is_pressed = button.is_pressed() 87 can_scroll_up = self.can_scroll_up() 88 can_scroll_up and button.set_light('Pressed' if is_pressed else 'Enabled') 89 else: 90 button.turn_off()
91
93 button = self._on_scroll_down_value.subject 94 if self.is_enabled() and button: 95 if button.is_momentary(): 96 is_pressed = button.is_pressed() 97 can_scroll_down = self.can_scroll_down() 98 can_scroll_down and button.set_light('Pressed' if is_pressed else 'Enabled') 99 else: 100 button.turn_off()
101 102 @subject_slot('value')
103 - def _on_scroll_up_value(self, value):
104 self._on_scroll_value(value, self._on_scroll_up_value.subject, self._do_scroll_up, self._scroll_task_up)
105 106 @subject_slot('value')
107 - def _on_scroll_down_value(self, value):
108 self._on_scroll_value(value, self._on_scroll_down_value.subject, self._do_scroll_down, self._scroll_task_down)
109
110 - def _do_scroll_up(self):
114
115 - def _do_scroll_down(self):
119
120 - def _on_scroll_value(self, value, button, scroll_step, scroll_task):
121 if self.is_enabled(): 122 is_momentary = button.is_momentary() 123 if not not self._scroll_task_up.is_killed: 124 is_scrolling = not self._scroll_task_down.is_killed 125 if not is_scrolling or not is_momentary: 126 scroll_step() 127 scroll_task.kill() 128 is_momentary and value and scroll_task.restart() 129 self._ensure_scroll_one_direction() 130 self.update()
131
133 scroll_up_button = self._on_scroll_up_value.subject 134 scroll_down_button = self._on_scroll_down_value.subject 135 if scroll_up_button and scroll_up_button.is_pressed() and scroll_down_button and scroll_down_button.is_pressed(): 136 self._scroll_task_up.pause() 137 self._scroll_task_down.pause() 138 else: 139 self._scroll_task_up.resume() 140 self._scroll_task_down.resume()
141