Timing help needed
Posted: Wed Nov 07, 2007 7:40 pm
This isn't really a newLISP question (that department is working fine) but more of a programming question. I know some of you guys are real programmers, so you might have a suggestion.
Here's a simple version of a project I'm working on:
As you see, the hard work is being done by calling the translator function. Yet - if this takes more than a certain time (which I've simulated), there are just too many calls, as newLISP responds to every keystroke and runs the function each time. In fact, newLISP-GS eventually hangs if the translator function doesn't get back pretty quickly... You can almost see it panicking as it has to handle a new call before it's finished the previous one.
Is there a way to get newLISP to not run the function after every keystroke, but only when the user stops typing rapidly?
Here's a simple version of a project I'm working on:
Code: Select all
load (string (env "NEWLISPDIR") "/guiserver.lsp"))
(gs:init)
(gs:frame 'Translator 200 200 400 550 "Translator")
(gs:panel 'MainPanel)
(gs:set-grid-layout 'MainPanel 2 2)
(gs:text-area 'string-input 'textfield-handler )
(gs:text-pane 'text-output 'gs:no-action "text/plain")
(gs:set-editable 'text-output nil)
(gs:add-to 'MainPanel 'string-input 'text-output)
(gs:add-to 'Translator 'MainPanel )
(gs:set-visible 'Translator true)
(define (textfield-handler id key dot mark)
(gs:get-text id 'gettextcallback-handler))
(define (gettextcallback-handler id text)
(and
text
(= id "MAIN:string-input")
(set 'strng (base64-dec text))
(set 'result (translator strng))
(gs:set-text 'text-output result)
))
(define (translator s)
(sleep 400)
(upper-case s))
(gs:listen)
Is there a way to get newLISP to not run the function after every keystroke, but only when the user stops typing rapidly?