Skip to content

Instantly share code, notes, and snippets.

@arian
Created April 1, 2013 00:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arian/5282553 to your computer and use it in GitHub Desktop.
Save arian/5282553 to your computer and use it in GitHub Desktop.
Using Prime in gjs to create Gtk Applications.
# use the split-generics branch of prime.
wrup -r prime ../../www/prime/index.js -r bind ../../www/prime/function/bind -o prime.js
#!/usr/bin/gjs
const Lang = imports.lang;
const Gtk = imports.gi.Gtk;
imports.searchPath.push ('.');
var prime = imports.prime.prime;
var bind = imports.prime.bind;
const Application = prime({
//create the application
constructor: function() {
this.application = new Gtk.Application();
//connect to 'activate' and 'startup' signals to handlers.
this.application.connect('activate', bind(this.onActivate, this));
this.application.connect('startup', bind(this.onStartup, this));
},
//create the UI
buildUI: function() {
this.window = new Gtk.ApplicationWindow({
application: this.application,
title: "Hello World!"
});
this.label = new Gtk.Label({
label: "Hello World"
});
this.window.add(this.label);
},
//handler for 'activate' signal
onActivate: function() {
//show the window and all child widgets
this.window.show_all();
},
//handler for 'startup' signal
onStartup: function() {
this.buildUI();
}
});
//run the application
let app = new Application();
app.application.run(ARGV);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment