|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2023 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing a dialog to configure the Access Point interface. |
|
8 """ |
|
9 |
|
10 from PyQt6.QtCore import pyqtSlot |
|
11 from PyQt6.QtWidgets import QDialog, QDialogButtonBox, QLineEdit |
|
12 |
|
13 from eric7 import Preferences |
|
14 from eric7.EricGui import EricPixmapCache |
|
15 |
|
16 from .Ui_WifiApConfigDialog import Ui_WifiApConfigDialog |
|
17 |
|
18 |
|
19 class WifiApConfigDialog(QDialog, Ui_WifiApConfigDialog): |
|
20 """ |
|
21 Class implementing a dialog to configure the Access Point interface. |
|
22 """ |
|
23 |
|
24 def __init__(self, parent=None): |
|
25 """ |
|
26 Constructor |
|
27 |
|
28 @param parent reference to the parent widget (defaults to None) |
|
29 @type QWidget (optional) |
|
30 """ |
|
31 super().__init__(parent) |
|
32 self.setupUi(self) |
|
33 |
|
34 self.apShowPasswordButton.setIcon(EricPixmapCache.getIcon("showPassword")) |
|
35 |
|
36 # populate the WiFi security mode combo box |
|
37 self.apSecurityComboBox.addItem(self.tr("open"), 0) |
|
38 self.apSecurityComboBox.addItem("WEP", 1) |
|
39 self.apSecurityComboBox.addItem("WPA", 2) |
|
40 self.apSecurityComboBox.addItem("WPA2", 3) |
|
41 self.apSecurityComboBox.addItem("WPA/WPA2", 4) |
|
42 self.apSecurityComboBox.addItem("WPA2 (CCMP)", 5) |
|
43 self.apSecurityComboBox.addItem("WPA3", 6) |
|
44 self.apSecurityComboBox.addItem("WPA2/WPA3", 7) |
|
45 |
|
46 self.buttonBox.button(QDialogButtonBox.StandardButton.Ok).setEnabled(False) |
|
47 |
|
48 self.apSsidEdit.textChanged.connect(self.__updateOk) |
|
49 self.apPasswordEdit.textChanged.connect(self.__updateOk) |
|
50 self.apSecurityComboBox.currentIndexChanged.connect(self.__updateOk) |
|
51 |
|
52 # populate the field with data saved to the preferences |
|
53 self.apSsidEdit.setText(Preferences.getMicroPython("WifiApName")) |
|
54 self.apPasswordEdit.setText(Preferences.getMicroPython("WifiApPassword")) |
|
55 index = self.apSecurityComboBox.findData( |
|
56 Preferences.getMicroPython("WifiApAuthMode") |
|
57 ) |
|
58 if index == -1: |
|
59 index = 5 # default it to WPA/WPA2 in case of an issue |
|
60 self.apSecurityComboBox.setCurrentIndex(index) |
|
61 |
|
62 msh = self.minimumSizeHint() |
|
63 self.resize(max(self.width(), msh.width()), msh.height()) |
|
64 |
|
65 @pyqtSlot() |
|
66 def __updateOk(self): |
|
67 """ |
|
68 Private method to update the enabled state of the OK button. |
|
69 """ |
|
70 enable = bool(self.apSsidEdit.text()) |
|
71 if self.apSecurityComboBox.currentData() != 0: |
|
72 # security needs a password |
|
73 enable &= bool(self.apPasswordEdit.text()) |
|
74 |
|
75 self.buttonBox.button(QDialogButtonBox.StandardButton.Ok).setEnabled(enable) |
|
76 |
|
77 @pyqtSlot(bool) |
|
78 def on_apShowPasswordButton_clicked(self, checked): |
|
79 """ |
|
80 Private slot to show or hide the WiFi Access Point password. |
|
81 |
|
82 @param checked state of the button |
|
83 @type bool |
|
84 """ |
|
85 if checked: |
|
86 self.apPasswordEdit.setEchoMode(QLineEdit.EchoMode.Normal) |
|
87 self.apShowPasswordButton.setIcon(EricPixmapCache.getIcon("hidePassword")) |
|
88 self.apShowPasswordButton.setToolTip(self.tr("Press to hide the password")) |
|
89 else: |
|
90 self.apPasswordEdit.setEchoMode(QLineEdit.EchoMode.Password) |
|
91 self.apShowPasswordButton.setIcon(EricPixmapCache.getIcon("showPassword")) |
|
92 self.apShowPasswordButton.setToolTip(self.tr("Press to show the password")) |
|
93 |
|
94 def getApConfig(self): |
|
95 """ |
|
96 Public method to get the entered access point configuration data. |
|
97 |
|
98 @return tuple containing the SSID, the password, the selected security mode |
|
99 and a flag indicating to save the parameters to the settings |
|
100 @rtype tuple of (str, str, int, bool) |
|
101 """ |
|
102 return ( |
|
103 self.apSsidEdit.text(), |
|
104 self.apPasswordEdit.text(), |
|
105 self.apSecurityComboBox.currentData(), |
|
106 self.rememberCheckBox.isChecked(), |
|
107 ) |