71 self.unsubscribeButton.setIcon(UI.PixmapCache.getIcon("minus.png")) |
71 self.unsubscribeButton.setIcon(UI.PixmapCache.getIcon("minus.png")) |
72 |
72 |
73 self.__subscribedTopics = [] |
73 self.__subscribedTopics = [] |
74 self.__topicQueue = {} |
74 self.__topicQueue = {} |
75 self.__updateUnsubscribeTopicComboBox() |
75 self.__updateUnsubscribeTopicComboBox() |
|
76 |
|
77 self.__publishedTopics = [] |
|
78 self.__updatePublishTopicComboBox() |
|
79 self.publishButton.setEnabled(False) |
76 |
80 |
77 prefix = MqttMonitorWidget.BrokerStatusTopicPrefix |
81 prefix = MqttMonitorWidget.BrokerStatusTopicPrefix |
78 self.__statusLabelMapping = { |
82 self.__statusLabelMapping = { |
79 # broker |
83 # broker |
80 prefix + "version": self.versionLabel, |
84 prefix + "version": self.versionLabel, |
150 |
154 |
151 self.connectButton.setIcon(UI.PixmapCache.getIcon("ircDisconnect.png")) |
155 self.connectButton.setIcon(UI.PixmapCache.getIcon("ircDisconnect.png")) |
152 |
156 |
153 self.subscribeGroup.setEnabled(True) |
157 self.subscribeGroup.setEnabled(True) |
154 self.unsubscribeGroup.setEnabled(True) |
158 self.unsubscribeGroup.setEnabled(True) |
|
159 self.publishGroup.setEnabled(True) |
155 self.brokerStatusButton.setEnabled(True) |
160 self.brokerStatusButton.setEnabled(True) |
156 |
161 |
157 self.__statusLoadValues.clear() |
162 self.__statusLoadValues.clear() |
158 |
163 |
159 @pyqtSlot(int) |
164 @pyqtSlot(int) |
178 self.connectButton.setIcon(UI.PixmapCache.getIcon("ircConnect.png")) |
183 self.connectButton.setIcon(UI.PixmapCache.getIcon("ircConnect.png")) |
179 |
184 |
180 self.__subscribedTopics = [] |
185 self.__subscribedTopics = [] |
181 self.__topicQueue = {} |
186 self.__topicQueue = {} |
182 self.__updateUnsubscribeTopicComboBox() |
187 self.__updateUnsubscribeTopicComboBox() |
|
188 self.__updatePublishTopicComboBox() |
183 |
189 |
184 self.subscribeGroup.setEnabled(False) |
190 self.subscribeGroup.setEnabled(False) |
185 self.unsubscribeGroup.setEnabled(False) |
191 self.unsubscribeGroup.setEnabled(False) |
|
192 self.publishGroup.setEnabled(False) |
186 self.brokerStatusButton.setEnabled(False) |
193 self.brokerStatusButton.setEnabled(False) |
187 |
194 |
188 self.__statusLoadValues.clear() |
195 self.__statusLoadValues.clear() |
189 |
196 |
190 @pyqtSlot(str, bytes, int, bool) |
197 @pyqtSlot(str, bytes, int, bool) |
231 topic = self.__topicQueue.pop(mid) |
238 topic = self.__topicQueue.pop(mid) |
232 self.__subscribedTopics.append(topic) |
239 self.__subscribedTopics.append(topic) |
233 self.subscribeTopicEdit.clear() |
240 self.subscribeTopicEdit.clear() |
234 |
241 |
235 self.__updateUnsubscribeTopicComboBox() |
242 self.__updateUnsubscribeTopicComboBox() |
|
243 self.__updatePublishTopicComboBox() |
236 |
244 |
237 @pyqtSlot(int) |
245 @pyqtSlot(int) |
238 def __topicUnsubscribed(self, mid): |
246 def __topicUnsubscribed(self, mid): |
239 """ |
247 """ |
240 Private slot to handle being unsubcribed from a topic. |
248 Private slot to handle being unsubcribed from a topic. |
245 if mid in self.__topicQueue: |
253 if mid in self.__topicQueue: |
246 topic = self.__topicQueue.pop(mid) |
254 topic = self.__topicQueue.pop(mid) |
247 try: |
255 try: |
248 self.__subscribedTopics.remove(topic) |
256 self.__subscribedTopics.remove(topic) |
249 self.__updateUnsubscribeTopicComboBox() |
257 self.__updateUnsubscribeTopicComboBox() |
|
258 self.__updatePublishTopicComboBox() |
250 except ValueError: |
259 except ValueError: |
251 # ignore it |
260 # ignore it |
252 pass |
261 pass |
253 |
262 |
254 ####################################################################### |
263 ####################################################################### |
340 """ |
349 """ |
341 topic = self.unsubscribeTopicComboBox.currentText() |
350 topic = self.unsubscribeTopicComboBox.currentText() |
342 if topic: |
351 if topic: |
343 self.__topicQueue[ |
352 self.__topicQueue[ |
344 self.__client.unsubscribe(topic)[1]] = topic |
353 self.__client.unsubscribe(topic)[1]] = topic |
|
354 |
|
355 @pyqtSlot(str) |
|
356 def on_publishTopicComboBox_editTextChanged(self, topic): |
|
357 """ |
|
358 Private slot to handle changes of the publish topic name. |
|
359 |
|
360 @param topic topic text |
|
361 @type str |
|
362 """ |
|
363 self.publishButton.setEnabled(bool(topic)) |
|
364 |
|
365 @pyqtSlot() |
|
366 def on_publishButton_clicked(self): |
|
367 """ |
|
368 Private slot to publish the entered message. |
|
369 """ |
|
370 topic = self.publishTopicComboBox.currentText() |
|
371 qos = self.publishQosSpinBox.value() |
|
372 retain = self.publishRetainCheckBox.isChecked() |
|
373 payloadStr = self.publishPayloadEdit.toPlainText() |
|
374 |
|
375 msgInfo = self.__client.publish(topic, payloadStr, qos, retain) |
|
376 if msgInfo.rc == 0: |
|
377 if topic not in self.__publishedTopics: |
|
378 self.__publishedTopics.append(topic) |
|
379 self.__updatePublishTopicComboBox() |
345 |
380 |
346 @pyqtSlot() |
381 @pyqtSlot() |
347 def on_brokerStatusButton_clicked(self): |
382 def on_brokerStatusButton_clicked(self): |
348 """ |
383 """ |
349 Private slot to subscribe or unsubscribe the broker status topic. |
384 Private slot to subscribe or unsubscribe the broker status topic. |
396 """ |
431 """ |
397 self.unsubscribeTopicComboBox.clear() |
432 self.unsubscribeTopicComboBox.clear() |
398 self.unsubscribeTopicComboBox.addItems(sorted(self.__subscribedTopics)) |
433 self.unsubscribeTopicComboBox.addItems(sorted(self.__subscribedTopics)) |
399 self.unsubscribeButton.setEnabled(len(self.__subscribedTopics) > 0) |
434 self.unsubscribeButton.setEnabled(len(self.__subscribedTopics) > 0) |
400 |
435 |
|
436 def __updatePublishTopicComboBox(self): |
|
437 """ |
|
438 Private method to update the publish topic combo box. |
|
439 """ |
|
440 self.publishTopicComboBox.clear() |
|
441 self.publishTopicComboBox.addItems( |
|
442 [""] + list(set(self.__publishedTopics + self.__subscribedTopics))) |
|
443 |
401 def __appendMessage(self, topic, payload): |
444 def __appendMessage(self, topic, payload): |
402 """ |
445 """ |
403 Private method to append a received message to the output. |
446 Private method to append a received message to the output. |
404 |
447 |
405 @param topic topic of the received message |
448 @param topic topic of the received message |
406 @type str |
449 @type str |
407 @param payload payload of the received message |
450 @param payload payload of the received message |
408 @type bytes |
451 @type bytes |
409 """ |
452 """ |
410 payloadStr = str(payload, encoding="utf-8", errors="replace") |
453 payloadStr = str(payload, encoding="utf-8", errors="replace") |
411 txt = "{0} {1}".format(topic, payloadStr) |
454 txt = self.tr("{0} -> {1}").format(topic, payloadStr) |
412 if not txt.endswith(("\r\n", "\r", "\n")): |
455 if not txt.endswith(("\r\n", "\r", "\n")): |
413 txt += "\n" |
456 txt += "\n" |
414 |
457 |
415 tc = self.messagesEdit.textCursor() |
458 tc = self.messagesEdit.textCursor() |
416 tc.movePosition(QTextCursor.End) |
459 tc.movePosition(QTextCursor.End) |