Fixed logsBrowser cursor behavior

This commit is contained in:
Olek Bojda 2018-09-25 13:54:49 +02:00
parent 18be3242c6
commit 31e856e258

View File

@ -10,6 +10,7 @@ from enums.clutch_state import ClutchState as CS
from enums.stop_state import StopState as SS from enums.stop_state import StopState as SS
from python_qt_binding.QtGui import QPixmap from python_qt_binding.QtGui import QPixmap
from python_qt_binding.QtGui import QTextCursor
from python_qt_binding.QtWidgets import QMessageBox from python_qt_binding.QtWidgets import QMessageBox
@ -220,18 +221,32 @@ class QtWrapper:
def log_info(self,info_text): def log_info(self,info_text):
time = datetime.datetime.now().strftime('[%H:%M:%S]') 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('<font color="black">' + str(time) + '. ' + info_text + '</font><br>') self.widget.logsBrowser.insertHtml('<font color="black">' + str(time) + '. ' + info_text + '</font><br>')
self.scroll_to_bottom() self.scroll_to_bottom()
# self.widget.logsBrowser.insertHtml(str(self.logger_counter) + '\t[INFO]\t' + info_text) # self.widget.logsBrowser.insertHtml(str(self.logger_counter) + '\t[INFO]\t' + info_text)
def log_warning(self,warning_text): def log_warning(self,warning_text):
time = datetime.datetime.now().strftime('[%H:%M:%S]') 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('<font color="orange">' + str(time) + '. ' + warning_text + '</font><br> ') self.widget.logsBrowser.insertHtml('<font color="orange">' + str(time) + '. ' + warning_text + '</font><br> ')
self.scroll_to_bottom() self.scroll_to_bottom()
# self.widget.logsBrowser.append(str(self.logger_counter) + '\t[WARN]\t' + warning_text) # self.widget.logsBrowser.append(str(self.logger_counter) + '\t[WARN]\t' + warning_text)
def log_error(self,error_text): def log_error(self,error_text):
time = datetime.datetime.now().strftime('[%H:%M:%S]') 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('<font color="red">' + str(time) + '. ' + error_text + '</font><br>') self.widget.logsBrowser.insertHtml('<font color="red">' + str(time) + '. ' + error_text + '</font><br>')
self.scroll_to_bottom() self.scroll_to_bottom()
# self.widget.logsBrowser.append(str(self.logger_counter) + '\t[ERROR]\t' + error_text) # 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)) self.log_info('Utrata polaczenia z robotem PIONIER' + str(lost_robot_id))
def connection_to_master_lost(self): 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): def scroll_to_bottom(self):
scrollbar = self.widget.logsBrowser.verticalScrollBar() scrollbar = self.widget.logsBrowser.verticalScrollBar()