Monday, February 01, 2010

“Hello Glade#” from IronPython

I was a little pessimistic yesterday about this operation -- but with a little sidestepping to use a different method on the Glade XML object, and a little bit of Python metaprogramming, we can actually get something much more general than the F# solution.

Same app as before

The trick here is in writing our own __getattr__ method that calls the name-to-widget look-up method of the Glade model, if we haven't already made a note of the object of that name. Written like this, the Handler class could be used in any IronPython/Glade# application.

Now I wonder whether there is a better way to do it in F# that can use generic typing, and not lose the elegance under the weight of type coercion operators.

Post a Comment