[ltk-user] listbox updates from separate thread

Kevin Raison raison at chatsubo.net
Tue Dec 14 18:43:42 UTC 2010


Thank you Peter;  that is exactly what I needed.

On 12/14/10 2:37 AM, Peter Herth wrote:
> Hi Kevin,
>
> in general LTk has no support for multithreading. Mostly because threads are
> supported only by a few common lisp implementations and that updating a
> user-interface requires some synchronisation of some sort. Which Lisp
> implementation are you using?
> In the presence of multi-threading, I would strongly suggest to only communicate
> with Tk from one thread only. So my solution would be to have a lisp
> variable which
> contains the content to be displayed in the list box, which can be
> updated from any
> number of threads (of course those would have to work together of some
> sort not to
> have random content in that variable, but thats outside of LTk) and have the LTk
> thread update the list box from that variable. But as the LTk thread
> is waiting for
> Tk events, how to wake it up? The solution here is to have Tk create
> periodic events
> which are used for updates. Something like:
>
> (defparamter *mylist* (list 1 2 3 4)) ;; this lists content is to be
> continously updated
>
> (defun update (listbox)
>     (unless *shutdown-gui*
>       (listbox-clear listbox)
>       (listbox-append listbox *mylist*)
>       (after 1000 (lambda ()
>                          (update listbox)))))
>
> The after function gets passed a time in milliseconds and a function
> to call after
> the time has passed. You start the update process by calling update
> once, passing
> it the listbox to update (you might want to add some code to update only if the
> list has actually changed for efficiency...). This feature is quite
> nice for any kind
> of animations and very useful for background processing in LTk
> applications on Lisp
> implementations which are not multithreaded.
>
> Peter
>
> _______________________________________________
> ltk-user site list
> ltk-user at common-lisp.net
> http://common-lisp.net/mailman/listinfo/ltk-user
>

-- 
Kevin Raison
Founder, CTO

Chatsubo.net, LLC
9708 1st Ave NW
Seattle, WA 98117
raison at chatsubo.net

ph: +1 (206) 801-5728
fx: +1 (206) 801-5729




More information about the ltk-user mailing list