Throttle GUI updates
Dieser Commit ist enthalten in:
Ursprung
4372f2fe5a
Commit
b8f35aafad
1 geänderte Dateien mit 22 neuen und 0 gelöschten Zeilen
22
pdf-sign
22
pdf-sign
|
@ -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])
|
||||||
|
|
||||||
|
|
Laden …
Tabelle hinzufügen
In neuem Issue referenzieren