Only redraw the screen once every 50ms
This commit is contained in:
parent
275161e0da
commit
050cf22f24
@ -58,6 +58,11 @@ class TerminalWidget(QWidget):
|
|||||||
t.setSingleShot(True)
|
t.setSingleShot(True)
|
||||||
t.setInterval(50)
|
t.setInterval(50)
|
||||||
t.timeout.connect(self.do_layout)
|
t.timeout.connect(self.do_layout)
|
||||||
|
self.debounce_update_timer = t = QTimer(self)
|
||||||
|
t.setSingleShot(True)
|
||||||
|
t.setInterval(50)
|
||||||
|
t.timeout.connect(self.do_update_screen)
|
||||||
|
self.pending_update = QRegion()
|
||||||
|
|
||||||
def apply_opts(self, opts):
|
def apply_opts(self, opts):
|
||||||
self.opts = opts
|
self.opts = opts
|
||||||
@ -100,8 +105,8 @@ class TerminalWidget(QWidget):
|
|||||||
def update_screen(self, changes):
|
def update_screen(self, changes):
|
||||||
self.cursor = changes['cursor'] or self.cursor
|
self.cursor = changes['cursor'] or self.cursor
|
||||||
if changes['screen']:
|
if changes['screen']:
|
||||||
self.update()
|
self.pending_update += self.rect()
|
||||||
return
|
else:
|
||||||
cell_positions, line_positions, cell_width, cell_height = self.cell_positions, self.line_positions, self.cell_width, self.cell_height
|
cell_positions, line_positions, cell_width, cell_height = self.cell_positions, self.line_positions, self.cell_width, self.cell_height
|
||||||
old_x, old_y = self.last_drew_cursor_at
|
old_x, old_y = self.last_drew_cursor_at
|
||||||
rects = []
|
rects = []
|
||||||
@ -123,22 +128,27 @@ class TerminalWidget(QWidget):
|
|||||||
if not cursor_added and self.cursor.y == lnum and (start <= self.cursor.x <= stop):
|
if not cursor_added and self.cursor.y == lnum and (start <= self.cursor.x <= stop):
|
||||||
cursor_added = True
|
cursor_added = True
|
||||||
rects.sort(key=lambda r: (r.y(), r.x()))
|
rects.sort(key=lambda r: (r.y(), r.x()))
|
||||||
reg = QRegion()
|
|
||||||
for r in rects:
|
for r in rects:
|
||||||
reg += r
|
self.pending_update += r
|
||||||
if not cursor_added:
|
if not cursor_added:
|
||||||
try:
|
try:
|
||||||
reg += QRect(cell_positions[self.cursor.x], line_positions[self.cursor.y], cell_width, cell_height)
|
self.pending_update += QRect(cell_positions[self.cursor.x], line_positions[self.cursor.y], cell_width, cell_height)
|
||||||
except IndexError:
|
except IndexError:
|
||||||
pass
|
pass
|
||||||
if self.cursor.y == old_y and self.cursor.x == old_x:
|
if self.cursor.y == old_y and self.cursor.x == old_x:
|
||||||
old_cursor_added = True
|
old_cursor_added = True
|
||||||
if not old_cursor_added:
|
if not old_cursor_added:
|
||||||
try:
|
try:
|
||||||
reg += QRect(cell_positions[old_x], line_positions[old_y], cell_width, cell_height)
|
self.pending_update += QRect(cell_positions[old_x], line_positions[old_y], cell_width, cell_height)
|
||||||
except IndexError:
|
except IndexError:
|
||||||
pass
|
pass
|
||||||
self.update(reg)
|
if not self.debounce_update_timer.isActive():
|
||||||
|
self.debounce_update_timer.start()
|
||||||
|
|
||||||
|
def do_update_screen(self):
|
||||||
|
if not self.pending_update.isEmpty():
|
||||||
|
self.update(self.pending_update)
|
||||||
|
self.pending_update = QRegion()
|
||||||
|
|
||||||
def dirty_cells(self, region: QRegion) -> Iterator[Tuple[int]]:
|
def dirty_cells(self, region: QRegion) -> Iterator[Tuple[int]]:
|
||||||
for rect in region.rects():
|
for rect in region.rects():
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user