MqttMonitor/MqttConnectionOptionsDialog.py

Sun, 18 Jul 2021 18:30:15 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sun, 18 Jul 2021 18:30:15 +0200
branch
eric7
changeset 97
21f9c010dc42
parent 92
2fb5c08019fd
child 103
5fe4f179975f
permissions
-rw-r--r--

Added the MQTT protocol version to the list of connection parameters.

10
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2
84
044df16e55aa Updated copyright for 2021.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 78
diff changeset
3 # Copyright (c) 2018 - 2021 Detlev Offenbach <detlev@die-offenbachs.de>
11
90d3ebed4cc0 Finished implementing the connection options dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10
diff changeset
4 #
90d3ebed4cc0 Finished implementing the connection options dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10
diff changeset
5
10
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6 """
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
7 Module implementing a dialog to enter MQTT connection options.
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
8 """
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9
92
2fb5c08019fd Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 86
diff changeset
10 from PyQt6.QtCore import pyqtSlot, QUuid
2fb5c08019fd Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 86
diff changeset
11 from PyQt6.QtWidgets import QDialog, QDialogButtonBox, QAbstractButton
10
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
12
92
2fb5c08019fd Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 86
diff changeset
13 from EricWidgets import EricMessageBox
2fb5c08019fd Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 86
diff changeset
14 from EricWidgets.EricPathPicker import EricPathPickerModes
20
3737a78bb6c5 MqttConnectionOptionsDialog: added some validity checks and added the default value for 'keepalive' setting.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 18
diff changeset
15
10
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
16 from .Ui_MqttConnectionOptionsDialog import Ui_MqttConnectionOptionsDialog
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
17
97
21f9c010dc42 Added the MQTT protocol version to the list of connection parameters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 92
diff changeset
18 from .MqttClient import MqttClient, MqttProtocols
21f9c010dc42 Added the MQTT protocol version to the list of connection parameters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 92
diff changeset
19
22
545979c7dcd4 MqttClient, MqttConnectionOptionsDialog: added support for encrypted passwords.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 20
diff changeset
20 from Utilities.crypto import pwConvert
545979c7dcd4 MqttClient, MqttConnectionOptionsDialog: added support for encrypted passwords.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 20
diff changeset
21
10
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
22
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
23 class MqttConnectionOptionsDialog(QDialog, Ui_MqttConnectionOptionsDialog):
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
24 """
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
25 Class implementing a dialog to enter MQTT connection options.
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
26 """
97
21f9c010dc42 Added the MQTT protocol version to the list of connection parameters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 92
diff changeset
27 def __init__(self, options=None, parent=None):
10
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
28 """
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
29 Constructor
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
30
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
31 @param options dictionary containing the connection options to
11
90d3ebed4cc0 Finished implementing the connection options dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10
diff changeset
32 populate the dialog with. It must have the keys "ClientId",
97
21f9c010dc42 Added the MQTT protocol version to the list of connection parameters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 92
diff changeset
33 "Protocol", "ConnectionTimeout", "Keepalive", "CleanSession",
21f9c010dc42 Added the MQTT protocol version to the list of connection parameters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 92
diff changeset
34 "Username", "Password", "WillTopic", "WillMessage", "WillQos",
21f9c010dc42 Added the MQTT protocol version to the list of connection parameters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 92
diff changeset
35 "WillRetain", "TlsEnable", "TlsCaCert".
18
bbfe5866b6aa MqttConnectionProfilesDialog: continued implementing the connections profile dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 11
diff changeset
36 @type dict
10
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
37 @param parent reference to the parent widget
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
38 @type QWidget
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
39 """
86
620022b14cb4 Implemented some code simplifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 84
diff changeset
40 super().__init__(parent)
10
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
41 self.setupUi(self)
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
42
92
2fb5c08019fd Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 86
diff changeset
43 self.tlsCertsFilePicker.setMode(EricPathPickerModes.OPEN_FILE_MODE)
25
01d44a4decf5 MqttConnectionOptionsDialog: added support for TLS.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 22
diff changeset
44 self.tlsCertsFilePicker.setFilters(
01d44a4decf5 MqttConnectionOptionsDialog: added support for TLS.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 22
diff changeset
45 self.tr("Certificate Files (*.crt *.pem);;All Files (*)"))
01d44a4decf5 MqttConnectionOptionsDialog: added support for TLS.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 22
diff changeset
46
10
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
47 self.__populateDefaults(options=options)
20
3737a78bb6c5 MqttConnectionOptionsDialog: added some validity checks and added the default value for 'keepalive' setting.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 18
diff changeset
48
3737a78bb6c5 MqttConnectionOptionsDialog: added some validity checks and added the default value for 'keepalive' setting.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 18
diff changeset
49 self.__updateOkButton()
3737a78bb6c5 MqttConnectionOptionsDialog: added some validity checks and added the default value for 'keepalive' setting.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 18
diff changeset
50
3737a78bb6c5 MqttConnectionOptionsDialog: added some validity checks and added the default value for 'keepalive' setting.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 18
diff changeset
51 def __updateOkButton(self):
3737a78bb6c5 MqttConnectionOptionsDialog: added some validity checks and added the default value for 'keepalive' setting.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 18
diff changeset
52 """
3737a78bb6c5 MqttConnectionOptionsDialog: added some validity checks and added the default value for 'keepalive' setting.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 18
diff changeset
53 Private method to update the enabled state of the OK button.
3737a78bb6c5 MqttConnectionOptionsDialog: added some validity checks and added the default value for 'keepalive' setting.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 18
diff changeset
54 """
78
a22328182bc2 Removed support for Python2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 66
diff changeset
55 if (
a22328182bc2 Removed support for Python2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 66
diff changeset
56 self.clientIdEdit.text() == "" and
a22328182bc2 Removed support for Python2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 66
diff changeset
57 not self.cleanSessionCheckBox.isChecked()
a22328182bc2 Removed support for Python2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 66
diff changeset
58 ):
20
3737a78bb6c5 MqttConnectionOptionsDialog: added some validity checks and added the default value for 'keepalive' setting.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 18
diff changeset
59 enable = False
92
2fb5c08019fd Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 86
diff changeset
60 EricMessageBox.critical(
20
3737a78bb6c5 MqttConnectionOptionsDialog: added some validity checks and added the default value for 'keepalive' setting.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 18
diff changeset
61 self,
3737a78bb6c5 MqttConnectionOptionsDialog: added some validity checks and added the default value for 'keepalive' setting.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 18
diff changeset
62 self.tr("Invalid Connection Parameters"),
3737a78bb6c5 MqttConnectionOptionsDialog: added some validity checks and added the default value for 'keepalive' setting.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 18
diff changeset
63 self.tr("""An empty Client ID requires a clean session."""))
3737a78bb6c5 MqttConnectionOptionsDialog: added some validity checks and added the default value for 'keepalive' setting.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 18
diff changeset
64 else:
3737a78bb6c5 MqttConnectionOptionsDialog: added some validity checks and added the default value for 'keepalive' setting.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 18
diff changeset
65 enable = True
3737a78bb6c5 MqttConnectionOptionsDialog: added some validity checks and added the default value for 'keepalive' setting.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 18
diff changeset
66
92
2fb5c08019fd Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 86
diff changeset
67 self.buttonBox.button(
2fb5c08019fd Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 86
diff changeset
68 QDialogButtonBox.StandardButton.Ok).setEnabled(enable)
11
90d3ebed4cc0 Finished implementing the connection options dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10
diff changeset
69
90d3ebed4cc0 Finished implementing the connection options dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10
diff changeset
70 @pyqtSlot()
90d3ebed4cc0 Finished implementing the connection options dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10
diff changeset
71 def on_generateIdButton_clicked(self):
90d3ebed4cc0 Finished implementing the connection options dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10
diff changeset
72 """
90d3ebed4cc0 Finished implementing the connection options dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10
diff changeset
73 Private slot to generate a client ID.
90d3ebed4cc0 Finished implementing the connection options dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10
diff changeset
74 """
90d3ebed4cc0 Finished implementing the connection options dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10
diff changeset
75 uuid = QUuid.createUuid()
92
2fb5c08019fd Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 86
diff changeset
76 self.clientIdEdit.setText(
2fb5c08019fd Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 86
diff changeset
77 uuid.toString(QUuid.StringFormat.WithoutBraces))
10
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
78
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
79 @pyqtSlot(QAbstractButton)
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
80 def on_buttonBox_clicked(self, button):
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
81 """
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
82 Private slot to handle the press of a button box button.
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
83
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
84 @param button button that has been pressed
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
85 @type QAbstractButton
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
86 """
92
2fb5c08019fd Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 86
diff changeset
87 if button == self.buttonBox.button(
2fb5c08019fd Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 86
diff changeset
88 QDialogButtonBox.StandardButton.RestoreDefaults
2fb5c08019fd Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 86
diff changeset
89 ):
10
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
90 self.__populateDefaults(options=None)
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
91
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
92 def __populateDefaults(self, options=None):
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
93 """
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
94 Private method to populate the dialog.
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
95
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
96 If no options dictionary is given, the dialog will be populated with
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
97 default values.
11
90d3ebed4cc0 Finished implementing the connection options dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10
diff changeset
98
90d3ebed4cc0 Finished implementing the connection options dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10
diff changeset
99 @param options dictionary containing the connection options to populate
90d3ebed4cc0 Finished implementing the connection options dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10
diff changeset
100 the dialog with. It must have the keys "ClientId", "Keepalive",
90d3ebed4cc0 Finished implementing the connection options dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10
diff changeset
101 "CleanSession", "Username", "Password", "WillTopic", "WillMessage",
31
40582e448c4b Added a connect timeout function with a settable timeout value.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 30
diff changeset
102 "WillQos", "WillRetain", "TlsEnable", "TlsCaCert",
40582e448c4b Added a connect timeout function with a settable timeout value.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 30
diff changeset
103 "ConnectionTimeout".
11
90d3ebed4cc0 Finished implementing the connection options dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10
diff changeset
104 @type dict
10
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
105 """
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
106 if options is None:
97
21f9c010dc42 Added the MQTT protocol version to the list of connection parameters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 92
diff changeset
107 options = MqttClient.defaultConnectionOptions()
10
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
108
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
109 # general
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
110 self.clientIdEdit.setText(options["ClientId"])
97
21f9c010dc42 Added the MQTT protocol version to the list of connection parameters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 92
diff changeset
111 self.mqttv31Button.setChecked(
21f9c010dc42 Added the MQTT protocol version to the list of connection parameters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 92
diff changeset
112 options["Protocol"] == MqttProtocols.MQTTv31)
21f9c010dc42 Added the MQTT protocol version to the list of connection parameters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 92
diff changeset
113 self.mqttv311Button.setChecked(
21f9c010dc42 Added the MQTT protocol version to the list of connection parameters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 92
diff changeset
114 options["Protocol"] == MqttProtocols.MQTTv311)
21f9c010dc42 Added the MQTT protocol version to the list of connection parameters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 92
diff changeset
115 self.mqttv5Button.setChecked(
21f9c010dc42 Added the MQTT protocol version to the list of connection parameters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 92
diff changeset
116 options["Protocol"] == MqttProtocols.MQTTv5)
31
40582e448c4b Added a connect timeout function with a settable timeout value.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 30
diff changeset
117 self.connectionTimeoutSpinBox.setValue(options["ConnectionTimeout"])
10
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
118 self.keepaliveSpinBox.setValue(options["Keepalive"])
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
119 self.cleanSessionCheckBox.setChecked(options["CleanSession"])
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
120
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
121 # user credentials
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
122 self.usernameEdit.setText(options["Username"])
22
545979c7dcd4 MqttClient, MqttConnectionOptionsDialog: added support for encrypted passwords.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 20
diff changeset
123 self.passwordEdit.setText(pwConvert(options["Password"], encode=False))
10
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
124
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
125 # last will and testament
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
126 self.willQosSpinBox.setValue(options["WillQos"])
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
127 self.willRetainCheckBox.setChecked(options["WillRetain"])
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
128 self.willTopicEdit.setText(options["WillTopic"])
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
129 self.willMessageEdit.setPlainText(options["WillMessage"])
25
01d44a4decf5 MqttConnectionOptionsDialog: added support for TLS.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 22
diff changeset
130
01d44a4decf5 MqttConnectionOptionsDialog: added support for TLS.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 22
diff changeset
131 # TLS parameters
01d44a4decf5 MqttConnectionOptionsDialog: added support for TLS.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 22
diff changeset
132 self.tlsEnableCheckBox.setChecked(options["TlsEnable"])
01d44a4decf5 MqttConnectionOptionsDialog: added support for TLS.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 22
diff changeset
133 self.tlsCertsFilePicker.setText(options["TlsCaCert"])
10
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
134
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
135 def getConnectionOptions(self):
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
136 """
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
137 Public method get the entered connection options.
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
138
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
139 @return dictionary containing the connection options. It has the keys
97
21f9c010dc42 Added the MQTT protocol version to the list of connection parameters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 92
diff changeset
140 "ClientId", "Protocol", "ConnectionTimeout", "Keepalive",
21f9c010dc42 Added the MQTT protocol version to the list of connection parameters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 92
diff changeset
141 "CleanSession", "Username", "Password", "WillTopic", "WillMessage",
21f9c010dc42 Added the MQTT protocol version to the list of connection parameters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 92
diff changeset
142 "WillQos", "WillRetain", "TlsEnable", "TlsCaCert".
92
2fb5c08019fd Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 86
diff changeset
143 @rtype dict
10
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
144 """
97
21f9c010dc42 Added the MQTT protocol version to the list of connection parameters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 92
diff changeset
145 if self.mqttv31Button.isChecked():
21f9c010dc42 Added the MQTT protocol version to the list of connection parameters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 92
diff changeset
146 protocol = MqttProtocols.MQTTv31
21f9c010dc42 Added the MQTT protocol version to the list of connection parameters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 92
diff changeset
147 elif self.mqttv311Button.isChecked():
21f9c010dc42 Added the MQTT protocol version to the list of connection parameters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 92
diff changeset
148 protocol = MqttProtocols.MQTTv311
21f9c010dc42 Added the MQTT protocol version to the list of connection parameters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 92
diff changeset
149 elif self.mqttv5Button.isChecked():
21f9c010dc42 Added the MQTT protocol version to the list of connection parameters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 92
diff changeset
150 protocol = MqttProtocols.MQTTv5
21f9c010dc42 Added the MQTT protocol version to the list of connection parameters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 92
diff changeset
151 else:
21f9c010dc42 Added the MQTT protocol version to the list of connection parameters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 92
diff changeset
152 protocol = MqttProtocols.MQTTv311
21f9c010dc42 Added the MQTT protocol version to the list of connection parameters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 92
diff changeset
153
10
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
154 return {
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
155 "ClientId": self.clientIdEdit.text(),
97
21f9c010dc42 Added the MQTT protocol version to the list of connection parameters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 92
diff changeset
156 "Protocol": protocol,
31
40582e448c4b Added a connect timeout function with a settable timeout value.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 30
diff changeset
157 "ConnectionTimeout": self.connectionTimeoutSpinBox.value(),
10
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
158 "Keepalive": self.keepaliveSpinBox.value(),
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
159 "CleanSession": self.cleanSessionCheckBox.isChecked(),
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
160 "Username": self.usernameEdit.text(),
22
545979c7dcd4 MqttClient, MqttConnectionOptionsDialog: added support for encrypted passwords.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 20
diff changeset
161 "Password": pwConvert(self.passwordEdit.text(), encode=True),
10
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
162 "WillTopic": self.willTopicEdit.text(),
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
163 "WillMessage": self.willMessageEdit.toPlainText(),
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
164 "WillQos": self.willQosSpinBox.value(),
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
165 "WillRetain": self.willRetainCheckBox.isChecked(),
25
01d44a4decf5 MqttConnectionOptionsDialog: added support for TLS.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 22
diff changeset
166 "TlsEnable": self.tlsEnableCheckBox.isChecked(),
01d44a4decf5 MqttConnectionOptionsDialog: added support for TLS.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 22
diff changeset
167 "TlsCaCert": self.tlsCertsFilePicker.text()
10
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
168 }
20
3737a78bb6c5 MqttConnectionOptionsDialog: added some validity checks and added the default value for 'keepalive' setting.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 18
diff changeset
169
3737a78bb6c5 MqttConnectionOptionsDialog: added some validity checks and added the default value for 'keepalive' setting.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 18
diff changeset
170 @pyqtSlot(str)
3737a78bb6c5 MqttConnectionOptionsDialog: added some validity checks and added the default value for 'keepalive' setting.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 18
diff changeset
171 def on_clientIdEdit_textChanged(self, clientId):
3737a78bb6c5 MqttConnectionOptionsDialog: added some validity checks and added the default value for 'keepalive' setting.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 18
diff changeset
172 """
3737a78bb6c5 MqttConnectionOptionsDialog: added some validity checks and added the default value for 'keepalive' setting.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 18
diff changeset
173 Private slot handling a change of the client ID string.
3737a78bb6c5 MqttConnectionOptionsDialog: added some validity checks and added the default value for 'keepalive' setting.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 18
diff changeset
174
3737a78bb6c5 MqttConnectionOptionsDialog: added some validity checks and added the default value for 'keepalive' setting.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 18
diff changeset
175 @param clientId client ID
3737a78bb6c5 MqttConnectionOptionsDialog: added some validity checks and added the default value for 'keepalive' setting.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 18
diff changeset
176 @type str
3737a78bb6c5 MqttConnectionOptionsDialog: added some validity checks and added the default value for 'keepalive' setting.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 18
diff changeset
177 """
3737a78bb6c5 MqttConnectionOptionsDialog: added some validity checks and added the default value for 'keepalive' setting.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 18
diff changeset
178 self.__updateOkButton()
3737a78bb6c5 MqttConnectionOptionsDialog: added some validity checks and added the default value for 'keepalive' setting.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 18
diff changeset
179
3737a78bb6c5 MqttConnectionOptionsDialog: added some validity checks and added the default value for 'keepalive' setting.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 18
diff changeset
180 @pyqtSlot(bool)
3737a78bb6c5 MqttConnectionOptionsDialog: added some validity checks and added the default value for 'keepalive' setting.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 18
diff changeset
181 def on_cleanSessionCheckBox_clicked(self, checked):
3737a78bb6c5 MqttConnectionOptionsDialog: added some validity checks and added the default value for 'keepalive' setting.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 18
diff changeset
182 """
3737a78bb6c5 MqttConnectionOptionsDialog: added some validity checks and added the default value for 'keepalive' setting.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 18
diff changeset
183 Private slot to handle a change of the clean session selection.
3737a78bb6c5 MqttConnectionOptionsDialog: added some validity checks and added the default value for 'keepalive' setting.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 18
diff changeset
184
3737a78bb6c5 MqttConnectionOptionsDialog: added some validity checks and added the default value for 'keepalive' setting.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 18
diff changeset
185 @param checked current state of the clean session selection
3737a78bb6c5 MqttConnectionOptionsDialog: added some validity checks and added the default value for 'keepalive' setting.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 18
diff changeset
186 @type bool
3737a78bb6c5 MqttConnectionOptionsDialog: added some validity checks and added the default value for 'keepalive' setting.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 18
diff changeset
187 """
3737a78bb6c5 MqttConnectionOptionsDialog: added some validity checks and added the default value for 'keepalive' setting.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 18
diff changeset
188 self.__updateOkButton()

eric ide

mercurial