diff options
Diffstat (limited to 'interface/channelbank.py')
-rwxr-xr-x | interface/channelbank.py | 119 |
1 files changed, 77 insertions, 42 deletions
diff --git a/interface/channelbank.py b/interface/channelbank.py index c9d971f..c7c7409 100755 --- a/interface/channelbank.py +++ b/interface/channelbank.py @@ -1,5 +1,7 @@ import curses +from .globals import CURSES_LOCK + _progress = [" "] for i in range(8): pos = i // 2 @@ -30,13 +32,15 @@ class ChannelView: height = 3 def _refresh_channel(self): - self.win.addstr(0, 0, "%03d.%03d" % (self.c.f.id, self.c.id), curses.A_UNDERLINE if self._active else 0) - self.win.noutrefresh() + with CURSES_LOCK: + self.win.addstr(0, 0, "%03d.%03d" % (self.c.f.id, self.c.id), curses.A_UNDERLINE if self._active else 0) + self.win.refresh() def _refresh_value(self): - self.win.addstr(1, 0, get_progress(self._value)) - self.win.addstr(1, 4, "%03d" % self._value, (curses.A_ITALIC|curses.A_BOLD if self._held else 0)) - self.win.noutrefresh() + with CURSES_LOCK: + self.win.addstr(1, 0, get_progress(self._value)) + self.win.addstr(1, 4, "%03d" % self._value, (curses.A_ITALIC|curses.A_BOLD if self._held else 0)) + self.win.refresh() def refresh(self): self._refresh_value() @@ -75,8 +79,9 @@ class ChannelView: def set_pos(self, y, x): self.y = self.y self.x = self.x - self.win.noutrefresh() - self.win.mvwin(y, x) + with CURSES_LOCK: + self.win.refresh() + self.win.mvwin(y, x) self.refresh() def __init__(self, root, c, y, x, value=0, held=False, active=False): @@ -89,7 +94,8 @@ class ChannelView: self.x = x self.root = root - self.win = root.subpad(self.height, self.width, self.y, self.x) + with CURSES_LOCK: + self.win = root.subpad(self.height, self.width, self.y, self.x) self._refresh_value() self._refresh_channel() @@ -100,45 +106,50 @@ class ChannelBank: raise NotImplementedError("Screen size to small") - if (height, width) != (self._height, self._width): - self.win.erase() - self.win.noutrefresh() + with CURSES_LOCK: + if (height, width) != (self._height, self._width): + self.win.erase() + self.win.refresh() - self.win.resize(height, width) - self.win.redrawwin() + self.win.resize(height, width) + self.win.redrawwin() - self._height = height - self._width = width - self._refresh_scope() - self.win.border() - self.win.noutrefresh() + self._height = height + self._width = width + self._refresh_scope() + self._put_title() + self.win.refresh() def _refresh_scope(self): - self.win.erase() - ncv = {} - cols = (self._width-4)//ChannelView.width - with open("out.txt", 'w+') as f: - f.write(str(cols)+'\n') - self._sscope = sorted(self.scope, key=lambda a: (a.f.id, a.id)) - for n, c in enumerate(self._sscope): - row = (n // cols)*ChannelView.height + 1 - col = (n % cols)*ChannelView.width + 2 - if c in self._cv: - active = self._cv[c].active - held = self._cv[c].held - value = self._cv[c].value - else: - active = False - held = False - value = 0 - ncv[c] = ChannelView(self.win, c, row, col, value=value, active=active, held=held) - self._cv = ncv + with CURSES_LOCK: + self.win.erase() + ncv = {} + cols = (self._width-4)//ChannelView.width + with open("out.txt", 'w+') as f: + f.write(str(cols)+'\n') + self._sscope = sorted(self.scope, key=lambda a: (a.f.id, a.id)) + for n, c in enumerate(self._sscope): + row = (n // cols)*ChannelView.height + 1 + col = (n % cols)*ChannelView.width + 2 + if c in self._cv: + active = self._cv[c].active + held = self._cv[c].held + value = self._cv[c].value + else: + active = False + held = False + value = 0 + ncv[c] = ChannelView(self.win, c, row, col, value=value, active=active, held=held) + self._cv = ncv + self._put_title() + self.win.refresh() def set_pos(self, y, x): if (y, x) != (self._y, self._x): - self.win.mvwin(y, x) - self.win.border() - self.win.noutrefresh() + with CURSES_LOCK: + self.win.mvwin(y, x) + self._put_title() + self.win.refresh() def set_active(self, channels, v=True): for c in channels: @@ -151,12 +162,36 @@ class ChannelBank: def set_values(self, cv): for c, v in cv: self._cv[c].value = v + + def set_scope(self, scope): + self.scope = frozenset(scope) + self._refresh_scope() + + @property + def title(self): + return self._title + + def _put_title(self): + self.win.border() + pos = min(self._width-2-len(self._title), (3*self._width)//4 - (len(self._title) // 2)) + self.win.addstr(self._height-1, pos, self._title) + + @title.setter + def title(self, v): + if v != self._title: + with CURSES_LOCK: + self._title = v + self.win.border() + self._put_title() + self.win.refresh() def __init__(self, y, x, height, width, scope=frozenset()): - self.win = curses.newwin(height, width, y, x) - self.win.keypad(True) + with CURSES_LOCK: + self.win = curses.newwin(height, width, y, x) + self.win.keypad(True) self.scope = frozenset(scope) self._sscope = [] + self._title = "Channels" self._cv = {} self._height = height self._width = width |