[gnome-devel-docs/wip/reorganization] Add helloworld.js example for UI page
- From: Ekaterina Gerasimova <egerasimov src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-devel-docs/wip/reorganization] Add helloworld.js example for UI page
- Date: Mon, 17 Jun 2013 21:17:34 +0000 (UTC)
commit 6ac28de422603e0e38f1320f54d8403cea18deda
Author: Gordon Hill <caseyweederman gmail com>
Date: Mon Jun 17 20:33:27 2013 +0100
Add helloworld.js example for UI page
tutorials/C/samples/helloworld.glade | 11 +++++++++
tutorials/C/samples/helloworld.js | 42 ++++++++++++++++++++++++++++++++++
2 files changed, 53 insertions(+), 0 deletions(-)
---
diff --git a/tutorials/C/samples/helloworld.glade b/tutorials/C/samples/helloworld.glade
new file mode 100644
index 0000000..6c25258
--- /dev/null
+++ b/tutorials/C/samples/helloworld.glade
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+ <!-- interface-requires gtk+ 3.6 -->
+ <object class="GtkWindow" id="window1">
+ <property name="can_focus">False</property>
+ <property name="title" translatable="yes">Hello World</property>
+ <child>
+ <placeholder/>
+ </child>
+ </object>
+</interface>
diff --git a/tutorials/C/samples/helloworld.js b/tutorials/C/samples/helloworld.js
new file mode 100644
index 0000000..f1f3b79
--- /dev/null
+++ b/tutorials/C/samples/helloworld.js
@@ -0,0 +1,42 @@
+#!/usr/bin/gjs
+//The line above calls gjs when this file is run from the command line.
+//If gjs is not installed, this will fail.
+
+//Import lang for bind and gi.Gtk for Gtk functions
+const Lang = imports.lang;
+const Gtk = imports.gi.Gtk;
+
+//Declare HelloWorld as a new Lang class
+const HelloWorld = new Lang.Class({
+ //gjs??? requires classes have the property Name
+ Name: 'HelloWorld',
+
+ //This is called when a new instance is created
+ _init: function() {
+ //Create a GtkApplication
+ this.application = new Gtk.Application();
+ //Connect activate and startup signals to the _onActivate and _onStartup handlers
+ this.application.connect('activate', Lang.bind(this, this._onActivate));
+ this.application.connect('startup', Lang.bind(this, this._onStartup));
+ },
+
+ _onActivate: function(){
+ //Show the window when activated
+ this._window.show_all();
+ },
+
+ _onStartup: function() {
+ //Load the UI file using GtkBuilder
+ let builder = new Gtk.Builder();
+ builder.add_from_file('helloworld.glade');
+ //In the example, 'window1' is the id (or name) of the window object in the UI file
+ this._window = builder.get_object('window1');
+ //Add the window to the application
+ this.application.add_window(this._window);
+ }
+
+});
+
+//Run the application
+let app = new HelloWorld();
+app.application.run(ARGV);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]