This is the mail archive of the guile-gtk@sources.redhat.com mailing list for the Guile project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: gtk-standalone-main


David Pirotte <david@altosw.be> writes:

> I think there is a little difference between launching guile and loading the
> module gtk or launching guile-gtk. here is an example of what happens on my
> machine:
> 
> 1.	;; first launching guile-gtk
> 	david@faust:~/alto/projects/guile/tactus 95 $ guile-gtk
> 	gtk> (use-modules (alto test))
> 	gtk> (test-gui)
> 	gtk> 
> 
> ==>	;; the window is realized and comes to the display normally
> 
> 
> 2.	;; launching guile
> 	david@faust:~/alto/projects/guile/tactus 93 $ guile
> 	guile> (use-modules (alto test))
> 	guile> (test-gui)
> 
> ==>	;; nothing happens, until I exit guile
> 	guile> (exit)
> ==>	;; the window is realized but of course only remains a fraction
> 	;; of a second on the screen

Yes, this is the intended behaviour.  (Or rather, this is what is
supposed to happen; it can certainly be improved upon...)

`gtk-standalone-main' is supposed to be used by programs that want to
start their own event-loop, but only when there isn't one running
already.  Here are some docs from the NEWS file:

    * New Scheme function `gtk-standalone?' that returns whether the
      Guile interpreter is running a Gtk-aware read-eval-print-loop or
      not.  When `(gtk-standalone?)' returns true you should call
      `gtk-main' or `gtk-exit' from your script at the approriate
      times.  When it returns false, you can assume that someone else
      will take care of running the Gtk event loops and quitting the
      interpreter.

      It would be ideal to arrange things so that gtk-standalone could
      always return false.  I'm not at all sure how to achieve this,
      tho.

    * New Scheme function `gtk-standalone-main' that can be used to
      conditionally run a stand-alone session.

            gtk-standalone-main TOPLEVEL

      When (gtk-standlone?) is true: connect gtk-exit to the "destroy"
      signal of TOPLEVEL and call gtk-main.

That is, you would use `gtk-standalone-main' in your code like this:
 
    (define-module (alto test)
      :use-module (gtk gtk))

    (export test-gui)

    (define (test-gui)
      (let ((window (gtk-window-new 'toplevel))
            (button (gtk-button-new-with-label "Hello")))
        (gtk-container-add window button)
        (gtk-signal-connect button "clicked" 
                            (lambda () (gtk-widget-destroy window)))
        (gtk-widget-show-all window)
        (gtk-standalone-main window)))

Alternatively, you can also start the event-loop in its own background
thread via

    (use-modules (gtk threads))
    (gtk-threads-ensure-handler)

This will launch the event-repl in the background if it isn't running
already.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]