Skip to content

Commit

Permalink
Fix use-case where canvas misses requests for a new draw
Browse files Browse the repository at this point in the history
  • Loading branch information
almarklein committed Nov 7, 2024
1 parent 7739f4a commit dfc31b3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion rendercanvas/_loop.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ def _schedule_next_tick(self):
return

# Determine delay
if self._mode == "fastest":
if self._mode == "fastest" or self._max_fps <= 0:
delay = 0
else:
delay = 1 / self._max_fps
Expand Down
9 changes: 9 additions & 0 deletions rendercanvas/qt.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,11 @@ def paintEngine(self): # noqa: N802 - this is a Qt method
def paintEvent(self, event): # noqa: N802 - this is a Qt method
self._draw_frame_and_present()

def update(self):
# Bypass Qt's mechanics and request a draw so that the scheduling mechanics work as intended.
# Eventually this will call _request_draw().
self.request_draw()

# Methods that we add for BaseRenderCanvas (snake_case)

def _request_draw(self):
Expand Down Expand Up @@ -490,6 +495,10 @@ def __init__(self, *, size=None, title=None, **kwargs):

# Qt methods

def update(self):
self._subwidget.request_draw()
super().update()

def closeEvent(self, event): # noqa: N802
self._subwidget._is_closed = True
self.submit_event({"event_type": "close"})
Expand Down

0 comments on commit dfc31b3

Please sign in to comment.