def update_back(self): x, y = self.position if x == 0: ping = 64 * max(timedelta(0), min(timedelta(seconds=30), datetime.utcnow() - self.main.last_message)).total_seconds() / 30 self.back = array([ c if i <= ping else Color('black') for i in range(64) for c in (self.ping_grad[min(63, int(ping))],) ]) self.back = np.flipud(self.back) elif x == 1: disk = ( 64 * self.main.status.get('disk_free', 0) / self.main.status.get('disk_size', 1)) self.back = array([ c if i < int(disk) else c * Lightness(disk - int(disk)) if i < disk else Color('black') for i in range(64) for c in (self.disk_grad[min(63, int(disk))],) ]) self.back = np.flipud(self.back) elif x == 2: pkgs = min( 64, self.main.status.get('builds_pending', 0)) self.back = array([ Color('blue') if i < pkgs else Color('black') for i in range(64) ]) self.back = np.flipud(self.back) elif x == 3: bph = ( 64 * self.main.status.get('builds_last_hour', 0) / 1000) self.back = array([ Color('blue') if i < int(bph) else Color('blue') * Lightness(bph - int(bph)) if i < bph else Color('black') for i in range(64) ]) self.back = np.flipud(self.back) else: self.back = array(Color('black'))
def _update_graph(self): self.graph = array(shape=(5, 8)) for x, stat in zip(reversed(range(8)), self.selected.history()): if stat is None: continue # Scale the value to the vertical size value = stat.value * self.graph.shape[0] for y in range(5): self.graph[4 - y, x] = (stat.color if y < int(value) else stat.color * Lightness(value - int(value)) if y < value else Color('black'))
def _render_stats(self, buf): for x, stat in enumerate(self.controls): if isinstance(stat, controls.LastSeen): # Always ensure last-seen is updated as its value can change # regardless of message arrival (and *should* change if message # arrival has stopped) stat.update(self.selected) # Scale the value to a range of 2, with an offset of 1 # to ensure that the status line is never black value = (stat.value * 2) + 1 buf[0:3, x] = [ stat.color if y < int(value) else stat.color * Lightness(value - int(value)) if y < value else Color('black') for y in range(3) ][::-1]
def test_color_mul(): verify_color(Color('magenta') * Color('blue'), Color('blue')) verify_color(Color('magenta') * Color('white'), Color('magenta')) verify_color(Color('magenta') * Red(0.5), Color(0.5, 0, 1)) verify_color(Color('magenta') * Green(0.5), Color('magenta')) verify_color(Color('magenta') * Blue(0.5), Color(1, 0, 0.5)) verify_color(Color('magenta') * Hue(0), Color('red')) verify_color(Color('magenta') * Lightness(0.5), Color(0.5, 0.0, 0.5)) verify_color(Color('magenta') * Saturation(0), Color(0.5, 0.5, 0.5)) verify_color(Color('magenta') * Luma(1), Color('magenta')) verify_color(Red(0.5) * Color('magenta'), Color(0.5, 0, 1)) # pylint: disable=expression-not-assigned with pytest.raises(TypeError): Color('magenta') * 1 with pytest.raises(TypeError): 1 * Color('magenta')
def test_color_add(): verify_color(Color('red') + Color('blue'), Color('magenta')) verify_color(Color('red') + Color('white'), Color('white')) verify_color(Color('red') + Red(1), Color('red')) verify_color(Color('red') + Green(1), Color('yellow')) verify_color(Color('red') + Blue(1), Color('magenta')) verify_color(Color('red') + Hue(0), Color('red')) verify_color(Color('red') + Lightness(0.5), Color('white')) verify_color(Color('red') + Saturation(1), Color('red')) verify_color(Color('red') + Luma(1), Color('white')) verify_color(Green(1) + Color('red'), Color('yellow')) # pylint: disable=expression-not-assigned with pytest.raises(TypeError): Color('red') + 1 with pytest.raises(TypeError): 1 + Color('red')
def test_color_sub(): verify_color(Color('magenta') - Color('blue'), Color('red')) verify_color(Color('magenta') - Color('white'), Color('black')) verify_color(Color('magenta') - Red(1), Color('blue')) verify_color(Color('magenta') - Green(1), Color('magenta')) verify_color(Color('magenta') - Blue(1), Color('red')) verify_color(Color('magenta') - Hue(0), Color('magenta')) verify_color(Color('magenta') - Lightness(0.5), Color('black')) verify_color(Color('magenta') - Saturation(1), Color(0.5, 0.5, 0.5)) verify_color(Color('magenta') - Luma(1), Color('black')) verify_color(Red(1) - Color('magenta'), Color(0, 0, 0)) verify_color(Green(1) - Color('magenta'), Color(0, 1, 0)) verify_color(Blue(1) - Color('magenta'), Color(0, 0, 0)) # pylint: disable=expression-not-assigned with pytest.raises(TypeError): Color('magenta') - 1 with pytest.raises(TypeError): 1 - Color('magenta')
def test_color_attr(): assert Color('red').hue == Hue(0) assert Color('red').lightness == Lightness(0.5) assert Color('red').saturation == Saturation(1) assert Color('red').luma == Luma(0.299)