REM
REM Demo to show how to use GTK-server
REM The GTK-server tries to access the incoming string directly (LIB interface) to spare memory.
REM For that reason, the command needs to be copied to a variable first.
REM PvE - March 2009.
REM

REM Get central function from GTK-server
IMPORT "gtk" FROM "libgtk-server.so" TYPE char*

REM Wrap around function
FUNCTION gui$(STRING c$)

dat$ = c$
RETURN gtk(dat$)

END FUNCTION

REM Setup GUI
REM gui$("gtk_server_cfg -log=/tmp/log.txt")
gui$("gtk_init NULL NULL")
gui$("glade_init")

REM Get Glade file
xml$ = gui$("glade_xml_new ./demo.glade NULL NULL")
gui$(CONCAT$("glade_xml_signal_autoconnect ", xml$))

REM Get main window ID and connect signal
window$ = gui$(CONCAT$("glade_xml_get_widget ", xml$, " window"))
gui$(CONCAT$("gtk_server_connect ", window$, " delete-event window"))

REM Get exit button ID and connect signal
exit$ = gui$(CONCAT$("glade_xml_get_widget ", xml$, " exit_button"))
gui$(CONCAT$("gtk_server_connect ", exit$, " clicked exit_button"))

REM Get print button ID and connect signal
button$ = gui$(CONCAT$("glade_xml_get_widget ", xml$, " print_button"))
gui$(CONCAT$("gtk_server_connect ", button$, " clicked print_button"))

REM Get entry ID
entry$ = gui$(CONCAT$("glade_xml_get_widget ", xml$, " entry"))

REM Mainloop
WHILE (NOT(EQUAL(event$, "window")) AND NOT(EQUAL(event$, "exit_button"))) DO

    event$ = gui$("gtk_server_callback wait")

    IF EQUAL(event$, "print_button") THEN
        result$ = gui$(CONCAT$("gtk_entry_get_text ", entry$))
        PRINT result$
    ENDIF
WEND

REM Exit GTK
gui$("gtk_server_exit")