def test_brush(): class DrawMethodsCanvas(x11.Canvas): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.c = False def on_button_pressed(self, button, state, x, y): if button == 1: self.dispose() @brush def rect(ctx, width, height): ctx.set_source_rgb(*[r() for _ in range(3)]) ctx.rectangle(0, 0, width, height) ctx.fill() def on_draw(self, ctx): if self.c: self.dispose() return for i in range(4): ctx.rect(self.width >> i, self.height >> i) self.c = True canvas = DrawMethodsCanvas(40, 40, 128, 128, interval=3000) canvas.show() x11.start_event_loop()
def test_text(): from blighty.x11 import Canvas class DrawMethodsCanvas(Canvas): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.c = False def on_button_pressed(self, button, state, x, y): if button == 1: self.dispose() def on_draw(self, ctx): if self.c: self.dispose() return for i in range(1, 10): ctx.write_text(self.width >> 1, self.height >> 1, str(i), align=i) self.c = True canvas = DrawMethodsCanvas(40, 40, 128, 128, interval=3000) canvas.show() x11.start_event_loop()
def test_canvas(): class TestMPL(Canvas): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.plot = SimplePlot(*self.get_size()) self.count = 5 def on_draw(self, cr): self.plot.push_value(psutil.cpu_percent(.1)) self.plot.draw(cr) self.count += 1 if self.count > 10: self.dispose() def on_button_pressed(self, button, state, x, y): if button == 1: self.dispose() def on_key_pressed(self, keysym, state): if keysym == 65307: self.dispose() canvas = TestMPL(10, 10, 320, 160, gravity=CanvasGravity.SOUTH_EAST) canvas.interval = 2000 canvas.show() start_event_loop()
def test_canvas(): class TestMPL(Canvas): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) width, height = self.get_size() self.plot = Graph(0, 0, width, height >> 1) self.refl = Graph(0, height >> 1, width, -(height >> 1), scale=None) self.count = 0 def on_draw(self, cr): cr.set_source_rgb(0.1, 0.1, 0.1) cr.rectangle(0, 0, *self.get_size()) cr.fill() v = psutil.cpu_percent(0.1) self.plot.push_value(v) self.refl.push_value(v) cr.set_source_rgb(1, 1, 1) self.plot.draw(cr) cr.set_source_rgb(.2, .2, .2) self.refl.draw(cr) self.count += 1 if self.count > 300: self.dispose() def on_button_pressed(self, button, state, x, y): if button == 1: self.dispose() def on_key_pressed(self, keysym, state): if keysym == 65307: self.dispose() canvas = TestMPL(10, 10, 160, 160, gravity = CanvasGravity.SOUTH_EAST) canvas.interval = 500 canvas.show() start_event_loop()
def test_grid(): class DrawMethodsCanvas(x11.Canvas): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.c = False def on_button_pressed(self, button, state, x, y): if button == 1: self.dispose() def on_draw(self, ctx): if self.c: self.dispose() return ctx.draw_grid() self.c = True canvas = DrawMethodsCanvas(40, 40, 512, 512, interval=3000) canvas.show() x11.start_event_loop()
def test_canvas(): canvases = [ MyCanvas(200 * i, 200 * i, width=200, height=200, interval=42, gravity=CanvasGravity.CENTER) for i in range(-1, 2) ] for canvas in canvases: assert canvas.interval == 42 canvas.interval = 100 assert canvas.show() is None assert x11.start_event_loop() is None
c.save() c.set_font_size(12) c.write_text( 0, 110, c.canvas.coreinfo[0]["model name"].strip().replace( "(TM)", "™").replace("(R)", "©")) c.restore() def on_draw(self, c): # c.draw_grid() c.select_font_face(*Fonts.LAKSAMAN_NORMAL) c.set_font_size(36) c.set_source_rgb(1, 1, 1) w, h = Cpu.SIZE y_poly = (Cpu.CORE_POLYGON.height + Cpu.CORE_POLYGON.length) c.write_text(0, y_poly, "CPU", align=TextAlign.TOP_LEFT) c.draw_core_polygon(w - y_poly, y_poly) c.draw_processes() c.draw_cpu_name() c.set_source_rgb(1, 1, 1) self.graph.draw(c) if __name__ == "__main__": Cpu.build(10, 10, gravity=CanvasGravity.EAST).show() start_event_loop()