MqttMonitor/MqttMonitorWidget.py

changeset 48
41dd2bfee4e4
parent 47
185fac480ed2
child 50
8e9e83221c15
equal deleted inserted replaced
47:185fac480ed2 48:41dd2bfee4e4
70 self.__messagesTopicFormat.setFontWeight(QFont.Bold) 70 self.__messagesTopicFormat.setFontWeight(QFont.Bold)
71 self.__messagesQosFormat = self.messagesEdit.currentCharFormat() 71 self.__messagesQosFormat = self.messagesEdit.currentCharFormat()
72 self.__messagesQosFormat.setFontItalic(True) 72 self.__messagesQosFormat.setFontItalic(True)
73 73
74 self.__isAlternate = False 74 self.__isAlternate = False
75 self.__followLatestMessage = True
76 75
77 # TODO: Messages Edit improvements: 76 # TODO: Messages Edit improvements:
78 # 1. add check box for self.__followLatestMessage 77 # 1. add capability to search
79 # 2. add capability to search 78 # 2. add capability to save contents to a file
80 # 3. add capability to save contents to a file
81 79
82 for logLevel in (MqttClient.LogDisabled, 80 for logLevel in (MqttClient.LogDisabled,
83 MqttClient.LogDebug, 81 MqttClient.LogDebug,
84 MqttClient.LogInfo, 82 MqttClient.LogInfo,
85 MqttClient.LogNotice, 83 MqttClient.LogNotice,
89 logLevel, isMqttLogLevel=False), logLevel) 87 logLevel, isMqttLogLevel=False), logLevel)
90 self.logLevelComboBox.setCurrentIndex( 88 self.logLevelComboBox.setCurrentIndex(
91 self.logLevelComboBox.count() - 1) 89 self.logLevelComboBox.count() - 1)
92 90
93 # TODO: Log Edit improvements: 91 # TODO: Log Edit improvements:
94 # 1. add check box for self.__followLatestLogMessage 92 # 1. add capability to search
95 # 2. add capability to search 93 # 2. add configuration capability for colors
96 # 3. add configuration capability for colors
97 94
98 self.__logMessagesBackgrounds = { 95 self.__logMessagesBackgrounds = {
99 MqttClient.LogDebug: QBrush(Qt.white), 96 MqttClient.LogDebug: QBrush(Qt.white),
100 MqttClient.LogInfo: QBrush(Qt.lightGray), 97 MqttClient.LogInfo: QBrush(Qt.lightGray),
101 MqttClient.LogNotice: QBrush(Qt.green), 98 MqttClient.LogNotice: QBrush(Qt.green),
102 MqttClient.LogWarning: QBrush(Qt.yellow), 99 MqttClient.LogWarning: QBrush(Qt.yellow),
103 MqttClient.LogError: QBrush(Qt.red), 100 MqttClient.LogError: QBrush(Qt.red),
104 MqttClient.LogDisabled: QBrush(Qt.magenta) 101 MqttClient.LogDisabled: QBrush(Qt.magenta)
105 # reuse LogDisabled for unknown log levels 102 # reuse LogDisabled for unknown log levels
106 } 103 }
107 self.__followLatestLogMessage = True
108 104
109 self.brokerWidget.setCurrentIndex(0) 105 self.brokerWidget.setCurrentIndex(0)
110 106
111 self.__connectionModeProfile = True 107 self.__connectionModeProfile = True
112 self.__setConnectionMode(True) # initial mode is 'profile connection' 108 self.__setConnectionMode(True) # initial mode is 'profile connection'
290 return 286 return
291 except KeyError: 287 except KeyError:
292 # always show unknown log levels 288 # always show unknown log levels
293 pass 289 pass
294 290
291 scrollbarValue = self.logEdit.verticalScrollBar().value()
292
295 textCursor = self.logEdit.textCursor() 293 textCursor = self.logEdit.textCursor()
296 if not self.logEdit.document().isEmpty(): 294 if not self.logEdit.document().isEmpty():
297 textCursor.movePosition(QTextCursor.End) 295 textCursor.movePosition(QTextCursor.End)
298 self.logEdit.setTextCursor(textCursor) 296 self.logEdit.setTextCursor(textCursor)
299 self.logEdit.insertPlainText("\n") 297 self.logEdit.insertPlainText("\n")
309 textCursor.movePosition(QTextCursor.End) 307 textCursor.movePosition(QTextCursor.End)
310 self.logEdit.setTextCursor(textCursor) 308 self.logEdit.setTextCursor(textCursor)
311 309
312 txt = self.tr("{0}: {1}").format(mqttLogLevelString(level), message) 310 txt = self.tr("{0}: {1}").format(mqttLogLevelString(level), message)
313 self.logEdit.insertPlainText(Utilities.filterAnsiSequences(txt)) 311 self.logEdit.insertPlainText(Utilities.filterAnsiSequences(txt))
314 if self.__followLatestLogMessage: 312
313 if self.followLogMessagesCheckBox.isChecked():
315 self.logEdit.ensureCursorVisible() 314 self.logEdit.ensureCursorVisible()
315 else:
316 self.logEdit.verticalScrollBar().setValue(scrollbarValue)
316 317
317 @pyqtSlot(str, bytes, int, bool) 318 @pyqtSlot(str, bytes, int, bool)
318 def __messageReceived(self, topic, payload, qos, retain): 319 def __messageReceived(self, topic, payload, qos, retain):
319 """ 320 """
320 Private slot to handle the receipt of a message. 321 Private slot to handle the receipt of a message.
747 @param payload payload of the received message 748 @param payload payload of the received message
748 @type bytes 749 @type bytes
749 @param qos quality of service indicator (0, 1, 2) 750 @param qos quality of service indicator (0, 1, 2)
750 @type int 751 @type int
751 """ 752 """
753 scrollbarValue = self.messagesEdit.verticalScrollBar().value()
754
752 textCursor = self.messagesEdit.textCursor() 755 textCursor = self.messagesEdit.textCursor()
753 if not self.messagesEdit.document().isEmpty(): 756 if not self.messagesEdit.document().isEmpty():
754 textCursor.movePosition(QTextCursor.End) 757 textCursor.movePosition(QTextCursor.End)
755 self.messagesEdit.setTextCursor(textCursor) 758 self.messagesEdit.setTextCursor(textCursor)
756 self.messagesEdit.insertPlainText("\n") 759 self.messagesEdit.insertPlainText("\n")
775 payloadStr = str(payload, encoding="utf-8", errors="replace") 778 payloadStr = str(payload, encoding="utf-8", errors="replace")
776 self.messagesEdit.setCurrentCharFormat(self.__messagesFormat) 779 self.messagesEdit.setCurrentCharFormat(self.__messagesFormat)
777 self.messagesEdit.insertPlainText( 780 self.messagesEdit.insertPlainText(
778 Utilities.filterAnsiSequences(payloadStr)) 781 Utilities.filterAnsiSequences(payloadStr))
779 782
780 if self.__followLatestMessage: 783 if self.followMessagesCheckBox.isChecked():
781 self.messagesEdit.ensureCursorVisible() 784 self.messagesEdit.ensureCursorVisible()
785 else:
786 self.messagesEdit.verticalScrollBar().setValue(scrollbarValue)
782 787
783 self.__isAlternate = not self.__isAlternate 788 self.__isAlternate = not self.__isAlternate
784 789
785 def __handleBrokerStatusMessage(self, topic, payload): 790 def __handleBrokerStatusMessage(self, topic, payload):
786 """ 791 """

eric ide

mercurial