1 # -*- coding: utf-8 -*- |
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2018 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
2 |
5 |
3 """ |
6 """ |
4 Module implementing a dialog to enter MQTT connection options. |
7 Module implementing a dialog to enter MQTT connection options. |
5 """ |
8 """ |
6 |
9 |
7 from __future__ import unicode_literals |
10 from __future__ import unicode_literals |
8 |
11 |
9 from PyQt5.QtCore import pyqtSlot |
12 from PyQt5.QtCore import pyqtSlot, QUuid |
10 from PyQt5.QtWidgets import QDialog, QDialogButtonBox, QAbstractButton |
13 from PyQt5.QtWidgets import QDialog, QDialogButtonBox, QAbstractButton |
11 |
14 |
12 from .Ui_MqttConnectionOptionsDialog import Ui_MqttConnectionOptionsDialog |
15 from .Ui_MqttConnectionOptionsDialog import Ui_MqttConnectionOptionsDialog |
13 |
16 |
14 |
17 |
21 Constructor |
24 Constructor |
22 |
25 |
23 @param client reference to the MQTT client object |
26 @param client reference to the MQTT client object |
24 @type MqttClient |
27 @type MqttClient |
25 @param options dictionary containing the connection options to |
28 @param options dictionary containing the connection options to |
26 populate the dialog with |
29 populate the dialog with. It must have the keys "ClientId", |
|
30 "Keepalive", "CleanSession", "Username", "Password", "WillTopic", |
|
31 "WillMessage", "WillQos", "WillRetain". |
27 @@type dict |
32 @@type dict |
28 @param parent reference to the parent widget |
33 @param parent reference to the parent widget |
29 @type QWidget |
34 @type QWidget |
30 """ |
35 """ |
31 super(MqttConnectionOptionsDialog, self).__init__(parent) |
36 super(MqttConnectionOptionsDialog, self).__init__(parent) |
32 self.setupUi(self) |
37 self.setupUi(self) |
33 |
38 |
34 self.__client = client |
39 self.__client = client |
35 |
40 |
36 self.__populateDefaults(options=options) |
41 self.__populateDefaults(options=options) |
37 |
42 |
|
43 @pyqtSlot() |
|
44 def on_generateIdButton_clicked(self): |
|
45 """ |
|
46 Private slot to generate a client ID. |
|
47 """ |
|
48 uuid = QUuid.createUuid() |
|
49 self.clientIdEdit.setText(uuid.toString(QUuid.WithoutBraces)) |
38 |
50 |
39 @pyqtSlot(QAbstractButton) |
51 @pyqtSlot(QAbstractButton) |
40 def on_buttonBox_clicked(self, button): |
52 def on_buttonBox_clicked(self, button): |
41 """ |
53 """ |
42 Private slot to handle the press of a button box button. |
54 Private slot to handle the press of a button box button. |
51 """ |
63 """ |
52 Private method to populate the dialog. |
64 Private method to populate the dialog. |
53 |
65 |
54 If no options dictionary is given, the dialog will be populated with |
66 If no options dictionary is given, the dialog will be populated with |
55 default values. |
67 default values. |
|
68 |
|
69 @param options dictionary containing the connection options to populate |
|
70 the dialog with. It must have the keys "ClientId", "Keepalive", |
|
71 "CleanSession", "Username", "Password", "WillTopic", "WillMessage", |
|
72 "WillQos", "WillRetain". |
|
73 @type dict |
56 """ |
74 """ |
57 if options is None: |
75 if options is None: |
58 options = self.__client.defaultConnectionOptions() |
76 options = self.__client.defaultConnectionOptions() |
59 |
77 |
60 # general |
78 # general |
76 """ |
94 """ |
77 Public method get the entered connection options. |
95 Public method get the entered connection options. |
78 |
96 |
79 @return dictionary containing the connection options. It has the keys |
97 @return dictionary containing the connection options. It has the keys |
80 "ClientId", "Keepalive", "CleanSession", "Username", "Password", |
98 "ClientId", "Keepalive", "CleanSession", "Username", "Password", |
81 "WillTopic", "WillMessage", "WillQos", "WillRetain" |
99 "WillTopic", "WillMessage", "WillQos", "WillRetain". |
82 @rtype tuple of (int, dict) |
100 @rtype tuple of (int, dict) |
83 """ |
101 """ |
84 return { |
102 return { |
85 "ClientId": self.clientIdEdit.text(), |
103 "ClientId": self.clientIdEdit.text(), |
86 "Keepalive": self.keepaliveSpinBox.value(), |
104 "Keepalive": self.keepaliveSpinBox.value(), |