Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Console tab: new messages should always appear at the bottom #509

Merged
merged 3 commits into from
Apr 26, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/cfclient/ui/tabs/ConsoleTab.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

from PyQt5 import uic
from PyQt5.QtCore import pyqtSignal
from PyQt5.QtGui import QTextCursor

import cfclient
from cfclient.ui.tab import Tab
Expand Down Expand Up @@ -88,8 +89,21 @@ def printText(self, text):
# Make sure we get printouts from the Crazyflie into the log (such as
# build version and test ok/fail)
logger.debug("[%s]", text)
scrollbar = self.console.verticalScrollBar()
prev_scroll = scrollbar.value()
prev_cursor = self.console.textCursor()
was_maximum = prev_scroll == scrollbar.maximum()

self.console.moveCursor(QTextCursor.End)
self.console.insertPlainText(text)

self.console.setTextCursor(prev_cursor)

if was_maximum and not prev_cursor.hasSelection():
scrollbar.setValue(scrollbar.maximum())
else:
scrollbar.setValue(prev_scroll)

def clear(self):
self.console.clear()

Expand Down