src/eric7/MicroPython/WifiDialogs/WifiStatusDialog.py

branch
eric7
changeset 11166
fd914f897dcf
parent 11090
f5f5f5803935
child 11236
75c26fe1d1c7
equal deleted inserted replaced
11165:24e1beb8779a 11166:fd914f897dcf
7 Module implementing a dialog to show the WiFi status of the connected device. 7 Module implementing a dialog to show the WiFi status of the connected device.
8 """ 8 """
9 9
10 import contextlib 10 import contextlib
11 11
12 from PyQt6.QtCore import Qt 12 from PyQt6.QtCore import Qt, pyqtSlot
13 from PyQt6.QtWidgets import QDialog, QDialogButtonBox, QTreeWidgetItem 13 from PyQt6.QtWidgets import QDialog, QDialogButtonBox, QTreeWidgetItem
14
15 from eric7.EricGui import EricPixmapCache
14 16
15 from .Ui_WifiStatusDialog import Ui_WifiStatusDialog 17 from .Ui_WifiStatusDialog import Ui_WifiStatusDialog
16 18
17 19
18 class WifiStatusDialog(QDialog, Ui_WifiStatusDialog): 20 class WifiStatusDialog(QDialog, Ui_WifiStatusDialog):
19 """ 21 """
20 Class implementing a dialog to show the WiFi status of the connected device. 22 Class implementing a dialog to show the WiFi status of the connected device.
21 """ 23 """
22 24
23 def __init__(self, clientStatus, apStatus, overallStatus, parent=None): 25 def __init__(self, microPython, parent=None):
24 """ 26 """
25 Constructor 27 Constructor
26 28
27 @param clientStatus dictionary containing the WiFi status data of the 29 @param microPython reference to the MicroPython widget
28 client interface 30 @type MicroPythonWidget
29 @type dict
30 @param apStatus dictionary containing the WiFi status data of the
31 access point interface
32 @type dict
33 @param overallStatus dictionary containing the overall WiFi status data
34 @type dict
35 @param parent reference to the parent widget (defaults to None) 31 @param parent reference to the parent widget (defaults to None)
36 @type QWidget (optional) 32 @type QWidget (optional)
37 """ 33 """
38 super().__init__(parent) 34 super().__init__(parent)
39 self.setupUi(self) 35 self.setupUi(self)
36 self.setWindowFlags(Qt.WindowType.Window)
40 37
41 self.statusTree.setColumnCount(2) 38 self.statusTree.setColumnCount(2)
42 39
43 # overall status 40 self.refreshButton.setIcon(EricPixmapCache.getIcon("reload"))
41 self.refreshButton.clicked.connect(self.__showStatus)
42
43 self.__mpy = microPython
44
45 self.__showStatus()
46
47 @pyqtSlot()
48 def __showStatus(self):
49 """
50 Private slot to show the current WiFi status.
51 """
52 # clear old data
53 self.statusTree.clear()
54
55 # get the status
56 try:
57 clientStatus, apStatus, overallStatus = self.__mpy.getDevice().getWifiData()
58 except Exception as exc:
59 self.__mpy.showError("getWifiData()", str(exc))
60 return
61
62 # populate overall status
44 QTreeWidgetItem( 63 QTreeWidgetItem(
45 self.statusTree, 64 self.statusTree,
46 [ 65 [
47 self.tr("Active"), 66 self.tr("Active"),
48 self.tr("Yes") if overallStatus["active"] else self.tr("No"), 67 self.tr("Yes") if overallStatus["active"] else self.tr("No"),
55 with contextlib.suppress(KeyError): 74 with contextlib.suppress(KeyError):
56 QTreeWidgetItem( 75 QTreeWidgetItem(
57 self.statusTree, [self.tr("Country"), overallStatus["country"]] 76 self.statusTree, [self.tr("Country"), overallStatus["country"]]
58 ) 77 )
59 78
60 # client interface 79 # populate status of client interface
61 if clientStatus: 80 if clientStatus:
62 header = self.__createHeader(self.tr("Client")) 81 header = self.__createHeader(self.tr("Client"))
63 QTreeWidgetItem( 82 QTreeWidgetItem(
64 header, 83 header,
65 [ 84 [
129 with contextlib.suppress(KeyError): 148 with contextlib.suppress(KeyError):
130 QTreeWidgetItem( 149 QTreeWidgetItem(
131 apHeader, [self.tr("Country"), clientStatus["ap_country"]] 150 apHeader, [self.tr("Country"), clientStatus["ap_country"]]
132 ) 151 )
133 152
134 # access point interface 153 # populate status of access point interface
135 if apStatus: 154 if apStatus:
136 header = self.__createHeader(self.tr("Access Point")) 155 header = self.__createHeader(self.tr("Access Point"))
137 QTreeWidgetItem( 156 QTreeWidgetItem(
138 header, 157 header,
139 [ 158 [

eric ide

mercurial