--- a/PluginMqttMonitor.py Thu Dec 30 16:36:40 2021 +0100 +++ b/PluginMqttMonitor.py Wed Sep 21 09:42:33 2022 +0200 @@ -26,7 +26,7 @@ author = "Detlev Offenbach <detlev@die-offenbachs.de>" autoactivate = True deactivateable = True -version = "10.2.1" +version = "10.2.2" className = "MqttMonitorPlugin" packageName = "MqttMonitor" shortDescription = "Plug-in implementing a tool to connect to a MQTT broker" @@ -50,7 +50,7 @@ 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 @@ -58,7 +58,7 @@ """ global mqttPluginObject from MqttMonitor.ConfigurationPage.MqttPage import MqttPage - + page = MqttPage(mqttPluginObject) return page @@ -66,37 +66,41 @@ 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], + os.path.join("MqttMonitor", "icons", "mqtt22-{0}".format(iconSuffix)), + createMqttPage, + None, + None, + ], } def exeDisplayData(): """ Module function to support the display of some executable info. - + @return dictionary containing the data to query the presence of the executable @rtype dict """ try: import paho.mqtt + version = paho.mqtt.__version__ except ImportError: version = QCoreApplication.translate( - "MqttMonitorPlugin", "(package not available)") - + "MqttMonitorPlugin", "(package not available)" + ) + return { "programEntry": False, "header": QCoreApplication.translate("MqttMonitorPlugin", "MQTT"), @@ -116,111 +120,118 @@ """ Class implementing the MQTT Monitor plug-in. """ + PreferencesKey = "MqttMonitor" - + def __init__(self, ui): """ Constructor - + @param ui reference to the user interface object @type UI.UserInterface """ super().__init__(ui) self.__ui = ui self.__initialize() - + self.__defaults = { - "RecentBrokersWithPort": "[]", # JSON formatted empty list - "BrokerProfiles": "{}", # JSON formatted empty dict + "RecentBrokersWithPort": "[]", # JSON formatted empty list + "BrokerProfiles": "{}", # JSON formatted empty dict # __IGNORE_WARNING_M613__ - "MostRecentProfile": "", # most recently used profile - "PublishProperties": "{}", # JSON formatted empty dict + "MostRecentProfile": "", # most recently used profile + "PublishProperties": "{}", # JSON formatted empty dict # __IGNORE_WARNING_M613__ - "SubscribeProperties": "{}", # JSON formatted empty dict + "SubscribeProperties": "{}", # JSON formatted empty dict # __IGNORE_WARNING_M613__ - "UnsubscribeProperties": "{}", # JSON formatted empty dict + "UnsubscribeProperties": "{}", # JSON formatted empty dict # __IGNORE_WARNING_M613__ "DefaultProtocol": MqttProtocols.MQTTv311, "RecentBrokersNumber": 20, "RecentTopicsNumber": 20, - "RecentTopics": "[]", # JSON formatted empty list + "RecentTopics": "[]", # JSON formatted empty list } - + self.__translator = None self.__loadTranslator() - + def __initialize(self): """ Private slot to (re)initialize the plugin. """ self.__widget = None - + def activate(self): """ Public method to activate this plug-in. - + @return tuple of None and activation status @rtype tuple of (None, bool) """ global error, mqttPluginObject - error = "" # clear previous error + error = "" # clear previous error mqttPluginObject = self - + try: - import paho.mqtt # __IGNORE_WARNING__ + import paho.mqtt # __IGNORE_WARNING__ except ImportError: error = self.tr("The 'paho-mqtt' package is not available.") return None, False - + from MqttMonitor.MqttMonitorWidget import MqttMonitorWidget - + usesDarkPalette = ericApp().usesDarkPalette() iconSuffix = "dark" if usesDarkPalette else "light" - + self.__widget = MqttMonitorWidget(self, usesDarkPalette) iconName = ( "sbMqttMonitor96" - if self.__ui.getLayoutType() == "Sidebars" else - "mqtt22-{0}".format(iconSuffix) + if self.__ui.getLayoutType() == "Sidebars" + else "mqtt22-{0}".format(iconSuffix) ) self.__ui.addSideWidget( - self.__ui.RightSide, self.__widget, - UI.PixmapCache.getIcon( - os.path.join("MqttMonitor", "icons", iconName)), - self.tr("MQTT Monitor")) - + self.__ui.RightSide, + self.__widget, + UI.PixmapCache.getIcon(os.path.join("MqttMonitor", "icons", iconName)), + self.tr("MQTT Monitor"), + ) + self.__activateAct = EricAction( - self.tr('MQTT Monitor'), - self.tr('M&QTT Monitor'), + self.tr("MQTT Monitor"), + self.tr("M&QTT Monitor"), QKeySequence(self.tr("Alt+Shift+Q")), - 0, self, - 'mqtt_monitor_activate') - self.__activateAct.setStatusTip(self.tr( - "Switch the input focus to the MQTT Monitor window.")) - self.__activateAct.setWhatsThis(self.tr( - """<b>Activate MQTT Monitor</b>""" - """<p>This switches the input focus to the MQTT Monitor""" - """ window.</p>""" - )) + 0, + self, + "mqtt_monitor_activate", + ) + self.__activateAct.setStatusTip( + self.tr("Switch the input focus to the MQTT Monitor window.") + ) + self.__activateAct.setWhatsThis( + self.tr( + """<b>Activate MQTT Monitor</b>""" + """<p>This switches the input focus to the MQTT Monitor""" + """ window.</p>""" + ) + ) self.__activateAct.triggered.connect(self.__activateWidget) - - self.__ui.addEricActions([self.__activateAct], 'ui') + + self.__ui.addEricActions([self.__activateAct], "ui") menu = self.__ui.getMenu("subwindow") menu.addAction(self.__activateAct) - + return None, True - + def deactivate(self): """ Public method to deactivate this plug-in. """ menu = self.__ui.getMenu("subwindow") menu.removeAction(self.__activateAct) - self.__ui.removeEricActions([self.__activateAct], 'ui') + self.__ui.removeEricActions([self.__activateAct], "ui") self.__ui.removeSideWidget(self.__widget) - + self.__initialize() - + def __loadTranslator(self): """ Private method to load the translation file. @@ -229,7 +240,8 @@ loc = self.__ui.getLocale() if loc and loc != "C": locale_dir = os.path.join( - os.path.dirname(__file__), "MqttMonitor", "i18n") + os.path.dirname(__file__), "MqttMonitor", "i18n" + ) translation = "mqttmonitor_{0}".format(loc) translator = QTranslator(None) loaded = translator.load(translation, locale_dir) @@ -237,16 +249,18 @@ self.__translator = translator ericApp().installTranslator(self.__translator) else: - print("Warning: translation file '{0}' could not be" - " loaded.".format(translation)) + print( + "Warning: translation file '{0}' could not be" + " loaded.".format(translation) + ) print("Using default.") - + def __activateWidget(self): """ Private slot to handle the activation of the MQTT Monitor. """ uiLayoutType = self.__ui.getLayoutType() - + if uiLayoutType == "Toolboxes": self.__ui.rToolboxDock.show() self.__ui.rToolbox.setCurrentWidget(self.__widget) @@ -256,65 +270,88 @@ else: self.__widget.show() self.__widget.setFocus(Qt.FocusReason.ActiveWindowFocusReason) - + def getPreferences(self, key): """ Public method to retrieve the various settings. - + @param key key of the setting @type str @return value of the requested setting @rtype Any """ - if key in ("RecentBrokersWithPort", "BrokerProfiles", - "SubscribeProperties", "UnsubscribeProperties", - "PublishProperties", "RecentTopics"): - 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])) + if key in ( + "RecentBrokersWithPort", + "BrokerProfiles", + "SubscribeProperties", + "UnsubscribeProperties", + "PublishProperties", + "RecentTopics", + ): + 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]) - + self.PreferencesKey + "/" + key, self.__defaults[key] + ) + def setPreferences(self, key, value): """ Public method to store the various settings. - + @param key key of the setting to be set @type str @param value value to be set @type Any """ - if key in ("RecentBrokersWithPort", "BrokerProfiles", - "SubscribeProperties", "UnsubscribeProperties", - "PublishProperties", "RecentTopics"): + if key in ( + "RecentBrokersWithPort", + "BrokerProfiles", + "SubscribeProperties", + "UnsubscribeProperties", + "PublishProperties", + "RecentTopics", + ): Preferences.Prefs.settings.setValue( - self.PreferencesKey + "/" + key, json.dumps(value)) - elif key in ("DefaultProtocol", ): + self.PreferencesKey + "/" + key, json.dumps(value) + ) + elif key in ("DefaultProtocol",): Preferences.Prefs.settings.setValue( - self.PreferencesKey + "/" + key, int(value)) + self.PreferencesKey + "/" + key, int(value) + ) else: - Preferences.Prefs.settings.setValue( - self.PreferencesKey + "/" + key, value) + Preferences.Prefs.settings.setValue(self.PreferencesKey + "/" + key, value) def installDependencies(pipInstall): """ Function to install dependencies of this plug-in. - + @param pipInstall function to be called with a list of package names. @type function """ try: - import paho.mqtt # __IGNORE_WARNING__ + import paho.mqtt # __IGNORE_WARNING__ except ImportError: pipInstall(["paho-mqtt"]) + # # eflag: noqa = M801