MqttMonitor/MqttMonitorWidget.py

branch
eric7
changeset 106
84498095d511
parent 105
36ec7431ad04
child 112
b287c1d2cc78
equal deleted inserted replaced
105:36ec7431ad04 106:84498095d511
67 67
68 self.publishPayloadFilePicker.setMode( 68 self.publishPayloadFilePicker.setMode(
69 EricPathPickerModes.OPEN_FILE_MODE) 69 EricPathPickerModes.OPEN_FILE_MODE)
70 self.publishPayloadFilePicker.setFilters(self.tr("All Files (*)")) 70 self.publishPayloadFilePicker.setFilters(self.tr("All Files (*)"))
71 71
72 self.brokerComboBox.lineEdit().setClearButtonEnabled(True)
73 self.publishTopicComboBox.lineEdit().setClearButtonEnabled(True)
74
72 self.__messagesFormat = self.messagesEdit.currentCharFormat() 75 self.__messagesFormat = self.messagesEdit.currentCharFormat()
73 self.__messagesTopicFormat = self.messagesEdit.currentCharFormat() 76 self.__messagesTopicFormat = self.messagesEdit.currentCharFormat()
74 self.__messagesTopicFormat.setFontWeight(QFont.Weight.Bold) 77 self.__messagesTopicFormat.setFontWeight(QFont.Weight.Bold)
75 self.__messagesQosFormat = self.messagesEdit.currentCharFormat() 78 self.__messagesQosFormat = self.messagesEdit.currentCharFormat()
76 self.__messagesQosFormat.setFontItalic(True) 79 self.__messagesQosFormat.setFontItalic(True)
137 )) 140 ))
138 self.__populateBrokerComboBoxes() 141 self.__populateBrokerComboBoxes()
139 self.brokerStatusLabel.hide() 142 self.brokerStatusLabel.hide()
140 self.clearWillButton.setIcon( 143 self.clearWillButton.setIcon(
141 UI.PixmapCache.getIcon("certificateDelete")) 144 UI.PixmapCache.getIcon("certificateDelete"))
145
146 self.subscribeTopicComboBox.lineEdit().setClearButtonEnabled(True)
147 self.subscribeTopicComboBox.lineEdit().returnPressed.connect(
148 self.on_subscribeButton_clicked)
149 self.__populateSubscribeTopicComboBox()
142 150
143 self.subscribeButton.setIcon(UI.PixmapCache.getIcon("plus")) 151 self.subscribeButton.setIcon(UI.PixmapCache.getIcon("plus"))
144 self.subscribeButton.setEnabled(False) 152 self.subscribeButton.setEnabled(False)
145 self.subscribePropertiesButton.setIcon( 153 self.subscribePropertiesButton.setIcon(
146 UI.PixmapCache.getIcon("listSelection")) 154 UI.PixmapCache.getIcon("listSelection"))
481 MQTT v3.1.1). 489 MQTT v3.1.1).
482 490
483 @param mid ID of the subscribe request 491 @param mid ID of the subscribe request
484 @type int 492 @type int
485 """ 493 """
486 # TODO: remember the successfully subscribed topic
487 # TODO: max. number of recent topics as a config item
488 if mid in self.__topicQueue: 494 if mid in self.__topicQueue:
489 topic = self.__topicQueue.pop(mid) 495 topic = self.__topicQueue.pop(mid)
490 self.__subscribedTopics.append(topic) 496 self.__subscribedTopics.append(topic)
491 self.subscribeTopicEdit.clear() 497 self.__addTopicToRecent(topic)
492 498
493 self.__updateUnsubscribeTopicComboBox() 499 self.__updateUnsubscribeTopicComboBox()
494 self.__updatePublishTopicComboBox() 500 self.__updatePublishTopicComboBox()
495 501
496 @pyqtSlot(int, list, dict) 502 @pyqtSlot(int, list, dict)
651 @pyqtSlot() 657 @pyqtSlot()
652 def on_subscribePropertiesButton_clicked(self): 658 def on_subscribePropertiesButton_clicked(self):
653 """ 659 """
654 Private slot to edit the subscribe user properties. 660 Private slot to edit the subscribe user properties.
655 """ 661 """
656 topic = self.subscribeTopicEdit.text() 662 topic = self.subscribeTopicComboBox.currentText()
657 self.__editProperties( 663 self.__editProperties(
658 "subscribe", 664 "subscribe",
659 self.tr("SUBSCRIBE: User Properties for '{0}'").format(topic), 665 self.tr("SUBSCRIBE: User Properties for '{0}'").format(topic),
660 topic 666 topic
661 ) 667 )
662 668
663 @pyqtSlot(str) 669 @pyqtSlot(str)
664 def on_subscribeTopicEdit_textChanged(self, topic): 670 def on_subscribeTopicComboBox_editTextChanged(self, topic):
665 """ 671 """
666 Private slot to handle a change of the entered topic. 672 Private slot to handle a change of the entered topic.
667 673
668 @param topic entered topic text 674 @param topic entered topic text
669 @type str 675 @type str
670 """ 676 """
671 self.subscribeButton.setEnabled(bool(topic)) 677 self.subscribeButton.setEnabled(bool(topic))
672 self.subscribePropertiesButton.setEnabled(bool(topic)) 678 self.subscribePropertiesButton.setEnabled(bool(topic))
673 679
674 @pyqtSlot() 680 @pyqtSlot()
675 def on_subscribeTopicEdit_returnPressed(self):
676 """
677 Private slot handling the user pressing the return button to subscribe
678 a topic.
679 """
680 self.on_subscribeButton_clicked()
681
682 @pyqtSlot()
683 def on_subscribeButton_clicked(self): 681 def on_subscribeButton_clicked(self):
684 """ 682 """
685 Private slot to subscribe to the entered topic. 683 Private slot to subscribe to the entered topic.
686 """ 684 """
687 topic = self.subscribeTopicEdit.text() 685 topic = self.subscribeTopicComboBox.currentText()
688 qos = self.subscribeQosSpinBox.value() 686 qos = self.subscribeQosSpinBox.value()
689 if topic: 687 if topic:
690 if topic.startswith(MqttMonitorWidget.BrokerStatusTopicPrefix): 688 if topic.startswith(MqttMonitorWidget.BrokerStatusTopicPrefix):
691 EricMessageBox.warning( 689 EricMessageBox.warning(
692 self, 690 self,
1032 brokerList = self.__plugin.getPreferences("RecentBrokersWithPort") 1030 brokerList = self.__plugin.getPreferences("RecentBrokersWithPort")
1033 hostAndPort = [host, port] 1031 hostAndPort = [host, port]
1034 if hostAndPort in brokerList: 1032 if hostAndPort in brokerList:
1035 brokerList.remove(hostAndPort) 1033 brokerList.remove(hostAndPort)
1036 brokerList.insert(0, hostAndPort) 1034 brokerList.insert(0, hostAndPort)
1037 # limit to most recently used 20 entries 1035 # limit the most recently used entries
1038 # TODO: make the amount of recent brokers a config item 1036 maxBrokers = self.__plugin.getPreferences("RecentBrokersNumber")
1039 brokerList = brokerList[:20] 1037 brokerList = brokerList[:maxBrokers]
1040 self.__plugin.setPreferences("RecentBrokersWithPort", brokerList) 1038 self.__plugin.setPreferences("RecentBrokersWithPort", brokerList)
1041 1039
1042 self.__populateBrokerComboBoxes() 1040 self.__populateBrokerComboBoxes()
1043 1041
1044 def __populateBrokerComboBoxes(self): 1042 def __populateBrokerComboBoxes(self):
1084 index = self.profileComboBox.findText(mostRecentProfile) 1082 index = self.profileComboBox.findText(mostRecentProfile)
1085 if index >= 0: 1083 if index >= 0:
1086 self.profileComboBox.setCurrentIndex(index) 1084 self.profileComboBox.setCurrentIndex(index)
1087 1085
1088 self.__setConnectButtonState() 1086 self.__setConnectButtonState()
1087
1088 def __addTopicToRecent(self, topic):
1089 """
1090 Private method to add a topic to the list of recently subscribed
1091 topics.
1092
1093 @param topic subscribed topic
1094 @type str
1095 """
1096 topicsList = self.__plugin.getPreferences("RecentTopics")
1097 if topic in topicsList:
1098 topicsList.remove(topic)
1099 topicsList.insert(0, topic)
1100 # limit the most recently used entries
1101 maxTopics = self.__plugin.getPreferences("RecentTopicsNumber")
1102 topicsList = topicsList[:maxTopics]
1103 self.__plugin.setPreferences("RecentTopics", topicsList)
1104
1105 self.__populateSubscribeTopicComboBox()
1106
1107 def __populateSubscribeTopicComboBox(self):
1108 """
1109 Private method to populate the subscribe topic combo box.
1110 """
1111 topicsList = self.__plugin.getPreferences("RecentTopics")
1112
1113 self.subscribeTopicComboBox.clear()
1114 self.subscribeTopicComboBox.addItems(sorted(topicsList))
1115 self.subscribeTopicComboBox.clearEditText()
1089 1116
1090 def __updateUnsubscribeTopicComboBox(self): 1117 def __updateUnsubscribeTopicComboBox(self):
1091 """ 1118 """
1092 Private method to update the unsubcribe topic combo box. 1119 Private method to update the unsubcribe topic combo box.
1093 """ 1120 """

eric ide

mercurial