diff -r 5f84d5eeee9e -r 163511257f24 src/eric7/MicroPython/WifiDialogs/WifiController.py --- a/src/eric7/MicroPython/WifiDialogs/WifiController.py Tue Feb 21 10:53:46 2023 +0100 +++ b/src/eric7/MicroPython/WifiDialogs/WifiController.py Wed Feb 22 07:45:54 2023 +0100 @@ -11,6 +11,7 @@ from PyQt6.QtWidgets import QDialog, QMenu from eric7 import Preferences +from eric7.EricGui.EricOverrideCursor import EricOverrideCursor from eric7.EricWidgets import EricMessageBox @@ -87,7 +88,7 @@ dlg = WifiStatusDialog(clientStatus, apStatus) dlg.exec() except Exception as exc: - self.__showError("getWifiData()", str(exc)) + self.__mpy.showError("getWifiData()", str(exc)) @pyqtSlot() def __connectWifi(self): @@ -187,8 +188,33 @@ This will also modify the boot script to perform an automatic WiFi connection. """ - # TODO: not implemented yet - pass + from .WifiConnectionDialog import WifiConnectionDialog + + dlg = WifiConnectionDialog() + if dlg.exec() == QDialog.DialogCode.Accepted: + ssid, password, remember = dlg.getConnectionParameters() + if remember: + # save the parameters to the preferences + Preferences.setMicroPython("WifiName", ssid) + Preferences.setMicroPython("WifiPassword", password) + success, error = self.__mpy.getDevice().writeCredentials(ssid, password) + if success: + EricMessageBox.information( + None, + self.tr("Write WiFi Credentials"), + self.tr( + "<p>The WiFi credentials were saved on the device. The device" + " will connect to the WiFi network at boot time.</p>"), + ) + else: + EricMessageBox.critical( + None, + self.tr("Write WiFi Credentials"), + self.tr( + "<p>The WiFi credentials could not be saved on the device.</p>" + "<p>Reason: {0}</p>" + ).format(error if error else self.tr("unknown")), + ) @pyqtSlot() def __removeCredentials(self): @@ -198,16 +224,71 @@ This will not remove the auto-connect part of the boot script. This needs to be done manually if desired. """ - # TODO: not implemented yet - pass + ok = EricMessageBox.yesNo( + None, + self.tr("Remove WiFi Credentials"), + self.tr( + "Shall the saved WiFi credentials really be removed from the connected" + " device?" + ), + ) + if ok: + success, error = self.__mpy.getDevice().removeCredentials() + if success: + EricMessageBox.information( + None, + self.tr("Remove WiFi Credentials"), + self.tr( + "<p>The WiFi credentials were removed the device. The device" + " will not connect to the WiFi network at boot time anymore." + "</p>"), + ) + else: + EricMessageBox.critical( + None, + self.tr("Remove WiFi Credentials"), + self.tr( + "<p>The WiFi credentials could not be removed from the device." + "</p><p>Reason: {0}</p>" + ).format(error if error else self.tr("unknown")), + ) @pyqtSlot() def __startAccessPoint(self): """ Private slot to start the Access Point interface of the connected device. """ - # TODO: not implemented yet - pass + from .WifiApConfigDialog import WifiApConfigDialog + + dlg = WifiApConfigDialog() + if dlg.exec() == QDialog.DialogCode.Accepted: + ssid, password, security, remember = dlg.getApConfig() + + if remember: + Preferences.setMicroPython("WifiApName", ssid) + Preferences.setMicroPython("WifiApPassword", password) + Preferences.setMicroPython("WifiApAuthMode", security) + + ok, err = self.__mpy.getDevice().startAccessPoint( + ssid, security=security, password=password + ) + if ok: + EricMessageBox.information( + None, + self.tr("Start WiFi Access Point"), + self.tr( + "The WiFi Access Point interface was started successfully." + ), + ) + else: + msg = self.tr("<p>The WiFi Access Point could not be started.</p>") + if err: + msg += self.tr("<p>Reason: {0}").format(err) + EricMessageBox.critical( + None, + self.tr("Start WiFi Access Point"), + msg, + ) @pyqtSlot() def __stopAccessPoint(self): @@ -237,8 +318,23 @@ Private slot to show a list of WiFi clients connected to the Access Point interface. """ - # TODO: not implemented yet - pass + from .WifiApStationsDialog import WifiApStationsDialog + + with EricOverrideCursor(): + stations, err = self.__mpy.getDevice().getConnectedClients() + + if err: + self.__mpy.showError("getConnectedClients()", err) + else: + if stations: + dlg = WifiApStationsDialog(stations) + dlg.exec() + else: + EricMessageBox.information( + None, + self.tr("Show Connected Clients"), + self.tr("No clients are connected to the access point."), + ) def __deactivateInterface(self, interface): """