From 31e856e258a51fbbd491727d13564544091431ae Mon Sep 17 00:00:00 2001 From: Olek Bojda Date: Tue, 25 Sep 2018 13:54:49 +0200 Subject: [PATCH] Fixed logsBrowser cursor behavior --- safety_user_plugin/scripts/qt_wrapper.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/safety_user_plugin/scripts/qt_wrapper.py b/safety_user_plugin/scripts/qt_wrapper.py index 9c33223..9969353 100644 --- a/safety_user_plugin/scripts/qt_wrapper.py +++ b/safety_user_plugin/scripts/qt_wrapper.py @@ -10,6 +10,7 @@ from enums.clutch_state import ClutchState as CS from enums.stop_state import StopState as SS from python_qt_binding.QtGui import QPixmap +from python_qt_binding.QtGui import QTextCursor from python_qt_binding.QtWidgets import QMessageBox @@ -220,18 +221,32 @@ class QtWrapper: def log_info(self,info_text): time = datetime.datetime.now().strftime('[%H:%M:%S]') + + cursor = self.widget.logsBrowser.textCursor() + cursor.movePosition(QTextCursor.End) + self.widget.logsBrowser.setTextCursor(cursor) self.widget.logsBrowser.insertHtml('' + str(time) + '. ' + info_text + '
') self.scroll_to_bottom() # self.widget.logsBrowser.insertHtml(str(self.logger_counter) + '\t[INFO]\t' + info_text) def log_warning(self,warning_text): time = datetime.datetime.now().strftime('[%H:%M:%S]') + + cursor = self.widget.logsBrowser.textCursor() + cursor.movePosition(QTextCursor.End) + self.widget.logsBrowser.setTextCursor(cursor) + self.widget.logsBrowser.textCursor().movePosition(QTextCursor.End) self.widget.logsBrowser.insertHtml('' + str(time) + '. ' + warning_text + '
') self.scroll_to_bottom() # self.widget.logsBrowser.append(str(self.logger_counter) + '\t[WARN]\t' + warning_text) def log_error(self,error_text): time = datetime.datetime.now().strftime('[%H:%M:%S]') + + cursor = self.widget.logsBrowser.textCursor() + cursor.movePosition(QTextCursor.End) + self.widget.logsBrowser.setTextCursor(cursor) + self.widget.logsBrowser.textCursor().movePosition(QTextCursor.End) self.widget.logsBrowser.insertHtml('' + str(time) + '. ' + error_text + '
') self.scroll_to_bottom() # self.widget.logsBrowser.append(str(self.logger_counter) + '\t[ERROR]\t' + error_text) @@ -243,7 +258,7 @@ class QtWrapper: self.log_info('Utrata polaczenia z robotem PIONIER' + str(lost_robot_id)) def connection_to_master_lost(self): - self.log_info('Utrata polaczenia z masterstopem') + self.log_error('Utrata polaczenia z masterstopem. Popros prowadzacego o jego uruchomienie') def scroll_to_bottom(self): scrollbar = self.widget.logsBrowser.verticalScrollBar()