19 class WifiApConfigDialog(QDialog, Ui_WifiApConfigDialog): |
19 class WifiApConfigDialog(QDialog, Ui_WifiApConfigDialog): |
20 """ |
20 """ |
21 Class implementing a dialog to configure the Access Point interface. |
21 Class implementing a dialog to configure the Access Point interface. |
22 """ |
22 """ |
23 |
23 |
24 def __init__(self, parent=None): |
24 def __init__(self, withIP, parent=None): |
25 """ |
25 """ |
26 Constructor |
26 Constructor |
27 |
27 |
|
28 @param withIP flag indicating to ask the user for an IP configuration |
|
29 @type bool |
28 @param parent reference to the parent widget (defaults to None) |
30 @param parent reference to the parent widget (defaults to None) |
29 @type QWidget (optional) |
31 @type QWidget (optional) |
30 """ |
32 """ |
31 super().__init__(parent) |
33 super().__init__(parent) |
32 self.setupUi(self) |
34 self.setupUi(self) |
43 self.apSecurityComboBox.addItem("WPA3", 6) |
45 self.apSecurityComboBox.addItem("WPA3", 6) |
44 self.apSecurityComboBox.addItem("WPA2/WPA3", 7) |
46 self.apSecurityComboBox.addItem("WPA2/WPA3", 7) |
45 |
47 |
46 self.buttonBox.button(QDialogButtonBox.StandardButton.Ok).setEnabled(False) |
48 self.buttonBox.button(QDialogButtonBox.StandardButton.Ok).setEnabled(False) |
47 |
49 |
48 self.apSsidEdit.textChanged.connect(self.__updateOk) |
50 # populate the WiFi fields with data saved to the preferences |
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")) |
51 self.apSsidEdit.setText(Preferences.getMicroPython("WifiApName")) |
54 self.apPasswordEdit.setText(Preferences.getMicroPython("WifiApPassword")) |
52 self.apPasswordEdit.setText(Preferences.getMicroPython("WifiApPassword")) |
55 index = self.apSecurityComboBox.findData( |
53 index = self.apSecurityComboBox.findData( |
56 Preferences.getMicroPython("WifiApAuthMode") |
54 Preferences.getMicroPython("WifiApAuthMode") |
57 ) |
55 ) |
58 if index == -1: |
56 if index == -1: |
59 index = 5 # default it to WPA/WPA2 in case of an issue |
57 index = 5 # default it to WPA/WPA2 in case of an issue |
60 self.apSecurityComboBox.setCurrentIndex(index) |
58 self.apSecurityComboBox.setCurrentIndex(index) |
|
59 |
|
60 self.__withIP = withIP |
|
61 |
|
62 self.ipv4GroupBox.setVisible(withIP) |
|
63 if withIP: |
|
64 # populate the IPv4 configuration with data saved to the preferences |
|
65 self.addressEdit.setText(Preferences.getMicroPython("WifiApAddress")) |
|
66 self.netmaskEdit.setText(Preferences.getMicroPython("WifiApNetmask")) |
|
67 self.gatewayEdit.setText(Preferences.getMicroPython("WifiApGateway")) |
|
68 self.dnsEdit.setText(Preferences.getMicroPython("WifiApDNS")) |
|
69 |
|
70 # connect the IPv4 fields |
|
71 self.addressEdit.addressChanged.connect(self.__updateOk) |
|
72 self.netmaskEdit.addressChanged.connect(self.__updateOk) |
|
73 self.gatewayEdit.addressChanged.connect(self.__updateOk) |
|
74 self.dnsEdit.addressChanged.connect(self.__updateOk) |
|
75 |
|
76 # connect the WiFi fields |
|
77 self.apSsidEdit.textChanged.connect(self.__updateOk) |
|
78 self.apPasswordEdit.textChanged.connect(self.__updateOk) |
|
79 self.apSecurityComboBox.currentIndexChanged.connect(self.__updateOk) |
|
80 |
|
81 self.__updateOk() |
61 |
82 |
62 msh = self.minimumSizeHint() |
83 msh = self.minimumSizeHint() |
63 self.resize(max(self.width(), msh.width()), msh.height()) |
84 self.resize(max(self.width(), msh.width()), msh.height()) |
64 |
85 |
65 @pyqtSlot() |
86 @pyqtSlot() |
69 """ |
90 """ |
70 enable = bool(self.apSsidEdit.text()) |
91 enable = bool(self.apSsidEdit.text()) |
71 if self.apSecurityComboBox.currentData() != 0: |
92 if self.apSecurityComboBox.currentData() != 0: |
72 # security needs a password |
93 # security needs a password |
73 enable &= bool(self.apPasswordEdit.text()) |
94 enable &= bool(self.apPasswordEdit.text()) |
|
95 if self.__withIP: |
|
96 enable &= ( |
|
97 self.addressEdit.hasAcceptableInput() |
|
98 and self.netmaskEdit.hasAcceptableInput() |
|
99 and self.gatewayEdit.hasAcceptableInput() |
|
100 and self.dnsEdit.hasAcceptableInput() |
|
101 ) |
74 |
102 |
75 self.buttonBox.button(QDialogButtonBox.StandardButton.Ok).setEnabled(enable) |
103 self.buttonBox.button(QDialogButtonBox.StandardButton.Ok).setEnabled(enable) |
76 |
104 |
77 @pyqtSlot(bool) |
105 @pyqtSlot(bool) |
78 def on_apShowPasswordButton_clicked(self, checked): |
106 def on_apShowPasswordButton_clicked(self, checked): |
97 |
125 |
98 @return tuple containing the SSID, the password, the selected security mode |
126 @return tuple containing the SSID, the password, the selected security mode |
99 and a flag indicating to save the parameters to the settings |
127 and a flag indicating to save the parameters to the settings |
100 @rtype tuple of (str, str, int, bool) |
128 @rtype tuple of (str, str, int, bool) |
101 """ |
129 """ |
|
130 if self.__withIP: |
|
131 ifconfig = ( |
|
132 self.addressEdit.text(), |
|
133 self.netmaskEdit.text(), |
|
134 self.gatewayEdit.text(), |
|
135 self.dnsEdit.text(), |
|
136 ) |
|
137 else: |
|
138 ifconfig = ("", "", "", "") |
|
139 |
102 return ( |
140 return ( |
103 self.apSsidEdit.text(), |
141 self.apSsidEdit.text(), |
104 self.apPasswordEdit.text(), |
142 self.apPasswordEdit.text(), |
105 self.apSecurityComboBox.currentData(), |
143 self.apSecurityComboBox.currentData(), |
106 self.rememberCheckBox.isChecked(), |
144 self.rememberCheckBox.isChecked(), |
|
145 ifconfig, |
107 ) |
146 ) |