const Application = new Lang.Class({
//A Class requires an explicit Name parameter. This is the Class Name.
Name: 'Application',
//create the application
_init: function() {
this.application = new Gtk.Application();
//connect to 'activate' and 'startup' signals to handlers.
this.application.connect('activate', Lang.bind(this, this._onActivate));
this.application.connect('startup', Lang.bind(this, this._onStartup));
},
//create the UI
_buildUI: function() {
this._window = new Gtk.ApplicationWindow({ application: this.application,
title: "Hello World!" });
},
//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();
}
});
«GtkApplication» inicializa GTK+. También conecta el botón
Se puede empezar a construir la primera ventana. Esto se hace creando una variable llamada _window y asignándole una «Gtk.ApplicationWindow» nueva.
Se le asignara una propiedad llamada title. El título puede ser la cadena que quiera pero, para estar seguro, es conveniente que tenga una codificación UTF-8.
Ya tiene una ventana que contiene un título y un botón «cerrar» que funciona. Ahora, añada el texto «Hola mundo».