|
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="cs">
|
|
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>Volba z více zaškrtávacích políček</desc>
|
|
Packit |
1470ea |
</info>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<title>RadioButton</title>
|
|
Packit |
1470ea |
<media type="image" mime="image/png" src="media/radiobutton.png"/>
|
|
Packit |
1470ea |
Tyto skupinové přepínače oznamují svoji aktivitu v terminálu.
|
|
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 |
/* Ukážeme si 3 různé metody vytvoření RadioButton */
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
// Vytvoří Radio Button
|
|
Packit |
1470ea |
var button1 = new Gtk.RadioButton (null);
|
|
Packit |
1470ea |
button1.set_label ("Button 1");
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
// Vytvoří RadioButton s popiskem a přidá jej do stejné skupiny, jako je button1
|
|
Packit |
1470ea |
var button2 = new Gtk.RadioButton.with_label (button1.get_group(),"Button 2");
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
// Vytvoří RadioButton s popiskem a přidá jej do skupiny skupinového přepínač button1
|
|
Packit |
1470ea |
var button3 = new Gtk.RadioButton.with_label_from_widget (button1, "Button 3");
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
// Připojí skupinové přepínače do mřížky
|
|
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 |
// Přidá mřížku do okna
|
|
Packit |
1470ea |
this.add (grid);
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
// Napojí obsluhu signálu (neboli funkce zpětného volání) ke skupinovým přepínačům
|
|
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 |
// Vše zobrazí
|
|
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 |
V této ukázce se používá následující:
|
|
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>
|