def update_text(self): x, y = self.position time = self.main.status.get('builds_time', timedelta(0)) time -= timedelta(microseconds=time.microseconds) ping = datetime.utcnow() - self.main.last_message ping -= timedelta(microseconds=ping.microseconds) text = { 0: 'Last Ping: {}s'.format(int(ping.total_seconds())), 1: 'Disk Free: {}%'.format(100 * self.main.status.get('disk_free', 0) // self.main.status.get('disk_size', 1)), 2: 'Queue Size: {}'.format(self.main.status.get('builds_pending', 0)), 3: 'Builds/Hour: {}'.format( self.main.status.get('builds_last_hour', 0)), 4: 'Build Time: {}'.format(time), 5: 'Build Size: {}'.format( format_size(self.main.status.get('builds_size', 0))), }[x] self.text = array( draw_text(text, foreground=Color('gray'), padding=(8, 0, 8, 1))) # Ensure the text doesn't "skip" while we're rendering it by starting # the offset cycle at the current position of the offset cycle (unless # it's out of range) last = next(self.offset) if last >= self.text.shape[1] - 8: last = 0 self.offset = iter( cycle(chain(range(last, self.text.shape[1] - 8), range(last))))
def update_text(self): x, y = self.position text = { 0: 'Quit?', 1: 'Reboot?', 2: 'Off?', }[x] self.text = array( draw_text(text, foreground=Color('red'), padding=(8, 0, 8, 1))) self.offset = iter(cycle(range(self.text.shape[1] - 8)))
def update_text(self): x, y = self.position text = { 0: 'Quit?', 1: 'Terminate?', }[x] self.text = array( draw_text(text, foreground=Color('red'), padding=(8, 0, 8, 1))) self.offset = iter( cycle(chain(range(8, self.text.shape[1] - 8), range(8))))
def thermometer(offset, reading): t = max(0, min(50, reading.temperature)) / 50 * 64 screen = array([ Color('red') if i < int(t) else Color('red') * Red(t - int(t)) if i < t else Color('black') for i in range(64) ]) screen = np.flipud(screen) text = image_to_rgb(draw_text(int(round(reading.temperature)), 'small.pil', foreground=Color('gray'), padding=(0, 0, 0, 3))) screen[:text.shape[0], :text.shape[1]] += text return screen.clip(0, 1)
def barometer(offset, reading): p = (max(950, min(1050, reading.pressure)) - 950) / 100 * 64 screen = array([ Color('green') if i < int(p) else Color('green') * Green(p - int(p)) if i < p else Color('black') for i in range(64) ]) screen = np.flipud(screen) text = image_to_rgb(draw_text(int(round(reading.pressure)), 'small.pil', foreground=Color('gray'), padding=(0, 0, 8, 3))) screen[:text.shape[0], :] += text[:, offset:offset + 8] return screen.clip(0, 1)
def hygrometer(offset, reading): h = reading.humidity / 100 * 64 screen = array([ Color('#008') if i < int(h) else Color('#008') * Blue(h - int(h)) if i < h else Color('black') for i in range(64) ]) screen = np.flipud(screen) text = image_to_rgb(draw_text('^^' if reading.humidity > 99 else int(round(reading.humidity)), 'small.pil', foreground=Color('gray'), padding=(0, 0, 0, 3))) screen[:text.shape[0], :text.shape[1]] += text return screen.clip(0, 1)
def update_text(self): x, y = self.position text, fg, bg = { 0: (self.slave.label, 'white', None), 1: ('ABI:' + self.slave.abi, 'white', None), 2: (self.slave.status, 'white', None), 3: ('Kill?', 'red', 'black'), }[x] self.text = array( draw_text(text, foreground=Color(fg), background=self.slave.color if bg is None else Color(bg), padding=(8, 0, 8, 1))) self.offset = iter( cycle(chain(range(8, self.text.shape[1] - 8), range(8))))
def _update_text(self, *, restart=True): self.text = array( draw_text(self.selected.label, font='small.pil', padding=(8, 3, 8, 0))) if restart or self.offset is None: last = 0 else: # Ensure the text doesn't "skip" while we're rendering it by # starting the offset cycle at the current position of the offset # cycle (unless it's out of range) last = next(self.offset) if last >= self.text.shape[1] - 8: last = 0 self.offset = iter( cycle(chain(range(last, self.text.shape[1] - 8), range(last))))
def __iter__(self): waiting = array( draw_text('Waiting for connection', padding=(8, 0, 8, 1))) for offset in cycle(range(waiting.shape[1] - 8)): if self.connected: break yield waiting[:, offset:offset + 8] buf = array(Color('black')) pulse = iter(bounce(range(10))) while True: x, y = self.position with self.watch_selection(): self.slaves.prune() buf[:] = Color('black') self._render_stats(buf) self._render_slaves(buf, next(pulse)) yield buf
def _update_text(self): label = [ 'Last Seen', 'Builds Queue/Build Time', 'Disk Used', 'Swap Used', 'Mem Used', 'CPU Temperature', 'Load Avg', 'Builds Done/Clock Skew', ][self.position[0]] self.text = array( draw_text(label, font='small.pil', foreground=Color('white'), background=Color('black'), padding=(8, 3, 8, 0))) self.offset = iter(cycle(range(self.text.shape[1] - 8)))