MqttMonitor/MqttMonitorWidget.py

changeset 43
a0853f7a8b80
parent 41
68f19bd4e61c
child 44
ca2e03cb6ed4
equal deleted inserted replaced
42:3e68b5ce2b0b 43:a0853f7a8b80
40 # include capability to filter on topic 40 # include capability to filter on topic
41 41
42 # TODO: change log display to a tree widget 42 # TODO: change log display to a tree widget
43 # two columns with log level and message 43 # two columns with log level and message
44 # colorize entries depending on log level 44 # colorize entries depending on log level
45
46 # TODO: add log level entry to disable logging
47 45
48 class MqttMonitorWidget(QWidget, Ui_MqttMonitorWidget): 46 class MqttMonitorWidget(QWidget, Ui_MqttMonitorWidget):
49 """ 47 """
50 Class implementing the MQTT Monitor widget. 48 Class implementing the MQTT Monitor widget.
51 """ 49 """
71 self.__brokerStatusTopicSubscribed = False 69 self.__brokerStatusTopicSubscribed = False
72 70
73 self.pixmapLabel.setPixmap(UI.PixmapCache.getPixmap( 71 self.pixmapLabel.setPixmap(UI.PixmapCache.getPixmap(
74 os.path.join("MqttMonitor", "icons", "mqtt48.png"))) 72 os.path.join("MqttMonitor", "icons", "mqtt48.png")))
75 73
76 for logLevel in (MqttClient.LogDebug, 74 for logLevel in (MqttClient.LogDisabled,
75 MqttClient.LogDebug,
77 MqttClient.LogInfo, 76 MqttClient.LogInfo,
78 MqttClient.LogNotice, 77 MqttClient.LogNotice,
79 MqttClient.LogWarning, 78 MqttClient.LogWarning,
80 MqttClient.LogError): 79 MqttClient.LogError):
81 self.logLevelComboBox.addItem(mqttLogLevelString( 80 self.logLevelComboBox.addItem(mqttLogLevelString(
592 brokerList = self.__plugin.getPreferences("RecentBrokersWithPort") 591 brokerList = self.__plugin.getPreferences("RecentBrokersWithPort")
593 hostAndPort = [host, port] 592 hostAndPort = [host, port]
594 if hostAndPort in brokerList: 593 if hostAndPort in brokerList:
595 brokerList.remove(hostAndPort) 594 brokerList.remove(hostAndPort)
596 brokerList.insert(0, hostAndPort) 595 brokerList.insert(0, hostAndPort)
597 # TODO: limit to most recently used 20 entries 596 # limit to most recently used 20 entries
597 brokerList = brokerList[:20]
598 self.__plugin.setPreferences("RecentBrokersWithPort", brokerList) 598 self.__plugin.setPreferences("RecentBrokersWithPort", brokerList)
599 599
600 self.__populateBrokerComboBoxes() 600 self.__populateBrokerComboBoxes()
601 601
602 def __populateBrokerComboBoxes(self): 602 def __populateBrokerComboBoxes(self):
603 """ 603 """
604 Private method to populate the broker name and port combo boxes. 604 Private method to populate the broker name and port combo boxes.
605 """ 605 """
606 brokerList = self.__plugin.getPreferences("RecentBrokersWithPort") 606 brokerPortList = self.__plugin.getPreferences("RecentBrokersWithPort")
607 607
608 # step 1: clear combo boxes 608 # step 1: clear combo boxes
609 self.brokerComboBox.clear() 609 self.brokerComboBox.clear()
610 self.brokerPortComboBox.clear() 610 self.brokerPortComboBox.clear()
611 611
612 # step 2a: populate the broker name list 612 # step 2a: populate the broker name list
613 # TODO: make list unique and sorted 613 if brokerPortList:
614 self.brokerComboBox.addItems([b[0].strip() for b in brokerList]) 614 currentBroker = brokerPortList[0][0]
615 615 else:
616 self.__setConnectButtonState() 616 currentBroker = ""
617 brokerSet = {b[0].strip() for b in brokerPortList}
618 self.brokerComboBox.addItems(sorted(brokerSet))
619 index = self.brokerComboBox.findText(currentBroker)
620 self.brokerComboBox.setCurrentIndex(index)
617 621
618 # step 2b: populate the broker ports list 622 # step 2b: populate the broker ports list
619 if brokerList: 623 if brokerPortList:
620 currentPort = brokerList[0][1] 624 currentPort = brokerPortList[0][1]
621 else: 625 else:
622 currentPort = 1883 626 currentPort = 1883
623 currentPortStr = "{0:5}".format(currentPort) 627 currentPortStr = "{0:5}".format(currentPort)
624 portsSet = {b[1] for b in brokerList} 628 portsSet = {b[1] for b in brokerPortList}
625 portsSet.update({1883, 8883}) 629 portsSet.update({1883, 8883})
626 self.brokerPortComboBox.addItems( 630 self.brokerPortComboBox.addItems(
627 sorted("{0:5}".format(p) for p in portsSet)) 631 sorted("{0:5}".format(p) for p in portsSet))
628 index = self.brokerPortComboBox.findText(currentPortStr) 632 index = self.brokerPortComboBox.findText(currentPortStr)
629 self.brokerPortComboBox.setCurrentIndex(index) 633 self.brokerPortComboBox.setCurrentIndex(index)
634
635 # step 3: update the connect button state
636 self.__setConnectButtonState()
630 637
631 def __populateProfileComboBox(self): 638 def __populateProfileComboBox(self):
632 """ 639 """
633 Private method to populate the profiles selection box. 640 Private method to populate the profiles selection box.
634 """ 641 """

eric ide

mercurial