PluginMqttMonitor.py

branch
eric7
changeset 105
36ec7431ad04
parent 103
5fe4f179975f
child 106
84498095d511
--- a/PluginMqttMonitor.py	Fri Jul 23 17:48:22 2021 +0200
+++ b/PluginMqttMonitor.py	Fri Jul 23 19:48:14 2021 +0200
@@ -19,6 +19,8 @@
 import UI.PixmapCache
 import Preferences
 
+from MqttMonitor.MqttProtocols import MqttProtocols
+
 # Start-Of-Header
 name = "MQTT Monitor Plugin"
 author = "Detlev Offenbach <detlev@die-offenbachs.de>"
@@ -41,7 +43,44 @@
 # End-Of-Header
 
 error = ""
+
+mqttPluginObject = None
+
+
+def createMqttPage(configDlg):
+    """
+    Module function to create the autocompletion configuration page.
     
+    @param configDlg reference to the configuration dialog
+    @type ConfigurationWidget
+    @return reference to the configuration page
+    @rtype AutoCompletionRopePage
+    """
+    global mqttPluginObject
+    from MqttMonitor.ConfigurationPage.MqttPage import MqttPage
+    
+    page = MqttPage(mqttPluginObject)
+    return page
+
+
+def getConfigData():
+    """
+    Module function returning data as required by the configuration dialog.
+    
+    @return dictionary containing the relevant data
+    @rtype dict
+    """
+    usesDarkPalette = ericApp().usesDarkPalette()
+    iconSuffix = "dark" if usesDarkPalette else "light"
+    
+    return {
+        "mqttPage": [
+            QCoreApplication.translate("MqttMonitorPlugin", "MQTT Monitor"),
+            os.path.join(
+                "MqttMonitor", "icons", "mqtt22-{0}".format(iconSuffix)),
+            createMqttPage, None, None],
+    }
+
 
 def exeDisplayData():
     """
@@ -101,6 +140,9 @@
             # __IGNORE_WARNING_M613__
             "UnsubscribeProperties": "{}",      # JSON formatted empty dict
             # __IGNORE_WARNING_M613__
+            "DefaultProtocol": MqttProtocols.MQTTv311,
+            "RecentBrokersNumber": 20,
+            "RecentTopicsNumber": 20,
         }
         
         self.__translator = None
@@ -119,8 +161,10 @@
         @return tuple of None and activation status
         @rtype tuple of (None, bool)
         """
-        global error
+        global error, mqttPluginObject
         error = ""     # clear previous error
+        mqttPluginObject = self
+        
         
         try:
             import paho.mqtt        # __IGNORE_WARNING__
@@ -218,11 +262,18 @@
         @return value of the requested setting
         @rtype Any
         """
-        if key in ["RecentBrokersWithPort", "BrokerProfiles",
+        if key in ("RecentBrokersWithPort", "BrokerProfiles",
                    "SubscribeProperties", "UnsubscribeProperties",
-                   "PublishProperties"]:
+                   "PublishProperties"):
             return json.loads(Preferences.Prefs.settings.value(
                 self.PreferencesKey + "/" + key, self.__defaults[key]))
+        elif key in ("DefaultProtocol", ):
+            return MqttProtocols(int(Preferences.Prefs.settings.value(
+                self.PreferencesKey + "/" + key, self.__defaults[key])))
+        elif key in ("DefaultProtocol", "RecentBrokersNumber",
+                     "RecentTopicsNumber"):
+            return int(Preferences.Prefs.settings.value(
+                self.PreferencesKey + "/" + key, self.__defaults[key]))
         else:
             return Preferences.Prefs.settings.value(
                 self.PreferencesKey + "/" + key, self.__defaults[key])
@@ -236,11 +287,14 @@
         @param value value to be set
         @type Any
         """
-        if key in ["RecentBrokersWithPort", "BrokerProfiles",
+        if key in ("RecentBrokersWithPort", "BrokerProfiles",
                    "SubscribeProperties", "UnsubscribeProperties",
-                   "PublishProperties"]:
+                   "PublishProperties"):
             Preferences.Prefs.settings.setValue(
                 self.PreferencesKey + "/" + key, json.dumps(value))
+        elif key in ("DefaultProtocol", ):
+            Preferences.Prefs.settings.setValue(
+                self.PreferencesKey + "/" + key, int(value))
         else:
             Preferences.Prefs.settings.setValue(
                 self.PreferencesKey + "/" + key, value)

eric ide

mercurial