MqttClient, MqttMonitorWidget: limited amount of recently used brokers to 20 and added a log level selection to disable logging.

Mon, 10 Sep 2018 16:52:37 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Mon, 10 Sep 2018 16:52:37 +0200
changeset 43
a0853f7a8b80
parent 42
3e68b5ce2b0b
child 44
ca2e03cb6ed4

MqttClient, MqttMonitorWidget: limited amount of recently used brokers to 20 and added a log level selection to disable logging.

ChangeLog file | annotate | diff | comparison | revisions
MqttMonitor/MqttClient.py file | annotate | diff | comparison | revisions
MqttMonitor/MqttMonitorWidget.py file | annotate | diff | comparison | revisions
--- a/ChangeLog	Mon Sep 10 16:42:15 2018 +0200
+++ b/ChangeLog	Mon Sep 10 16:52:37 2018 +0200
@@ -1,4 +1,9 @@
 ChangeLog
 ---------
+Version 1.1.0
+- bug fixes
+- limited amount of recently used brokers to 20
+- added log level selection to disable logging
+
 Version 1.0.0
 - first stable release
--- a/MqttMonitor/MqttClient.py	Mon Sep 10 16:42:15 2018 +0200
+++ b/MqttMonitor/MqttClient.py	Mon Sep 10 16:52:37 2018 +0200
@@ -51,6 +51,7 @@
     LogNotice = 0x04
     LogWarning = 0x08
     LogError = 0x10
+    LogDisabled = 0xff
     LogLevelMap = {
         mqtt.MQTT_LOG_DEBUG: LogDebug,
         mqtt.MQTT_LOG_INFO: LogInfo,
@@ -591,5 +592,8 @@
         return QCoreApplication.translate("MqttLogLevelString", "Error")
     elif logLevel == MqttClient.LogDebug:
         return QCoreApplication.translate("MqttLogLevelString", "Debug")
+    elif logLevel == MqttClient.LogDisabled:
+        return QCoreApplication.translate("MqttLogLevelString",
+                                          "Logging Disabled")
     else:
         return QCoreApplication.translate("MqttLogLevelString", "Unknown")
--- a/MqttMonitor/MqttMonitorWidget.py	Mon Sep 10 16:42:15 2018 +0200
+++ b/MqttMonitor/MqttMonitorWidget.py	Mon Sep 10 16:52:37 2018 +0200
@@ -43,8 +43,6 @@
 #   two columns with log level and message
 #   colorize entries depending on log level
 
-# TODO: add log level entry to disable logging
-
 class MqttMonitorWidget(QWidget, Ui_MqttMonitorWidget):
     """
     Class implementing the MQTT Monitor widget.
@@ -73,7 +71,8 @@
         self.pixmapLabel.setPixmap(UI.PixmapCache.getPixmap(
             os.path.join("MqttMonitor", "icons", "mqtt48.png")))
         
-        for logLevel in (MqttClient.LogDebug,
+        for logLevel in (MqttClient.LogDisabled,
+                         MqttClient.LogDebug,
                          MqttClient.LogInfo,
                          MqttClient.LogNotice,
                          MqttClient.LogWarning,
@@ -594,7 +593,8 @@
         if hostAndPort in brokerList:
             brokerList.remove(hostAndPort)
         brokerList.insert(0, hostAndPort)
-        # TODO: limit to most recently used 20 entries
+        # limit to most recently used 20 entries
+        brokerList = brokerList[:20]
         self.__plugin.setPreferences("RecentBrokersWithPort", brokerList)
         
         self.__populateBrokerComboBoxes()
@@ -603,30 +603,37 @@
         """
         Private method to populate the broker name and port combo boxes.
         """
-        brokerList = self.__plugin.getPreferences("RecentBrokersWithPort")
+        brokerPortList = self.__plugin.getPreferences("RecentBrokersWithPort")
         
         # step 1: clear combo boxes
         self.brokerComboBox.clear()
         self.brokerPortComboBox.clear()
         
         # step 2a: populate the broker name list
-        # TODO: make list unique and sorted
-        self.brokerComboBox.addItems([b[0].strip() for b in brokerList])
-        
-        self.__setConnectButtonState()
+        if brokerPortList:
+            currentBroker = brokerPortList[0][0]
+        else:
+            currentBroker = ""
+        brokerSet = {b[0].strip() for b in brokerPortList}
+        self.brokerComboBox.addItems(sorted(brokerSet))
+        index = self.brokerComboBox.findText(currentBroker)
+        self.brokerComboBox.setCurrentIndex(index)
         
         # step 2b: populate the broker ports list
-        if brokerList:
-            currentPort = brokerList[0][1]
+        if brokerPortList:
+            currentPort = brokerPortList[0][1]
         else:
             currentPort = 1883
         currentPortStr = "{0:5}".format(currentPort)
-        portsSet = {b[1] for b in brokerList}
+        portsSet = {b[1] for b in brokerPortList}
         portsSet.update({1883, 8883})
         self.brokerPortComboBox.addItems(
             sorted("{0:5}".format(p) for p in portsSet))
         index = self.brokerPortComboBox.findText(currentPortStr)
         self.brokerPortComboBox.setCurrentIndex(index)
+        
+        # step 3: update the connect button state
+        self.__setConnectButtonState()
     
     def __populateProfileComboBox(self):
         """

eric ide

mercurial