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

Source Code for Module _Framework.DisplayDataSource

 1  #Embedded file name: /Users/versonator/Hudson/live/Projects/AppLive/Resources/MIDI Remote Scripts/_Framework/DisplayDataSource.py 
 2   
 3   
4 -class DisplayDataSource(object):
5 """ 6 Data object that is fed with a specific string and notifies a 7 observer via its update_callback. 8 """ 9
10 - def __init__(self, display_string = '', separator = None, *a, **k):
11 super(DisplayDataSource, self).__init__(*a, **k) 12 self._display_string = display_string 13 self._separator = separator 14 self._update_callback = None 15 self._represented_data_source = None 16 self._in_update = False
17
18 - def _get_separator(self):
19 return self._separator
20
21 - def _set_separator(self, separator):
22 if separator != self._separator: 23 self._separator = separator 24 self.update()
25 26 separator = property(_get_separator, _set_separator) 27
28 - def set_update_callback(self, update_callback):
29 if not (not update_callback or callable(update_callback)): 30 raise AssertionError 31 self._update_callback = update_callback 32 update_callback and self.update()
33
34 - def set_display_string(self, new_string):
35 if not new_string != None: 36 raise AssertionError 37 raise isinstance(new_string, str) or isinstance(new_string, unicode) or AssertionError 38 self._display_string = self._display_string != new_string and new_string 39 self.update()
40
41 - def connect_to(self, data_source):
42 if self._represented_data_source != None: 43 self._represented_data_source.set_update_callback(None) 44 self._represented_data_source = data_source 45 if self._represented_data_source != None: 46 self._represented_data_source.set_update_callback(self.update) 47 self.update()
48
49 - def disconnect_from(self, data_source):
50 raise data_source != None or AssertionError 51 raise data_source == self._represented_data_source or AssertionError 52 self.connect_to(None)
53
54 - def update(self):
55 if not not self._in_update: 56 raise AssertionError 57 self._in_update = True 58 self._update_callback != None and self._update_callback() 59 self._in_update = False
60
61 - def display_string(self):
62 return self._display_string if self._represented_data_source == None else self._represented_data_source.display_string()
63