1/* A window in the application. */ 2public class MyWindow : Gtk.ApplicationWindow { 3 4 /* Constructor */ 5 internal MyWindow (MyApplication app) { 6 Object (application: app, title: "GNOME Button"); 7 8 this.window_position = Gtk.WindowPosition.CENTER; 9 this.set_default_size (250,50); 10 11 var button = new Gtk.Button.with_label ("Click Me"); 12 13 /* Connect the button's "clicked" signal to 14 * the signal handler (aka. this.callback function). 15 */ 16 button.clicked.connect (this.on_button_click); 17 18 /* Add the button to this window and show it. */ 19 this.add (button); 20 button.show (); 21 } 22 23 /* The signal handler for the buttons 'clicked' signal. */ 24 void on_button_click (Gtk.Button button) { 25 var dialog = new Gtk.Dialog.with_buttons ("A Gtk+ Dialog", this, 26 Gtk.DialogFlags.MODAL, 27 Gtk.Stock.OK, 28 Gtk.ResponseType.OK, null); 29 30 var content_area = dialog.get_content_area (); 31 var label = new Gtk.Label ("This demonstrates a dialog with a label"); 32 33 content_area.add (label); 34 35 /* Connect the 'response' signal of the dialog 36 * the signal handler. It is emitted when the dialog's 37 * OK button is clicked. 38 */ 39 dialog.response.connect (on_response); 40 41 /* Show the dialog and all the widgets. */ 42 dialog.show_all (); 43 } 44 45 /* Signal handler for the 'response' signal of the dialog. */ 46 void on_response (Gtk.Dialog dialog, int response_id) { 47 48 /* To see the int value of the ResponseType. This is only 49 * for demonstration purposes.*/ 50 print ("response is %d\n", response_id); 51 52 /* This causes the dialog to be destroyed. */ 53 dialog.destroy (); 54 } 55 56} 57 58/* This is the application. */ 59public class MyApplication : Gtk.Application { 60 61 /* The constructor of the application. */ 62 internal MyApplication () { 63 Object (application_id: "org.example.MyApplication"); 64 } 65 66 /* Override the 'activate' signal of GLib.Application. */ 67 protected override void activate () { 68 69 /* Create a window for the this application and show it. */ 70 new MyWindow (this).show (); 71 } 72} 73 74/* The main function creates and runs the application. */ 75public int main (string[] args) { 76 return new MyApplication ().run (args); 77} 78