Sunday, January 31, 2010

“Hello Glade#” from F#

Another bit of spiking, a rather tardy follow up from raw GTK#, starting from the C# example at the Mono Project site, but incorporating the earlier example, so as to build in a clean application exit, for one thing.

In the .glade file, I changed the label size from 38, as in

<widget class="GtkLabel" id="label1">
       <property name="width_request">38</property>

to 88, so as to allow the displayed text to be longer.

In VS2008 I added the .glade file by including a new F# script file, but renaming it to, pasting in the XML, and setting its properties to have a Build Action of Embedded Resource. The code looks like:

Here the widgets are surfaced via a plain data object, Handler, and their events are wired up much as before via F#'s first class reactive events, which are much more natural (especially when combining events to one handler is required). The project needs a reference to the glade-sharp assembly, above and beyond the ones already required for pure GTK#

Unfortunately, the need for CLR attributes on members is problematic for IronPython -- the least nasty way to achieve the equivalent of the Handler class would be to compile some C# on the fly.

Unchanged by version, February 2010 CTP.

Unchanged by version 3.1.1, January 2014 (except that Add Existing Item works better for the .glade file in VS2010 and up).

No comments :