Page 1 of 1

New GTK# docs

PostPosted: Fri Nov 04, 2011 8:18 pm
by Charles
Thanks to user "callisto" for contributing GTK# docs including screenshots, example code for various widgets, layouts, menus, etc. It starts here:

http://cobra-language.com/trac/cobra/wiki/GtkLibrary

Re: New GTK# docs

PostPosted: Sat Nov 05, 2011 4:35 am
by callisto
Thanks Charles - I hope the material is useful. (You beat me to the announcement!)

A cobra question: is it possible to write something like:

listen button.clicked, ref do(obj,e)=Application.quit  # this doesn't work!


i.e. pass a reference to an anonymous method? (I've tried creating sigs and local variables, but can't find a combination that works.) This would save a lot of boilerplate code, constructing single-use methods, just to get a name to reference.

The wiki entry for Listen, http://cobra-language.com/trac/cobra/wiki/Listen, ends with "# Todo example using closure/anonymous method", but I'm not sure that is referring to what I need.

Re: New GTK# docs

PostPosted: Sat Nov 05, 2011 10:44 am
by Charles
Good question.
listen button.clicked, do(sender, args as EventArgs)
print 'Quitting'
Application.quit

The "do(args)=expr" form is only for expressions and is suitable when the return value is of interest and will be used. In the case where you need statements, they go on the next line indented and you can have as many statements as you like.

The type for "args" is currently required because Cobra is not yet as good as it should be about inferring the arg types. That will be improved in the future.

You need the "ref" keyword to refer to a named method so that it is not invoked. You never need "ref" and "do" at the same time--just one of them.

Re: New GTK# docs

PostPosted: Sat Nov 05, 2011 5:14 pm
by callisto
Charles wrote:The "do(args)=expr" form is only for expressions and is suitable when the return value is of interest and will be used. In the case where you need statements, they go on the next line indented and you can have as many statements as you like.


Thanks, that's a helpful clarification. I've got a few examples working now, and, in the right place, the anonymous methods are a convenient simplification.