me
/
guix
Archived
1
0
Fork 0

marionette: Add a callback arguments to wait-for-screen-text.

* gnu/build/marionette.scm (wait-for-screen-text): New 'pre-action' and
'post-action' arguments.  Update doc.  Call the procedures before and after
the OCR occurs, respectively.
master
Maxim Cournoyer 2022-09-23 00:23:47 -04:00
parent f24e0fc233
commit 133901a396
No known key found for this signature in database
GPG Key ID: 1260E46482E63562
1 changed files with 9 additions and 3 deletions

View File

@ -331,11 +331,15 @@ if it is not needed."
(define* (wait-for-screen-text marionette predicate (define* (wait-for-screen-text marionette predicate
#:key #:key
(ocr "ocrad") (ocr "ocrad")
(timeout 30)) (timeout 30)
pre-action
post-action)
"Wait for TIMEOUT seconds or until the screen text on MARIONETTE matches "Wait for TIMEOUT seconds or until the screen text on MARIONETTE matches
PREDICATE, whichever comes first. Raise an error when TIMEOUT is exceeded. PREDICATE, whichever comes first. Raise an error when TIMEOUT is exceeded.
The error contains the recognized text along the preserved file name of the The error contains the recognized text along the preserved file name of the
screen dump, which is relative to the current working directory." screen dump, which is relative to the current working directory. If
PRE-ACTION is provided, it should be a thunk to call before each OCR attempt.
Likewise for POST-ACTION, except it runs at the end of a successful OCR."
(define start (define start
(car (gettimeofday))) (car (gettimeofday)))
@ -353,7 +357,9 @@ screen dump, which is relative to the current working directory."
(error "'wait-for-screen-text' timeout" (error "'wait-for-screen-text' timeout"
'ocr-text: last-text 'ocr-text: last-text
'screendump: screendump-backup)) 'screendump: screendump-backup))
(let* ((text screendump (marionette-screen-text marionette #:ocr ocr)) (let* ((_ (and (procedure? pre-action) (pre-action)))
(text screendump (marionette-screen-text marionette #:ocr ocr))
(_ (and (procedure? post-action) (post-action)))
(result (predicate text))) (result (predicate text)))
(cond (result (cond (result
(delete-file screendump) (delete-file screendump)