src/eric7/MicroPython/WifiDialogs/WifiApConfigDialog.py

branch
mpy_network
changeset 9787
163511257f24
child 9797
3be7b2326e2c
diff -r 5f84d5eeee9e -r 163511257f24 src/eric7/MicroPython/WifiDialogs/WifiApConfigDialog.py
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/eric7/MicroPython/WifiDialogs/WifiApConfigDialog.py	Wed Feb 22 07:45:54 2023 +0100
@@ -0,0 +1,107 @@
+# -*- coding: utf-8 -*-
+
+# Copyright (c) 2023 Detlev Offenbach <detlev@die-offenbachs.de>
+#
+
+"""
+Module implementing a dialog to configure the Access Point interface.
+"""
+
+from PyQt6.QtCore import pyqtSlot
+from PyQt6.QtWidgets import QDialog, QDialogButtonBox, QLineEdit
+
+from eric7 import Preferences
+from eric7.EricGui import EricPixmapCache
+
+from .Ui_WifiApConfigDialog import Ui_WifiApConfigDialog
+
+
+class WifiApConfigDialog(QDialog, Ui_WifiApConfigDialog):
+    """
+    Class implementing a dialog to configure the Access Point interface.
+    """
+
+    def __init__(self, parent=None):
+        """
+        Constructor
+
+        @param parent reference to the parent widget (defaults to None)
+        @type QWidget (optional)
+        """
+        super().__init__(parent)
+        self.setupUi(self)
+
+        self.apShowPasswordButton.setIcon(EricPixmapCache.getIcon("showPassword"))
+
+        # populate the WiFi security mode combo box
+        self.apSecurityComboBox.addItem(self.tr("open"), 0)
+        self.apSecurityComboBox.addItem("WEP", 1)
+        self.apSecurityComboBox.addItem("WPA", 2)
+        self.apSecurityComboBox.addItem("WPA2", 3)
+        self.apSecurityComboBox.addItem("WPA/WPA2", 4)
+        self.apSecurityComboBox.addItem("WPA2 (CCMP)", 5)
+        self.apSecurityComboBox.addItem("WPA3", 6)
+        self.apSecurityComboBox.addItem("WPA2/WPA3", 7)
+
+        self.buttonBox.button(QDialogButtonBox.StandardButton.Ok).setEnabled(False)
+
+        self.apSsidEdit.textChanged.connect(self.__updateOk)
+        self.apPasswordEdit.textChanged.connect(self.__updateOk)
+        self.apSecurityComboBox.currentIndexChanged.connect(self.__updateOk)
+
+        # populate the field with data saved to the preferences
+        self.apSsidEdit.setText(Preferences.getMicroPython("WifiApName"))
+        self.apPasswordEdit.setText(Preferences.getMicroPython("WifiApPassword"))
+        index = self.apSecurityComboBox.findData(
+            Preferences.getMicroPython("WifiApAuthMode")
+        )
+        if index == -1:
+            index = 5  # default it to WPA/WPA2 in case of an issue
+        self.apSecurityComboBox.setCurrentIndex(index)
+
+        msh = self.minimumSizeHint()
+        self.resize(max(self.width(), msh.width()), msh.height())
+
+    @pyqtSlot()
+    def __updateOk(self):
+        """
+        Private method to update the enabled state of the OK button.
+        """
+        enable = bool(self.apSsidEdit.text())
+        if self.apSecurityComboBox.currentData() != 0:
+            # security needs a password
+            enable &= bool(self.apPasswordEdit.text())
+
+        self.buttonBox.button(QDialogButtonBox.StandardButton.Ok).setEnabled(enable)
+
+    @pyqtSlot(bool)
+    def on_apShowPasswordButton_clicked(self, checked):
+        """
+        Private slot to show or hide the WiFi Access Point password.
+
+        @param checked state of the button
+        @type bool
+        """
+        if checked:
+            self.apPasswordEdit.setEchoMode(QLineEdit.EchoMode.Normal)
+            self.apShowPasswordButton.setIcon(EricPixmapCache.getIcon("hidePassword"))
+            self.apShowPasswordButton.setToolTip(self.tr("Press to hide the password"))
+        else:
+            self.apPasswordEdit.setEchoMode(QLineEdit.EchoMode.Password)
+            self.apShowPasswordButton.setIcon(EricPixmapCache.getIcon("showPassword"))
+            self.apShowPasswordButton.setToolTip(self.tr("Press to show the password"))
+
+    def getApConfig(self):
+        """
+        Public method to get the entered access point configuration data.
+
+        @return tuple containing the SSID, the password, the selected security mode
+            and a flag indicating to save the parameters to the settings
+        @rtype tuple of (str, str, int, bool)
+        """
+        return (
+            self.apSsidEdit.text(),
+            self.apPasswordEdit.text(),
+            self.apSecurityComboBox.currentData(),
+            self.rememberCheckBox.isChecked(),
+        )

eric ide

mercurial