JuliaLang/Gtk.jl — pull request #10 by timholy (2013-12-26 16:10:27+00:00)
Title: More changes towards getting ImageView running

The most important of these---and the one that deserves the most careful scrutiny---is the patch adding `connect`. I added it because I was finding it awkward to pass extra data to callbacks. Usage of `connect` would take either of the following patterns:
```
connect(upbutton, "clicked", obj -> upbutton_cb(obj, state, displayfunc))
connect(upbutton, "button-press-event", (obj, event) -> upbutton_cb(obj, event, state, displayfunc))
```
The latter is used when there is a `GdkEvent` associated with the signal.

Overall, I think this is a fairly nice interface, but there are alternatives. Rather than using an anonymous function to store the extra arguments, we could presumably define it as
```
connect(object, signal, func, args...)
```
where `func` gets called as `func(obj, event, args...)`, and set the `args` tuple as the data argument of `g_signal_connect_data`. However, one problem with that interface is how to handle `gconnectflags`. So the anonymous-function interface seemed the better way to go.

I should also mention that do find the current `signal_connect` slightly confusing:
- The `data` argument is named `closure`.
- The `data` argument is last, after `gconnectflags`, which is presumably a rarely-used option. That propagates to `on_signal_button_press` and friends, meaning that most usages of this function might look like this:
```
on_signal_button_press(func, widget, 0, extradata)
```
where `extradata` contains whatever state information the widget callback needs in order to do its job. If one could pass it as
```
on_signal_button_press(func, widget, 0, extradata1, extradata2, ...)
```
then that argument order might make more sense, but that doesn't work either unless `signal_connect`'s function declaration were written in terms of `closure...`.

I suspect I'm simply not understanding how you intended to use it, and perhaps that's part of why I decided to create a wrapper.

The other patches in this PR (so far) should be fairly straightforward, as long as you like the names. The key constants are a bit awkward to use in practice,
```
if event.keyval == Gtk.GdkKeySyms.GDK_KEY_Up
# do something
end
```
which is quite a lot of characters to type in front of the key constant. Though naturally, one can say
```
const KSYM = Gtk.GdkKeySyms
```
and shorten it. (Seemingly, one can't say `using` for a `baremodule`.)