|
Packit |
1470ea |
#!/usr/bin/gjs
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
imports.gi.versions.Gtk = '3.0';
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
const Gio = imports.gi.Gio;
|
|
Packit |
1470ea |
const GLib = imports.gi.GLib;
|
|
Packit |
1470ea |
const Gtk = imports.gi.Gtk;
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
class AboutDialogExample {
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
// Create the application itself
|
|
Packit |
1470ea |
constructor() {
|
|
Packit |
1470ea |
this.application = new Gtk.Application({
|
|
Packit |
1470ea |
application_id: 'org.example.jsaboutdialog',
|
|
Packit |
1470ea |
flags: Gio.ApplicationFlags.FLAGS_NONE
|
|
Packit |
1470ea |
});
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
// Connect 'activate' and 'startup' signals to the callback functions
|
|
Packit |
1470ea |
this.application.connect('activate', this._onActivate.bind(this));
|
|
Packit |
1470ea |
this.application.connect('startup', this._onStartup.bind(this));
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
// Callback function for 'activate' signal presents windows when active
|
|
Packit |
1470ea |
_onActivate() {
|
|
Packit |
1470ea |
this._window.present();
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
// Callback function for 'startup' signal creates the menu and builds the UI
|
|
Packit |
1470ea |
_onStartup() {
|
|
Packit |
1470ea |
this._initMenus();
|
|
Packit |
1470ea |
this._buildUI();
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
// Build the application's UI
|
|
Packit |
1470ea |
_buildUI() {
|
|
Packit |
1470ea |
// Create the application window
|
|
Packit |
1470ea |
this._window = new Gtk.ApplicationWindow({ application: this.application,
|
|
Packit |
1470ea |
window_position: Gtk.WindowPosition.CENTER,
|
|
Packit |
1470ea |
title: "AboutDialog Example",
|
|
Packit |
1470ea |
default_height: 250,
|
|
Packit |
1470ea |
default_width: 350 });
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
// Show the window and all child widgets
|
|
Packit |
1470ea |
this._window.show_all();
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
// Create the application menu
|
|
Packit |
1470ea |
_initMenus() {
|
|
Packit |
1470ea |
let menu = new Gio.Menu();
|
|
Packit |
1470ea |
menu.append("About", 'app.about');
|
|
Packit |
1470ea |
menu.append("Quit",'app.quit');
|
|
Packit |
1470ea |
this.application.set_app_menu(menu);
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
// Create the "About" menu option and have it call the _showAbout() function
|
|
Packit |
1470ea |
let aboutAction = new Gio.SimpleAction({ name: 'about' });
|
|
Packit |
1470ea |
aboutAction.connect('activate', () => { this._showAbout(); });
|
|
Packit |
1470ea |
this.application.add_action(aboutAction);
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
// Create the "Quit" menu option and have it close the window
|
|
Packit |
1470ea |
let quitAction = new Gio.SimpleAction ({ name: 'quit' });
|
|
Packit |
1470ea |
quitAction.connect('activate', () => { this._window.destroy(); });
|
|
Packit |
1470ea |
this.application.add_action(quitAction);
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
_showAbout() {
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
// String arrays of the names of the people involved in the project
|
|
Packit |
1470ea |
var authors = ["GNOME Documentation Team"];
|
|
Packit |
1470ea |
var documenters = ["GNOME Documentation Team"];
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
// Create the About dialog
|
|
Packit |
1470ea |
let aboutDialog = new Gtk.AboutDialog({ title: "AboutDialog Example",
|
|
Packit |
1470ea |
program_name: "GtkApplication Example",
|
|
Packit |
1470ea |
copyright: "Copyright \xa9 2012 GNOME Documentation Team",
|
|
Packit |
1470ea |
authors: authors,
|
|
Packit |
1470ea |
documenters: documenters,
|
|
Packit |
1470ea |
website: "http://developer.gnome.org",
|
|
Packit |
1470ea |
website_label: "GNOME Developer Website" });
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
// Attach the About dialog to the window
|
|
Packit |
1470ea |
aboutDialog.modal = true;
|
|
Packit |
1470ea |
aboutDialog.transient_for = this._window;
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
// Show the About dialog
|
|
Packit |
1470ea |
aboutDialog.show();
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
// Connect the Close button to the destroy signal for the dialog
|
|
Packit |
1470ea |
aboutDialog.connect('response', function() {
|
|
Packit |
1470ea |
aboutDialog.destroy();
|
|
Packit |
1470ea |
});
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
};
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
// Run the application
|
|
Packit |
1470ea |
let app = new AboutDialogExample();
|
|
Packit |
1470ea |
app.application.run(ARGV);
|