Browse Source

chore: cleaned the draw loop

315-transition-to-asyncio
Parodi, Eugenio (Principal SI Engineer - Sky) 1 year ago
parent
commit
f2c1df17e6
  1. 6
      TermTk/TTkCore/helper_draw.py
  2. 35
      TermTk/TTkCore/ttk_asyncio.py

6
TermTk/TTkCore/helper_draw.py

@ -47,11 +47,7 @@ class TTkHelperDraw:
@staticmethod
def unlockPaint():
if rw := TTkHelper._rootWidget:
async def _set():
rw._paintEvent.set()
# TTkAsyncio.create_task(rw._paintEvent.set )
# rw._paintEvent.set()
TTkAsyncio.create_task(_set())
rw._paintEvent.set()
@staticmethod
def addUpdateWidget(widget):

35
TermTk/TTkCore/ttk_asyncio.py

@ -292,29 +292,18 @@ class TTk(TTkContainer):
TTkHelper.prevFocus(focusWidget if focusWidget else self)
async def _drawLoop(self):
# Event.{wait and clear} should be atomic,
# BUTt: ( y )
# if an update event (set) happen in between the wait and clear
# the widget is still processed in the current paint routine
# if an update event (set) happen after the wait and clear
# the widget is processed in the current paint routine
# an extra paint routine is triggered which return immediately due to
# the empty list of widgets to be processed - Not a big deal
# if an update event (set) happen after the wait and clear and the paintAll Routine
# well, it works as it is supposed to be
await self._paintEvent.wait()
self._paintEvent.clear()
w,h = TTkTerm.getTerminalSize()
await self._drawMutex.acquire()
self.setGeometry(0,0,w,h)
self._fps()
TTkHelperDraw.paintAll()
self.paintExecuted.emit()
self._drawMutex.release()
await TTkAsyncio.sleep(1/TTkCfg.maxFps)
TTkAsyncio.create_task(self._drawLoop())
# self._timer.start(1/TTkCfg.maxFps)
while True:
await self._paintEvent.wait()
self._paintEvent.clear()
w,h = TTkTerm.getTerminalSize()
await self._drawMutex.acquire()
self.setGeometry(0,0,w,h)
self._fps()
TTkHelperDraw.paintAll()
self.paintExecuted.emit()
self._drawMutex.release()
await TTkAsyncio.sleep(1/TTkCfg.maxFps)
def _win_resize_cb(self, width, height):
TTkGlbl.term_w = int(width)

Loading…
Cancel
Save