Hello,

i'm a hobby coder having a lot of fun with vala and gtk (except
treeview ;). and i'm now in the process off trying to create something
useful with vala (more on that later).

i was trying to adapt the GladeSample[0] to use Gtk.Builder (as i didn't
found any examples of this), after a (long) while i got something that
didn't give me any compile-time errors... but sadly i lack some general
info about all this, to understand why the signal handler is not found.

so, would be very helpful if someone could kick me in the right
direction. attached is a test case how far i got.

cheers
Andre "Osku" Schmidt

[0] http://live.gnome.org/Vala/GladeSample

ps. my system is ubuntu9.04 64bit, glade3.6.1, valac0.7.2(svn)

Attachment: test-gtkbuilder.ui
Description: application/designer

// -*- tab-width: 4 -*-

/*
valac --Xcc="-Wl,--export-dynamic" --pkg gtk+-2.0 --pkg gmodule-2.0 test-gtkbuilder.vala
*/

using Gtk;

public class GtkBuilderSample {

	private const string UI_FILE = "test-gtkbuilder.ui";

	public void run () {
		try {
			var builder = new Builder ();
			builder.add_from_file (UI_FILE);
			var window = builder.get_object ("window1") as Window;
			window.show_all ();
			window.destroy += Gtk.main_quit;
			builder.connect_signals_full (connect_signals);
		} catch (Error e) {
			var msg = new MessageDialog (null, DialogFlags.MODAL,
									MessageType.ERROR, ButtonsType.CANCEL, 
									"Failed to load UI\n%s", e.message);
			msg.run ();
		} 
	}

    [CCode (instance_pos = -1)]
    public void on_button1_clicked (Widget widget) {
    	stdout.printf ("button clicked\n");
    }

    [CCode (instance_pos = -1)]
	private void connect_signals (Gtk.Builder builder, GLib.Object object,
								string signal_name, string handler_name,
								GLib.Object? connect_object,
								GLib.ConnectFlags flags) 
	{
		var module = Module.open (null, ModuleFlags.BIND_LAZY);
		void* sym;
		if (!module.symbol (handler_name, out sym)) {
			stdout.printf ("Symbol not found! %s\n", handler_name);
		} else {
			Signal.connect (object, signal_name, (GLib.Callback) sym, this);
		}
	}

public static int main (string[] args) {
		Gtk.init (ref args);

		var sample = new GtkBuilderSample ();
		sample.run ();

		Gtk.main ();
		return 0;
	}
}

// vim:tabstop=4:

_______________________________________________
Vala-list mailing list
[email protected]
http://mail.gnome.org/mailman/listinfo/vala-list

Reply via email to