At this point you would probably like to see an example of the
Hello World variety, so here is our very own howdy.sl
:
import("gtk");
variable win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
() = g_signal_connect(win, "destroy", >k_main_quit);
variable button = gtk_button_new_with_label("Howdy: Press Me to Quit!");
gtk_container_add(win,button);
() = g_signal_connect_swapped(button, "clicked", >k_widget_destroy, win);
gtk_widget_show_all(win);
gtk_main();
This script may be executed in any application which embeds an S-Lang
interpreter endowed with the capacity to import()
modules. The
slsh
shell is one such program, which if invoked on Unix/Linux
(assuming you've installed SLgtk) as follows
unix% slsh ./howdy.sl
should raise on your display an image which looks something like:
The next example shows how to use the powerful Gtk font selector, and
is taken directly from the SLgtk examples/fontsel.sl
sample code.
static variable window = NULL;
define display_selection (widget, fs)
{
variable s = gtk_font_selection_dialog_get_font_name (fs);
vmessage ("Currently Selected Font: %s\n", s);
gtk_widget_destroy (fs);
}
define create_fontsel (test)
{
if (window == NULL) {
window = gtk_font_selection_dialog_new ("Font Selection Dialog");
gtk_window_set_position (window, GTK_WIN_POS_MOUSE);
() = g_signal_connect (window,"destroy",>k_widget_destroyed,&window);
() = g_signal_connect (
gtk_font_selection_dialog_get_ok_button(window),
"clicked", &display_selection,window);
test.lower = gtk_font_selection_dialog_get_cancel_button(window);
() = g_signal_connect(test.lower,"clicked",&display_selection,window);
}
if (gtk_widget_visible (window))
gtk_widget_destroy (window);
else
gtk_widget_show (window);
}
Note that a wealth of sample guilets are packaged within the SLgtk
distribution. The examples
directory alone contains more than
than 4000 lines of code, in roughly 40 working guilets (largely
adaptations from testgtk.c packaged with Gtk), while the packages
directory contains the vwhere() guilet and supporting scripts.