|
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 |
}
|