From 020cab78d4596b0c58db5db177a1ef1eb583cd02 Mon Sep 17 00:00:00 2001 From: ThibaultDECO <80053070+ThibaultDECO@users.noreply.github.com> Date: Sat, 15 Nov 2025 20:05:26 +0100 Subject: [PATCH 1/3] A few tweaks --- examples/sys_info.py | 45 ++++++++++++++++++++++++++++---------------- 1 file changed, 29 insertions(+), 16 deletions(-) diff --git a/examples/sys_info.py b/examples/sys_info.py index e42f7cd..6115fde 100755 --- a/examples/sys_info.py +++ b/examples/sys_info.py @@ -56,23 +56,32 @@ def bytes2human(n): def cpu_usage(): - # load average, uptime + # cpu usage, uptime uptime = datetime.now() - datetime.fromtimestamp(psutil.boot_time()) - av1, av2, av3 = os.getloadavg() - return "Ld:%.1f %.1f %.1f Up: %s" \ - % (av1, av2, av3, str(uptime).split('.')[0]) + days = uptime.days + hours, remainder = divmod(uptime.seconds, 3600) + minutes, _ = divmod(remainder, 60) + + cpu_percent = psutil.cpu_percent(interval=1) + return "CPU: %d%% Up: %dd%dh%dm" % (cpu_percent, days, hours, minutes) def mem_usage(): usage = psutil.virtual_memory() - return "Mem: %s %.0f%%" \ - % (bytes2human(usage.used), 100 - usage.percent) + return "RAM: %s/%s (%.0f%%)" % ( + bytes2human(usage.used), + bytes2human(usage.total), + usage.percent + ) def disk_usage(dir): usage = psutil.disk_usage(dir) - return "SD: %s %.0f%%" \ - % (bytes2human(usage.used), usage.percent) + return "SD: %s/%s (%.0f%%)" % ( + bytes2human(usage.used), + bytes2human(usage.total), + usage.percent + ) def network(iface): @@ -83,18 +92,22 @@ def network(iface): def stats(device): # use custom font - font_path = str(Path(__file__).resolve().parent.joinpath('fonts', 'C&C Red Alert [INET].ttf')) - font2 = ImageFont.truetype(font_path, 12) + font_path = str(Path(__file__).resolve().parent.joinpath('fonts', 'DejaVuSansMono.ttf')) + font2 = ImageFont.truetype(font_path, 10) + ascent, descent = font2.getmetrics() + line_height = ascent + descent with canvas(device) as draw: - draw.text((0, 0), cpu_usage(), font=font2, fill="white") - if device.height >= 32: - draw.text((0, 14), mem_usage(), font=font2, fill="white") + draw.rectangle(device.bounding_box, outline="white", fill=None) + draw.text((2, line_height * 0), cpu_usage(), font=font2, fill="white") + if device.height >= (line_height * 2): + draw.text((2, line_height * 1), mem_usage(), font=font2, fill="white") - if device.height >= 64: - draw.text((0, 26), disk_usage('/'), font=font2, fill="white") + if device.height >= (line_height * 3): + draw.text((2, line_height * 2), disk_usage('/'), font=font2, fill="white") try: - draw.text((0, 38), network('wlan0'), font=font2, fill="white") + if device.height >= (line_height * 4): + draw.text((2, line_height * 3), network('wlan0'), font=font2, fill="white") except KeyError: # no wifi enabled/available pass From b0836591b399fe7c464ba240cebcea4bc9e3dd1b Mon Sep 17 00:00:00 2001 From: ThibaultDECO <80053070+ThibaultDECO@users.noreply.github.com> Date: Sat, 15 Nov 2025 20:56:09 +0100 Subject: [PATCH 2/3] graceful exit --- examples/sys_info.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/examples/sys_info.py b/examples/sys_info.py index 6115fde..ce619ee 100755 --- a/examples/sys_info.py +++ b/examples/sys_info.py @@ -14,6 +14,7 @@ """ import os +import signal import sys import time from pathlib import Path @@ -37,6 +38,15 @@ # TODO: Load histogram +def shutdown(signum, frame): + device.clear() + sys.exit(0) + + +signal.signal(signal.SIGTERM, shutdown) +signal.signal(signal.SIGINT, shutdown) + + def bytes2human(n): """ >>> bytes2human(10000) @@ -125,3 +135,5 @@ def main(): main() except KeyboardInterrupt: pass + finally: + device.clear() From 434bf097889650b94366983797045ee7ec39d29a Mon Sep 17 00:00:00 2001 From: Richard Hull Date: Sat, 15 Nov 2025 22:35:00 +0000 Subject: [PATCH 3/3] Update sys_info.py --- examples/sys_info.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/sys_info.py b/examples/sys_info.py index ce619ee..4c0ba3f 100755 --- a/examples/sys_info.py +++ b/examples/sys_info.py @@ -71,7 +71,7 @@ def cpu_usage(): days = uptime.days hours, remainder = divmod(uptime.seconds, 3600) minutes, _ = divmod(remainder, 60) - + cpu_percent = psutil.cpu_percent(interval=1) return "CPU: %d%% Up: %dd%dh%dm" % (cpu_percent, days, hours, minutes)