def main(): img_path = os.path.abspath(os.path.join(os.path.dirname(__file__), 'images', 'starwars.png')) logo = Image.open(img_path) virtual = viewport(device, width=128, height=768) for _ in range(2): with canvas(virtual) as draw: draw.text((0, 0), "A long time ago", fill="white") draw.text((0, 12), "in a galaxy far", fill="white") draw.text((0, 24), "far away....", fill="white") time.sleep(5) for _ in range(2): with canvas(virtual) as draw: draw.bitmap((20, 0), logo, fill="white") for i, line in enumerate(blurb.split("\n")): draw.text((0, 40 + (i * 12)), text=line, fill="white") time.sleep(2) # update the viewport one position below, causing a refresh, # giving a rolling up scroll effect when done repeatedly for y in range(450): virtual.set_position((0, y)) time.sleep(0.01)
def main(): fonts = [make_font("code2000.ttf", sz) for sz in range(24, 8, -2)] w, h = 256, 256 virtual = viewport(device, w, h) for welcome_a, welcome_b in pairs(infinite_shuffle(welcome)): widget_a = make_snapshot(device.width, device.height, welcome_a, fonts) widget_b = make_snapshot(device.width, device.height, welcome_b, fonts) posn_a = random_point(w - device.width, h - device.height) posn_b = random_point(w - device.width, h - device.height) while overlapping(posn_a, posn_b, device.width, device.height): posn_b = random_point(w - device.width, h - device.height) virtual.add_hotspot(widget_a, posn_a) virtual.add_hotspot(widget_b, posn_b) for _ in range(10): virtual.set_position(posn_a) time.sleep(0.3) for posn in lerp_2d(posn_a, posn_b, 30): virtual.set_position(posn) virtual.remove_hotspot(widget_a, posn_a) virtual.remove_hotspot(widget_b, posn_b)
def main(): if device.rotate in (0, 2): # Horizontal widget_width = device.width // 2 widget_height = device.height else: # Vertical widget_width = device.width widget_height = device.height // 2 # Either function or subclass # cpuload = hotspot(widget_width, widget_height, cpu_load.render) # cpuload = cpu_load.CPU_Load(widget_width, widget_height, interval=1.0) utime = snapshot(widget_width, widget_height, uptime.render, interval=1.0) mem = snapshot(widget_width, widget_height, memory.render, interval=2.0) dsk = snapshot(widget_width, widget_height, disk.render, interval=2.0) cpuload = snapshot(widget_width, widget_height, cpu_load.render, interval=0.5) clk = snapshot(widget_width, widget_height, clock.render, interval=1.0) network_ifs = psutil.net_if_stats().keys() wlan = first(intersect(network_ifs, ["wlan0", "wl0"]), "wlan0") eth = first(intersect(network_ifs, ["eth0", "en0"]), "eth0") lo = first(intersect(network_ifs, ["lo", "lo0"]), "lo") net_wlan = snapshot(widget_width, widget_height, network.stats(wlan), interval=2.0) net_eth = snapshot(widget_width, widget_height, network.stats(eth), interval=2.0) net_lo = snapshot(widget_width, widget_height, network.stats(lo), interval=2.0) widgets = [cpuload, utime, clk, net_wlan, net_eth, net_lo, mem, dsk] if device.rotate in (0, 2): virtual = viewport(device, width=widget_width * len(widgets), height=widget_height) for i, widget in enumerate(widgets): virtual.add_hotspot(widget, (i * widget_width, 0)) for x in pause_every(widget_width, position(widget_width * (len(widgets) - 2))): virtual.set_position((x, 0)) else: virtual = viewport(device, width=widget_width, height=widget_height * len(widgets)) for i, widget in enumerate(widgets): virtual.add_hotspot(widget, (0, i * widget_height)) for y in pause_every(widget_height, position(widget_height * (len(widgets) - 2))): virtual.set_position((0, y))
def test_viewport_set_position(): reference = os.path.abspath( os.path.join(os.path.dirname(__file__), 'reference', 'set_position.png')) fname = NamedTemporaryFile(suffix=".png").name device = capture(file_template=fname, transform="none") virtual = viewport(device, 200, 200) # Use the same drawing primitives as the demo with canvas(virtual) as draw: baseline_data.primitives(virtual, draw) virtual.set_position((20, 30)) assert md5(reference) == md5(fname)
def test_viewport_hotspot(): reference = os.path.abspath( os.path.join(os.path.dirname(__file__), 'reference', 'hotspot.png')) fname = NamedTemporaryFile(suffix=".png").name device = capture(file_template=fname, transform="none") virtual = viewport(device, 200, 200) def draw_fn(draw, width, height): baseline_data.primitives(device, draw) widget = hotspot(device.width, device.height, draw_fn) virtual.add_hotspot(widget, (19, 56)) virtual.set_position((28, 30)) assert md5(reference) == md5(fname)