-
Notifications
You must be signed in to change notification settings - Fork 5
/
serialout_textedit.py
41 lines (32 loc) · 1.39 KB
/
serialout_textedit.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
from PyQt5.QtWidgets import QTextEdit
from PyQt5.QtCore import Qt
from PyQt5.QtGui import QTextCursor
import platform
class SerialOut_TextEdit(QTextEdit):
"""docstring for SerialOut_TextEdit"""
def __init__(self, parent=None):
super(SerialOut_TextEdit, self).__init__(parent)
self.parent = parent
self.OS_TYPE = platform.system()
self.is_auto_scrolling = True
def on_serial_read(self, text):
prev_cursor_pos = self.textCursor()
prev_v_scrollbar_pos = self.verticalScrollBar().value()
prev_h_scrollbar_pos = self.horizontalScrollBar().value()
self.moveCursor(QTextCursor.End)
self.insertPlainText(text)
if self.is_auto_scrolling is False:
self.setTextCursor(prev_cursor_pos)
self.verticalScrollBar().setValue(prev_v_scrollbar_pos)
self.horizontalScrollBar().setValue(prev_h_scrollbar_pos)
elif self.is_auto_scrolling is True:
self.moveCursor(QTextCursor.End)
self.verticalScrollBar().setValue(self.verticalScrollBar().maximum())
self.horizontalScrollBar().setValue(self.horizontalScrollBar().maximum())
def on_autoscroll_state_changed(self, state):
if state == Qt.Checked:
self.is_auto_scrolling = True
elif state == Qt.Unchecked:
self.is_auto_scrolling = False
def reset(self):
self.clear()