--- a/MqttMonitor/MqttMonitorWidget.py Mon Sep 10 19:46:58 2018 +0200 +++ b/MqttMonitor/MqttMonitorWidget.py Tue Sep 11 19:30:00 2018 +0200 @@ -71,6 +71,8 @@ self.__messagesQosFormat = self.messagesEdit.currentCharFormat() self.__messagesQosFormat.setFontItalic(True) + self.__isAlternate = False + for logLevel in (MqttClient.LogDisabled, MqttClient.LogDebug, MqttClient.LogInfo, @@ -708,17 +710,33 @@ @param qos quality of service indicator (0, 1, 2) @type int """ + if self.messagesEdit.blockCount() != 1: + # empty document has block count of 1 + self.messagesEdit.insertPlainText("\n") + payloadStr = str(payload, encoding="utf-8", errors="replace") + textCursor = self.messagesEdit.textCursor() + textBlockFormat = textCursor.blockFormat() + if self.__isAlternate: + textBlockFormat.setBackground( + self.messagesEdit.palette().alternateBase()) + else: + textBlockFormat.setBackground( + self.messagesEdit.palette().base()) + textCursor.setBlockFormat(textBlockFormat) + self.messagesEdit.setTextCursor(textCursor) + self.messagesEdit.setCurrentCharFormat(self.__messagesTopicFormat) - self.messagesEdit.appendPlainText(topic) - self.messagesEdit.setCurrentCharFormat(self.__messagesQFormat) - self.messagesEdit.appendPlainText(self.tr("QoS: {0}").format(qos)) + self.messagesEdit.insertPlainText(topic + "\n") + self.messagesEdit.setCurrentCharFormat(self.__messagesQosFormat) + self.messagesEdit.insertPlainText(self.tr("QoS: {0}\n").format(qos)) self.messagesEdit.setCurrentCharFormat(self.__messagesFormat) - self.messagesEdit.appendPlainText( + self.messagesEdit.insertPlainText( Utilities.filterAnsiSequences(payloadStr)) - self.messagesEdit.appendPlainText(60 * "#") self.messagesEdit.ensureCursorVisible() + + self.__isAlternate = not self.__isAlternate def __handleBrokerStatusMessage(self, topic, payload): """