Sat, 01 Sep 2018 20:18:11 +0200
Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
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 | |
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
|
3 | """ |
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
|
4 | 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
|
5 | """ |
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 | from __future__ import unicode_literals |
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 | from PyQt5.QtCore import pyqtSlot |
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
|
10 | from PyQt5.QtWidgets import QDialog, QDialogButtonBox, 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
|
11 | |
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 | 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
|
13 | |
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
|
14 | |
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
|
15 | 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
|
16 | """ |
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 | 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
|
18 | """ |
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
|
19 | def __init__(self, client, options=None, parent=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
|
20 | """ |
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
|
21 | 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
|
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 | @param client reference to the MQTT client object |
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 | @type MqttClient |
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 | @param options dictionary containing the connection options to |
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 | populate the dialog 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
|
27 | @@type dict |
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 | @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
|
29 | @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
|
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 | super(MqttConnectionOptionsDialog, self).__init__(parent) |
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
|
32 | 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
|
33 | |
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
|
34 | self.__client = client |
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
|
35 | |
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
|
36 | self.__populateDefaults(options=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
|
37 | |
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 | |
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 | @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
|
40 | 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
|
41 | """ |
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 | 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
|
43 | |
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
|
44 | @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
|
45 | @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
|
46 | """ |
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 | if button == self.buttonBox.button(QDialogButtonBox.RestoreDefaults): |
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
|
48 | 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
|
49 | |
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
|
50 | 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
|
51 | """ |
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
|
52 | 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
|
53 | |
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
|
54 | 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
|
55 | default values. |
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
|
56 | """ |
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
|
57 | if options is 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
|
58 | options = self.__client.defaultConnectionOptions() |
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
|
59 | |
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
|
60 | # 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
|
61 | self.clientIdEdit.setText(options["ClientId"]) |
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
|
62 | 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
|
63 | 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
|
64 | |
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
|
65 | # 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
|
66 | self.usernameEdit.setText(options["Username"]) |
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
|
67 | self.passwordEdit.setText(options["Password"]) |
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
|
68 | |
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
|
69 | # 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
|
70 | 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
|
71 | 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
|
72 | 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
|
73 | self.willMessageEdit.setPlainText(options["WillMessage"]) |
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
|
74 | |
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
|
75 | 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
|
76 | """ |
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
|
77 | 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
|
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 | @return dictionary containing the connection options. It has the keys |
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 | "ClientId", "Keepalive", "CleanSession", "Username", "Password", |
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 | "WillTopic", "WillMessage", "WillQos", "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
|
82 | @rtype tuple of (int, dict) |
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 | 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
|
85 | "ClientId": self.clientIdEdit.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
|
86 | "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
|
87 | "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
|
88 | "Username": self.usernameEdit.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
|
89 | "Password": self.passwordEdit.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
|
90 | "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
|
91 | "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
|
92 | "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
|
93 | "WillRetain": self.willRetainCheckBox.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
|
94 | } |