|
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="button.vala" xml:lang="gl">
|
|
Packit |
1470ea |
<info>
|
|
Packit |
1470ea |
<title type="text">Button (Vala)</title>
|
|
Packit |
1470ea |
<link type="guide" xref="beginner.vala#buttons"/>
|
|
Packit |
1470ea |
<link type="seealso" xref="GtkApplicationWindow.vala"/>
|
|
Packit |
1470ea |
<revision version="0.1" date="2012-02-21" status="stub"/>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<credit type="author copyright">
|
|
Packit |
1470ea |
<name>Tiffany Antopolski</name>
|
|
Packit |
1470ea |
<email its:translate="no">tiffany.antopolski@gmail.com</email>
|
|
Packit |
1470ea |
<years>2012</years>
|
|
Packit |
1470ea |
</credit>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<desc>A button widget which emits a signal when clicked</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>Widget de botón</title>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<media type="image" mime="image/png" src="media/button.png"/>
|
|
Packit |
1470ea |
A button widget connected to a simple callback function.
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
/* A window in the application */
|
|
Packit |
1470ea |
public class MyWindow : Gtk.ApplicationWindow {
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
/* The constructor of the window */
|
|
Packit |
1470ea |
internal MyWindow (MyApplication app) {
|
|
Packit |
1470ea |
Object (application: app, title: "GNOME Button");
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
var button = new Gtk.Button.with_label ("Click Me");
|
|
Packit |
1470ea |
button.clicked.connect (this.reverse_label);
|
|
Packit |
1470ea |
button.show ();
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
this.window_position = Gtk.WindowPosition.CENTER;
|
|
Packit |
1470ea |
this.set_default_size (250,50);
|
|
Packit |
1470ea |
this.add (button);
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
/* The callback function connected to the
|
|
Packit |
1470ea |
* 'clicked' signal of the button.
|
|
Packit |
1470ea |
*/
|
|
Packit |
1470ea |
void reverse_label (Gtk.Button button) {
|
|
Packit |
1470ea |
button.label = button.label.reverse ();
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
/* This is the application. */
|
|
Packit |
1470ea |
public class MyApplication : Gtk.Application {
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
/* This is the constructor */
|
|
Packit |
1470ea |
internal MyApplication () {
|
|
Packit |
1470ea |
Object (application_id: "org.example.MyApplication");
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
/* Override the activate signal of GLib.Application */
|
|
Packit |
1470ea |
protected override void activate () {
|
|
Packit |
1470ea |
new MyWindow (this).show ();
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
/* main creates and runs the application */
|
|
Packit |
1470ea |
public int main (string[] args) {
|
|
Packit |
1470ea |
return new MyApplication ().run (args);
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
In this sample we used the following:
|
|
Packit |
1470ea |
<link href="http://www.valadoc.org/gtk+-3.0/Gtk.Button.html">Gtk.Button</link>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
</page>
|