162 self.unsubscribeGroup.setEnabled(True) |
162 self.unsubscribeGroup.setEnabled(True) |
163 self.publishGroup.setEnabled(True) |
163 self.publishGroup.setEnabled(True) |
164 self.brokerStatusButton.setEnabled(True) |
164 self.brokerStatusButton.setEnabled(True) |
165 |
165 |
166 self.__statusLoadValues.clear() |
166 self.__statusLoadValues.clear() |
|
167 self.__clearBrokerStatusLabels() |
|
168 self.__setBrokerStatusSubscribed(False) |
167 |
169 |
168 @pyqtSlot(int) |
170 @pyqtSlot(int) |
169 def __brokerDisconnected(self, rc): |
171 def __brokerDisconnected(self, rc): |
170 """ |
172 """ |
171 Private slot to handle a disconnection from the broker. |
173 Private slot to handle a disconnection from the broker. |
320 except ValueError: |
322 except ValueError: |
321 # use standard port at 1883 |
323 # use standard port at 1883 |
322 port = 1883 |
324 port = 1883 |
323 if host: |
325 if host: |
324 self.__addBrokerToRecent(host, port) |
326 self.__addBrokerToRecent(host, port) |
325 self.__client.connectToServer(host, port=port) |
327 if self.__connectionOptions is None: |
|
328 self.__client.connectToServer(host, port=port) |
|
329 else: |
|
330 self.__client.connectToServerWithOptions( |
|
331 host, port=port, options=self.__connectionOptions) |
326 |
332 |
327 @pyqtSlot(str) |
333 @pyqtSlot(str) |
328 def on_subscribeTopicEdit_textChanged(self, topic): |
334 def on_subscribeTopicEdit_textChanged(self, topic): |
329 """ |
335 """ |
330 Private slot to handle a change of the entered topic. |
336 Private slot to handle a change of the entered topic. |
401 if topic not in self.__publishedTopics: |
407 if topic not in self.__publishedTopics: |
402 self.__publishedTopics.append(topic) |
408 self.__publishedTopics.append(topic) |
403 self.__updatePublishTopicComboBox() |
409 self.__updatePublishTopicComboBox() |
404 |
410 |
405 @pyqtSlot() |
411 @pyqtSlot() |
|
412 def on_publishClearButton_clicked(self): |
|
413 """ |
|
414 Private slot to clear the publish data fields. |
|
415 """ |
|
416 self.publishTopicComboBox.clearEditText() |
|
417 self.publishPayloadEdit.clear() |
|
418 self.publishQosSpinBox.setValue(0) |
|
419 self.publishRetainCheckBox.setChecked(False) |
|
420 |
|
421 @pyqtSlot() |
406 def on_brokerStatusButton_clicked(self): |
422 def on_brokerStatusButton_clicked(self): |
407 """ |
423 """ |
408 Private slot to subscribe or unsubscribe the broker status topic. |
424 Private slot to subscribe or unsubscribe the broker status topic. |
409 """ |
425 """ |
410 if self.__brokerStatusTopicSubscribed: |
426 if self.__brokerStatusTopicSubscribed: |
411 # unsubscribe status topic |
427 # unsubscribe status topic |
412 rc, _ = self.__client.unsubscribe( |
428 rc, _ = self.__client.unsubscribe( |
413 MqttMonitorWidget.BrokerStatusTopic) |
429 MqttMonitorWidget.BrokerStatusTopic) |
414 if rc == 0: |
430 if rc == 0: |
415 # successfully sent |
431 # successfully sent |
416 self.__brokerStatusTopicSubscribed = False |
432 self.__setBrokerStatusSubscribed(False) |
417 self.brokerStatusButton.setText(self.tr("Subscribe")) |
|
418 self.brokerStatusButton.setToolTip( |
|
419 self.tr("Press to activate the status display")) |
|
420 else: |
433 else: |
421 # subscribe status topic |
434 # subscribe status topic |
422 rc, _ = self.__client.subscribe( |
435 rc, _ = self.__client.subscribe( |
423 MqttMonitorWidget.BrokerStatusTopic) |
436 MqttMonitorWidget.BrokerStatusTopic) |
424 if rc == 0: |
437 if rc == 0: |
425 # successfully sent |
438 # successfully sent |
426 self.__brokerStatusTopicSubscribed = True |
439 self.__setBrokerStatusSubscribed(True) |
427 self.brokerStatusButton.setText(self.tr("Unsubscribe")) |
440 |
428 self.brokerStatusButton.setToolTip( |
441 def __setBrokerStatusSubscribed(self, subscribed): |
429 self.tr("Press to deactivate the status display")) |
442 """ |
|
443 Private method to set the subscription status for the broker status |
|
444 topics. |
|
445 |
|
446 @param subscribed subscription status for the broker status topics |
|
447 @type bool |
|
448 """ |
|
449 self.__brokerStatusTopicSubscribed = subscribed |
|
450 if subscribed: |
|
451 self.brokerStatusButton.setText(self.tr("Unsubscribe")) |
|
452 self.brokerStatusButton.setToolTip( |
|
453 self.tr("Press to deactivate the status display")) |
|
454 else: |
|
455 self.brokerStatusButton.setText(self.tr("Subscribe")) |
|
456 self.brokerStatusButton.setToolTip( |
|
457 self.tr("Press to activate the status display")) |
430 |
458 |
431 ####################################################################### |
459 ####################################################################### |
432 ## Utility methods |
460 ## Utility methods |
433 ####################################################################### |
461 ####################################################################### |
434 |
462 |
468 if brokerList: |
496 if brokerList: |
469 currentPort = brokerList[0][1] |
497 currentPort = brokerList[0][1] |
470 else: |
498 else: |
471 currentPort = 1883 |
499 currentPort = 1883 |
472 currentPortStr = "{0:5}".format(currentPort) |
500 currentPortStr = "{0:5}".format(currentPort) |
473 portsSet = set([b[1] for b in brokerList]) |
501 portsSet = {b[1] for b in brokerList} |
474 portsSet.update([1883, 8883]) |
502 portsSet.update({1883, 8883}) |
475 self.brokerPortComboBox.addItems( |
503 self.brokerPortComboBox.addItems( |
476 sorted(["{0:5}".format(p) for p in portsSet])) |
504 sorted("{0:5}".format(p) for p in portsSet)) |
477 index = self.brokerPortComboBox.findText(currentPortStr) |
505 index = self.brokerPortComboBox.findText(currentPortStr) |
478 self.brokerPortComboBox.setCurrentIndex(index) |
506 self.brokerPortComboBox.setCurrentIndex(index) |
479 |
507 |
480 def __updateUnsubscribeTopicComboBox(self): |
508 def __updateUnsubscribeTopicComboBox(self): |
481 """ |
509 """ |
557 )) |
585 )) |
558 except KeyError: |
586 except KeyError: |
559 # ignore topics not shown in display |
587 # ignore topics not shown in display |
560 pass |
588 pass |
561 |
589 |
|
590 def __clearBrokerStatusLabels(self): |
|
591 """ |
|
592 Private method to clear the broker status labels. |
|
593 """ |
|
594 for statusLabelKey in self.__statusLabelMapping: |
|
595 if statusLabelKey.startswith( |
|
596 MqttMonitorWidget.BrokerStatusTopicLoadPrefix): |
|
597 label = "- / - / -" |
|
598 else: |
|
599 label = "-" |
|
600 self.__statusLabelMapping[statusLabelKey].setText(label) |
|
601 |
562 def __loadDefaultDictFactory(self): |
602 def __loadDefaultDictFactory(self): |
563 """ |
603 """ |
564 Private method to populate non-existing load items. |
604 Private method to populate non-existing load items. |
565 |
605 |
566 @return default dictionary entry |
606 @return default dictionary entry |