[gnome-devel-docs/wip/dxhackfest2013] platform-demos: add colorbuttonexample.js
- From: Meg Ford (Margaret) <megford src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-devel-docs/wip/dxhackfest2013] platform-demos: add colorbuttonexample.js
- Date: Fri, 22 Feb 2013 03:19:59 +0000 (UTC)
commit 7b97062a18a2fb5811f5103025c4c6ae4ee89545
Author: Meg Ford <megford gnome org>
Date: Thu Feb 21 21:19:00 2013 -0600
platform-demos: add colorbuttonexample.js
platform-demos/C/colorbuttonexample.js | 69 ++++++++++++++++++++++++++++++++
1 files changed, 69 insertions(+), 0 deletions(-)
---
diff --git a/platform-demos/C/colorbuttonexample.js b/platform-demos/C/colorbuttonexample.js
new file mode 100644
index 0000000..3c454c6
--- /dev/null
+++ b/platform-demos/C/colorbuttonexample.js
@@ -0,0 +1,69 @@
+#!/usr/bin/gjs
+
+const Gdk = imports.gi.Gdk;
+const GObject = imports.gi.GObject;
+const Gtk = imports.gi.Gtk;
+const Lang = imports.lang;
+
+const ColorbuttonExample = new Lang.Class ({
+ Name: 'Colorbutton Example',
+
+ // Create the application itself
+ _init: function () {
+ this.application = new Gtk.Application ({ application_id: 'org.example.jscolorbutton' });
+
+ // 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 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: "Colorbutton Example",
+ default_width: 150,
+ default_height: 50,
+ border_width: 10 });
+
+ this.button = new Gtk.ColorButton();
+ this.color = new Gdk.RGBA();
+ this.color.red = 0.0;
+ this.color.green = 0.0;
+ this.color.blue = 1.0;
+ this.color.alpha = 0.5;
+ this.button.set_rgba(this.color);
+ this.button.connect("color-set", Lang.bind(this, this.onColorChosen));
+ this.label = new Gtk.Label();
+ this.label.set_text("Click to choose a color");
+
+ let grid = new Gtk.Grid();
+ grid.attach(this.button, 0, 0, 2, 1);
+ grid.attach(this.label, 0, 1, 2, 1);
+ this.window.add(grid);
+ this.window.show_all();
+ },
+
+ onColorChosen: function() {
+ let colorName = this.color.to_string();
+ this.label.set_text("You chose the color " + colorName);
+ }
+});
+
+// Run the application
+let app = new ColorbuttonExample ();
+app.application.run (ARGV);
+
+
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]