First Gtk program in Smalltalk

Hi,

In this short tutorial I will explain how to create a simple GTK application with GNU Smalltalk. First of all we download the gtk-tools package which contains improvements for Gtk.

git clone git@gitorious.org:gst-objectspaces/gtk-tools.git
cd gtk-tools
./package.sh

Now we can create a first Gtk application; first we load the gtk-tools package

" Create a temporary variable "

 | window |

 PackageLoader fileInPackage: 'GtkTools'.

" This is a simple program that creates a window with a button and a status bar: "

" Create a new window "

   window := GtkTools GtkMainWindow new.

" Set a button as the main widget, change the title and status bar "

   window
       centralWidget: (GTK.GtkButton labeled: 'Hello World');
       title: 'simple';
       statusMessage: 'GTK Tutorial';
       showAll. " Display me and my children "

" Launch the Gtk event loop "

   GTK.Gtk main.

Here is the result:


As you can see it is really easy to create a simple toy application with Gtk and GNU Smalltalk.
In the next episode we will see how to do a simple counter application ;-)

$ git clone git@gitorious.org:gst-objectspaces/gtk-tools.git
Cloning into 'gtk-tools'...
The authenticity of host 'gitorious.org (87.238.52.168)' can't be established.
RSA key fingerprint is 7e:af:8d:ec:f0:39:5e:ba:52:16:ce:19:fa:d4:b8:7d.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'gitorious.org,87.238.52.168' (RSA) to the list of known hosts.
Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

Gitorius doesn't exist anymore.

Does not close clicking x.
Edited some (sorry) and chmod+x:
$ cat gtkt.helloWorld.gst

  1. !/usr/bin/env gst

PackageLoader fileInPackage: 'GtkTools'.

| window |

  window := GtkTools GtkMainWindow new.
  window
     centralWidget:
        (GTK.GtkButton labeled: 'Hello World');
        title: 'simple';
        statusMessage: 'GTK Tutorial';
        showAll.
   GTK Gtk main

$ ./gtkt.helloWorld.gst
"Global garbage collection... done"
Loading package Cairo
Loading package Parser
Loading package GTK
"Global garbage collection... done, heap grown"
Loading package GtkTools
a Smalltalk string:2: parse error, expected '['
a Smalltalk string:2: parse error, expected '['
a Smalltalk string:2: parse error, expected '['
a Smalltalk string:2: parse error, expected '['
press Control-C here!
^CObject: nil error: interrupted!!!
SystemExceptions.UserInterrupt(Exception)>>signal (ExcHandling.st:254)
SystemExceptions.UserInterrupt class(Exception class)>>signal (ExcHandling.st:151)
UndefinedObject(Object)>>userInterrupt (Object.st:1414)
[] in GTK.Gtk class>>main (GTK.star#VFS.ZipFile/GtkImpl.st:535)
BlockClosure>>ensure: (BlkClosure.st:269)
GTK.Gtk class>>main (GTK.star#VFS.ZipFile/GtkImpl.st:531)
UndefinedObject>>executeStatements (gtkt.helloWorld.gst:10)

And are these different GTK.Gtk main.
to GTK Gtk main ?
G

Or are these the "original" GTK bindings for Smalltalk?

Cheers

This is an original GTK binding but I plan to use GObjectInstrospection
in a near future

Its conceptually as nice as smalltalk, but has a much saner syntax. Has also nice gtk bindings. O'reillys "The Ruby Programming Language" makes for a nice initial read.

Smalltalk is the grandaddy of Ruby!!

User login