@Luis @Supernovali @duwudi
Well I have done it again this time i have got animating widget image added with icons
https://www.youtube.com/watch?v=0YbDhvnn4ZQ
How i done it was take the WiFi code and just take out everything i do not need and added the system monitor stuff in its place
This is the gif used for all the images,
- Save it this gif to the pi-top and rename it to cpu_info.gif (assuming you put it on Desktop)
- add it to
/usr/share/pt-sys-oled/images/sys_info
via
sudo cp /home/pi/Desktop/cpu_info.gif /usr/share/pt-sys-oled/images/sys_info/cpi_info.gif
- then chmod the file
sudo chmod 644 /usr/share/pt-sys-oled/images/sys_info/cpu_info.gif
Do not forget to add a menu item for it
Here is the updated code for the animation
/usr/lib/pt-sys-oled/components/widgets/sys_info/cpu_info.py
import psutil
from gpiozero import CPUTemperature
from components.widgets.common.base_widgets import BaseSnapshot
from components.widgets.common.functions import get_image_file_path, draw_text
from components.widgets.common.image_component import ImageComponent
from components.widgets.common.values import (
default_margin_x,
common_first_line_y,
common_second_line_y,
common_third_line_y,
)
class Hotspot(BaseSnapshot):
def __init__(self, width, height, mode, interval, **data):
super(Hotspot, self).__init__(width, height, interval, self.render)
self.cpu = CPUTemperature()
self.width = width
self.height = height
self.mode = mode
self.gif = ImageComponent(
device_mode=self.mode,
width=self.width,
height=self.height,
image_path=get_image_file_path("sys_info/cpu_info.gif"),
loop=False,
playback_speed=2.0,
)
self.cpuSpeed = ''
self.cpuTemp = ''
self.cpuLoad = ''
self.cSpeed = ''
self.initialised = False
self.default_interval = interval
def reset(self):
self.gif = ImageComponent(
device_mode=self.mode,
width=self.width,
height=self.height,
image_path=get_image_file_path("sys_info/cpu_info.gif"),
loop=False,
playback_speed=2.0,
)
self.cpuSpeed = ''
self.cpuTemp = ''
self.cpuLoad = ''
self.cSpeed = ''
self.initialised = False
self.interval = self.default_interval
def set_data_members(self):
self.cpuSpeed = round(float(psutil.cpu_freq(percpu=False).current))
self.cpuTemp = round(self.cpu.temperature,2)
self.cpuLoad = psutil.cpu_percent(percpu=False)
self.cSpeed = f'{self.cpuSpeed} MHz' if self.cpuSpeed < 1000 else f'{self.cpuSpeed/1000} GHz'
self.initialised = True
def render(self, draw, width, height):
first_frame = not self.initialised
# Determine initial connection state
if first_frame:
self.set_data_members()
# Determine connection state
if not self.gif.is_animating():
self.set_data_members()
# Determine animation speed
# TODO: fix frame speed in GIF
# self.interval = self.gif.frame_duration
if first_frame:
self.interval = 0.5
else:
if self.gif.is_animating():
self.interval = 0.025
else:
self.interval = self.default_interval
# Draw to OLED
self.gif.render(draw)
if self.initialised and not self.gif.is_animating():
self.interval = 1
if self.gif.finished:
draw_text(draw, xy=(default_margin_x,common_first_line_y), text=f'{self.cpuLoad}%')
draw_text(draw, xy=(default_margin_x,common_second_line_y), text=f'{self.cSpeed}')
draw_text(draw, xy=(default_margin_x,common_third_line_y), text=f'{self.cpuTemp}°C')
elif self.gif.hold_first_frame:
draw.ellipse((69, 21) + (83, 35), 0, 0)
draw.ellipse((70, 22) + (82, 34), 1, 0)
draw.line((73, 25) + (78, 30), "black", 2)
draw.line((74, 30) + (79, 25), "black", 2)