[gnome-devel-docs] Vala ComboBox sample and add Python Label sample to Makefile.am



commit f18a1d2f4b7e1ac68beb08d3883338a346a2075f
Author: Tiffany Antopolski <tiffany antopolski gmail com>
Date:   Mon May 7 16:05:08 2012 -0400

    Vala ComboBox sample and add Python Label sample to Makefile.am

 platform-demos/C/combobox.vala.page    |   32 +++++++++++++++++++
 platform-demos/C/media/combobox.png    |  Bin 0 -> 11983 bytes
 platform-demos/C/samples/combobox.vala |   53 ++++++++++++++++++++++++++++++++
 platform-demos/Makefile.am             |    3 ++
 4 files changed, 88 insertions(+), 0 deletions(-)
---
diff --git a/platform-demos/C/combobox.vala.page b/platform-demos/C/combobox.vala.page
new file mode 100644
index 0000000..e871f5d
--- /dev/null
+++ b/platform-demos/C/combobox.vala.page
@@ -0,0 +1,32 @@
+<page xmlns="http://projectmallard.org/1.0/";
+      xmlns:xi="http://www.w3.org/2001/XInclude";
+      type="guide" style="task"
+      id="combobox.vala">
+  <info>
+    <link type="guide" xref="beginner.vala#menu-combo-toolbar"/>
+    <revision version="0.1" date="2012-05-07" status="draft"/>
+
+    <credit type="author copyright">
+      <name>Tiffany Antopolski</name>
+      <email>tiffany antopolski gmail com</email>
+      <years>2012</years>
+    </credit>
+
+    <desc>A widget used to choose from a list of items</desc>
+  </info>
+
+  <title>ComboBox</title>
+  <media type="image" mime="image/png" src="media/combobox.png"/>
+  <p>This ComboBox prints to the terminal when you change your selection.</p>
+
+<code mime="text/x-vala" style="numbered"><xi:include href="samples/combobox.vala" parse="text"><xi:fallback/></xi:include></code>
+<p>
+  In this sample we used the following:
+</p>
+<list>
+  <item><p><link href="http://valadoc.org/#!api=gtk+-3.0/Gtk.ListStore";>Gtk.ListStore</link></p></item>
+  <item><p><link href="http://valadoc.org/#!api=gtk+-3.0/Gtk.ComboBox";>Gtk.ComboBox</link></p></item>
+  <item><p><link href="http://valadoc.org/#!api=gtk+-3.0/Gtk.CellRendererText";>Gtk.CellRendererText</link></p></item>
+  <item><p><link href="http://valadoc.org/#!api=gtk+-3.0/Gtk.CellLayout.set_attributes";>set_attributes</link></p></item>
+</list>
+</page>
diff --git a/platform-demos/C/media/combobox.png b/platform-demos/C/media/combobox.png
new file mode 100644
index 0000000..ecb3c67
Binary files /dev/null and b/platform-demos/C/media/combobox.png differ
diff --git a/platform-demos/C/samples/combobox.vala b/platform-demos/C/samples/combobox.vala
new file mode 100644
index 0000000..873acd8
--- /dev/null
+++ b/platform-demos/C/samples/combobox.vala
@@ -0,0 +1,53 @@
+class MyWindow : Gtk.ApplicationWindow {
+	
+	string[] distros = {"Select distribution", "Fedora", "Mint", "Suse"};
+	
+	internal MyWindow (MyApplication app) {
+		Object (application: app, title: "Welcome to GNOME");
+
+		this.set_default_size (200, -1);
+		this.border_width = 10;
+
+		Gtk.ListStore liststore = new Gtk.ListStore (1, typeof (string));
+
+		for (int i = 0; i < distros.length; i++){
+			Gtk.TreeIter iter;
+			liststore.append (out iter);
+			liststore.set (iter, 0, 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_active (0);
+
+		combobox.changed.connect (this.item_changed);
+		
+		this.add (combobox);
+		combobox.show ();
+	}
+
+	void item_changed (Gtk.ComboBox combo) {
+		if (combo.get_active () !=0) {
+			print ("You chose " + distros [combo.get_active ()] +"\n");
+		}
+	}
+}
+
+class MyApplication : Gtk.Application {
+	protected override void activate () {
+		new MyWindow (this).show_all ();
+	}
+
+	internal MyApplication () {
+		Object (application_id: "org.example.MyApplication");
+	}
+}
+
+int main (string[] args) {
+	return new MyApplication ().run (args);
+}
diff --git a/platform-demos/Makefile.am b/platform-demos/Makefile.am
index 3f3a321..e78ffcb 100644
--- a/platform-demos/Makefile.am
+++ b/platform-demos/Makefile.am
@@ -24,6 +24,7 @@ demo_sources = \
 	samples/aboutdialog.vala		\
 	samples/button.py			\
 	samples/button.vala			\
+	samples/combobox.vala			\
 	samples/dialog.vala			\
 	samples/entry.vala			\
 	samples/gmenu.c				\
@@ -51,6 +52,7 @@ demo_sources = \
 DOC_FIGURES = \
 	media/aboutdialog_GMenu.png		\
 	media/button.png			\
+	media/combobox.png			\
 	media/dialog.png			\
 	media/entry.png				\
 	media/fedora.png			\
@@ -92,6 +94,7 @@ DOC_PAGES =				\
 	bug-filing.page			\
 	button.py.page			\
 	button.vala.page		\
+	combobox.vala.page		\
 	c.page				\
 	cpp.page			\
 	desktop.js.page			\



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