[gnome-devel-docs] JS GtkApplicationWindow sample



commit 4869547848c4b0fcd5d0963ce9ff78af05e0555a
Author: Tiffany Antopolski <tiffany antopolski gmail com>
Date:   Tue May 1 22:48:07 2012 -0400

    JS GtkApplicationWindow sample

 platform-demos/C/samples/GtkApplicationWindow.js |   49 ++++++++++++++++++++++
 1 files changed, 49 insertions(+), 0 deletions(-)
---
diff --git a/platform-demos/C/samples/GtkApplicationWindow.js b/platform-demos/C/samples/GtkApplicationWindow.js
new file mode 100644
index 0000000..24d69f1
--- /dev/null
+++ b/platform-demos/C/samples/GtkApplicationWindow.js
@@ -0,0 +1,49 @@
+#!/usr/bin/gjs
+
+const Gio = imports.gi.Gio;
+const GLib = imports.gi.GLib;
+const Gtk = imports.gi.Gtk;
+const Lang = imports.lang;
+
+const Application = new Lang.Class ({
+    Name: 'Application',
+   
+    //create the application
+    _init: function () {
+        this.application = new Gtk.Application ({
+            application_id: 'org.example.myapp',
+            flags: Gio.ApplicationFlags.FLAGS_NONE
+        });
+       
+       //connect to '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));
+    },
+
+    //create the UI (in this case it's just the ApplicationWindow
+    _buildUI: function (app) {
+        this._window = new Gtk.ApplicationWindow  ({ application: app,
+                                                   window_position: Gtk.WindowPosition.CENTER,
+                                                   title: "Welcome to GNOME" });
+
+        //uncommenting the line below will change the window size
+        //this._window.set_size_request(600, 400);
+
+        //show the window and all child widgets (none in this case)
+        this._window.show_all();
+    },
+
+    //callback function for 'activate' signal
+    _onActivate: function () {
+        this._window.present ();
+    },
+
+    //callback function for 'startup' signal
+    _onStartup: function (app) {
+        this._buildUI (app);
+    }
+});
+
+//run the application
+let app = new Application ();
+app.application.run (ARGV);



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