[gtkada] libglade and Windows
Michael Bode
michael.bode at laserline.de
Wed Apr 27 16:56:48 CEST 2005
Michael Bode <michael.bode at laserline.de> writes:
> > I have also read that using libglade with GtkAda is frowned upon,
> > because the use of libglade bypasses some of GtkAda's strong type
> > checking.
>
>
> Of course I will get problems @ run time if I define "SampleWidget" as a
> label in glade and try to use it as a button in my program, while the
> compiler would have told me @ compile time.
It's actually not as bad as I thought. Consider the following sample:
with Gtk.Main;
with Glade.XML; use Glade.XML;
with Gtk.Window; use Gtk.Window;
with Gtk.GEntry; use Gtk.GEntry;
with Gtk.Style; use Gtk.Style;
with Pango.Font; use Pango.Font;
procedure Window1 is
XML : Glade_XML;
Entry2 : Gtk_Entry;
Style : Gtk_Style;
Window1 : Gtk_Window;
begin
Gtk.Main.Set_Locale;
Gtk.Main.Init;
Gtk_New (XML, "glade-test.glade");
Window1 := Gtk_Window (Get_Widget (XML, "window1"));
Entry2 := Gtk_Entry (Get_Widget (XML, "entry2"));
Style := Copy (Get_Style (Window1));
-- set some fancy font
Set_Font_Description (Style, From_String ("LcdD 38"));
Set_Style (Entry2, Style);
Gtk.Main.Main;
end Window1;
This program takes a glade file, creates the UI and then changes the
font of Entry2 to some large fancy font. If by mistake I change
Entry2 := Gtk_Entry (Get_Widget (XML, "entry2"));
to
Entry2 := Gtk_Entry (Get_Widget (XML, "label2"));
where label2 is also defined in the glade file, this is checked at
this point at runtime:
raised CONSTRAINT_ERROR : window1.adb:18 tag check failed
So the error is caught as early as possible at runtime.
More information about the gtkada
mailing list