kiosk: add client data to boot view

show IP, MAC, link speed and hostname in the top left of the Kiosk
boot view.

Adjust boot view layout to better fit the new widget.

Add get_mac_from_interface() to net.py
ogkiosk
Alejandro Sirgo Rica 2025-02-06 13:52:22 +01:00
parent 213c9f47a3
commit 3ae6298f2c
3 changed files with 45 additions and 5 deletions

View File

@ -6,13 +6,15 @@
# (at your option) any later version.
from PyQt6.QtWidgets import (
QWidget, QPushButton, QVBoxLayout, QHBoxLayout, QLabel, QToolButton
QWidget, QPushButton, QVBoxLayout, QHBoxLayout, QLabel, QToolButton, QFrame
)
from PyQt6.QtCore import Qt, QSize, pyqtSignal
from PyQt6.QtGui import QPixmap, QIcon
from src.utils.probe import OSFamily
from src.kiosk.config import *
from src.kiosk.theme import *
from src.utils.net import *
import os
class BootView(QWidget):
@ -31,11 +33,42 @@ class BootView(QWidget):
self.layout.setSpacing(10)
self.layout.setAlignment(Qt.AlignmentFlag.AlignCenter)
# Client data frame
self.data_widget = QFrame(self)
self.data_widget.setFrameStyle(QFrame.Shape.StyledPanel | QFrame.Shadow.Plain)
data_layout = QVBoxLayout(self.data_widget)
data_layout.setAlignment(Qt.AlignmentFlag.AlignCenter)
ethernet_interface = get_ethernet_interface()
client_ip = getifaddr(ethernet_interface)
client_mac = get_mac_from_interface(ethernet_interface)
client_hostname = os.uname().nodename
client_link = ethtool(ethernet_interface)
label_data_list = [
f'IP: {client_ip}',
f'MAC: {client_mac}',
f'HOSTNAME: {client_hostname}',
f'LINK: {client_link} Mbps'
]
for label_text in label_data_list:
data_label = QLabel(label_text)
data_label.setStyleSheet('font-weight: 600;')
data_layout.addWidget(data_label)
self.data_widget.setParent(self)
self.data_widget.adjustSize()
self.data_widget.move(0, 0)
# Header
image_label = QLabel()
image_label.setStyleSheet("background: transparent;")
pixmap = get_image('header.png')
image_label.setPixmap(pixmap)
image_label.setAlignment(Qt.AlignmentFlag.AlignCenter)
self.layout.addWidget(image_label)
self.layout.addStretch()
boot_os_list = get_boot_os_list()
@ -121,7 +154,9 @@ class BootView(QWidget):
poweroff_button.clicked.connect(self.on_poweroff_pressed)
# Footer
self.layout.addStretch()
image_label = QLabel()
image_label.setStyleSheet("background: transparent;")
pixmap = get_image('footer.png')
image_label.setPixmap(pixmap)
image_label.setAlignment(Qt.AlignmentFlag.AlignCenter)

View File

@ -37,11 +37,8 @@ def set_status(value):
def is_busy_enabled():
return config_data.get('status', 'idle') == 'busy'
def get_ip():
return getifaddr(get_ethernet_interface())
def get_log_path():
return f'/opt/opengnsys/log/{get_ip()}.log'
return f'/opt/opengnsys/log/{getifaddr(get_ethernet_interface())}.log'
def get_os_columns():
return config_data.get('os_columns', 2)

View File

@ -82,6 +82,14 @@ def get_ethernet_interface():
return eth_interfaces[0]
def get_mac_from_interface(interface):
interfaces = psutil.net_if_addrs()
if interface in interfaces:
for addr in interfaces[interface]:
if addr.family == psutil.AF_LINK:
return addr.address
return None
def ethtool(interface):
try:
ETHTOOL_GSET = 0x00000001