|
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="radiobutton.vala" xml:lang="gl">
|
|
Packit |
1470ea |
<info>
|
|
Packit |
1470ea |
<title type="text">RadioButton (Vala)</title>
|
|
Packit |
1470ea |
<link type="guide" xref="beginner.vala#buttons"/>
|
|
Packit |
1470ea |
<link type="seealso" xref="togglebutton.vala"/>
|
|
Packit |
1470ea |
<link type="seealso" xref="grid.vala"/>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<revision version="0.1" date="2012-05-09" status="draft"/>
|
|
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 choice from multiple CheckButtons.</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>RadioButton</title>
|
|
Packit |
1470ea |
<media type="image" mime="image/png" src="media/radiobutton.png"/>
|
|
Packit |
1470ea |
These RadioButtons report their activity in the terminal.
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
public class MyWindow : Gtk.ApplicationWindow {
|
|
Packit |
1470ea |
internal MyWindow (MyApplication app) {
|
|
Packit |
1470ea |
Object (application: app, title: "RadioButton Example");
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
this.border_width = 20;
|
|
Packit |
1470ea |
this.set_default_size (250, 100);
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
/* We demonstrate 3 different RadioButton creation methods */
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
//Create a Radio Button
|
|
Packit |
1470ea |
var button1 = new Gtk.RadioButton (null);
|
|
Packit |
1470ea |
button1.set_label ("Button 1");
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
//Create a RadioButton with a label, and add it to the same group as button1.
|
|
Packit |
1470ea |
var button2 = new Gtk.RadioButton.with_label (button1.get_group(),"Button 2");
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
//Create a RadioButton with a label, adding it to button1's group.
|
|
Packit |
1470ea |
var button3 = new Gtk.RadioButton.with_label_from_widget (button1, "Button 3");
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
//Attach the buttons to a grid.
|
|
Packit |
1470ea |
var grid = new Gtk.Grid ();
|
|
Packit |
1470ea |
grid.attach (button1, 0, 0, 1, 1);
|
|
Packit |
1470ea |
grid.attach (button2, 0, 1, 1, 1);
|
|
Packit |
1470ea |
grid.attach (button3, 0, 2, 1, 1);
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
//Add the button to the window.
|
|
Packit |
1470ea |
this.add (grid);
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
//Connect the signal handlers (aka. callback functions) to the buttons.
|
|
Packit |
1470ea |
button1.toggled.connect (button_toggled_cb);
|
|
Packit |
1470ea |
button2.toggled.connect (button_toggled_cb);
|
|
Packit |
1470ea |
button3.toggled.connect (button_toggled_cb);
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
void button_toggled_cb (Gtk.ToggleButton button)
|
|
Packit |
1470ea |
{
|
|
Packit |
1470ea |
var state = "unknown";
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
if (button.get_active ())
|
|
Packit |
1470ea |
state = "on";
|
|
Packit |
1470ea |
else {
|
|
Packit |
1470ea |
state = "off";
|
|
Packit |
1470ea |
print ("\n");
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
print (button.get_label() + " was turned " + state + "\n");
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
public class MyApplication : Gtk.Application {
|
|
Packit |
1470ea |
protected override void activate () {
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
//Show all of the things.
|
|
Packit |
1470ea |
new MyWindow (this).show_all ();
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
internal MyApplication () {
|
|
Packit |
1470ea |
Object (application_id: "org.example.MyApplication");
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
public int main (string[] args) {
|
|
Packit |
1470ea |
return new MyApplication ().run (args);
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
Neste exemplo empregaremos o seguinte:
|
|
Packit |
1470ea |
<list>
|
|
Packit |
1470ea |
<item><link href="http://www.valadoc.org/gtk+-3.0/Gtk.RadioButton.html">Gtk.RadioButton</link> </item>
|
|
Packit |
1470ea |
</list>
|
|
Packit |
1470ea |
</page>
|