|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2023 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing a dialog to show the WiFi status of the connected device. |
|
8 """ |
|
9 |
|
10 from PyQt6.QtWidgets import QDialog, QTreeWidgetItem |
|
11 |
|
12 from .Ui_WifiStatusDialog import Ui_WifiStatusDialog |
|
13 |
|
14 |
|
15 class WifiStatusDialog(QDialog, Ui_WifiStatusDialog): |
|
16 """ |
|
17 Class implementing a dialog to show the WiFi status of the connected device. |
|
18 """ |
|
19 |
|
20 def __init__(self, clientStatus, apStatus, parent=None): |
|
21 """ |
|
22 Constructor |
|
23 |
|
24 @param clientStatus dictionary containing the WiFi status data of the |
|
25 client interface |
|
26 @type dict |
|
27 @param apStatus dictionary containing the WiFi status data of the |
|
28 access point interface |
|
29 @type dict |
|
30 @param parent reference to the parent widget (defaults to None) |
|
31 @type QWidget (optional) |
|
32 """ |
|
33 super().__init__(parent) |
|
34 self.setupUi(self) |
|
35 |
|
36 self.statusTree.setColumnCount(2) |
|
37 |
|
38 # client interface |
|
39 if clientStatus: |
|
40 header = self.__createHeader(self.tr("Client")) |
|
41 QTreeWidgetItem( |
|
42 header, |
|
43 [ |
|
44 self.tr("Active"), |
|
45 self.tr("Yes") if clientStatus["active"] else self.tr("No"), |
|
46 ], |
|
47 ) |
|
48 if clientStatus["active"]: |
|
49 QTreeWidgetItem( |
|
50 header, |
|
51 [ |
|
52 self.tr("Connected"), |
|
53 self.tr("Yes") if clientStatus["connected"] else self.tr("No"), |
|
54 ], |
|
55 ) |
|
56 QTreeWidgetItem(header, [self.tr("Status"), clientStatus["status"]]) |
|
57 QTreeWidgetItem( |
|
58 header, [self.tr("IPv4 Address"), clientStatus["ifconfig"][0]] |
|
59 ) |
|
60 QTreeWidgetItem( |
|
61 header, [self.tr("Netmask"), clientStatus["ifconfig"][1]] |
|
62 ) |
|
63 QTreeWidgetItem( |
|
64 header, [self.tr("Gateway"), clientStatus["ifconfig"][2]] |
|
65 ) |
|
66 QTreeWidgetItem(header, [self.tr("DNS"), clientStatus["ifconfig"][3]]) |
|
67 QTreeWidgetItem(header, [self.tr("MAC-Address"), clientStatus["mac"]]) |
|
68 QTreeWidgetItem( |
|
69 header, [self.tr("Channel"), str(clientStatus["channel"])] |
|
70 ) |
|
71 QTreeWidgetItem( |
|
72 header, |
|
73 [ |
|
74 self.tr("Tx-Power"), |
|
75 self.tr("{0} dBm").format(clientStatus["txpower"]), |
|
76 ], |
|
77 ) |
|
78 |
|
79 # access point interface |
|
80 if apStatus: |
|
81 header = self.__createHeader(self.tr("Access Point")) |
|
82 QTreeWidgetItem( |
|
83 header, |
|
84 [ |
|
85 self.tr("Active"), |
|
86 self.tr("Yes") if apStatus["active"] else self.tr("No"), |
|
87 ], |
|
88 ) |
|
89 if apStatus["active"]: |
|
90 QTreeWidgetItem( |
|
91 header, |
|
92 [ |
|
93 self.tr("Connected"), |
|
94 self.tr("Yes") if apStatus["connected"] else self.tr("No"), |
|
95 ], |
|
96 ) |
|
97 QTreeWidgetItem(header, [self.tr("Status"), apStatus["status"]]) |
|
98 QTreeWidgetItem( |
|
99 header, [self.tr("IPv4 Address"), apStatus["ifconfig"][0]] |
|
100 ) |
|
101 QTreeWidgetItem(header, [self.tr("Netmask"), apStatus["ifconfig"][1]]) |
|
102 QTreeWidgetItem(header, [self.tr("Gateway"), apStatus["ifconfig"][2]]) |
|
103 QTreeWidgetItem(header, [self.tr("DNS"), apStatus["ifconfig"][3]]) |
|
104 QTreeWidgetItem(header, [self.tr("SSID"), apStatus["essid"]]) |
|
105 QTreeWidgetItem(header, [self.tr("MAC-Address"), apStatus["mac"]]) |
|
106 QTreeWidgetItem(header, [self.tr("Channel"), str(apStatus["channel"])]) |
|
107 QTreeWidgetItem( |
|
108 header, |
|
109 [ |
|
110 self.tr("Tx-Power"), |
|
111 self.tr("{0} dBm").format(apStatus["txpower"]), |
|
112 ], |
|
113 ) |
|
114 |
|
115 for col in range(self.statusTree.columnCount()): |
|
116 self.statusTree.resizeColumnToContents(col) |
|
117 |
|
118 def __createHeader(self, headerText): |
|
119 """ |
|
120 Private method to create a header item. |
|
121 |
|
122 @param headerText text for the header item |
|
123 @type str |
|
124 @return reference to the created header item |
|
125 @rtype QTreeWidgetItem |
|
126 """ |
|
127 headerItem = QTreeWidgetItem(self.statusTree, [headerText]) |
|
128 headerItem.setExpanded(True) |
|
129 headerItem.setFirstColumnSpanned(True) |
|
130 |
|
131 font = headerItem.font(0) |
|
132 font.setBold(True) |
|
133 |
|
134 headerItem.setFont(0, font) |
|
135 |
|
136 return headerItem |