SOLVED Vala: modify the state of widgets in a gtkbuilder gui
Posted: Tue 03 Apr 2012, 12:19
I'm trying to port a VB.NET program I maintain to Vala and Gtkbuilder.
My first problem is that I can't figure out how to refer to a widget if I want to do something to it. e.g. how would I modify the example code below, so that when you click one of the buttons and it is made insensitive, the other button is also made sensitive?
My first problem is that I can't figure out how to refer to a widget if I want to do something to it. e.g. how would I modify the example code below, so that when you click one of the buttons and it is made insensitive, the other button is also made sensitive?
Code: Select all
using Gtk;
public void on_button1_clicked (Button source) {
source.label = "Thank you!";
source.sensitive = false;
}
public void on_button2_clicked (Button source) {
source.label = "Thanks!";
source.sensitive = false;
}
int main (string[] args) {
Gtk.init (ref args);
try {
var builder = new Builder ();
builder.add_from_file ("sample.ui");
builder.connect_signals (null);
var window = builder.get_object ("window") as Window;
window.show_all ();
Gtk.main ();
} catch (Error e) {
stderr.printf ("Could not load UI: %s\n", e.message);
return 1;
}
return 0;
}
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<requires lib="gtk+" version="2.16"/>
<object class="GtkWindow" id="window">
<property name="can_focus">False</property>
<property name="border_width">10</property>
<property name="title" translatable="yes">Sample Application</property>
<property name="window_position">center</property>
<property name="default_width">300</property>
<property name="default_height">70</property>
<signal name="destroy" handler="gtk_main_quit" swapped="no"/>
<child>
<object class="GtkHBox" id="hbox1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="spacing">4</property>
<property name="orientation">GTK_ORIENTATION_HORIZONTAL</property>
<child>
<object class="GtkButton" id="button1">
<property name="label" translatable="yes">Click me!</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="use_action_appearance">False</property>
<signal name="clicked" handler="on_button1_clicked" swapped="no"/>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="button2">
<property name="label" translatable="yes">Me too!</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="use_action_appearance">False</property>
<signal name="clicked" handler="on_button2_clicked" swapped="no"/>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
</child>
</object>
</interface>