#!/usr/bin/octave -q function hello(widget) disp("Hello World\n"); end function x=delete_event(widget,event) % /* If you return FALSE in the "delete_event" signal handler, % * GTK will emit the "destroy" signal. Returning TRUE means % * you don't want the window to be destroyed. % * This is useful for popping up 'are you sure you want to quit?' % * type dialogs. */ printf("delete event occurred\n"); % /* Change TRUE to FALSE and the main window will be destroyed with % * a "delete_event". */ x=1; return; end %/* Another callback */ function destroy(widget) gtk_main_quit (); end function main() % /* GtkWidget is the storage type for widgets */ gtk() gtkextra() % /* This is called in all GTK applications. Arguments are parsed % * from the command line and are returned to the application. */ gtk_init (); % /* create a new window */ %GTK_WINDOW_TOPLEVEL=0; window = gtk_window_new (GTK_WINDOW_TOPLEVEL); box = gtk_vbox_new(FALSE,FALSE); % /* When the window is given the "delete_event" signal (this is given % * by the window manager, usually by the "close" option, or on the % * titlebar), we ask it to call the delete_event () function % * as defined above. The data passed to the callback % * function is NULL and is ignored in the callback function. */ g_signal_connect ( (window), "delete_event", " delete_event", 0); % /* Here we connect the "destroy" event to a signal handler. % * This event occurs when we call gtk_widget_destroy() on the window, % * or if we return FALSE in the "delete_event" callback. */ g_signal_connect ( (window), "destroy", "destroy", 0); % /* Sets the border width of the window. */ gtk_container_set_border_width ( (window), 10); % /* Creates a new button with the label "Hello World". */ button = gtk_button_new_with_label ("Hello World"); combo = gtk_color_combo_new(); gtk_container_add (box,button); gtk_container_add (box,gtk_file_list_new(10,2,"./test")); gtk_container_add (box,gtk_font_combo_new()); gtk_container_add (box,combo); % /* When the button receives the "clicked" signal, it will call the % * function hello() passing it NULL as its argument. The hello() % * function is defined above. */ g_signal_connect ( (button), "clicked", "hello", 0); % /* This will cause the window to be destroyed by calling % * gtk_widget_destroy(window) when "clicked". Again, the destroy % * signal could come from here, or the window manager. */ g_signal_connect( (button), "clicked", "gtk_widget_destroy"); % /* This packs the button into the window (a gtk container). */ gtk_container_add ( (window),box); % /* The final step is to display this newly created widget. */ gtk_widget_show(box); % /* and the window */ gtk_widget_show_all (window); gtk_window_set_title(window,"GtkExtra for Octave-GTK+!!"); % /* All GTK applications must have a gtk_main(). Control ends here % * and waits for an event to occur (like a key press or % * mouse event). */ gtk_main (); return; end main();