REM
REM Bacon and Glade and GTK.
REM PvE - April 2009.
REM
REM Improved August 18, 2009 - PvE.
REM Improved February 20, 2010 - PvE.
REM

REM Get functions from GLADE
INCLUDE "glade.bac"

REM Get needed functions from GTK
IMPORT "g_signal_connect_data" FROM "libgobject-2.0.so" TYPE void
IMPORT "gtk_init(int*, char*)" FROM "libgtk-x11-2.0.so" TYPE void
IMPORT "gtk_entry_get_text(long)" FROM "libgtk-x11-2.0.so" TYPE char*
IMPORT "gtk_exit(int)" FROM "libgtk-x11-2.0.so" TYPE void
IMPORT "gtk_main" FROM "libgtk-x11-2.0.so" TYPE void

REM Callback for closing window
SUB exit_prog
    gtk_exit(0)
END SUB

REM Callback to get entry contents
SUB get_entry(long button, long entry)
    result$ = gtk_entry_get_text(entry)
    PRINT result$
END SUB

REM Setup GUI
gtk_init(0, 0)
glade_init

REM Get Glade file
xml = glade_xml_new("./demo.glade", 0, 0)
glade_xml_signal_autoconnect(xml)

REM Get main window ID and connect signal
window = glade_xml_get_widget(xml, "window")
g_signal_connect_data(window, "delete-event", exit_prog, 0, 0, 0)

REM Get exit button ID and connect signal
quit = glade_xml_get_widget(xml, "exit_button")
g_signal_connect_data(quit, "clicked", exit_prog, 0, 0, 0)

REM Get entry
entry = glade_xml_get_widget(xml, "entry")

REM Get print button ID and connect signal and pass entry as data to callback function
button = glade_xml_get_widget(xml, "print_button")
g_signal_connect_data(button, "clicked", get_entry, entry, 0, 0)

REM Endless event handling by GTK
gtk_main