This is the mail archive of the
guile@sourceware.cygnus.com
mailing list for the Guile project.
gtk and threads
- To: guile at sourceware dot cygnus dot com
- Subject: gtk and threads
- From: Ole Myren Rohne <ole dot rohne at cern dot ch>
- Date: Fri, 17 Mar 2000 12:33:59 +0100 (CET)
Sorry if this is off-topic, please tell if there is a dedicated
list for guile/gtk integration...
As I didn't expect gtk and threads to mix at all, I was surprised to
see that the naive approach sort of works - see below.
However, when looking closer it appears that widget drawing is not
done properly: pressed buttons are not rendered as pressed and more
complicated examples (eg gtk-tree-new) gets totally messed up. I use a
slightly dated gtk-1.3.
I suspect (gtk-idle-add yield) is really causing the trouble. In fact,
it seems that adding anything to the idle loop is bad even when no
threading is involved.
Then my question: Is there a way of making threads and gtk work together?
Thanks, Ole
(use-modules (gtk gtk)
(ice-9 threads))
;;; Create hello/goodbye window
(let ((w (gtk-widget-new 'GtkWindow #:type 'toplevel #:title "hello"))
(b (gtk-hbox-new #f 0))
(b1 (gtk-button-new-with-label "hello"))
(b2 (gtk-button-new-with-label "goodbye")))
(gtk-signal-connect b1 "clicked"
(lambda ()
(display "hello" (current-error-port))))
(gtk-signal-connect b2 "clicked"
(lambda ()
(display "goodbye" (current-error-port))
(gtk-widget-destroy w)))
(gtk-container-add w b)
(gtk-box-pack-start b b1 #f #f 1)
(gtk-box-pack-start b b2 #f #f 1)
(gtk-widget-show-all w))
;;; Start gtk-main in separate thread
(gtk-idle-add yield)
(call-with-new-thread
gtk-main
(lambda args
(display "throw from gtk-main: " (current-error-port))
(display args (current-error-port))))
;;; Mess with gtk-idle-add
; (gtk-idle-add (lambda () (display #\. (current-error-port))))
;;; Start gtk-main normally
; (gtk-main)