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