[gnome-devel-docs] Vala samples: Code examples for GtkApplication and AboutDialog
- From: Tiffany Antopolski <antopolski src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-devel-docs] Vala samples: Code examples for GtkApplication and AboutDialog
- Date: Sat, 14 Apr 2012 05:48:43 +0000 (UTC)
commit fe98e795212db87ceb51dc209590d515da313daf
Author: Tiffany Antopolski <tiffany antopolski gmail com>
Date: Sat Apr 14 00:13:24 2012 -0400
Vala samples: Code examples for GtkApplication and AboutDialog
Both these examples use GtkApplication, so requite Gtk+3.4 min.
Still need to create Mallard pages for these two examples.
platform-demos/C/GtkApplication.vala.page | 95 ++++++++++++++++++++++++++
platform-demos/C/aboutdialog.vala.page | 81 ++++++++++++++++++++++
platform-demos/C/media/GtkApplication.png | Bin 0 -> 13119 bytes
platform-demos/C/media/aboutdialog.png | Bin 0 -> 15084 bytes
platform-demos/C/samples/GtkApplication.vala | 64 +++++++++++++++++
platform-demos/C/samples/aboutdialog.vala | 47 +++++++++++++
platform-demos/Makefile.am | 7 ++-
7 files changed, 292 insertions(+), 2 deletions(-)
---
diff --git a/platform-demos/C/GtkApplication.vala.page b/platform-demos/C/GtkApplication.vala.page
new file mode 100644
index 0000000..4ff1032
--- /dev/null
+++ b/platform-demos/C/GtkApplication.vala.page
@@ -0,0 +1,95 @@
+<page xmlns="http://projectmallard.org/1.0/"
+ type="guide" style="task"
+ id="GtkApplication.vala">
+ <info>
+ <link type="guide" xref="beginner.vala#windows"/>
+ <revision version="0.1" date="2012-04-07" status="stub"/>
+
+ <credit type="author copyright">
+ <name>Ryan Lortie</name>
+ <email>desrt desrt ca</email>
+ <years>2012</years>
+ </credit>
+
+ <credit type="author">
+ <name>Tiffany Antopolski</name>
+ <email>tiffany antopolski gmail com</email>
+ </credit>
+
+ <desc>A Gtk.ApplicationWindow</desc>
+ </info>
+
+ <title>ApplicationWindow</title>
+ <media type="image" mime="image/png" src="media/GtkApplication.png"/>
+ <p>A demonstration of the menu integration.</p>
+
+ <code mime="text/x-vala" style="numbered"><![CDATA[
+/*** You need to be running Gtk+-3.4 or later for this to work ***/
+
+//A window in the application
+public class Window : Gtk.ApplicationWindow {
+ public Window (Application app) {
+ Object (application: app, title: "GtkApplication Example");
+
+ var label = new Gtk.Label ("Hello GtkApplication!");
+ add (label);
+
+ var about_action = new SimpleAction ("about", null);
+ about_action.activate.connect (about);
+ add_action (about_action);
+
+ set_default_size (400, 200);
+ show_all ();
+ }
+
+ void about () {
+ string[] authors = { "GNOME Documentation Team", null };
+ string[] documenters = { "GNOME Documentation Team", null };
+
+ Gtk.show_about_dialog (this,
+ "program-name", ("GtkApplication Example"),
+ "copyright", ("Copyright \xc2\xa9 2012 GNOME Documentation Team"),
+ "authors", authors,
+ "documenters", documenters,
+ "website", "http://developer.gnome.org",
+ "website-label", ("GNOME Developer Website"),
+ null);
+ }
+}
+
+//This is the Application
+public class Application : Gtk.Application {
+ protected override void activate () {
+ new Window (this);
+ }
+
+ protected override void startup () {
+ base.startup ();
+
+ var menu = new Menu ();
+ menu.append ("About", "win.about");
+ menu.append ("Quit", "app.quit");
+ app_menu = menu;
+
+ var quit_action = new SimpleAction ("quit", null);
+ quit_action.activate.connect (quit);
+ add_action (quit_action);
+ }
+
+ public Application () {
+ Object (application_id: "org.example.application");
+ }
+}
+
+//main function creates Application and runs it
+int main (string[] args) {
+ return new Application ().run (args);
+}
+]]></code>
+<p>
+ In this sample we used the following:
+</p>
+<list>
+ <item><p><link href="">thing1</link></p></item>
+</list>
+</page>
diff --git a/platform-demos/C/aboutdialog.vala.page b/platform-demos/C/aboutdialog.vala.page
new file mode 100644
index 0000000..bbaf015
--- /dev/null
+++ b/platform-demos/C/aboutdialog.vala.page
@@ -0,0 +1,81 @@
+<page xmlns="http://projectmallard.org/1.0/"
+ type="guide" style="task"
+ id="aboutdialog.vala">
+ <info>
+ <link type="guide" xref="beginner.vala#windows"/>
+ <revision version="0.1" date="2012-04-07" status="stub"/>
+
+ <credit type="author copyright">
+ <name>Ryan Lortie</name>
+ <email>desrt desrt ca</email>
+ <years>2012</years>
+ </credit>
+
+ <credit type="author">
+ <name>Tiffany Antopolski</name>
+ <email>tiffany antopolski gmail com</email>
+ <years></years>
+ </credit>
+
+
+ <desc>Display information about an application</desc>
+ </info>
+
+ <title>AboutDialog</title>
+ <media type="image" mime="image/png" src="media/aboutdialog.png"/>
+ <p>An AboutDialog example using Gtk.Application</p>
+
+ <code mime="text/x-vala" style="numbered"><![CDATA[
+/*** You need to be running Gtk3.4 or later for this to work ***/
+
+//A window in the application
+public class Window : Gtk.ApplicationWindow {
+ public Window (Application app) {
+ Object (application: app, title: "AboutDialog Example");
+ set_default_size (400, 200);
+
+ var button = new Gtk.Button.with_label ("About");
+ button.clicked.connect (about_clicked);
+ add (button);
+
+ show_all ();
+ }
+
+ void about_clicked () {
+ string[] authors = { "GNOME Documentation Team", null };
+ string[] documenters = {"GNOME Documentation Team", null };
+
+ Gtk.show_about_dialog (this,
+ "program-name", ("AboutDialog Example"),
+ "copyright", ("Copyright \xc2\xa9 2012 GNOME Documentation Team"),
+ "authors", authors,
+ "documenters", documenters,
+ "website", "http://developer.gnome.org",
+ "website-label", ("GNOME Developer Website"),
+ null);
+ }
+}
+
+//This is the Application
+public class Application : Gtk.Application {
+ protected override void activate () {
+ new Window (this);
+ }
+
+ public Application () {
+ Object (application_id: "org.example.application");
+ }
+}
+
+//main function creates Application and runs it
+int main (string[] args) {
+ return new Application ().run (args);
+}
+]]></code>
+<p>
+ In this sample we used the following:
+</p>
+<list>
+ <item><p><link href="">thing1</link></p></item>
+</list>
+</page>
diff --git a/platform-demos/C/media/GtkApplication.png b/platform-demos/C/media/GtkApplication.png
new file mode 100644
index 0000000..50eb425
Binary files /dev/null and b/platform-demos/C/media/GtkApplication.png differ
diff --git a/platform-demos/C/media/aboutdialog.png b/platform-demos/C/media/aboutdialog.png
new file mode 100644
index 0000000..3089d50
Binary files /dev/null and b/platform-demos/C/media/aboutdialog.png differ
diff --git a/platform-demos/C/samples/GtkApplication.vala b/platform-demos/C/samples/GtkApplication.vala
new file mode 100644
index 0000000..95debb1
--- /dev/null
+++ b/platform-demos/C/samples/GtkApplication.vala
@@ -0,0 +1,64 @@
+//Note to self: Python and JS need to import Glib for the menu
+
+/*** You need to be running Gtk+-3.4 or later for this to work ***/
+
+//A window in the application
+public class Window : Gtk.ApplicationWindow {
+ public Window (Application app) {
+ Object (application: app, title: "GtkApplication Example");
+
+ var label = new Gtk.Label ("Hello GtkApplication!");
+ add (label);
+
+ var about_action = new SimpleAction ("about", null);
+ about_action.activate.connect (about);
+ add_action (about_action);
+
+ set_default_size (400, 200);
+ show_all ();
+ }
+
+ void about () {
+ string[] authors = { "GNOME Documentation Team", null };
+ string[] documenters = { "GNOME Documentation Team", null };
+
+ Gtk.show_about_dialog (this,
+ "program-name", ("GtkApplication Example"),
+ "copyright", ("Copyright \xc2\xa9 2012 GNOME Documentation Team"),
+ "authors", authors,
+ "documenters", documenters,
+ "website", "http://developer.gnome.org",
+ "website-label", ("GNOME Developer Website"),
+ null);
+ }
+}
+
+//This is the Application
+public class Application : Gtk.Application {
+ protected override void activate () {
+ new Window (this);
+ }
+
+ protected override void startup () {
+ base.startup ();
+
+ var menu = new Menu ();
+ menu.append ("About", "win.about");
+ menu.append ("Quit", "app.quit");
+ app_menu = menu;
+
+ var quit_action = new SimpleAction ("quit", null);
+ quit_action.activate.connect (quit);
+ add_action (quit_action);
+ }
+
+ public Application () {
+ Object (application_id: "org.example.application");
+ }
+}
+
+//main function creates Application and runs it
+int main (string[] args) {
+ return new Application ().run (args);
+}
+
diff --git a/platform-demos/C/samples/aboutdialog.vala b/platform-demos/C/samples/aboutdialog.vala
new file mode 100644
index 0000000..633cf1f
--- /dev/null
+++ b/platform-demos/C/samples/aboutdialog.vala
@@ -0,0 +1,47 @@
+//An AboutDialog example using Gtk.Application
+
+/*** You need to be running Gtk3.4 or later for this to work ***/
+
+//A window in the application
+public class Window : Gtk.ApplicationWindow {
+ public Window (Application app) {
+ Object (application: app, title: "AboutDialog Example");
+ set_default_size (400, 200);
+ var button = new Gtk.Button.with_label ("About");
+ button.clicked.connect (about_clicked);
+ add (button);
+
+ show_all ();
+ }
+
+ void about_clicked () {
+ string[] authors = { "GNOME Documentation Team", null };
+ string[] documenters = {"GNOME Documentation Team", null };
+
+ Gtk.show_about_dialog (this,
+ "program-name", ("AboutDialog Example"),
+ "copyright", ("Copyright \xc2\xa9 2012 GNOME Documentation Team"),
+ "authors", authors,
+ "documenters", documenters,
+ "website", "http://developer.gnome.org",
+ "website-label", ("GNOME Developer Website"),
+ null);
+ }
+}
+
+//This is the Application
+public class Application : Gtk.Application {
+ protected override void activate () {
+ new Window (this);
+ }
+
+ public Application () {
+ Object (application_id: "org.example.application");
+ }
+}
+
+//main function creates Application and runs it
+int main (string[] args) {
+ return new Application ().run (args);
+}
+
diff --git a/platform-demos/Makefile.am b/platform-demos/Makefile.am
index 2e2e00c..206785e 100644
--- a/platform-demos/Makefile.am
+++ b/platform-demos/Makefile.am
@@ -24,12 +24,13 @@ demo_sources = \
media/gnome-devtools.catalog
DOC_FIGURES = \
- media/ubuntu.png \
+ media/aboutdialog.png \
media/button.png \
media/button_with_progress_bar.png \
media/entry.png \
media/fedora.png \
media/opensuse.png \
+ media/GtkApplication.png \
media/guitar-tuner.png \
media/guitar-tuner-glade.png \
media/guitar-tuner-pipeline.png \
@@ -42,12 +43,13 @@ DOC_FIGURES = \
media/photo-wall-focused.png \
media/record-collection.png \
media/toolbar.png \
- media/magic-mirror.png \
+ media/ubuntu.png \
media/weatherAppJs.png \
media/window.png \
$(demo_sources)
DOC_PAGES = \
+ aboutdialog.vala.page \
audio-player.vala.page \
beginner.c.page \
beginner.js.page \
@@ -61,6 +63,7 @@ DOC_PAGES = \
documentation.page \
entry.js.page \
getting-ready.page \
+ GtkApplication.vala.page \
guitar-tuner.c.page \
guitar-tuner.cpp.page \
guitar-tuner.js.page \
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]