--- a/MqttMonitor/MqttMonitorWidget.py Sun May 30 17:40:40 2021 +0200 +++ b/MqttMonitor/MqttMonitorWidget.py Sun May 30 18:21:40 2021 +0200 @@ -12,12 +12,12 @@ import copy import contextlib -from PyQt5.QtCore import pyqtSlot, Qt, QTimer, QFileInfo -from PyQt5.QtGui import QFont, QTextCursor, QBrush -from PyQt5.QtWidgets import QWidget, QDialog +from PyQt6.QtCore import pyqtSlot, Qt, QTimer, QFileInfo +from PyQt6.QtGui import QFont, QTextCursor, QBrush, QColor +from PyQt6.QtWidgets import QWidget, QDialog -from E5Gui import E5MessageBox, E5FileDialog -from E5Gui.E5PathPicker import E5PathPickerModes +from EricWidgets import EricMessageBox, EricFileDialog +from EricWidgets.EricPathPicker import EricPathPickerModes from .Ui_MqttMonitorWidget import Ui_MqttMonitorWidget @@ -37,14 +37,15 @@ BrokerStatusTopic = "$SYS/broker/#" BrokerStatusTopicLoadPrefix = "$SYS/broker/load/" - def __init__(self, plugin, iconSuffix, parent=None): + def __init__(self, plugin, usesDarkPalette, parent=None): """ Constructor @param plugin reference to the plug-in object @type MqttMonitorPlugin - @param iconSuffix suffix for the icons - @type str + @param usesDarkPalette flag indicating the use of a dark application + palette + @type bool @param parent reference to the parent widget @type QWidget """ @@ -52,7 +53,7 @@ self.setupUi(self) self.__plugin = plugin - self.__iconSuffix = iconSuffix + self.__iconSuffix = "dark" if usesDarkPalette else "light" self.__connectedToBroker = False self.__brokerStatusTopicSubscribed = False @@ -62,12 +63,13 @@ "mqtt48-{0}".format(self.__iconSuffix)) )) - self.publishPayloadFilePicker.setMode(E5PathPickerModes.OpenFileMode) + self.publishPayloadFilePicker.setMode( + EricPathPickerModes.OPEN_FILE_MODE) self.publishPayloadFilePicker.setFilters(self.tr("All Files (*)")) self.__messagesFormat = self.messagesEdit.currentCharFormat() self.__messagesTopicFormat = self.messagesEdit.currentCharFormat() - self.__messagesTopicFormat.setFontWeight(QFont.Bold) + self.__messagesTopicFormat.setFontWeight(QFont.Weight.Bold) self.__messagesQosFormat = self.messagesEdit.currentCharFormat() self.__messagesQosFormat.setFontItalic(True) @@ -87,15 +89,26 @@ self.logLevelComboBox.setCurrentIndex( self.logLevelComboBox.count() - 1) - self.__logMessagesBackgrounds = { - MqttClient.LogDebug: QBrush(Qt.white), - MqttClient.LogInfo: QBrush(Qt.lightGray), - MqttClient.LogNotice: QBrush(Qt.green), - MqttClient.LogWarning: QBrush(Qt.yellow), - MqttClient.LogError: QBrush(Qt.red), - MqttClient.LogDisabled: QBrush(Qt.magenta) - # reuse LogDisabled for unknown log levels - } + if usesDarkPalette: + self.__logMessagesBackgrounds = { + MqttClient.LogDebug: QBrush(QColor("#2f2f2f")), + MqttClient.LogInfo: QBrush(QColor("#868686")), + MqttClient.LogNotice: QBrush(QColor("#009900")), + MqttClient.LogWarning: QBrush(QColor("#999900")), + MqttClient.LogError: QBrush(QColor("#990000")), + MqttClient.LogDisabled: QBrush(QColor("#990099")), + # reuse LogDisabled for unknown log levels + } + else: + self.__logMessagesBackgrounds = { + MqttClient.LogDebug: QBrush(Qt.GlobalColor.white), + MqttClient.LogInfo: QBrush(Qt.GlobalColor.lightGray), + MqttClient.LogNotice: QBrush(Qt.GlobalColor.green), + MqttClient.LogWarning: QBrush(Qt.GlobalColor.yellow), + MqttClient.LogError: QBrush(Qt.GlobalColor.red), + MqttClient.LogDisabled: QBrush(Qt.GlobalColor.magenta) + # reuse LogDisabled for unknown log levels + } self.logSearchWidget.attachTextEdit(self.logEdit) self.logSearchWidget.setWidthForHeight(False) @@ -106,7 +119,7 @@ self.__setConnectionMode(True) # initial mode is 'profile connection' self.__populateProfileComboBox() - self.connectButton.setIcon(UI.PixmapCache.getIcon("ircConnect.png")) + self.connectButton.setIcon(UI.PixmapCache.getIcon("ircConnect")) self.brokerConnectionOptionsButton.setIcon(UI.PixmapCache.getIcon( os.path.join("MqttMonitor", "icons", "connectionOptions-{0}".format(self.__iconSuffix)) @@ -114,9 +127,9 @@ self.__populateBrokerComboBoxes() self.brokerStatusLabel.hide() - self.subscribeButton.setIcon(UI.PixmapCache.getIcon("plus.png")) + self.subscribeButton.setIcon(UI.PixmapCache.getIcon("plus")) self.subscribeButton.setEnabled(False) - self.unsubscribeButton.setIcon(UI.PixmapCache.getIcon("minus.png")) + self.unsubscribeButton.setIcon(UI.PixmapCache.getIcon("minus")) self.__subscribedTopics = [] self.__topicQueue = {} @@ -215,7 +228,7 @@ self.__connectionOptions = None self.connectButton.setIcon( - UI.PixmapCache.getIcon("ircDisconnect.png")) + UI.PixmapCache.getIcon("ircDisconnect")) self.subscribeGroup.setEnabled(True) self.unsubscribeGroup.setEnabled(True) @@ -256,7 +269,7 @@ ) self.__flashBrokerStatusLabel(msg) - self.connectButton.setIcon(UI.PixmapCache.getIcon("ircConnect.png")) + self.connectButton.setIcon(UI.PixmapCache.getIcon("ircConnect")) self.__setConnectButtonState() self.__subscribedTopics = [] @@ -290,7 +303,7 @@ textCursor = self.logEdit.textCursor() if not self.logEdit.document().isEmpty(): - textCursor.movePosition(QTextCursor.End) + textCursor.movePosition(QTextCursor.MoveOperation.End) self.logEdit.setTextCursor(textCursor) self.logEdit.insertPlainText("\n") @@ -302,7 +315,7 @@ textBlockFormat.setBackground( self.__logMessagesBackgrounds[MqttClient.LogDisabled]) textCursor.setBlockFormat(textBlockFormat) - textCursor.movePosition(QTextCursor.End) + textCursor.movePosition(QTextCursor.MoveOperation.End) self.logEdit.setTextCursor(textCursor) txt = self.tr("{0}: {1}").format(mqttLogLevelString(level), message) @@ -341,6 +354,7 @@ @param mid ID of the published message @type int """ + # TODO: check this 'pass' statement pass @pyqtSlot(int, tuple) @@ -434,7 +448,7 @@ dlg = MqttConnectionProfilesDialog( self.__client, self.__plugin.getPreferences("BrokerProfiles"), parent=self) - if dlg.exec() == QDialog.Accepted: + if dlg.exec() == QDialog.DialogCode.Accepted: profilesDict = dlg.getProfiles() self.__plugin.setPreferences("BrokerProfiles", profilesDict) self.__populateProfileComboBox() @@ -444,7 +458,7 @@ ) dlg = MqttConnectionOptionsDialog( self.__client, self.__connectionOptions, parent=self) - if dlg.exec() == QDialog.Accepted: + if dlg.exec() == QDialog.DialogCode.Accepted: self.__connectionOptions = dlg.getConnectionOptions() if self.__connectionOptions["TlsEnable"]: port = self.brokerPortComboBox.currentText().strip() @@ -497,7 +511,7 @@ qos = self.subscribeQosSpinBox.value() if topic: if topic.startswith(MqttMonitorWidget.BrokerStatusTopicPrefix): - E5MessageBox.warning( + EricMessageBox.warning( self, self.tr("Subscribe to Topic"), self.tr("Subscriptions to the Status topic '$SYS' shall" @@ -555,7 +569,7 @@ with open(payloadFile, "rb") as f: payloadStr = f.read() except EnvironmentError as err: - E5MessageBox.critical( + EricMessageBox.critical( self, self.tr("Read Payload from File"), self.tr("""<p>The file <b>{0}</b> could not be read.""" @@ -635,13 +649,13 @@ """ Private slot to save the received messages. """ - fn, selectedFilter = E5FileDialog.getSaveFileNameAndFilter( + fn, selectedFilter = EricFileDialog.getSaveFileNameAndFilter( self, self.tr("Save Messages"), "", self.tr("Messages Files (*.txt);;All Files (*)"), "", - E5FileDialog.Options(E5FileDialog.DontConfirmOverwrite)) + EricFileDialog.DontConfirmOverwrite) if fn: if fn.endswith("."): @@ -653,12 +667,12 @@ if ex: fn += ex if QFileInfo(fn).exists(): - res = E5MessageBox.yesNo( + res = EricMessageBox.yesNo( self, self.tr("Save Messages"), self.tr("<p>The file <b>{0}</b> already exists." " Overwrite it?</p>").format(fn), - icon=E5MessageBox.Warning) + icon=EricMessageBox.Warning) if not res: return @@ -667,7 +681,7 @@ with open(fn, "w") as f: f.write(self.messagesEdit.toPlainText()) except EnvironmentError as err: - E5MessageBox.critical( + EricMessageBox.critical( self, self.tr("Save Messages"), self.tr("""<p>The file <b>{0}</b> could not be written.""" @@ -691,13 +705,13 @@ """ Private slot to save the log messages. """ - fn, selectedFilter = E5FileDialog.getSaveFileNameAndFilter( + fn, selectedFilter = EricFileDialog.getSaveFileNameAndFilter( self, self.tr("Save Log Messages"), "", self.tr("Log Files (*.log);;All Files (*)"), "", - E5FileDialog.Options(E5FileDialog.DontConfirmOverwrite)) + EricFileDialog.DontConfirmOverwrite) if fn: if fn.endswith("."): @@ -709,12 +723,12 @@ if ex: fn += ex if QFileInfo(fn).exists(): - res = E5MessageBox.yesNo( + res = EricMessageBox.yesNo( self, self.tr("Save Log Messages"), self.tr("<p>The file <b>{0}</b> already exists." " Overwrite it?</p>").format(fn), - icon=E5MessageBox.Warning) + icon=EricMessageBox.Warning) if not res: return @@ -723,7 +737,7 @@ with open(fn, "w") as f: f.write(self.logEdit.toPlainText()) except EnvironmentError as err: - E5MessageBox.critical( + EricMessageBox.critical( self, self.tr("Save Log Messages"), self.tr("""<p>The file <b>{0}</b> could not be written.""" @@ -859,7 +873,7 @@ textCursor = self.messagesEdit.textCursor() if not self.messagesEdit.document().isEmpty(): - textCursor.movePosition(QTextCursor.End) + textCursor.movePosition(QTextCursor.MoveOperation.End) self.messagesEdit.setTextCursor(textCursor) self.messagesEdit.insertPlainText("\n") @@ -871,7 +885,7 @@ textBlockFormat.setBackground( self.messagesEdit.palette().base()) textCursor.setBlockFormat(textBlockFormat) - textCursor.movePosition(QTextCursor.End) + textCursor.movePosition(QTextCursor.MoveOperation.End) self.messagesEdit.setTextCursor(textCursor) self.messagesEdit.setCurrentCharFormat(self.__messagesTopicFormat)