Skip to content

Instantly share code, notes, and snippets.

@diegotoral
Created June 2, 2012 21:00
Show Gist options
  • Save diegotoral/2859945 to your computer and use it in GitHub Desktop.
Save diegotoral/2859945 to your computer and use it in GitHub Desktop.
GMenu and Applcation example
#!/usr/bin/gjs
const Gio = imports.gi.Gio;
const Gtk = imports.gi.Gtk;
const Lang = imports.lang;
const App = new Lang.Class ({
Name : "App",
_init : function () {
this.app = new Gtk.Application ({
application_id: 'example.myapp',
flags: Gio.ApplicationFlags.FLAGS_NONE
});
this.app.connect('activate', Lang.bind(this, this._on_activate));
this.app.connect('startup', Lang.bind(this, this._on_startup));
},
_on_activate : function () {
this._window.present ();
},
_on_startup : function () {
this._build_ui ();
},
_build_ui: function () {
this._window = new Gtk.ApplicationWindow ({ application: this.app,
window_position: Gtk.WindowPosition.CENTER,
title: "Welcome to GNOME" });
let menu = new Gio.Menu ();
menu.append ("SuperMegaHiperDuper legal", "app.quit");
this.app.set_app_menu (menu);
let quitAction = new Gio.SimpleAction ({ name: 'quit' });
quitAction.connect('activate', Lang.bind(this,
function() {
this._window.destroy();
}));
this.app.add_action(quitAction);
this._window.set_default_size(600, 400);
this._window.show_all();
},
});
let app = new App ();
this.app.app.run (ARGV);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment