Throttle GUI updates

Dieser Commit ist enthalten in:
Axel Svensson 2021-10-12 16:22:46 +02:00
Ursprung 4372f2fe5a
Commit b8f35aafad

Datei anzeigen

@ -225,6 +225,7 @@ def main(args):
@Cell @Cell
def updateTitle(): def updateTitle():
root.title(f'Signing page {pageNumber()}/{pageCount} of {filePath}') root.title(f'Signing page {pageNumber()}/{pageCount} of {filePath}')
@tkthrottle(100, root)
def update(): def update():
(w, h) = displaySize() (w, h) = displaySize()
root._docImg = tk.PhotoImage(file=displayPNG()) root._docImg = tk.PhotoImage(file=displayPNG())
@ -308,6 +309,27 @@ class Cell():
d.dirty() d.dirty()
self._dependents=[] self._dependents=[]
def tkthrottle(frequency, root):
wait=1/frequency
now=lambda: time.time()
def decorator(fn):
def throttled():
if(throttled._suppressUntil<now()):
fn()
else:
throttled._callAfterWait=True
throttled._suppressUntil=now()+wait
root.after(int(wait*1000+10), atend)
def atend():
if throttled._callAfterWait:
if throttled._suppressUntil<now():
throttled._callAfterWait=False
fn()
throttled._suppressUntil=0
throttled._callAfterWait=False
return throttled
return decorator
def pdfCountPages(filePath): def pdfCountPages(filePath):
return int(fromCmdOutput(["pdfinfo", filePath], "^.*\nPages: +([0-9]+)\n.*$")[1]) return int(fromCmdOutput(["pdfinfo", filePath], "^.*\nPages: +([0-9]+)\n.*$")[1])