First of all, your official tutorial on getting started with Vala GUI development is excellent. I am wanting to move away from hand-coding my window layouts and I want to use Glade XML files. I have the following code which works:
using Gtk;
public void on_button1_clicked (Button source) {
source.label = "Thank you!";
}
public void on_button2_clicked (Button source) {
source.label = "Thanks!";
}
int main (string[] args) {
Gtk.init (ref args);
try {
// If the UI contains custom widgets, their types must've been instantiated once
// Type type = typeof(Foo.BarEntry);
// assert(type != 0);
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;
}
However, it only works because I have hard-coded the location of the glade XML file (sample.ui
). If I move the .ui
file then the app breaks. I have done some research and it looks like I need to use a GResource to specify the XML file and then load it.
Would it be possible to create a short tutorial on how to properly compile and access assets when building a Vala GUI app please?
valac --pkg gtk+-3.0 hello.vala
from the Terminal to compile myhello.vala
file to a binary. The leap from this level of compiling to these build systems is too complicated...