16 |
16 |
17 from E5Gui.E5Application import e5App |
17 from E5Gui.E5Application import e5App |
18 from E5Gui.E5Action import E5Action |
18 from E5Gui.E5Action import E5Action |
19 |
19 |
20 import UI.PixmapCache |
20 import UI.PixmapCache |
|
21 import Preferences |
21 |
22 |
22 # Start-Of-Header |
23 # Start-Of-Header |
23 name = "MQTT Monitor Plugin" |
24 name = "MQTT Monitor Plugin" |
24 author = "Detlev Offenbach <detlev@die-offenbachs.de>" |
25 author = "Detlev Offenbach <detlev@die-offenbachs.de>" |
25 autoactivate = True |
26 autoactivate = True |
26 deactivateable = True |
27 deactivateable = True |
27 version = "1.x" |
28 version = "1.0.0" |
28 className = "MqttMonitorPlugin" |
29 className = "MqttMonitorPlugin" |
29 packageName = "MqttMonitor" |
30 packageName = "MqttMonitor" |
30 shortDescription = "Plug-in implementing a tool to connect to a MQTT broker" |
31 shortDescription = "Plug-in implementing a tool to connect to a MQTT broker" |
31 longDescription = ( |
32 longDescription = ( |
32 """Plug-in implementing a tool to connect to a MQTT broker, subscribe""" |
33 """Plug-in implementing a tool to connect to a MQTT broker, subscribe""" |
64 } |
65 } |
65 |
66 |
66 return data |
67 return data |
67 |
68 |
68 |
69 |
|
70 def prepareUninstall(): |
|
71 """ |
|
72 Module function to prepare for an uninstallation. |
|
73 """ |
|
74 Preferences.Prefs.settings.remove(MqttMonitorPlugin.PreferencesKey) |
|
75 |
|
76 |
69 class MqttMonitorPlugin(QObject): |
77 class MqttMonitorPlugin(QObject): |
70 """ |
78 """ |
71 Class implementing the MQTT Monitor plug-in. |
79 Class implementing the MQTT Monitor plug-in. |
72 """ |
80 """ |
|
81 PreferencesKey = "MqttMonitor" |
|
82 |
73 def __init__(self, ui): |
83 def __init__(self, ui): |
74 """ |
84 """ |
75 Constructor |
85 Constructor |
76 |
86 |
77 @param ui reference to the user interface object |
87 @param ui reference to the user interface object |
78 @type UI.UserInterface |
88 @type UI.UserInterface |
79 """ |
89 """ |
80 super(MqttMonitorPlugin, self).__init__(ui) |
90 super(MqttMonitorPlugin, self).__init__(ui) |
81 self.__ui = ui |
91 self.__ui = ui |
82 self.__initialize() |
92 self.__initialize() |
|
93 |
|
94 self.__defaults = { |
|
95 "RecentBrokers": [], |
|
96 } |
83 |
97 |
84 self.__translator = None |
98 self.__translator = None |
85 self.__loadTranslator() |
99 self.__loadTranslator() |
86 |
100 |
87 def __initialize(self): |
101 def __initialize(self): |
104 import paho.mqtt # __IGNORE_WARNING__ |
118 import paho.mqtt # __IGNORE_WARNING__ |
105 except ImportError: |
119 except ImportError: |
106 error = self.tr("The 'paho-mqtt' package is not available.") |
120 error = self.tr("The 'paho-mqtt' package is not available.") |
107 return None, False |
121 return None, False |
108 |
122 |
109 ## self.__object = MqttMonitorWidget(self, self.__ui) |
|
110 ## self.__object.activate() |
|
111 ## e5App().registerPluginObject("MqttMonitor", self.__object) |
|
112 from MqttMonitor.MqttMonitorWidget import MqttMonitorWidget |
123 from MqttMonitor.MqttMonitorWidget import MqttMonitorWidget |
113 |
124 |
114 self.__widget = MqttMonitorWidget()##self.__ui) |
125 self.__widget = MqttMonitorWidget(self) |
115 self.__ui.addSideWidget( |
126 self.__ui.addSideWidget( |
116 self.__ui.RightSide, self.__widget, |
127 self.__ui.RightSide, self.__widget, |
117 UI.PixmapCache.getIcon( |
128 UI.PixmapCache.getIcon( |
118 os.path.join("MqttMonitor", "icons", "mqtt22.png")), |
129 os.path.join("MqttMonitor", "icons", "mqtt22.png")), |
119 self.tr("MQTT Monitor")) |
130 self.tr("MQTT Monitor")) |
141 |
152 |
142 def deactivate(self): |
153 def deactivate(self): |
143 """ |
154 """ |
144 Public method to deactivate this plug-in. |
155 Public method to deactivate this plug-in. |
145 """ |
156 """ |
146 ## e5App().unregisterPluginObject("TimeTracker") |
|
147 ## self.__object.deactivate() |
|
148 menu = self.__ui.getMenu("subwindow") |
157 menu = self.__ui.getMenu("subwindow") |
149 menu.removeAction(self.__activateAct) |
158 menu.removeAction(self.__activateAct) |
150 self.__ui.removeE5Actions([self.__activateAct], 'ui') |
159 self.__ui.removeE5Actions([self.__activateAct], 'ui') |
151 self.__ui.removeSideWidget(self.__widget) |
160 self.__ui.removeSideWidget(self.__widget) |
152 |
161 |
189 self.__ui.rightSidebar.show() |
198 self.__ui.rightSidebar.show() |
190 self.__ui.rightSidebar.setCurrentWidget(self.__widget) |
199 self.__ui.rightSidebar.setCurrentWidget(self.__widget) |
191 else: |
200 else: |
192 self.__widget.show() |
201 self.__widget.show() |
193 self.__widget.setFocus(Qt.ActiveWindowFocusReason) |
202 self.__widget.setFocus(Qt.ActiveWindowFocusReason) |
|
203 |
|
204 def getPreferences(self, key): |
|
205 """ |
|
206 Public method to retrieve the various settings. |
|
207 |
|
208 @param key the key of the value to get |
|
209 @return the requested setting |
|
210 """ |
|
211 if key in ["RecentBrokers"]: |
|
212 return Preferences.toList(Preferences.Prefs.settings.value( |
|
213 self.PreferencesKey + "/" + key, self.__defaults[key])) |
|
214 else: |
|
215 return Preferences.Prefs.settings.value( |
|
216 self.PreferencesKey + "/" + key, self.__defaults[key]) |
|
217 |
|
218 def setPreferences(self, key, value): |
|
219 """ |
|
220 Public method to store the various settings. |
|
221 |
|
222 @param key the key of the setting to be set (string) |
|
223 @param value the value to be set |
|
224 """ |
|
225 Preferences.Prefs.settings.setValue( |
|
226 self.PreferencesKey + "/" + key, value) |
|
227 |
|
228 # |
|
229 # eflag: noqa = M801 |