|
Packit |
1470ea |
|
|
Packit |
1470ea |
<page xmlns="http://projectmallard.org/1.0/" xmlns:its="http://www.w3.org/2005/11/its" xmlns:xi="http://www.w3.org/2001/XInclude" type="guide" style="task" id="dialog.js" xml:lang="gl">
|
|
Packit |
1470ea |
<info>
|
|
Packit |
1470ea |
<title type="text">Dialog (JavaScript)</title>
|
|
Packit |
1470ea |
<link type="guide" xref="beginner.js#windows"/>
|
|
Packit |
1470ea |
<revision version="0.1" date="2012-05-29" status="draft"/>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<credit type="author copyright">
|
|
Packit |
1470ea |
<name>Taryn Fox</name>
|
|
Packit |
1470ea |
<email its:translate="no">jewelfox@fursona.net</email>
|
|
Packit |
1470ea |
<years>2012</years>
|
|
Packit |
1470ea |
</credit>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<desc>A popup window</desc>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<mal:credit xmlns:mal="http://projectmallard.org/1.0/" type="translator copyright">
|
|
Packit |
1470ea |
<mal:name>Fran Dieguez</mal:name>
|
|
Packit |
1470ea |
<mal:email>frandieguez@gnome.org</mal:email>
|
|
Packit |
1470ea |
<mal:years>2012-2013.</mal:years>
|
|
Packit |
1470ea |
</mal:credit>
|
|
Packit |
1470ea |
</info>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<title>Dialog</title>
|
|
Packit |
1470ea |
<media type="image" mime="image/png" src="media/dialog.png"/>
|
|
Packit |
1470ea |
A customizable popup window, which has a content area and an action area. This example dialog's content area contains a short message, and its action area contains a button which dismisses the dialog.
|
|
Packit |
1470ea |
|
|
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 DialogExample {
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
// Create the application itself
|
|
Packit |
1470ea |
constructor() {
|
|
Packit |
1470ea |
this.application = new Gtk.Application ({
|
|
Packit |
1470ea |
application_id: 'org.example.jsdialog',
|
|
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 builds the UI
|
|
Packit |
1470ea |
_onStartup() {
|
|
Packit |
1470ea |
this._buildUI();
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
// Build the application's UI
|
|
Packit |
1470ea |
_buildUI() {
|
|
Packit |
1470ea |
|
|
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: "Gtk.Dialog Example",
|
|
Packit |
1470ea |
default_height: 50,
|
|
Packit |
1470ea |
default_width: 250 });
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
// Create a button
|
|
Packit |
1470ea |
this._button = new Gtk.Button ({label: "Click Me"});
|
|
Packit |
1470ea |
this._window.add (this._button);
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
// Bind it to the function that creates the dialog
|
|
Packit |
1470ea |
this._button.connect ("clicked", this._createDialog.bind(this));
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
// Show the window and all child widgets
|
|
Packit |
1470ea |
this._window.show_all();
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
_createDialog() {
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
// Create the dialog
|
|
Packit |
1470ea |
this._dialog = new Gtk.Dialog ({ transient_for: this._window,
|
|
Packit |
1470ea |
modal: true,
|
|
Packit |
1470ea |
title: "A Gtk+ dialog" });
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
// Create the dialog's content area, which contains a message
|
|
Packit |
1470ea |
this._contentArea = this._dialog.get_content_area();
|
|
Packit |
1470ea |
this._message = new Gtk.Label ({label: "This demonstrates a dialog with a label"});
|
|
Packit |
1470ea |
this._contentArea.add (this._message);
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
// Create the dialog's action area, which contains a stock OK button
|
|
Packit |
1470ea |
this._actionArea = this._dialog.get_action_area();
|
|
Packit |
1470ea |
this._OKButton = Gtk.Button.new_from_stock (Gtk.STOCK_OK);
|
|
Packit |
1470ea |
this._actionArea.add (this._OKButton);
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
// Connect the button to the function that handles what it does
|
|
Packit |
1470ea |
this._OKButton.connect ("clicked", this._OKHandler.bind(this));
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
this._dialog.show_all();
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
_OKHandler(dialog, response_id) {
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
// Destroy the dialog
|
|
Packit |
1470ea |
this._dialog.destroy();
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
};
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
// Run the application
|
|
Packit |
1470ea |
let app = new DialogExample ();
|
|
Packit |
1470ea |
app.application.run (ARGV);
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
Neste exemplo empregaremos o seguinte:
|
|
Packit |
1470ea |
<list>
|
|
Packit |
1470ea |
<item><link href="http://www.roojs.com/seed/gir-1.2-gtk-3.0/gjs/Gtk.Application.html">Gtk.Application</link> </item>
|
|
Packit |
1470ea |
<item><link href="http://developer.gnome.org/gtk3/stable/GtkApplicationWindow.html">Gtk.ApplicationWindow</link> </item>
|
|
Packit |
1470ea |
<item><link href="http://www.roojs.com/seed/gir-1.2-gtk-3.0/gjs/Gtk.Dialog.html">Gtk.Dialog</link> </item>
|
|
Packit |
1470ea |
</list>
|
|
Packit |
1470ea |
</page>
|