[gnome-devel-docs] tutorials <javascript>: Added image sample code and Mallard page



commit 43b6c35223b79ec6c4fc069e7c25c0a382225248
Author: Taryn Fox <jewelfox fursona net>
Date:   Fri May 25 22:59:55 2012 -0400

    tutorials <javascript>: Added image sample code and Mallard page

 platform-demos/C/image.js.page    |   34 +++++++++++++++++++++
 platform-demos/C/samples/image.js |   60 +++++++++++++++++++++++++++++++++++++
 2 files changed, 94 insertions(+), 0 deletions(-)
---
diff --git a/platform-demos/C/image.js.page b/platform-demos/C/image.js.page
new file mode 100644
index 0000000..727ad26
--- /dev/null
+++ b/platform-demos/C/image.js.page
@@ -0,0 +1,34 @@
+<page xmlns="http://projectmallard.org/1.0/";
+      xmlns:xi="http://www.w3.org/2001/XInclude";
+      type="guide" style="task"
+      id="image.js">
+  <info>
+    <link type="guide" xref="beginner.js#display-widgets"/>
+    <revision version="0.1" date="2012-05-24" status="draft"/>
+
+    <credit type="author copyright">
+      <name>Taryn Fox</name>
+      <email>jewelfox fursona net</email>
+      <years>2012</years>
+    </credit>
+
+    <desc>A widget displaying an image</desc>
+  </info>
+
+  <title>Image</title>
+  <media type="image" mime="image/png" src="media/image.png"/>
+  <p>This GtkApplication displays an image file from the current directory.</p>
+  <note><p>
+    If the image file isn't loaded successfully, the image will contain a "broken image" icon.  The <file>filename.png</file> needs to be in the current directory for this code to work.  Use your favorite picture!
+  </p></note>
+
+<code mime="text/javascript" style="numbered"><xi:include href="samples/image.js" parse="text"><xi:fallback/></xi:include></code>
+<p>
+  In this sample we used the following:
+</p>
+<list>
+  <item><p><link href="http://www.roojs.com/seed/gir-1.2-gtk-3.0/gjs/Gtk.Application.html";>Gtk.Application</link></p></item>
+  <item><p><link href="http://developer.gnome.org/gtk3/stable/GtkApplicationWindow.html";>Gtk.ApplicationWindow</link></p></item>
+  <item><p><link href="http://www.roojs.com/seed/gir-1.2-gtk-3.0/gjs/Gtk.Image.html";>Gtk.Image</link></p></item>
+</list>
+</page>
diff --git a/platform-demos/C/samples/image.js b/platform-demos/C/samples/image.js
new file mode 100644
index 0000000..50be45b
--- /dev/null
+++ b/platform-demos/C/samples/image.js
@@ -0,0 +1,60 @@
+#!/usr/bin/gjs
+
+const Gio = imports.gi.Gio;
+const GLib = imports.gi.GLib;
+const Gtk = imports.gi.Gtk;
+const Lang = imports.lang;
+
+const ImageExample = new Lang.Class ({
+	Name: 'Image Example',
+
+	/* Create the application itself
+	   This boilerplate code is needed to build any GTK+ application. */
+        _init: function () {
+   	     this.application = new Gtk.Application ({
+  	          application_id: 'org.example.jsimage',
+  	          flags: Gio.ApplicationFlags.FLAGS_NONE
+   	     });
+
+	// Connect 'activate' and 'startup' signals to the callback functions
+	this.application.connect('activate', Lang.bind(this, this._onActivate));
+	this.application.connect('startup', Lang.bind(this, this._onStartup));
+	},
+
+	// Callback function for 'activate' signal presents windows when active
+	_onActivate: function () {
+		this._window.present ();
+	},
+
+	// Callback function for 'startup' signal initializes menus and builds the UI
+	_onStartup: function () {
+		this._buildUI ();
+	},
+
+
+
+
+	// Build the application's UI
+	_buildUI: function () {
+
+		// Create the application window
+        	this._window = new Gtk.ApplicationWindow  ({ application: this.application,
+                                                     	     window_position: Gtk.WindowPosition.CENTER,
+                                                     	     title: "Welcome to GNOME",
+                                                     	     default_height: 300,
+                                                     	     default_width: 300 });
+
+		// Create the label
+		this.jsimage = new Gtk.Image ({file: "gnome-image.png"});
+		this._window.add (this.jsimage);
+
+       	 	// Show the window and all child widgets
+       	 	this._window.show_all();
+	}
+
+
+});
+
+// Run the application
+let app = new ImageExample ();
+app.application.run (ARGV);



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