Sun, 26 Aug 2018 17:27:45 +0200
Added first outline of the MQTT Monitor.
--- a/.hgignore Sun Aug 26 15:16:33 2018 +0200 +++ b/.hgignore Sun Aug 26 17:27:45 2018 +0200 @@ -11,3 +11,4 @@ glob:tmp glob:__pycache__ glob:**.DS_Store +glob:**Ui_*.py
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MqttMonitor/MqttMonitorWidget.py Sun Aug 26 17:27:45 2018 +0200 @@ -0,0 +1,34 @@ +# -*- coding: utf-8 -*- + +""" +Module implementing MqttMonitorWidget. +""" + +from __future__ import unicode_literals + +import os + +from PyQt5.QtCore import pyqtSlot +from PyQt5.QtWidgets import QWidget + +from .Ui_MqttMonitorWidget import Ui_MqttMonitorWidget + +import UI.PixmapCache + + +class MqttMonitorWidget(QWidget, Ui_MqttMonitorWidget): + """ + Class documentation goes here. + """ + def __init__(self, parent=None): + """ + Constructor + + @param parent reference to the parent widget + @type QWidget + """ + super(MqttMonitorWidget, self).__init__(parent) + self.setupUi(self) + + self.pixmapLabel.setPixmap(UI.PixmapCache.getPixmap( + os.path.join("MqttMonitor", "icons", "mqtt48.png")))
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MqttMonitor/MqttMonitorWidget.ui Sun Aug 26 17:27:45 2018 +0200 @@ -0,0 +1,54 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>MqttMonitorWidget</class> + <widget class="QWidget" name="MqttMonitorWidget"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>400</width> + <height>300</height> + </rect> + </property> + <layout class="QVBoxLayout" name="verticalLayout"> + <item> + <layout class="QHBoxLayout" name="horizontalLayout"> + <item> + <widget class="QLabel" name="pixmapLabel"/> + </item> + <item> + <widget class="QLabel" name="label_2"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Expanding" vsizetype="Preferred"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string><b>MQTT Monitor</b></string> + </property> + <property name="alignment"> + <set>Qt::AlignCenter</set> + </property> + </widget> + </item> + </layout> + </item> + <item> + <spacer name="verticalSpacer"> + <property name="orientation"> + <enum>Qt::Vertical</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>20</width> + <height>251</height> + </size> + </property> + </spacer> + </item> + </layout> + </widget> + <resources/> + <connections/> +</ui>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MqttMonitor/__init__.py Sun Aug 26 17:27:45 2018 +0200 @@ -0,0 +1,8 @@ +# -*- coding: utf-8 -*- + +# Copyright (c) 2018 Detlev Offenbach <detlev@die-offenbachs.de> +# + +""" +Package containing the MQTT Monitor modules and data files. +"""
--- a/PluginMqttMonitor.e4p Sun Aug 26 15:16:33 2018 +0200 +++ b/PluginMqttMonitor.e4p Sun Aug 26 17:27:45 2018 +0200 @@ -16,11 +16,19 @@ <TranslationPattern>MqttMonitor/i18n/tmqttmonitor_%language%.ts</TranslationPattern> <Eol index="1"/> <Sources> + <Source>MqttMonitor/MqttMonitorWidget.py</Source> + <Source>MqttMonitor/__init__.py</Source> <Source>PluginMqttMonitor.py</Source> <Source>__init__.py</Source> </Sources> + <Forms> + <Form>MqttMonitor/MqttMonitorWidget.ui</Form> + </Forms> <Others> <Other>.hgignore</Other> + <Other>MqttMonitor/icons/mqtt22.png</Other> + <Other>MqttMonitor/icons/mqtt48.png</Other> + <Other>PluginMqttMonitor.e4p</Other> </Others> <MainScript>PluginMqttMonitor.py</MainScript> <Vcs> @@ -145,6 +153,7 @@ <FiletypeAssociation pattern="Makefile" type="OTHERS"/> <FiletypeAssociation pattern="README" type="OTHERS"/> <FiletypeAssociation pattern="README.*" type="OTHERS"/> + <FiletypeAssociation pattern="Ui_*.py" type="__IGNORE__"/> <FiletypeAssociation pattern="makefile" type="OTHERS"/> </FiletypeAssociations> </Project>
--- a/PluginMqttMonitor.py Sun Aug 26 15:16:33 2018 +0200 +++ b/PluginMqttMonitor.py Sun Aug 26 17:27:45 2018 +0200 @@ -0,0 +1,193 @@ +# -*- coding: utf-8 -*- + +# Copyright (c) 2018 Detlev Offenbach <detlev@die-offenbachs.de> +# + +""" +Module implementing the MQTT Monitor plug-in. +""" + +from __future__ import unicode_literals + +import os + +from PyQt5.QtCore import Qt, QObject, QTranslator, QCoreApplication +from PyQt5.QtGui import QKeySequence + +from E5Gui.E5Application import e5App +from E5Gui.E5Action import E5Action + +import UI.PixmapCache + +# Start-Of-Header +name = "MQTT Monitor Plugin" +author = "Detlev Offenbach <detlev@die-offenbachs.de>" +autoactivate = True +deactivateable = True +version = "1.x" +className = "MqttMonitorPlugin" +packageName = "MqttMonitor" +shortDescription = "Plug-in implementing a tool to connect to a MQTT broker" +longDescription = ( + """Plug-in implementing a tool to connect to a MQTT broker, subscribe""" + """ to topics, present received messages and publish messages.\n\n""" + """Note: The paho-mqtt Python package must be installed.""" +) +needsRestart = False +pyqtApi = 2 +python2Compatible = True +# End-Of-Header + +error = "" + + +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") + + data = { + "programEntry": False, + "header": QCoreApplication.translate("MqttMonitorPlugin", "MQTT"), + "text": QCoreApplication.translate("MqttMonitorPlugin", "paho-mqtt"), + "version": version, + } + + return data + + +class MqttMonitorPlugin(QObject): + """ + Class implementing the MQTT Monitor plug-in. + """ + def __init__(self, ui): + """ + Constructor + + @param ui reference to the user interface object + @type UI.UserInterface + """ + super(MqttMonitorPlugin, self).__init__(ui) + self.__ui = ui + self.__initialize() + + 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 bool + """ + global error + error = "" # clear previous error + + try: + import paho.mqtt # __IGNORE_WARNING__ + except ImportError: + error = self.tr("The 'paho-mqtt' package is not available.") + return None, False + +## self.__object = MqttMonitorWidget(self, self.__ui) +## self.__object.activate() +## e5App().registerPluginObject("MqttMonitor", self.__object) + from MqttMonitor.MqttMonitorWidget import MqttMonitorWidget + + self.__widget = MqttMonitorWidget()##self.__ui) + self.__ui.addSideWidget( + self.__ui.RightSide, self.__widget, + UI.PixmapCache.getIcon( + os.path.join("MqttMonitor", "icons", "mqtt22.png")), + self.tr("MQTT Monitor")) + + self.__activateAct = E5Action( + 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>""" + )) + self.__activateAct.triggered.connect(self.__activateWidget) + + self.__ui.addE5Actions([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. + """ +## e5App().unregisterPluginObject("TimeTracker") +## self.__object.deactivate() + menu = self.__ui.getMenu("subwindow") + menu.removeAction(self.__activateAct) + self.__ui.removeE5Actions([self.__activateAct], 'ui') + self.__ui.removeSideWidget(self.__widget) + + self.__initialize() + + def __loadTranslator(self): + """ + Private method to load the translation file. + """ + if self.__ui is not None: + loc = self.__ui.getLocale() + if loc and loc != "C": + locale_dir = os.path.join( + os.path.dirname(__file__), "MqttMonitor", "i18n") + translation = "mqttmonitor{0}".format(loc) + translator = QTranslator(None) + loaded = translator.load(translation, locale_dir) + if loaded: + self.__translator = translator + e5App().installTranslator(self.__translator) + else: + 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. + """ + try: + uiLayoutType = self.__ui.getLayoutType() + except AttributeError: + # backward compatibility for eric < 18.08 + uiLayoutType = self.__ui.layoutType + + if uiLayoutType == "Toolboxes": + self.__ui.rToolboxDock.show() + self.__ui.rToolbox.setCurrentWidget(self.__widget) + elif uiLayoutType == "Sidebars": + self.__ui.rightSidebar.show() + self.__ui.rightSidebar.setCurrentWidget(self.__widget) + else: + self.__widget.show() + self.__widget.setFocus(Qt.ActiveWindowFocusReason)