5 |
5 |
6 """ |
6 """ |
7 Module implementing a dialog to show Ethernet related status information. |
7 Module implementing a dialog to show Ethernet related status information. |
8 """ |
8 """ |
9 |
9 |
10 from PyQt6.QtCore import Qt |
10 from PyQt6.QtCore import Qt, pyqtSlot |
11 from PyQt6.QtWidgets import QDialog, QDialogButtonBox, QTreeWidgetItem |
11 from PyQt6.QtWidgets import QDialog, QDialogButtonBox, QTreeWidgetItem |
|
12 |
|
13 from eric7.EricGui import EricPixmapCache |
|
14 from eric7.SystemUtilities.NetworkUtilities import ipv6AddressScope |
12 |
15 |
13 from .Ui_EthernetStatusDialog import Ui_EthernetStatusDialog |
16 from .Ui_EthernetStatusDialog import Ui_EthernetStatusDialog |
14 |
17 |
15 |
18 |
16 class EthernetStatusDialog(QDialog, Ui_EthernetStatusDialog): |
19 class EthernetStatusDialog(QDialog, Ui_EthernetStatusDialog): |
17 """ |
20 """ |
18 Class implementing a dialog to show Ethernet related status information. |
21 Class implementing a dialog to show Ethernet related status information. |
19 """ |
22 """ |
20 |
23 |
21 def __init__(self, status, parent=None): |
24 def __init__(self, microPython, parent=None): |
22 """ |
25 """ |
23 Constructor |
26 Constructor |
24 |
27 |
25 @param status status data to be show |
28 @param microPython reference to the MicroPython widget |
26 @type list of tuples of (str, str) |
29 @type MicroPythonWidget |
27 @param parent reference to the parent widget (defaults to None) |
30 @param parent reference to the parent widget (defaults to None) |
28 @type QWidget (optional) |
31 @type QWidget (optional) |
29 """ |
32 """ |
30 super().__init__(parent) |
33 super().__init__(parent) |
31 self.setupUi(self) |
34 self.setupUi(self) |
|
35 self.setWindowFlags(Qt.WindowType.Window) |
32 |
36 |
33 self.statusTree.setColumnCount(2) |
37 self.statusTree.setColumnCount(2) |
34 |
38 |
|
39 self.refreshButton.setIcon(EricPixmapCache.getIcon("reload")) |
|
40 self.refreshButton.clicked.connect(self.__showStatus) |
|
41 |
|
42 self.__mpy = microPython |
|
43 |
|
44 self.__showStatus() |
|
45 |
|
46 @pyqtSlot() |
|
47 def __showStatus(self): |
|
48 """ |
|
49 Private slot to show the current WiFi status. |
|
50 """ |
|
51 # clear old data |
|
52 self.statusTree.clear() |
|
53 |
|
54 # get the status |
|
55 try: |
|
56 status, addressInfo = self.__mpy.getDevice().getEthernetStatus() |
|
57 except Exception as exc: |
|
58 self.__mpy.showError("getEthernetStatus()", str(exc)) |
|
59 return |
|
60 |
35 for topic, value in status: |
61 for topic, value in status: |
36 QTreeWidgetItem(self.statusTree, [topic, str(value)]) |
62 QTreeWidgetItem(self.statusTree, [topic, str(value)]) |
|
63 |
|
64 if addressInfo["ipv4"]: |
|
65 header = self.__createHeader(self.statusTree, self.tr("IPv4")) |
|
66 QTreeWidgetItem(header, [self.tr("Address"), addressInfo["ipv4"][0]]) |
|
67 QTreeWidgetItem(header, [self.tr("Netmask"), addressInfo["ipv4"][1]]) |
|
68 QTreeWidgetItem(header, [self.tr("Gateway"), addressInfo["ipv4"][2]]) |
|
69 QTreeWidgetItem(header, [self.tr("DNS"), addressInfo["ipv4"][3]]) |
|
70 |
|
71 if addressInfo["ipv6"]: |
|
72 header = self.__createHeader(self.statusTree, self.tr("IPv6")) |
|
73 addrHeader = self.__createHeader( |
|
74 header, self.tr("Addresses"), underlined=False |
|
75 ) |
|
76 for addr in sorted(addressInfo["ipv6"]): |
|
77 QTreeWidgetItem(addrHeader, [addr.lower(), ipv6AddressScope(addr)]) |
37 |
78 |
38 for col in range(self.statusTree.columnCount()): |
79 for col in range(self.statusTree.columnCount()): |
39 self.statusTree.resizeColumnToContents(col) |
80 self.statusTree.resizeColumnToContents(col) |
40 |
81 |
41 self.buttonBox.button(QDialogButtonBox.StandardButton.Close).setDefault(True) |
82 self.buttonBox.button(QDialogButtonBox.StandardButton.Close).setDefault(True) |
42 self.buttonBox.setFocus(Qt.FocusReason.OtherFocusReason) |
83 self.buttonBox.setFocus(Qt.FocusReason.OtherFocusReason) |
|
84 |
|
85 def __createHeader(self, parent, text, underlined=True): |
|
86 """ |
|
87 Private method to create a subheader item. |
|
88 |
|
89 @param parent reference to the parent item |
|
90 @type QTreeWidgetItem |
|
91 @param text text for the header item |
|
92 @type str |
|
93 @param underlined flag indicating an underlined header (defaults to True) |
|
94 @type bool (optional) |
|
95 @return reference to the created header item |
|
96 @rtype QTreeWidgetItem |
|
97 """ |
|
98 headerItem = QTreeWidgetItem(parent, [text]) |
|
99 headerItem.setExpanded(True) |
|
100 headerItem.setFirstColumnSpanned(True) |
|
101 |
|
102 if underlined: |
|
103 font = headerItem.font(0) |
|
104 font.setUnderline(True) |
|
105 headerItem.setFont(0, font) |
|
106 |
|
107 return headerItem |