[gnome-devel-docs] Added comments to many of the samples.



commit 9e42ab1c4d2889e354b8d6ba1f1baa17e16e7ab2
Author: Tiffany Antopolski <tiffany antopolski gmail com>
Date:   Thu May 10 22:50:59 2012 -0400

    Added comments to many of the samples.

 platform-demos/C/samples/GtkApplicationWindow.vala |   16 ++++-
 platform-demos/C/samples/aboutdialog.vala          |   24 +++++--
 platform-demos/C/samples/button.vala               |   28 +++++--
 platform-demos/C/samples/checkbutton.vala          |   24 +++++-
 platform-demos/C/samples/combobox.vala             |   46 ++++++++++---
 platform-demos/C/samples/dialog.vala               |   74 ++++++++++++++------
 platform-demos/C/samples/entry.vala                |   42 ++++++++---
 platform-demos/C/samples/gmenu.vala                |   37 +++++++---
 .../C/samples/treeview_simple_liststore.vala       |   16 ++---
 platform-demos/C/samples/window.vala               |   24 ++++--
 10 files changed, 238 insertions(+), 93 deletions(-)
---
diff --git a/platform-demos/C/samples/GtkApplicationWindow.vala b/platform-demos/C/samples/GtkApplicationWindow.vala
index 47ea2d3..5be150b 100644
--- a/platform-demos/C/samples/GtkApplicationWindow.vala
+++ b/platform-demos/C/samples/GtkApplicationWindow.vala
@@ -1,19 +1,29 @@
+/* A window in the Application. */
 public class MyWindow : Gtk.ApplicationWindow {
+
+	/* Constructor */
 	internal MyWindow (MyApplication app) {
 		Object (application: app, title: "Welcome to GNOME");
 	}
 }
 
+/* This is the application. */
 public class MyApplication : Gtk.Application {
-	protected override void activate () {
-		new MyWindow (this).show ();
-	}
 
+	/* Constructor. */
 	internal MyApplication () {
 		Object (application_id: "org.example.MyApplication");
 	}
+
+	/* Override the 'activate' signal of GLib.Application. */
+	protected override void activate () {
+
+		/* Create the window of this application and show it. */
+		new MyWindow (this).show ();
+	}
 }
 
+/* main creates and runs the application. */
 public int main (string[] args) {
 	return new MyApplication ().run (args);
 }
diff --git a/platform-demos/C/samples/aboutdialog.vala b/platform-demos/C/samples/aboutdialog.vala
index 151cbb7..d44f73b 100644
--- a/platform-demos/C/samples/aboutdialog.vala
+++ b/platform-demos/C/samples/aboutdialog.vala
@@ -1,16 +1,21 @@
-//A window in the application
+/* A window in the application */
 public class Window : Gtk.ApplicationWindow {
+
+	/* The constructor */
 	public Window (Application app) {
 		Object (application: app, title: "AboutDialog Example");
 
 		var about_action = new SimpleAction ("about", null);
-		about_action.activate.connect (about);
-		this.add_action (about_action);
 
+		about_action.activate.connect (this.about_cb);
+		this.add_action (about_action);
 		this.show_all ();
 	}
-
-	void about () {
+	
+	/* This is the callback function connected to the 'activate' signal 
+	 * of the SimpleAction about_action.
+	 */
+	void about_cb () {
 		string[] authors = { "GNOME Documentation Team", null };
 		string[] documenters = { "GNOME Documentation Team", null };
 
@@ -25,13 +30,17 @@ public class Window : Gtk.ApplicationWindow {
 	}
 }
 
-//This is the Application
+/* This is the Application */
 public class Application : Gtk.Application {
+	
+	/* Here we override the activate signal of GLib.Application */
 	protected override void activate () {
 		new Window (this);
 	}
 
+	/* Here we override the startup signal of GLib.Application */
 	protected override void startup () {
+		
 		base.startup ();
 
 		var menu = new Menu ();
@@ -44,12 +53,13 @@ public class Application : Gtk.Application {
 		this.add_action (quit_action);
 	}
 
+	/* The constructor */
 	public Application () {
 		Object (application_id: "org.example.application");
 	}
 }
 
-//main function creates Application and runs it
+/* main function creates Application and runs it */
 int main (string[] args) {
 	return new Application ().run (args);
 }
diff --git a/platform-demos/C/samples/button.vala b/platform-demos/C/samples/button.vala
index 0a14d2a..480966d 100644
--- a/platform-demos/C/samples/button.vala
+++ b/platform-demos/C/samples/button.vala
@@ -1,31 +1,43 @@
+/* A window in the application */
 public class MyWindow : Gtk.ApplicationWindow {
-	void reverse_label (Gtk.Button button) {
-		button.label = button.label.reverse ();
-	}
-
+	
+	/* The constructor of the window */
 	internal MyWindow (MyApplication app) {
 		Object (application: app, title: "GNOME Button");
 
 		var button = new Gtk.Button.with_label ("Click Me");
-		button.clicked.connect (reverse_label);
+		button.clicked.connect (this.reverse_label);
 		button.show ();
 
 		this.window_position = Gtk.WindowPosition.CENTER;
 		this.set_default_size (250,50);
 		this.add (button);
+	}	
+
+	/* The callback function connected to the 
+	 * 'clicked' signal of the button.
+	 */	
+	void reverse_label (Gtk.Button button) {
+		button.label = button.label.reverse ();
 	}
+
 }
 
+/* This is the application. */
 public class MyApplication : Gtk.Application {
-	protected override void activate () {
-		new MyWindow (this).show ();
-	}
 
+	/* This is the constructor */
 	internal MyApplication () {
 		Object (application_id: "org.example.MyApplication");
 	}
+	
+	/* Override the activate signal of GLib.Application */
+	protected override void activate () {
+		new MyWindow (this).show ();
+	}
 }
 
+/* main creates and runs the application */
 public int main (string[] args) {
 	return new MyApplication ().run (args);
 }
diff --git a/platform-demos/C/samples/checkbutton.vala b/platform-demos/C/samples/checkbutton.vala
index dc059d1..0c760b8 100644
--- a/platform-demos/C/samples/checkbutton.vala
+++ b/platform-demos/C/samples/checkbutton.vala
@@ -1,5 +1,7 @@
+/* A window in the application */
 class MyWindow : Gtk.ApplicationWindow {
 	
+	/* The constructor */
 	internal MyWindow (MyApplication app) {
 		Object (application: app, title: "CheckButton Example");
 
@@ -7,12 +9,20 @@ class MyWindow : Gtk.ApplicationWindow {
 		this.border_width = 10;
 	
 		var checkbutton = new Gtk.CheckButton.with_label ("Show Title");
-		checkbutton.toggled.connect (toggled_cb);
+
+		/* Connect the checkbutton to the 
+		 * callback function (aka. signal handler).
+		 */
+		checkbutton.toggled.connect (this.toggled_cb);
+
+		/* Add the button to the this window */
 		this.add (checkbutton);
+
 		checkbutton.set_active (true);
 		checkbutton.show ();
 	}
 
+	/* The signal handler for the 'toggled' signal of the checkbutton. */
 	void toggled_cb (Gtk.ToggleButton checkbutton) {
 		if (checkbutton.get_active())
 			this.set_title ("CheckButton Example");
@@ -21,16 +31,22 @@ class MyWindow : Gtk.ApplicationWindow {
 	}
 }
 
+/* This is the application */
 class MyApplication : Gtk.Application {
-	protected override void activate () {
-		new MyWindow (this).show ();
-	}
 
+	/* The constructor */
 	internal MyApplication () {
 		Object (application_id: "org.example.checkbutton");
 	}
+	
+	/* Override the activate signal of GLib.Application */
+	protected override void activate () {
+		new MyWindow (this).show ();
+	}
+
 }
 
+/* main creates and runs the application */
 int main (string[] args) {
 	return new MyApplication ().run (args);
 }
diff --git a/platform-demos/C/samples/combobox.vala b/platform-demos/C/samples/combobox.vala
index 873acd8..fde2246 100644
--- a/platform-demos/C/samples/combobox.vala
+++ b/platform-demos/C/samples/combobox.vala
@@ -1,7 +1,17 @@
+/* A window in the application */
 class MyWindow : Gtk.ApplicationWindow {
-	
+
+	/* An instance array of linux distributions belonging to this window. */	
 	string[] distros = {"Select distribution", "Fedora", "Mint", "Suse"};
-	
+
+	/* This enum makes the code more readable when we refer to 
+	 * the column as Column.DISTRO, instead of just 0.
+	 */
+	enum Column {
+		DISTRO
+	}
+
+	/* Constructor */	
 	internal MyWindow (MyApplication app) {
 		Object (application: app, title: "Welcome to GNOME");
 
@@ -13,24 +23,29 @@ class MyWindow : Gtk.ApplicationWindow {
 		for (int i = 0; i < distros.length; i++){
 			Gtk.TreeIter iter;
 			liststore.append (out iter);
-			liststore.set (iter, 0, distros[i]);
+			liststore.set (iter, Column.DISTRO, distros[i]);
 		}
 
 		Gtk.ComboBox combobox = new Gtk.ComboBox.with_model (liststore);
 		Gtk.CellRendererText cell = new Gtk.CellRendererText ();
 		combobox.pack_start (cell, false);
 
-		//set the attributes in the list as the attributes of the cell. 
-		combobox.set_attributes (cell, "text", 0);
+		combobox.set_attributes (cell, "text", Column.DISTRO);
 
+		/* Set the first item in the list to be selected (active). */
 		combobox.set_active (0);
 
+		/* Connect the 'changed' signal of the combobox 
+		 * to the signal handler (aka. callback function.
+		 */
 		combobox.changed.connect (this.item_changed);
-		
+	
+		/* Add the combobox to this window */	
 		this.add (combobox);
 		combobox.show ();
 	}
 
+	/* Signal handler for the 'changed' signal of the combobox. */
 	void item_changed (Gtk.ComboBox combo) {
 		if (combo.get_active () !=0) {
 			print ("You chose " + distros [combo.get_active ()] +"\n");
@@ -38,16 +53,29 @@ class MyWindow : Gtk.ApplicationWindow {
 	}
 }
 
+/* This is the application */
 class MyApplication : Gtk.Application {
-	protected override void activate () {
-		new MyWindow (this).show_all ();
-	}
 
+	/* Constructor */
 	internal MyApplication () {
 		Object (application_id: "org.example.MyApplication");
 	}
+
+	/* Override the activate signal of GLib.Application,
+	 * which is inherited by Gtk.Application.
+	 */
+	protected override void activate () {
+	
+		/* Create the window of this application
+		 * and show it.
+		 */
+		new MyWindow (this).show ();
+	}
+
+
 }
 
+/* main creates and runs the application */
 int main (string[] args) {
 	return new MyApplication ().run (args);
 }
diff --git a/platform-demos/C/samples/dialog.vala b/platform-demos/C/samples/dialog.vala
index 11435d3..7ee360b 100644
--- a/platform-demos/C/samples/dialog.vala
+++ b/platform-demos/C/samples/dialog.vala
@@ -1,49 +1,77 @@
+/* A window in the application. */
 public class MyWindow : Gtk.ApplicationWindow {
 
-        void on_response (Gtk.Dialog dialog, int response_id) {
-                /*To see the int value of the ResponseType*/
-                print ("response is %d\n", response_id);
+	/* Constructor */
+	internal MyWindow (MyApplication app) {
+		Object (application: app, title: "GNOME Button");
+   
+		this.window_position = Gtk.WindowPosition.CENTER;
+		this.set_default_size (250,50);
+		
+		var button = new Gtk.Button.with_label ("Click Me");
 
-                dialog.destroy ();
-        }
+		/* Connect the button's "clicked" signal to
+		 * the signal handler (aka. this.callback function).
+		 */
+		button.clicked.connect (this.on_button_click);
 
+		/* Add the button to this window and show it. */
+		this.add (button);
+		button.show ();
+	}
+
+	/* The signal handler for the buttons 'clicked' signal. */	
 	void on_button_click (Gtk.Button button) {
-                var dialog = new Gtk.Dialog.with_buttons ("A Gtk+ Dialog", this,
+		var dialog = new Gtk.Dialog.with_buttons ("A Gtk+ Dialog", this,
                                                           Gtk.DialogFlags.MODAL,
                                                           Gtk.Stock.OK,
                                                           Gtk.ResponseType.OK, null);
 
-                var content_area = dialog.get_content_area ();
-                var label = new Gtk.Label ("This demonstrates a dialog with a label");
+		var content_area = dialog.get_content_area ();
+		var label = new Gtk.Label ("This demonstrates a dialog with a label");
+
+		content_area.add (label);
+
+		/* Connect the 'response' signal of the dialog
+		 * the signal handler.  It is emitted when the dialog's
+		 * OK button is clicked.
+		 */
+		dialog.response.connect (on_response);
 
-                content_area.add (label);
-                dialog.response.connect (on_response);
-                dialog.show_all ();
+		/* Show the dialog and all the widgets. */
+		dialog.show_all (); 
 	}
 
-	internal MyWindow (MyApplication app) {
-		Object (application: app, title: "GNOME Button");
+	/* Signal handler for the 'response' signal of the dialog. */
+        void on_response (Gtk.Dialog dialog, int response_id) {
 
-		var button = new Gtk.Button.with_label ("Click Me");
-		button.clicked.connect (on_button_click);
-                button.show ();
+                /* To see the int value of the ResponseType. This is only
+		 * for demonstration purposes.*/
+                print ("response is %d\n", response_id);
+
+		/* This causes the dialog to be destroyed. */
+                dialog.destroy ();
+        }
 
-                this.window_position = Gtk.WindowPosition.CENTER;
-                this.set_default_size (250,50);
-		this.add (button);
-	}
 }
 
+/* This is the application. */
 public class MyApplication : Gtk.Application {
-	protected override void activate () {
-		new MyWindow (this).show ();
-	}
 
+	/* The constructore of the application. */
 	internal MyApplication () {
 		Object (application_id: "org.example.MyApplication");
 	}
+
+	/* Override the 'activate' signal of GLib.Application. */
+	protected override void activate () {
+		
+		/* Create a window for the this application and show it. */
+		new MyWindow (this).show ();
+	}
 }
 
+/* The main function creates and runs the application. */
 public int main (string[] args) {
 	return new MyApplication ().run (args);
 }
diff --git a/platform-demos/C/samples/entry.vala b/platform-demos/C/samples/entry.vala
index e4b06ad..f188715 100644
--- a/platform-demos/C/samples/entry.vala
+++ b/platform-demos/C/samples/entry.vala
@@ -1,33 +1,51 @@
-public class MyWindow : Gtk.ApplicationWindow {
-	
-	void on_activate (Gtk.Entry entry) {
-		name = entry.get_text ();
-		print ("Hello " + name + "!\n");
-	}
+/* A window in the application. */
+class MyWindow : Gtk.ApplicationWindow {
 
+	/* Constructor */
 	internal MyWindow (MyApplication app) {
 		Object (application: app, title: "What is your name?");
 
 		var name_box = new Gtk.Entry ();
-		name_box.activate.connect (on_activate);
+
+		/* Connect to the signal handler. */
+		name_box.activate.connect (this.on_activate);
 		name_box.show ();
 
 		this.set_default_size (300, 100);
 		this.border_width = 10;
+
+		/* Add the name_box to this window. */
 		this.add (name_box);
 	}
-}
 
-public class MyApplication : Gtk.Application {
-	protected override void activate () {
-		new MyWindow (this).show ();
+	/* Signal handler (aka. callback function) for the 'activate'
+	 * signal of a Gtk.Entry.
+	 */
+	void on_activate (Gtk.Entry entry) {
+		name = entry.get_text ();
+		print ("\nHello " + name + "!\n\n");
 	}
+}
+
+/* This is the application. */
+class MyApplication : Gtk.Application {
 
+	/* Constructor for the application. */
 	internal MyApplication () {
 		Object (application_id: "org.example.MyApplication");
 	}
+
+	/* Override the 'activate' signal of GLib.Application. */
+	protected override void activate () {
+
+		/* Create a new window for this application
+		 * and show it. */
+		new MyWindow (this).show ();
+	}
+
 }
 
-public int main (string[] args) {
+/* The main function creats and runs the application. */
+int main (string[] args) {
 	return new MyApplication ().run (args);
 }
diff --git a/platform-demos/C/samples/gmenu.vala b/platform-demos/C/samples/gmenu.vala
index 3e503f8..98bc330 100644
--- a/platform-demos/C/samples/gmenu.vala
+++ b/platform-demos/C/samples/gmenu.vala
@@ -1,26 +1,45 @@
-//A window in the application
+/* A window in the application. */
 public class Window : Gtk.ApplicationWindow {
+
+	/* Constructor */
 	public Window (Application app) {
 		Object (application: app, title: "Gmenu Example");
 
 		var about_action = new SimpleAction ("about", null);
-		about_action.activate.connect (about);
+
+		/* Connect the 'activate' signal to the 
+		 * signal handler (aka. callback).
+		 */
+		about_action.activate.connect (this.about_cb);
+
+		/* Add the action to this window. */
 		this.add_action (about_action);
 
-		this.show_all ();
+		this.show ();
 	}
 
-	void about () {
-		print ("This does nothing.  It is only a demonstration\n");
+	/* Signal handler for 'activate' signal of the SimpleAction. */
+	void about_cb () {
+		print ("This does nothing.  It is only a demonstration.\n");
 	}
 }
 
-//This is the Application
+/* This is the Application. */
 public class Application : Gtk.Application {
+
+	/* Constructor */
+	public Application () {
+		Object (application_id: "org.example.application");
+	}
+
+	/* Override the 'activate' signal of GLib.Application. */
 	protected override void activate () {
+
+		/* Create a new window for this application. */
 		new Window (this);
 	}
 
+	/* Override the 'startup' signal of GLib.Application. */
 	protected override void startup () {
 		base.startup ();
 
@@ -34,12 +53,10 @@ public class Application : Gtk.Application {
 		this.add_action (quit_action);
 	}
 
-	public Application () {
-		Object (application_id: "org.example.application");
-	}
+
 }
 
-//main function creates Application and runs it
+/* main function creates Application and runs it. */
 int main (string[] args) {
 	return new Application ().run (args);
 }
diff --git a/platform-demos/C/samples/treeview_simple_liststore.vala b/platform-demos/C/samples/treeview_simple_liststore.vala
index baa0f03..9d1870b 100644
--- a/platform-demos/C/samples/treeview_simple_liststore.vala
+++ b/platform-demos/C/samples/treeview_simple_liststore.vala
@@ -27,8 +27,7 @@ class TreeViewSimpleListStore : Gtk.ApplicationWindow {
 	enum Column {
 		FIRSTNAME, 
 		LASTNAME, 
-		PHONE,
-		WEIGHT
+		PHONE
 	}
 
 	internal TreeViewSimpleListStore (MyApplication app) {
@@ -54,11 +53,10 @@ class TreeViewSimpleListStore : Gtk.ApplicationWindow {
 	}
 
 	void setup_treeview (Gtk.TreeView view) {
-        	var listmodel = new Gtk.ListStore (4, 
+        	var listmodel = new Gtk.ListStore (3, 
                                                    typeof (string), 
                                                    typeof (string),
-                                                   typeof (string),
-                                                   typeof (int));
+                                                   typeof (string));
 			view.set_model (listmodel);
 
 			var cell = new Gtk.CellRendererText ();
@@ -68,13 +66,13 @@ class TreeViewSimpleListStore : Gtk.ApplicationWindow {
 		 	 *  700 is bold.
 		 	 */
 			cell.set ("weight_set", true);
+                        cell.set ("weight", 700);
  
 			/*columns*/
 			view.insert_column_with_attributes (-1,
                                                             "First Name",
                                                             cell, "text",
-                                                            Column.FIRSTNAME,
-                                                            "weight", Column.WEIGHT);
+                                                            Column.FIRSTNAME);
 
 			view.insert_column_with_attributes (-1, 
                                                             "Last Name",
@@ -93,8 +91,7 @@ class TreeViewSimpleListStore : Gtk.ApplicationWindow {
 			listmodel.set (iter, Column.FIRSTNAME,
                                        phonebook[i].firstname,
                                        Column.LASTNAME, phonebook[i].lastname,
-                                       Column.PHONE, phonebook[i].phone,
-                                       Column.WEIGHT, 700);
+                                       Column.PHONE, phonebook[i].phone);
 		}
 	}
 
@@ -131,3 +128,4 @@ class MyApplication : Gtk.Application {
 int main (string[] args) {
 	return new MyApplication ().run (args);
 }
+
diff --git a/platform-demos/C/samples/window.vala b/platform-demos/C/samples/window.vala
index b1132d0..657a919 100644
--- a/platform-demos/C/samples/window.vala
+++ b/platform-demos/C/samples/window.vala
@@ -1,28 +1,36 @@
-//This is the application
+/* This is the application. */
 public class Application : Gtk.Application {
+
+	/* Constructor */
 	public Application () {
 		Object (application_id: "org.example.window");
 	}
 	
+	/* Override the 'activate' signal of GLib.Application,
+	 * which is inherited by Gtk.Application. */
 	public override void activate () {
+
 		var window = new Gtk.Window ();
 		window.title = "Welcome to GNOME";
 
-		/*
-		 The following 3 lines are included here to introduce
-		 you to ways you can adjust the toplevel window to suit
-		 your needs.  Uncomment them to see what they do.
-		*/
+		/* The following 3 lines are included here to introduce
+		 * you to ways you can adjust the toplevel window to suit
+		 * your needs.  Uncomment them to see what they do.
+		 */
+
 		//window.border_width = 10;
 		//window.set_default_size (350, 70);
 		//window.window_position = Gtk.WindowPosition.CENTER;
 
-		window.show ();
+		/* Add the window to this application. */
 		this.add_window (window);
+
+		/* Show the window. */
+		window.show ();
 	}
 }
 
-//The main function creates the application and runs it.
+/* The main function creates the application and runs it.*/
 int main (string[] args) {
 	var app = new Application ();
 	return app.run (args);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]