Fri, 24 Feb 2023 18:36:43 +0100
MicroPython
- some corrections, little extension and code style changes to the WiFi related parts
# -*- coding: utf-8 -*- # Copyright (c) 2023 Detlev Offenbach <detlev@die-offenbachs.de> # """ Module implementing a dialog to show the WiFi status of the connected device. """ import contextlib from PyQt6.QtWidgets import QDialog, QTreeWidgetItem from .Ui_WifiStatusDialog import Ui_WifiStatusDialog class WifiStatusDialog(QDialog, Ui_WifiStatusDialog): """ Class implementing a dialog to show the WiFi status of the connected device. """ def __init__(self, clientStatus, apStatus, overallStatus, parent=None): """ Constructor @param clientStatus dictionary containing the WiFi status data of the client interface @type dict @param apStatus dictionary containing the WiFi status data of the access point interface @type dict @param overallStatus dictionary containing the overall WiFi status data @type dict @param parent reference to the parent widget (defaults to None) @type QWidget (optional) """ super().__init__(parent) self.setupUi(self) self.statusTree.setColumnCount(2) # overall status QTreeWidgetItem( self.statusTree, [ self.tr("Active"), self.tr("Yes") if overallStatus["active"] else self.tr("No"), ], ) # client interface if clientStatus: header = self.__createHeader(self.tr("Client")) QTreeWidgetItem( header, [ self.tr("Active"), self.tr("Yes") if clientStatus["active"] else self.tr("No"), ], ) if clientStatus["active"]: QTreeWidgetItem( header, [ self.tr("Connected"), self.tr("Yes") if clientStatus["connected"] else self.tr("No"), ], ) with contextlib.suppress(KeyError): QTreeWidgetItem(header, [self.tr("Status"), clientStatus["status"]]) with contextlib.suppress(KeyError): QTreeWidgetItem( header, [self.tr("Hostname"), clientStatus["hostname"]] ) QTreeWidgetItem( header, [self.tr("IPv4 Address"), clientStatus["ifconfig"][0]] ) QTreeWidgetItem( header, [self.tr("Netmask"), clientStatus["ifconfig"][1]] ) QTreeWidgetItem( header, [self.tr("Gateway"), clientStatus["ifconfig"][2]] ) QTreeWidgetItem(header, [self.tr("DNS"), clientStatus["ifconfig"][3]]) QTreeWidgetItem(header, [self.tr("MAC-Address"), clientStatus["mac"]]) with contextlib.suppress(KeyError): QTreeWidgetItem( header, [self.tr("Channel"), str(clientStatus["channel"])] ) with contextlib.suppress(KeyError): QTreeWidgetItem( header, [self.tr("Country"), clientStatus["country"]] ) with contextlib.suppress(KeyError): QTreeWidgetItem( header, [ self.tr("Tx-Power"), self.tr("{0} dBm").format(clientStatus["txpower"]), ], ) # access point interface if apStatus: header = self.__createHeader(self.tr("Access Point")) QTreeWidgetItem( header, [ self.tr("Active"), self.tr("Yes") if apStatus["active"] else self.tr("No"), ], ) if apStatus["active"]: QTreeWidgetItem( header, [ self.tr("Connected"), self.tr("Yes") if apStatus["connected"] else self.tr("No"), ], ) with contextlib.suppress(KeyError): QTreeWidgetItem(header, [self.tr("Status"), apStatus["status"]]) with contextlib.suppress(KeyError): QTreeWidgetItem(header, [self.tr("Hostname"), apStatus["hostname"]]) QTreeWidgetItem( header, [self.tr("IPv4 Address"), apStatus["ifconfig"][0]] ) QTreeWidgetItem(header, [self.tr("Netmask"), apStatus["ifconfig"][1]]) QTreeWidgetItem(header, [self.tr("Gateway"), apStatus["ifconfig"][2]]) QTreeWidgetItem(header, [self.tr("DNS"), apStatus["ifconfig"][3]]) with contextlib.suppress(KeyError): QTreeWidgetItem(header, [self.tr("SSID"), apStatus["essid"]]) QTreeWidgetItem(header, [self.tr("MAC-Address"), apStatus["mac"]]) with contextlib.suppress(KeyError): QTreeWidgetItem( header, [self.tr("Channel"), str(apStatus["channel"])] ) with contextlib.suppress(KeyError): QTreeWidgetItem(header, [self.tr("Country"), apStatus["country"]]) with contextlib.suppress(KeyError): QTreeWidgetItem( header, [ self.tr("Tx-Power"), self.tr("{0} dBm").format(apStatus["txpower"]), ], ) for col in range(self.statusTree.columnCount()): self.statusTree.resizeColumnToContents(col) def __createHeader(self, headerText): """ Private method to create a header item. @param headerText text for the header item @type str @return reference to the created header item @rtype QTreeWidgetItem """ headerItem = QTreeWidgetItem(self.statusTree, [headerText]) headerItem.setExpanded(True) headerItem.setFirstColumnSpanned(True) font = headerItem.font(0) font.setBold(True) headerItem.setFont(0, font) return headerItem