MqttMonitor/MqttMonitorWidget.py

branch
eric7
changeset 127
8982ef7b7d67
parent 123
3d7e63ed4fd1
child 129
9d54bf366323
equal deleted inserted replaced
126:eb9ca3b5bb7b 127:8982ef7b7d67
14 14
15 from PyQt6.QtCore import pyqtSlot, Qt, QTimer, QFileInfo, QPoint 15 from PyQt6.QtCore import pyqtSlot, Qt, QTimer, QFileInfo, QPoint
16 from PyQt6.QtGui import QFont, QTextCursor, QBrush, QColor 16 from PyQt6.QtGui import QFont, QTextCursor, QBrush, QColor
17 from PyQt6.QtWidgets import QWidget, QDialog, QMenu 17 from PyQt6.QtWidgets import QWidget, QDialog, QMenu
18 18
19 from EricWidgets.EricApplication import ericApp 19 from eric7 import Utilities
20 from EricWidgets import EricMessageBox, EricFileDialog 20
21 from EricWidgets.EricPathPicker import EricPathPickerModes 21 try:
22 from eric7.EricGui import EricPixmapCache
23 except ImportError:
24 from UI import PixmapCache as EricPixmapCache
25 from eric7.EricWidgets import EricMessageBox, EricFileDialog
26 from eric7.EricWidgets.EricApplication import ericApp
27 from eric7.EricWidgets.EricPathPicker import EricPathPickerModes
22 28
23 from .Ui_MqttMonitorWidget import Ui_MqttMonitorWidget 29 from .Ui_MqttMonitorWidget import Ui_MqttMonitorWidget
24 30
25 from .MqttClient import ( 31 from .MqttClient import (
26 MqttClient, 32 MqttClient,
29 mqttLogLevelString, 35 mqttLogLevelString,
30 ) 36 )
31 from .MqttReasonCodes import mqttReasonCode 37 from .MqttReasonCodes import mqttReasonCode
32 from .MqttProtocols import MqttProtocols 38 from .MqttProtocols import MqttProtocols
33 39
34 import UI.PixmapCache
35 import Utilities
36
37 40
38 class MqttMonitorWidget(QWidget, Ui_MqttMonitorWidget): 41 class MqttMonitorWidget(QWidget, Ui_MqttMonitorWidget):
39 """ 42 """
40 Class implementing the MQTT Monitor widget. 43 Class implementing the MQTT Monitor widget.
41 """ 44 """
69 72
70 with contextlib.suppress(AttributeError): 73 with contextlib.suppress(AttributeError):
71 # backward compatibility 74 # backward compatibility
72 if not ericApp().usesSmallScreen(): 75 if not ericApp().usesSmallScreen():
73 self.pixmapLabel.setPixmap( 76 self.pixmapLabel.setPixmap(
74 UI.PixmapCache.getPixmap( 77 EricPixmapCache.getPixmap(
75 os.path.join( 78 os.path.join(
76 "MqttMonitor", 79 "MqttMonitor",
77 "icons", 80 "icons",
78 "mqtt48-{0}".format(self.__iconSuffix), 81 "mqtt48-{0}".format(self.__iconSuffix),
79 ) 82 )
147 150
148 self.__connectionModeProfile = True 151 self.__connectionModeProfile = True
149 self.__setConnectionMode(True) # initial mode is 'profile connection' 152 self.__setConnectionMode(True) # initial mode is 'profile connection'
150 self.__populateProfileComboBox() 153 self.__populateProfileComboBox()
151 154
152 self.connectButton.setIcon(UI.PixmapCache.getIcon("ircConnect")) 155 self.connectButton.setIcon(EricPixmapCache.getIcon("ircConnect"))
153 self.brokerConnectionOptionsButton.setIcon( 156 self.brokerConnectionOptionsButton.setIcon(
154 UI.PixmapCache.getIcon( 157 EricPixmapCache.getIcon(
155 os.path.join( 158 os.path.join(
156 "MqttMonitor", 159 "MqttMonitor",
157 "icons", 160 "icons",
158 "connectionOptions-{0}".format(self.__iconSuffix), 161 "connectionOptions-{0}".format(self.__iconSuffix),
159 ) 162 )
160 ) 163 )
161 ) 164 )
162 self.__populateBrokerComboBoxes() 165 self.__populateBrokerComboBoxes()
163 self.brokerStatusLabel.hide() 166 self.brokerStatusLabel.hide()
164 self.clearWillButton.setIcon(UI.PixmapCache.getIcon("certificateDelete")) 167 self.clearWillButton.setIcon(EricPixmapCache.getIcon("certificateDelete"))
165 168
166 self.subscribeTopicComboBox.lineEdit().setClearButtonEnabled(True) 169 self.subscribeTopicComboBox.lineEdit().setClearButtonEnabled(True)
167 self.subscribeTopicComboBox.lineEdit().returnPressed.connect( 170 self.subscribeTopicComboBox.lineEdit().returnPressed.connect(
168 self.on_subscribeButton_clicked 171 self.on_subscribeButton_clicked
169 ) 172 )
170 self.__populateSubscribeTopicComboBox() 173 self.__populateSubscribeTopicComboBox()
171 174
172 self.subscribeButton.setIcon(UI.PixmapCache.getIcon("plus")) 175 self.subscribeButton.setIcon(EricPixmapCache.getIcon("plus"))
173 self.subscribeButton.setEnabled(False) 176 self.subscribeButton.setEnabled(False)
174 self.subscribePropertiesButton.setIcon(UI.PixmapCache.getIcon("listSelection")) 177 self.subscribePropertiesButton.setIcon(EricPixmapCache.getIcon("listSelection"))
175 self.subscribePropertiesButton.setEnabled(False) 178 self.subscribePropertiesButton.setEnabled(False)
176 self.subscribePropertiesButton.setVisible(False) 179 self.subscribePropertiesButton.setVisible(False)
177 180
178 self.unsubscribeButton.setIcon(UI.PixmapCache.getIcon("minus")) 181 self.unsubscribeButton.setIcon(EricPixmapCache.getIcon("minus"))
179 self.unsubscribeButton.setEnabled(False) 182 self.unsubscribeButton.setEnabled(False)
180 self.unsubscribePropertiesButton.setIcon( 183 self.unsubscribePropertiesButton.setIcon(
181 UI.PixmapCache.getIcon("listSelection") 184 EricPixmapCache.getIcon("listSelection")
182 ) 185 )
183 self.unsubscribePropertiesButton.setEnabled(False) 186 self.unsubscribePropertiesButton.setEnabled(False)
184 self.unsubscribePropertiesButton.setVisible(False) 187 self.unsubscribePropertiesButton.setVisible(False)
185 188
186 self.__initPropertiesEditMenu() 189 self.__initPropertiesEditMenu()
190 self.__updateUnsubscribeTopicComboBox() 193 self.__updateUnsubscribeTopicComboBox()
191 194
192 self.__publishedTopics = [] 195 self.__publishedTopics = []
193 self.__updatePublishTopicComboBox() 196 self.__updatePublishTopicComboBox()
194 self.publishButton.setEnabled(False) 197 self.publishButton.setEnabled(False)
195 self.publishPropertiesButton.setIcon(UI.PixmapCache.getIcon("listSelection")) 198 self.publishPropertiesButton.setIcon(EricPixmapCache.getIcon("listSelection"))
196 self.publishPropertiesButton.setEnabled(False) 199 self.publishPropertiesButton.setEnabled(False)
197 self.publishPropertiesButton.setVisible(False) 200 self.publishPropertiesButton.setVisible(False)
198 201
199 self.__connectionOptions = None 202 self.__connectionOptions = None
200 203
281 """ 284 """
282 Private method to create the properties output context menu. 285 Private method to create the properties output context menu.
283 """ 286 """
284 self.__propertiesEditMenu = QMenu(self) 287 self.__propertiesEditMenu = QMenu(self)
285 self.__copyPropertiesAct = self.__propertiesEditMenu.addAction( 288 self.__copyPropertiesAct = self.__propertiesEditMenu.addAction(
286 UI.PixmapCache.getIcon("editCopy"), 289 EricPixmapCache.getIcon("editCopy"),
287 self.tr("Copy"), 290 self.tr("Copy"),
288 self.propertiesEdit.copy, 291 self.propertiesEdit.copy,
289 ) 292 )
290 self.__propertiesEditMenu.addSeparator() 293 self.__propertiesEditMenu.addSeparator()
291 self.__selectAllPropertiesAct = self.__propertiesEditMenu.addAction( 294 self.__selectAllPropertiesAct = self.__propertiesEditMenu.addAction(
292 UI.PixmapCache.getIcon("editSelectAll"), 295 EricPixmapCache.getIcon("editSelectAll"),
293 self.tr("Select All"), 296 self.tr("Select All"),
294 self.propertiesEdit.selectAll, 297 self.propertiesEdit.selectAll,
295 ) 298 )
296 self.__propertiesEditMenu.addSeparator() 299 self.__propertiesEditMenu.addSeparator()
297 self.__clearPropertiesAct = self.__propertiesEditMenu.addAction( 300 self.__clearPropertiesAct = self.__propertiesEditMenu.addAction(
298 UI.PixmapCache.getIcon("editDelete"), 301 EricPixmapCache.getIcon("editDelete"),
299 self.tr("Clear"), 302 self.tr("Clear"),
300 self.propertiesEdit.clear, 303 self.propertiesEdit.clear,
301 ) 304 )
302 305
303 self.propertiesEdit.copyAvailable.connect(self.__copyPropertiesAct.setEnabled) 306 self.propertiesEdit.copyAvailable.connect(self.__copyPropertiesAct.setEnabled)
350 self.connectButton.setEnabled(True) 353 self.connectButton.setEnabled(True)
351 if rc == 0: 354 if rc == 0:
352 self.__connectedToBroker = True 355 self.__connectedToBroker = True
353 self.__connectionOptions = None 356 self.__connectionOptions = None
354 357
355 self.connectButton.setIcon(UI.PixmapCache.getIcon("ircDisconnect")) 358 self.connectButton.setIcon(EricPixmapCache.getIcon("ircDisconnect"))
356 359
357 self.subscribeGroup.setEnabled(True) 360 self.subscribeGroup.setEnabled(True)
358 self.subscribePropertiesButton.setVisible( 361 self.subscribePropertiesButton.setVisible(
359 self.__client.getProtocol() == MqttProtocols.MQTTv5 362 self.__client.getProtocol() == MqttProtocols.MQTTv5
360 ) 363 )
410 else self.tr("Connection to Broker shut down cleanly.") 413 else self.tr("Connection to Broker shut down cleanly.")
411 ) 414 )
412 ) 415 )
413 self.__flashBrokerStatusLabel(msg) 416 self.__flashBrokerStatusLabel(msg)
414 417
415 self.connectButton.setIcon(UI.PixmapCache.getIcon("ircConnect")) 418 self.connectButton.setIcon(EricPixmapCache.getIcon("ircConnect"))
416 self.__setConnectButtonState() 419 self.__setConnectButtonState()
417 420
418 self.__subscribedTopics = [] 421 self.__subscribedTopics = []
419 self.__topicQueue = {} 422 self.__topicQueue = {}
420 self.__updateUnsubscribeTopicComboBox() 423 self.__updateUnsubscribeTopicComboBox()
1327 @type bool 1330 @type bool
1328 """ 1331 """
1329 self.__connectionModeProfile = profileMode 1332 self.__connectionModeProfile = profileMode
1330 if profileMode: 1333 if profileMode:
1331 self.modeButton.setIcon( 1334 self.modeButton.setIcon(
1332 UI.PixmapCache.getIcon( 1335 EricPixmapCache.getIcon(
1333 os.path.join( 1336 os.path.join(
1334 "MqttMonitor", "icons", "profiles-{0}".format(self.__iconSuffix) 1337 "MqttMonitor", "icons", "profiles-{0}".format(self.__iconSuffix)
1335 ) 1338 )
1336 ) 1339 )
1337 ) 1340 )
1338 else: 1341 else:
1339 self.modeButton.setIcon( 1342 self.modeButton.setIcon(
1340 UI.PixmapCache.getIcon( 1343 EricPixmapCache.getIcon(
1341 os.path.join( 1344 os.path.join(
1342 "MqttMonitor", 1345 "MqttMonitor",
1343 "icons", 1346 "icons",
1344 "quickopen-{0}".format(self.__iconSuffix), 1347 "quickopen-{0}".format(self.__iconSuffix),
1345 ) 1348 )

eric ide

mercurial