forked from CreatBot/CreatBotKlipperScreen
add system info panel
This commit is contained in:
@@ -147,4 +147,8 @@ icon: spoolman
|
||||
panel: spoolman
|
||||
enable: {{ moonraker.spoolman }}
|
||||
|
||||
|
||||
[menu __main more system]
|
||||
name: {{ gettext('System') }}
|
||||
icon: info
|
||||
panel: system
|
||||
enable: {{ moonraker_connected }}
|
||||
|
@@ -85,3 +85,9 @@ name: Spoolman
|
||||
icon: spoolman
|
||||
panel: spoolman
|
||||
enable: {{ moonraker.spoolman }}
|
||||
|
||||
[menu __print system]
|
||||
name: {{ gettext('System') }}
|
||||
icon: info
|
||||
panel: system
|
||||
enable: {{ moonraker_connected }}
|
@@ -26,3 +26,9 @@ enable: {{ moonraker_connected }}
|
||||
name: KlipperScreen
|
||||
icon: settings
|
||||
panel: settings
|
||||
|
||||
[menu __splashscreen system]
|
||||
name: {{ gettext('System') }}
|
||||
icon: info
|
||||
panel: system
|
||||
enable: {{ moonraker_connected }}
|
||||
|
@@ -26,6 +26,7 @@ class Printer:
|
||||
self.available_commands = {}
|
||||
self.spoolman = False
|
||||
self.temp_devices = self.sensors = None
|
||||
self.system_info = {}
|
||||
|
||||
def reinit(self, printer_info, data):
|
||||
self.config = data['configfile']['config']
|
||||
@@ -41,6 +42,7 @@ class Printer:
|
||||
self.available_commands.clear()
|
||||
self.temp_devices = self.sensors = None
|
||||
self.stop_tempstore_updates()
|
||||
self.system_info.clear()
|
||||
|
||||
for x in self.config.keys():
|
||||
if x[:8] == "extruder":
|
||||
|
90
panels/system.py
Normal file
90
panels/system.py
Normal file
@@ -0,0 +1,90 @@
|
||||
import logging
|
||||
import gi
|
||||
|
||||
gi.require_version("Gtk", "3.0")
|
||||
from gi.repository import Gtk
|
||||
from ks_includes.screen_panel import ScreenPanel
|
||||
|
||||
|
||||
class Panel(ScreenPanel):
|
||||
def __init__(self, screen, title):
|
||||
super().__init__(screen, title)
|
||||
self.current_row = 0
|
||||
sysinfo = screen.printer.system_info
|
||||
logging.debug(sysinfo)
|
||||
|
||||
self.grid = Gtk.Grid(column_spacing=10, row_spacing=5)
|
||||
self.populate_info(sysinfo)
|
||||
|
||||
scroll = self._gtk.ScrolledWindow()
|
||||
scroll.add(self.grid)
|
||||
self.content.add(scroll)
|
||||
|
||||
def add_label_to_grid(self, text, column, bold=False):
|
||||
if bold:
|
||||
text = f"<b>{text}</b>"
|
||||
label = Gtk.Label(label=text, use_markup=True, xalign=0, wrap=True)
|
||||
self.grid.attach(label, column, self.current_row, 1, 1)
|
||||
self.current_row += 1
|
||||
|
||||
def populate_info(self, sysinfo):
|
||||
logging.debug(sysinfo.items())
|
||||
for category, data in sysinfo.items():
|
||||
if category == "python":
|
||||
self.add_label_to_grid(self.prettify(category), 0, bold=True)
|
||||
self.add_label_to_grid(
|
||||
f'Version: {data["version"][0]}.{data["version"][1]}', 1
|
||||
)
|
||||
continue
|
||||
|
||||
if (
|
||||
category
|
||||
in (
|
||||
"virtualization",
|
||||
"provider",
|
||||
"available_services",
|
||||
"service_state",
|
||||
"instance_ids",
|
||||
)
|
||||
or not sysinfo[category]
|
||||
):
|
||||
continue
|
||||
|
||||
self.add_label_to_grid(self.prettify(category), 0, bold=True)
|
||||
|
||||
if isinstance(data, dict):
|
||||
for key, value in data.items():
|
||||
if key in ("version_parts", "memory_units") or not value:
|
||||
continue
|
||||
if key == "total_memory":
|
||||
memory_units = data.get("memory_units", "kB").lower()
|
||||
units_mapping = {
|
||||
"kb": 1024,
|
||||
"mb": 1024**2,
|
||||
"gb": 1024**3,
|
||||
"tb": 1024**4,
|
||||
"pb": 1024**5,
|
||||
}
|
||||
multiplier = units_mapping.get(memory_units, 1)
|
||||
value = self.format_size(int(value) * multiplier)
|
||||
if isinstance(value, dict):
|
||||
self.add_label_to_grid(self.prettify(key), 0)
|
||||
self.current_row -= 1
|
||||
for sub_key, sub_value in value.items():
|
||||
if not sub_value:
|
||||
continue
|
||||
elif (
|
||||
isinstance(sub_value, list)
|
||||
and sub_key == "ip_addresses"
|
||||
):
|
||||
logging.info(sub_value)
|
||||
for _ip in sub_value:
|
||||
self.add_label_to_grid(
|
||||
f"{self.prettify(sub_key)}: {_ip['address']}", 1
|
||||
)
|
||||
continue
|
||||
self.add_label_to_grid(
|
||||
f"{self.prettify(sub_key)}: {sub_value}", 1
|
||||
)
|
||||
else:
|
||||
self.add_label_to_grid(f"{self.prettify(key)}: {value}", 1)
|
@@ -10,7 +10,6 @@ class Panel(ScreenPanel):
|
||||
def __init__(self, screen, title):
|
||||
super().__init__(screen, title)
|
||||
self.update_status = None
|
||||
self.system_info = self._screen.apiclient.send_request("machine/system_info")
|
||||
|
||||
self.update_all = self._gtk.Button('arrow-up', _('Full Update'), 'color1', self.bts, Gtk.PositionType.LEFT, 1)
|
||||
self.update_all.connect("clicked", self.show_update_info, "full")
|
||||
@@ -49,7 +48,7 @@ class Panel(ScreenPanel):
|
||||
self.labels[f"{prog}_status"].connect("clicked", self.show_update_info, prog)
|
||||
|
||||
try:
|
||||
if prog in self.system_info['system_info']['available_services']:
|
||||
if prog in self._printer.system_info['available_services']:
|
||||
self.labels[f"{prog}_restart"] = self._gtk.Button("refresh", _("Restart"),
|
||||
"color2",
|
||||
position=Gtk.PositionType.LEFT,
|
||||
@@ -236,9 +235,9 @@ class Panel(ScreenPanel):
|
||||
|
||||
if p == "system":
|
||||
distro = (
|
||||
self.system_info['system_info']['distribution']['name']
|
||||
if 'system_info' in self.system_info
|
||||
and 'distribution' in self.system_info['system_info']
|
||||
self._printer.system_info['distribution']['name']
|
||||
if 'distribution' in self._printer.system_info
|
||||
and 'name' in self._printer.system_info['distribution']
|
||||
else _('System'))
|
||||
self.labels[p].set_markup(f"<b>{distro}</b>")
|
||||
if info['package_count'] == 0:
|
||||
|
@@ -981,6 +981,9 @@ class KlipperScreen(Gtk.Window):
|
||||
return False
|
||||
self.printer.reinit(printer_info, config['status'])
|
||||
self.printer.available_commands = self.apiclient.get_gcode_help()
|
||||
info = self.apiclient.send_request("machine/system_info")
|
||||
if info and 'system_info' in info:
|
||||
self.printer.system_info = info['system_info']
|
||||
|
||||
items = (
|
||||
'bed_mesh',
|
||||
|
Reference in New Issue
Block a user