From: ·················@gmail.com
Subject: cells-gtk: run application in its own thread
Date: 
Message-ID: <6d04979e-9dcf-40a3-a6b2-2903adb428bf@p69g2000hsa.googlegroups.com>
I've been trying for a while to launch a gtk application in a distinct
thread (using cells-gtk on sbcl), along these lines:

(sb-thread:make-thread #'(lambda () (cells-gtk-init) (start-app 'my-
app)))

The thread appears to runs fine up to the point where (gtk-main) is
called, however no window is ever being displayed.


The objective is to launch a GUI in the background, then return back
to the REPL (with the GUI still runnning in the background), and
modifying the underlying data structures directly, while the GUI
visualizes the results.  For another app I have this up and running
with cl-glut, but for this project I'd like a "real" GUI toolkit (and
besides the threading issue, cells-gtk is a perfect match for my needs
here).

Did anybody ever encounter this issue, or has any ideas how to work
around it?

Help is highly appreciated,

Peter

(This has been crossposted on the cells-gtk-devel mailing list)

From: Maciej Katafiasz
Subject: Re: cells-gtk: run application in its own thread
Date: 
Message-ID: <fj1caj$dt7$1@news.net.uni-c.dk>
Den Mon, 03 Dec 2007 03:34:18 -0800 skrev ·················@gmail.com:

> I've been trying for a while to launch a gtk application in a distinct
> thread (using cells-gtk on sbcl), along these lines:
> 
> (sb-thread:make-thread #'(lambda () (cells-gtk-init) (start-app 'my-
> app)))
> 
> The thread appears to runs fine up to the point where (gtk-main) is
> called, however no window is ever being displayed.
> 
> 
> The objective is to launch a GUI in the background, then return back to
> the REPL (with the GUI still runnning in the background), and modifying
> the underlying data structures directly, while the GUI visualizes the
> results.  For another app I have this up and running with cl-glut, but
> for this project I'd like a "real" GUI toolkit (and besides the
> threading issue, cells-gtk is a perfect match for my needs here).
> 
> Did anybody ever encounter this issue, or has any ideas how to work
> around it?

This is just a guess, based on the experience with common problems with 
threading in GTK+ itself, so it might be terribly wrong. However, to work 
properly, cells-gtk has to either:

1) call g_thread_init(); gdk_threads_init() before it initialises GTK+
2) promise to never, ever touch (or let anything else touch) GTK+ outside 
the thread that initalised it

If it doesn't, then all bets are off the moment you attempt to use GTK+ 
in a threaded environment.

Cheers,
Maciej
From: Andreas Davour
Subject: Re: cells-gtk: run application in its own thread
Date: 
Message-ID: <cs9zlwq9tzv.fsf@Psilocybe.Update.UU.SE>
··················@gmail.com" <·················@gmail.com> writes:

> I've been trying for a while to launch a gtk application in a distinct
> thread (using cells-gtk on sbcl), along these lines:
>
> (sb-thread:make-thread #'(lambda () (cells-gtk-init) (start-app 'my-
> app)))
>
> The thread appears to runs fine up to the point where (gtk-main) is
> called, however no window is ever being displayed.
>
>
> The objective is to launch a GUI in the background, then return back
> to the REPL (with the GUI still runnning in the background), and
> modifying the underlying data structures directly, while the GUI
> visualizes the results.  For another app I have this up and running
> with cl-glut, but for this project I'd like a "real" GUI toolkit (and
> besides the threading issue, cells-gtk is a perfect match for my needs
> here).

What the heck is cl-glut?

/Andreas

-- 
A: Because it fouls the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
From: ·················@gmail.com
Subject: Re: cells-gtk: run application in its own thread
Date: 
Message-ID: <a3065114-9405-408a-a8f6-1d9158dc4617@e23g2000prf.googlegroups.com>
On Dec 4, 7:48 pm, Andreas Davour <·······@updateLIKE.uu.HELLse>
wrote:
> ··················@gmail.com" <·················@gmail.com> writes:
> > I've been trying for a while to launch a gtk application in a distinct
> > thread (using cells-gtk on sbcl), along these lines:
>
> > (sb-thread:make-thread #'(lambda () (cells-gtk-init) (start-app 'my-
> > app)))
>
> > The thread appears to runs fine up to the point where (gtk-main) is
> > called, however no window is ever being displayed.
>
> > The objective is to launch a GUI in the background, then return back
> > to the REPL (with the GUI still runnning in the background), and
> > modifying the underlying data structures directly, while the GUI
> > visualizes the results.  For another app I have this up and running
> > with cl-glut, but for this project I'd like a "real" GUI toolkit (and
> > besides the threading issue, cells-gtk is a perfect match for my needs
> > here).
>
> What the heck is cl-glut?

The freeGLUT bindings from cl-opengl:

http://common-lisp.net/cgi-bin/darcsweb/darcsweb.cgi?r=cl-opengl-cl-opengl;a=headblob;f=/glut/package.lisp

> /Andreas
>
> --
> A: Because it fouls the order in which people normally read text.
> Q: Why is top-posting such a bad thing?
> A: Top-posting.
> Q: What is the most annoying thing on usenet and in e-mail?
From: ·················@gmail.com
Subject: Re: cells-gtk: run application in its own thread
Date: 
Message-ID: <1aa496a4-d6b1-473d-9b19-f1c29f9b8618@x69g2000hsx.googlegroups.com>
On Dec 3, 12:34 pm, ··················@gmail.com"
<·················@gmail.com> wrote:
> I've been trying for a while to launch a gtk application in a distinct
> thread (using cells-gtk on sbcl), along these lines:
>
> (sb-thread:make-thread #'(lambda () (cells-gtk-init) (start-app 'my-
> app)))
>
> The thread appears to runs fine up to the point where (gtk-main) is
> called, however no window is ever being displayed.
>
> The objective is to launch a GUI in the background, then return back
> to the REPL (with the GUI still runnning in the background), and
> modifying the underlying data structures directly, while the GUI
> visualizes the results.  For another app I have this up and running
> with cl-glut, but for this project I'd like a "real" GUI toolkit (and
> besides the threading issue, cells-gtk is a perfect match for my needs
> here).
>
> Did anybody ever encounter this issue, or has any ideas how to work
> around it?

I wrote a patch for the current CVS version of cells-gtk.  Thanks
everyone for their help.  The patch is available from my blog and will
probably be committed to cvs next weekend (if no one breaks it
seriously before than)

http://www.washbear-network.de/peterblog/wp-content/uploads/2007/12/cells-gtk-threading-121207.patch

Given SBCL/linux, the patch offers the new (start-win 'type initargs)
that creates an instance of 'type, runs it in the background, and
returns the instance right to the repl. So it can be modified while
the window is running in the background.  Here's a simple Hello World
from the repl, one command at a time

(defpackage :cgtk-user (:use :cl :cells :cells-gtk))
(in-package :cgtk:user)

;; fire up a hello world window
(start-win 'gtk-app :title "Hello World" :kids (c-in nil))
;; it pops up

;; create a playground
(defparameter vbox (first (push (mk-vbox :kids (c-in nil)) (kids *))))
(push (mk-label :text (c-in "Heyho!")) (kids vbox))
;; it appears

;; have some fun
(push (mk-button :label "Click me!" :on-clicked (callback (w e d)
(print :hello-world))) (kids vbox))
;; click it

;; now something exciting
(push (mk-label :text (c-in "") :md-name :counter) (kids vbox))
(push (mk-button :label "Count" :on-clicked (let ((c 0))
                                               (callback (w e d)
                                                  (setf (text (fm-
other :counter))
                                                        (format nil
"~r" (incf c)))))) (kids vbox))
;; clean up
(close-all-windows)
From: ·················@gmail.com
Subject: Re: cells-gtk: run application in its own thread
Date: 
Message-ID: <666b5c40-a2bb-4326-bbf8-886f14ce94aa@i72g2000hsd.googlegroups.com>
> (defpackage :cgtk-user (:use :cl :cells :cells-gtk))
> (in-package :cgtk:user)

This is of-course
 (in-package :cgtk-user)


>
> ;; fire up a hello world window
> (start-win 'gtk-app :title "Hello World" :kids (c-in nil))
> ;; it pops up
>
> ;; create a playground
> (defparameter vbox (first (push (mk-vbox :kids (c-in nil)) (kids *))))
> (push (mk-label :text (c-in "Heyho!")) (kids vbox))
> ;; it appears
>
> ;; have some fun
> (push (mk-button :label "Click me!" :on-clicked (callback (w e d)
> (print :hello-world))) (kids vbox))
> ;; click it
>
> ;; now something exciting
> (push (mk-label :text (c-in "") :md-name :counter) (kids vbox))
> (push (mk-button :label "Count" :on-clicked (let ((c 0))
>                                                (callback (w e d)
>                                                   (setf (text (fm-
> other :counter))
>                                                         (format nil
> "~r" (incf c)))))) (kids vbox))
> ;; clean up
> (close-all-windows)
From: Maciej Katafiasz
Subject: Re: cells-gtk: run application in its own thread
Date: 
Message-ID: <fjp597$ctm$1@news.net.uni-c.dk>
Den Tue, 11 Dec 2007 17:27:17 -0800 skrev ·················@gmail.com:

> I wrote a patch for the current CVS version of cells-gtk.  Thanks
> everyone for their help.  The patch is available from my blog and will
> probably be committed to cvs next weekend (if no one breaks it seriously
> before than)
> 
> http://www.washbear-network.de/peterblog/wp-content/uploads/2007/12/
cells-gtk-threading-121207.patch

Long URL is looooong, also, 401 Auth Required.
 
Cheers,
Maciej
From: ·················@gmail.com
Subject: Re: cells-gtk: run application in its own thread
Date: 
Message-ID: <45b5c392-2def-4fc4-928f-cd48c5366e56@i12g2000prf.googlegroups.com>
On Dec 12, 6:20 pm, Maciej Katafiasz <········@gmail.com> wrote:
> Den Tue, 11 Dec 2007 17:27:17 -0800 skrev ·················@gmail.com:
>
> > I wrote a patch for the current CVS version of cells-gtk.  Thanks
> > everyone for their help.  The patch is available from my blog and will
> > probably be committed to cvs next weekend (if no one breaks it seriously
> > before than)
>
> >http://www.washbear-network.de/peterblog/wp-content/uploads/2007/12/
>
> cells-gtk-threading-121207.patch
>
> Long URL is looooong, also, 401 Auth Required.

Thanks for pointing that out.  Fixed both:

This is the patch:
http://tinyurl.com/3xee4a

I will put further patches here:
http://www.washbear-network.de/peterblog/cells-gtk-patches

My blog is at http://www.washbear-network.de/peterblog/ -- hopefully
that's short enough [1].

I recently took up work on cells-gtk, and I figured this could be
interesting for other people, too.  So I revived my old blog, but I
forgot about the old .htaccess (haven't restarted Opera in weeks, so I
must have logged on a while ago and forgot about it.)  I should have
checked with another browser anyway.  My bad.  Sorry about the
confusion.

----
[1] The url dates back to high school.  Was a cool joke back then.
Don't want to talk about it now.

> Cheers,
> Maciej
From: ·················@gmail.com
Subject: Re: cells-gtk: run application in its own thread
Date: 
Message-ID: <abddcf5c-e8ed-4858-8588-e2da99fb0992@c4g2000hsg.googlegroups.com>
On Dec 13, 5:15 pm, ··················@gmail.com"
<·················@gmail.com> wrote:
> On Dec 12, 6:20 pm, Maciej Katafiasz <········@gmail.com> wrote:
>
> > Den Tue, 11 Dec 2007 17:27:17 -0800 skrev ·················@gmail.com:
>
> > > I wrote a patch for the current CVS version ofcells-gtk.  Thanks
> > > everyone for their help.  The patch is available from my blog and will
> > > probably be committed to cvs next weekend (if no one breaks it seriously
> > > before than)
>
> > >http://www.washbear-network.de/peterblog/wp-content/uploads/2007/12/
>
> >cells-gtk-threading-121207.patch
>
> > Long URL is looooong, also, 401 Auth Required.
>
> Thanks for pointing that out.  Fixed both:
>
> This is the patch:
http://tinyurl.com/3xee4a

This was down for the last 72 hours, but is up again.  Sorry for any
inconvenience.

>
> I will put further patches here:
http://www.washbear-network.de/peterblog/cells-gtk-patches
>
> My blog is athttp://www.washbear-network.de/peterblog/-- hopefully
> that's short enough [1].
>
> I recently took up work oncells-gtk, and I figured this could be
> interesting for other people, too.  So I revived my old blog, but I
> forgot about the old .htaccess (haven't restarted Opera in weeks, so I
> must have logged on a while ago and forgot about it.)  I should have
> checked with another browser anyway.  My bad.  Sorry about the
> confusion.
>
> ----
> [1] The url dates back to high school.  Was a cool joke back then.
> Don't want to talk about it now.
>
> > Cheers,
> > Maciej