|
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="entry.js" xml:lang="gl">
|
|
Packit |
1470ea |
<info>
|
|
Packit |
1470ea |
<title type="text">Entry (JavaScript)</title>
|
|
Packit |
1470ea |
<link type="guide" xref="beginner.js#entry"/>
|
|
Packit |
1470ea |
<revision version="0.1" date="2012-06-03" 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 single-line text entry field</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>Entry</title>
|
|
Packit |
1470ea |
<media type="image" mime="image/png" src="media/entry.png"/>
|
|
Packit |
1470ea |
This application greets you by name through a pop-up window.
|
|
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 EntryExample {
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
// Create the application itself
|
|
Packit |
1470ea |
constructor() {
|
|
Packit |
1470ea |
this.application = new Gtk.Application({
|
|
Packit |
1470ea |
application_id: 'org.example.jsentry',
|
|
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({
|
|
Packit |
1470ea |
application: this.application,
|
|
Packit |
1470ea |
window_position: Gtk.WindowPosition.CENTER,
|
|
Packit |
1470ea |
default_height: 100,
|
|
Packit |
1470ea |
default_width: 300,
|
|
Packit |
1470ea |
border_width: 10,
|
|
Packit |
1470ea |
title: "What is your name?"});
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
// Create the text entry box
|
|
Packit |
1470ea |
this.entry = new Gtk.Entry ();
|
|
Packit |
1470ea |
this._window.add(this.entry);
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
// Connect the text entry box to a function that responds to what you type in
|
|
Packit |
1470ea |
this.entry.connect("activate", this._hello.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 |
_hello() {
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
// Create a popup dialog to greet the person who types in their name
|
|
Packit |
1470ea |
this._greeter = new Gtk.MessageDialog ({
|
|
Packit |
1470ea |
transient_for: this._window,
|
|
Packit |
1470ea |
modal: true,
|
|
Packit |
1470ea |
text: "Hello, " + this.entry.get_text() + "!",
|
|
Packit |
1470ea |
message_type: Gtk.MessageType.OTHER,
|
|
Packit |
1470ea |
buttons: Gtk.ButtonsType.OK,
|
|
Packit |
1470ea |
});
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
// Show the popup dialog
|
|
Packit |
1470ea |
this._greeter.show();
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
// Bind the OK button to the function that closes the popup
|
|
Packit |
1470ea |
this._greeter.connect ("response", this._okClicked.bind(this));
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
_okClicked() {
|
|
Packit |
1470ea |
this._greeter.destroy();
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
};
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
// Run the application
|
|
Packit |
1470ea |
let app = new EntryExample ();
|
|
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.org/seed/gir-1.2-gtk-3.0/gjs/Gtk.Entry.html">Gtk.Entry</link> </item>
|
|
Packit |
1470ea |
<item><link href="http://www.roojs.com/seed/gir-1.2-gtk-3.0/gjs/Gtk.MessageDialog.html">Gtk.MessageDialog</link> </item>
|
|
Packit |
1470ea |
</list>
|
|
Packit |
1470ea |
</page>
|