PluginMqttMonitor.py

branch
eric7
changeset 105
36ec7431ad04
parent 103
5fe4f179975f
child 106
84498095d511
equal deleted inserted replaced
104:9a4c9b7f078c 105:36ec7431ad04
16 from EricWidgets.EricApplication import ericApp 16 from EricWidgets.EricApplication import ericApp
17 from EricGui.EricAction import EricAction 17 from EricGui.EricAction import EricAction
18 18
19 import UI.PixmapCache 19 import UI.PixmapCache
20 import Preferences 20 import Preferences
21
22 from MqttMonitor.MqttProtocols import MqttProtocols
21 23
22 # Start-Of-Header 24 # Start-Of-Header
23 name = "MQTT Monitor Plugin" 25 name = "MQTT Monitor Plugin"
24 author = "Detlev Offenbach <detlev@die-offenbachs.de>" 26 author = "Detlev Offenbach <detlev@die-offenbachs.de>"
25 autoactivate = True 27 autoactivate = True
39 needsRestart = False 41 needsRestart = False
40 pyqtApi = 2 42 pyqtApi = 2
41 # End-Of-Header 43 # End-Of-Header
42 44
43 error = "" 45 error = ""
44 46
47 mqttPluginObject = None
48
49
50 def createMqttPage(configDlg):
51 """
52 Module function to create the autocompletion configuration page.
53
54 @param configDlg reference to the configuration dialog
55 @type ConfigurationWidget
56 @return reference to the configuration page
57 @rtype AutoCompletionRopePage
58 """
59 global mqttPluginObject
60 from MqttMonitor.ConfigurationPage.MqttPage import MqttPage
61
62 page = MqttPage(mqttPluginObject)
63 return page
64
65
66 def getConfigData():
67 """
68 Module function returning data as required by the configuration dialog.
69
70 @return dictionary containing the relevant data
71 @rtype dict
72 """
73 usesDarkPalette = ericApp().usesDarkPalette()
74 iconSuffix = "dark" if usesDarkPalette else "light"
75
76 return {
77 "mqttPage": [
78 QCoreApplication.translate("MqttMonitorPlugin", "MQTT Monitor"),
79 os.path.join(
80 "MqttMonitor", "icons", "mqtt22-{0}".format(iconSuffix)),
81 createMqttPage, None, None],
82 }
83
45 84
46 def exeDisplayData(): 85 def exeDisplayData():
47 """ 86 """
48 Module function to support the display of some executable info. 87 Module function to support the display of some executable info.
49 88
99 # __IGNORE_WARNING_M613__ 138 # __IGNORE_WARNING_M613__
100 "SubscribeProperties": "{}", # JSON formatted empty dict 139 "SubscribeProperties": "{}", # JSON formatted empty dict
101 # __IGNORE_WARNING_M613__ 140 # __IGNORE_WARNING_M613__
102 "UnsubscribeProperties": "{}", # JSON formatted empty dict 141 "UnsubscribeProperties": "{}", # JSON formatted empty dict
103 # __IGNORE_WARNING_M613__ 142 # __IGNORE_WARNING_M613__
143 "DefaultProtocol": MqttProtocols.MQTTv311,
144 "RecentBrokersNumber": 20,
145 "RecentTopicsNumber": 20,
104 } 146 }
105 147
106 self.__translator = None 148 self.__translator = None
107 self.__loadTranslator() 149 self.__loadTranslator()
108 150
117 Public method to activate this plug-in. 159 Public method to activate this plug-in.
118 160
119 @return tuple of None and activation status 161 @return tuple of None and activation status
120 @rtype tuple of (None, bool) 162 @rtype tuple of (None, bool)
121 """ 163 """
122 global error 164 global error, mqttPluginObject
123 error = "" # clear previous error 165 error = "" # clear previous error
166 mqttPluginObject = self
167
124 168
125 try: 169 try:
126 import paho.mqtt # __IGNORE_WARNING__ 170 import paho.mqtt # __IGNORE_WARNING__
127 except ImportError: 171 except ImportError:
128 error = self.tr("The 'paho-mqtt' package is not available.") 172 error = self.tr("The 'paho-mqtt' package is not available.")
216 @param key key of the setting 260 @param key key of the setting
217 @type str 261 @type str
218 @return value of the requested setting 262 @return value of the requested setting
219 @rtype Any 263 @rtype Any
220 """ 264 """
221 if key in ["RecentBrokersWithPort", "BrokerProfiles", 265 if key in ("RecentBrokersWithPort", "BrokerProfiles",
222 "SubscribeProperties", "UnsubscribeProperties", 266 "SubscribeProperties", "UnsubscribeProperties",
223 "PublishProperties"]: 267 "PublishProperties"):
224 return json.loads(Preferences.Prefs.settings.value( 268 return json.loads(Preferences.Prefs.settings.value(
269 self.PreferencesKey + "/" + key, self.__defaults[key]))
270 elif key in ("DefaultProtocol", ):
271 return MqttProtocols(int(Preferences.Prefs.settings.value(
272 self.PreferencesKey + "/" + key, self.__defaults[key])))
273 elif key in ("DefaultProtocol", "RecentBrokersNumber",
274 "RecentTopicsNumber"):
275 return int(Preferences.Prefs.settings.value(
225 self.PreferencesKey + "/" + key, self.__defaults[key])) 276 self.PreferencesKey + "/" + key, self.__defaults[key]))
226 else: 277 else:
227 return Preferences.Prefs.settings.value( 278 return Preferences.Prefs.settings.value(
228 self.PreferencesKey + "/" + key, self.__defaults[key]) 279 self.PreferencesKey + "/" + key, self.__defaults[key])
229 280
234 @param key key of the setting to be set 285 @param key key of the setting to be set
235 @type str 286 @type str
236 @param value value to be set 287 @param value value to be set
237 @type Any 288 @type Any
238 """ 289 """
239 if key in ["RecentBrokersWithPort", "BrokerProfiles", 290 if key in ("RecentBrokersWithPort", "BrokerProfiles",
240 "SubscribeProperties", "UnsubscribeProperties", 291 "SubscribeProperties", "UnsubscribeProperties",
241 "PublishProperties"]: 292 "PublishProperties"):
242 Preferences.Prefs.settings.setValue( 293 Preferences.Prefs.settings.setValue(
243 self.PreferencesKey + "/" + key, json.dumps(value)) 294 self.PreferencesKey + "/" + key, json.dumps(value))
295 elif key in ("DefaultProtocol", ):
296 Preferences.Prefs.settings.setValue(
297 self.PreferencesKey + "/" + key, int(value))
244 else: 298 else:
245 Preferences.Prefs.settings.setValue( 299 Preferences.Prefs.settings.setValue(
246 self.PreferencesKey + "/" + key, value) 300 self.PreferencesKey + "/" + key, value)
247 301
248 302

eric ide

mercurial