4 # |
4 # |
5 |
5 |
6 """ |
6 """ |
7 Module implementing the Debugger General configuration page. |
7 Module implementing the Debugger General configuration page. |
8 """ |
8 """ |
9 |
|
10 import re |
|
11 |
9 |
12 from PyQt6.QtCore import QAbstractItemModel, QModelIndex, Qt, pyqtSlot |
10 from PyQt6.QtCore import QAbstractItemModel, QModelIndex, Qt, pyqtSlot |
13 from PyQt6.QtGui import QBrush, QColor |
11 from PyQt6.QtGui import QBrush, QColor |
14 from PyQt6.QtNetwork import QAbstractSocket, QHostAddress, QNetworkInterface |
12 from PyQt6.QtNetwork import QAbstractSocket, QHostAddress, QNetworkInterface |
15 from PyQt6.QtWidgets import QInputDialog, QLineEdit |
13 from PyQt6.QtWidgets import QInputDialog, QLineEdit |
56 self.consoleDbgCompleter = EricFileCompleter(self.consoleDbgEdit) |
54 self.consoleDbgCompleter = EricFileCompleter(self.consoleDbgEdit) |
57 self.dbgTranslationLocalCompleter = EricDirCompleter( |
55 self.dbgTranslationLocalCompleter = EricDirCompleter( |
58 self.dbgTranslationLocalEdit |
56 self.dbgTranslationLocalEdit |
59 ) |
57 ) |
60 |
58 |
61 # set initial values |
59 self.interfaceSelectorComboBox.addItem( |
62 interfaces = [] |
60 self.tr("All Network Interfaces (IPv4 & IPv6)"), |
|
61 "all", |
|
62 ) |
|
63 self.interfaceSelectorComboBox.addItem( |
|
64 self.tr("All Network Interfaces (IPv4"), |
|
65 "allv4", |
|
66 ) |
|
67 self.interfaceSelectorComboBox.addItem( |
|
68 self.tr("All Network Interfaces (IPv6)"), |
|
69 "allv6", |
|
70 ) |
|
71 self.interfaceSelectorComboBox.addItem( |
|
72 self.tr("Localhost (IPv4)"), |
|
73 "localv4", |
|
74 ) |
|
75 self.interfaceSelectorComboBox.addItem( |
|
76 self.tr("Localhost (IPv6)"), |
|
77 "localv6", |
|
78 ) |
|
79 self.interfaceSelectorComboBox.addItem( |
|
80 self.tr("Selected Interface"), |
|
81 "selected", |
|
82 ) |
|
83 |
63 networkInterfaces = QNetworkInterface.allInterfaces() |
84 networkInterfaces = QNetworkInterface.allInterfaces() |
64 for networkInterface in networkInterfaces: |
85 for networkInterface in networkInterfaces: |
65 addressEntries = networkInterface.addressEntries() |
86 addressEntries = networkInterface.addressEntries() |
66 if len(addressEntries) > 0: |
87 if len(addressEntries) > 0: |
67 for addressEntry in addressEntries: |
88 for addressEntry in addressEntries: |
68 interfaces.append( |
89 ip = addressEntry.ip().toString() |
69 "{0} ({1})".format( |
90 self.interfacesCombo.addItem( |
70 networkInterface.humanReadableName(), |
91 "{0} ({1})".format(networkInterface.humanReadableName(), ip), ip |
71 addressEntry.ip().toString(), |
|
72 ) |
|
73 ) |
92 ) |
74 self.interfacesCombo.addItems(interfaces) |
93 |
|
94 # set initial values |
75 interface = Preferences.getDebugger("NetworkInterface") |
95 interface = Preferences.getDebugger("NetworkInterface") |
76 # TODO: change config 'all' to 'allv4' |
96 selectorIndex = self.interfaceSelectorComboBox.findData(interface) |
77 # TODO: change radiobutton selection to combo box and include |
97 if selectorIndex != -1: |
78 # - Localhost (IPv4) (localv4) |
98 self.interfaceSelectorComboBox.setCurrentIndex(selectorIndex) |
79 # - LocalHost (IPv6) (localv6) |
99 else: |
80 # - Any (IPv4) (allv4) |
100 # Interface given by IP address |
81 # - Any (IPv6) (allv6) |
101 self.interfaceSelectorComboBox.setCurrentIndex( |
82 # - Any (IPv4 and IPv6) (all) |
102 self.interfaceSelectorComboBox.count() - 1 |
83 # - Selected Interface |
103 ) |
|
104 self.interfacesCombo.setCurrentIndex( |
|
105 self.interfacesCombo.findData(interface) |
|
106 ) |
|
107 self.on_interfaceSelectorComboBox_currentIndexChanged( |
|
108 self.interfacesCombo.currentIndex() |
|
109 ) |
|
110 self.serverPortStaticGroup.setChecked( |
|
111 Preferences.getDebugger("NetworkPortFixed") |
|
112 ) |
|
113 self.serverPortIncrementCheckBox.setChecked( |
|
114 Preferences.getDebugger("NetworkPortIncrement") |
|
115 ) |
|
116 self.serverPortSpinBox.setValue(Preferences.getDebugger("NetworkPort")) |
84 # TODO: allow to listen on a specific port with auto-increment if port is in |
117 # TODO: allow to listen on a specific port with auto-increment if port is in |
85 # use already |
118 # use already |
86 if interface == "all": |
|
87 self.allInterfacesButton.setChecked(True) |
|
88 elif interface == "allv6": |
|
89 self.all6InterfacesButton.setChecked(True) |
|
90 else: |
|
91 self.selectedInterfaceButton.setChecked(True) |
|
92 index = -1 |
|
93 for i in range(len(interfaces)): |
|
94 if re.fullmatch(".*{0}.*".format(interface), interfaces[i]): |
|
95 index = i |
|
96 break |
|
97 self.interfacesCombo.setCurrentIndex(index) |
|
98 |
119 |
99 self.allowedHostsList.addItems(Preferences.getDebugger("AllowedHosts")) |
120 self.allowedHostsList.addItems(Preferences.getDebugger("AllowedHosts")) |
100 |
121 |
101 self.remoteDebuggerGroup.setChecked(Preferences.getDebugger("RemoteDbgEnabled")) |
122 self.remoteDebuggerGroup.setChecked(Preferences.getDebugger("RemoteDbgEnabled")) |
102 self.hostLineEdit.setText(Preferences.getDebugger("RemoteHost")) |
123 self.hostLineEdit.setText(Preferences.getDebugger("RemoteHost")) |
191 Preferences.setDebugger("PassiveDbgPort", self.passiveDbgPortSpinBox.value()) |
212 Preferences.setDebugger("PassiveDbgPort", self.passiveDbgPortSpinBox.value()) |
192 Preferences.setDebugger( |
213 Preferences.setDebugger( |
193 "PassiveDbgType", self.passiveDbgBackendCombo.currentText() |
214 "PassiveDbgType", self.passiveDbgBackendCombo.currentText() |
194 ) |
215 ) |
195 |
216 |
196 if self.allInterfacesButton.isChecked(): |
217 interface = self.interfaceSelectorComboBox.currentData() |
197 Preferences.setDebugger("NetworkInterface", "all") |
218 if interface == "selected": |
198 elif self.all6InterfacesButton.isChecked(): |
219 interface = self.interfacesCombo.currentData() |
199 Preferences.setDebugger("NetworkInterface", "allv6") |
220 Preferences.setDebugger("NetworkInterface", interface) |
200 else: |
221 Preferences.setDebugger( |
201 interface = self.interfacesCombo.currentText() |
222 "NetworkPortFixed", self.serverPortStaticGroup.isChecked() |
202 interface = interface.split("(")[1].split(")")[0] |
223 ) |
203 if not interface: |
224 Preferences.setDebugger( |
204 Preferences.setDebugger("NetworkInterface", "all") |
225 "NetworkPortIncrement", self.serverPortIncrementCheckBox.isChecked() |
205 else: |
226 ) |
206 Preferences.setDebugger("NetworkInterface", interface) |
227 Preferences.setDebugger("NetworkPort", self.serverPortSpinBox.value()) |
207 |
228 |
208 allowedHosts = [] |
229 allowedHosts = [] |
209 for row in range(self.allowedHostsList.count()): |
230 for row in range(self.allowedHostsList.count()): |
210 allowedHosts.append(self.allowedHostsList.item(row).text()) |
231 allowedHosts.append(self.allowedHostsList.item(row).text()) |
211 Preferences.setDebugger("AllowedHosts", allowedHosts) |
232 Preferences.setDebugger("AllowedHosts", allowedHosts) |
251 # Store background colors for debug viewer |
272 # Store background colors for debug viewer |
252 self.saveColours(Preferences.setDebugger) |
273 self.saveColours(Preferences.setDebugger) |
253 |
274 |
254 Preferences.setDebugger( |
275 Preferences.setDebugger( |
255 "AutoViewSourceCode", self.autoViewSourcecodeCheckBox.isChecked() |
276 "AutoViewSourceCode", self.autoViewSourcecodeCheckBox.isChecked() |
|
277 ) |
|
278 |
|
279 @pyqtSlot(int) |
|
280 def on_interfaceSelectorComboBox_currentIndexChanged(self, index): |
|
281 """ |
|
282 Private slot to handle the selection of a network interface type. |
|
283 |
|
284 @param index index of the selected entry |
|
285 @type int |
|
286 """ |
|
287 self.interfacesCombo.setEnabled( |
|
288 index == self.interfaceSelectorComboBox.count() - 1 |
256 ) |
289 ) |
257 |
290 |
258 def on_allowedHostsList_currentItemChanged(self, current, previous): |
291 def on_allowedHostsList_currentItemChanged(self, current, previous): |
259 """ |
292 """ |
260 Private method set the state of the edit and delete button. |
293 Private method set the state of the edit and delete button. |