-------------------------------------------------------- -- -- Euphoria demonstration with GTK-server -- -- Peter van Eerten, january 2008 -- -- This code may not be beautifull but I hope -- Euphoria users get the idea. -- -- Tested with Euphoria 3.1 and GTK-server 2.2.2 in Linux -- Run with 'exu demo-lib.ex' -- -- For Windows, open 'gtk-server.dll' instead. -- -------------------------------------------------------- include dll.e include machine.e global integer gtk atom gtkserver gtkserver = open_dll("libgtk-server.so") gtk = define_c_func(gtkserver, "gtk", {C_POINTER}, C_POINTER) if gtk = -1 then puts(1, "GTK-server could not be found!\n") abort(1) end if -------------------------------------------------------- -- -- This function 'get_string' is from: -- Michael J. Sabal -- -------------------------------------------------------- function get_string(atom lpsz) atom ptr, c sequence s s = "" if lpsz = 0 then return s end if ptr = 0 c = peek(lpsz+ptr) while c != 0 do s = s & c ptr = ptr + 1 c = peek(lpsz+ptr) end while return s end function -------------------------------------------------------- function wrap_gtk(sequence arg) atom result, string string = allocate_string(arg) result = c_func(gtk, {string}) free(string) return get_string(result) end function -------------------------------------------------------- sequence answer, window, table, button, check, entry, event answer = wrap_gtk("gtk_server_cfg log") answer = wrap_gtk("gtk_server_version") answer = wrap_gtk("gtk_init NULL NULL") window = wrap_gtk("gtk_window_new 0") answer = wrap_gtk("gtk_window_set_title " & window & " 'Euphoria and GTK'") answer = wrap_gtk("gtk_window_set_position " & window & " 1") table = wrap_gtk("gtk_table_new 10 10 1") answer = wrap_gtk("gtk_container_add " & window & " " & table) button = wrap_gtk("gtk_button_new_with_label 'Click here!'") answer = wrap_gtk("gtk_table_attach_defaults " & table & " " & button & " 5 9 7 9") check = wrap_gtk("gtk_check_button_new_with_label 'Check \t this \n out!'") answer = wrap_gtk("gtk_table_attach_defaults " & table & " " & check & " 1 6 1 2") entry = wrap_gtk("gtk_entry_new") answer = wrap_gtk("gtk_table_attach_defaults " & table & " " & entry & " 1 6 3 4") answer = wrap_gtk("gtk_widget_show_all " & window) event = "" while not equal(event, window) and not equal(event, button) do event = wrap_gtk("gtk_server_callback wait") if equal(event, entry) then answer = wrap_gtk("gtk_entry_get_text " & entry) puts(1, answer & "\n") end if end while