diff --git a/TermTk/TTkCore/timer.py b/TermTk/TTkCore/timer.py index 50dcef54..f1806b61 100644 --- a/TermTk/TTkCore/timer.py +++ b/TermTk/TTkCore/timer.py @@ -33,7 +33,7 @@ if importlib.util.find_spec('pyodideProxy'): _uid = 0 __slots__ = ( - '_id', '_running', + '_id', '_running', '_timer', 'timeout', '_timerEvent', '_delay', '_delayLock', '_quit', '_stopTime') @@ -42,6 +42,7 @@ if importlib.util.find_spec('pyodideProxy'): # Define Signals self.timeout = pyTTkSignal() self._running = True + self._timer = None self._id = TTkTimer._uid TTkTimer._uid +=1 @@ -67,17 +68,19 @@ if importlib.util.find_spec('pyodideProxy'): def quit(self): pass - def run(self): - pass - - @pyTTkSlot(int) - def start(self, sec=0): + @pyTTkSlot(float) + def start(self, sec=0.0): + self.stop() if self._running: - pyodideProxy.setTimeout(int(sec*1000), self._id) + self._timer = pyodideProxy.setTimeout(int(sec*1000), self._id) + # pyodideProxy.consoleLog(f"Timer {self._timer}") @pyTTkSlot() def stop(self): - pass + # pyodideProxy.consoleLog(f"Timer {self._timer}") + if self._timer: + pyodideProxy.stopTimeout(self._timer) + self._timer = None else: # from .log import TTkLog class TTkTimer(): @@ -98,8 +101,8 @@ else: if self._timer: self._timer.cancel() - @pyTTkSlot(int) - def start(self, sec=0): + @pyTTkSlot(float) + def start(self, sec=0.0): if self._timer: self._timer.cancel() self._timer = threading.Timer(sec, self.timeout.emit) diff --git a/tests/sandbox/Makefile b/tests/sandbox/Makefile index 80f70c67..ee932f08 100644 --- a/tests/sandbox/Makefile +++ b/tests/sandbox/Makefile @@ -39,4 +39,14 @@ buildSandbox: www find ../../tmp/TermTk/ -name "*.py" | sed 's,.*tmp/,,' | sort | xargs tar cvzf bin/TermTk.tgz -C ../../tmp find ../../tutorial -name "*.py" | sort | xargs tar cvzf bin/tutorial.tgz + find ../../demo/paint.py ../../demo/ttkode.py ../../demo/demo.py ../../demo/showcase/*.* | sort | xargs tar cvzf bin/demo.tgz + +buildTestSandbox: www + rm -rf bin + mkdir -p bin + + $( cd ../../ ; tools/prepareBuild.sh release ; ) + + find ../../TermTk/ -name "*.py" | sort | xargs tar cvzf bin/TermTk.tgz + find ../../tutorial -name "*.py" | sort | xargs tar cvzf bin/tutorial.tgz find ../../demo/paint.py ../../demo/ttkode.py ../../demo/demo.py ../../demo/showcase/*.* | sort | xargs tar cvzf bin/demo.tgz \ No newline at end of file diff --git a/tests/sandbox/sandbox.html b/tests/sandbox/sandbox.html index bb6f9077..f94fab2a 100644 --- a/tests/sandbox/sandbox.html +++ b/tests/sandbox/sandbox.html @@ -144,8 +144,12 @@ return [term.cols, term.rows] }, setTimeout: function(t, i) { - // console.log("TIME",i,t) - setTimeout(() => ttk_timer(i), t) + // console.log("TIME (Start)",i,t) + return setTimeout(() => ttk_timer(i), t) + }, + stopTimeout: function(t) { + // console.log("TIME (Stop)",t) + clearTimeout(t) }, clearTimeout: function(){ let highestTimeoutId = setTimeout(";");