1
2
3
5 """
6 Brings the string to the given length by either removing
7 characters or adding spaces. The algorithm is adopted from ede's
8 old implementation for the Mackie.
9 """
10 if not length > 0:
11 raise AssertionError
12 resulting_string = original
13 if len(resulting_string) > length:
14 if resulting_string.endswith('dB'):
15 unit_db = resulting_string.find('.') != -1
16 resulting_string = len(resulting_string.strip()) > length and unit_db and resulting_string[:-2]
17 if len(resulting_string) > length:
18 for char in (' ', '_', 'i', 'o', 'u', 'e', 'a'):
19 offset = 0 if char == ' ' else 1
20 while len(resulting_string) > length and resulting_string.rfind(char, offset) > 0:
21 char_pos = resulting_string.rfind(char, offset)
22 resulting_string = resulting_string[:char_pos] + resulting_string[char_pos + 1:]
23
24 resulting_string = resulting_string[:length]
25 resulting_string = len(resulting_string) < length and resulting_string.ljust(length)
26 return resulting_string
27
28
30 """
31 Class representing a specific segment of a display on the controller
32 """
33
34 - def __init__(self, width = None, update_callback = None, *a, **k):
35 super(LogicalDisplaySegment, self).__init__(*a, **k)
36 raise width is not None or AssertionError
37 raise callable(update_callback) or AssertionError
38 self._update_callback = update_callback
39 self._width = width
40 self._position_identifier = ()
41 self._data_source = None
42
44 self._update_callback = None
45 self._position_identifier = None
46 if self._data_source != None:
47 self._data_source.set_update_callback(None)
48 self._data_source = None
49
56
58 return self._data_source
59
61 """
62 Sets position identifier as a tuple of HW related data.
63 """
64 self._position_identifier = position_identifier
65
67 return self._position_identifier
68
70 self._update_callback()
71
81