X-Git-Url: http://repo.macrolet.net/gitweb/?a=blobdiff_plain;ds=sidebyside;f=doc%2Ftutorial.xml;h=d28a0a53a90d713553f6b0f8d6c04db7b059d445;hb=10f80fc9d1404cd451160086301a8ff69bfec38a;hp=160e20d2a6b1117c6fe674237eaf9dcab1c49803;hpb=3f21f82bc65738f3d355c7cb00940ad622f50b34;p=cl-gtk2.git
diff --git a/doc/tutorial.xml b/doc/tutorial.xml
index 160e20d..d28a0a5 100644
--- a/doc/tutorial.xml
+++ b/doc/tutorial.xml
@@ -47,40 +47,21 @@
"Hello world" example
Let's start from a simple example.
- Load the GTK system: (asdf:oos 'asdf:load-op :gtk)
- Having loaded the GTK system, compile the following code:
+ Start Slime, type the following code in the REPL:
-(defpackage :gtk-hello
- (:use :cl :gtk :gobject :glib)
- (:export :run))
+(asdf:oos 'asdf:load-op :gtk)
-(in-package :gtk-hello)
-
-(defun run ()
- (let ((output *standard-output*))
- (with-main-loop
- (let ((window (make-instance 'gtk-window
- :type :toplevel
- :window-position :center
- :title "Hello world!"
- :default-width 300
- :default-height 100))
- (button (make-instance 'button :label "Hello, world!"))
- (counter 0))
- (g-signal-connect button "clicked"
- (lambda (b)
- (declare (ignore b))
- (format output "Hello, world!~%")
- (setf (button-label button)
- (format nil
- "Hello, world! (clicked ~D times)"
- (incf counter)))))
- (container-add window button)
- (widget-show window :all t)))))
+(gtk:within-main-loop
+ (let ((window (make-instance 'gtk:gtk-window :title "Hello, world!")))
+ (gtk:widget-show window)))
- And now, run it:(gtk-hello:run)
- This code should create a form with a button. When the button is clicked, this program prints a message to standard output and changes the text of the button.
- If you have a window, then congratulations! Otherwise, contact the author for support.
+ The empty window with title "Hello, world!" should appear.
+ Let's analyze this example line-by-line.
+ (asdf:oos 'asdf:load-op :gtk) loads the GTK system into Lisp.
+ CL-GTK2 runs Gtk+ main loop in background thread (because Lisp development is interactive in its nature; if main loop would block the REPL thread, you would have to restart the Lisp image too often). Because all access to Gtk+ should come from Gtk+ thread, we should run the code in that thread. Macro gtk:within-main-loop does exactly that: it schedules the code to be tun in the Gtk+ thread. You should use this macro whenever you want evaluate the code from the REPL or when you start you application.
+ Next, we create the window with make-instance and set its title property to "Hello, world!".
+ When the window is created, it is not yet shown on the screen. To show it, we call (gtk:widget-show window).
+ After this code executes, you should get back to the REPL (rememer, Gtk+ runs in background thread) and the window should appear on the screen.