# Gtk menubar (and gtkglarea) question

**URL:** <https://discourse.julialang.org/t/gtk-menubar-and-gtkglarea-question/25876>\
**Category:** New to Julia\
**Created:** [June 30, 2019, 11:30pm UTC](https://discourse.julialang.org/t/gtk-menubar-and-gtkglarea-question/25876 "2019-06-30T23:30:49Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![purplishrock](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/purplishrock/32/13451_2.png) [@purplishrock](https://discourse.julialang.org/u/purplishrock)\
**Post date:** [June 30, 2019, 11:30pm UTC](https://discourse.julialang.org/t/gtk-menubar-and-gtkglarea-question/25876/1 "2019-06-30T23:30:49Z")

</div>

I hate to ask this question here, but I’m wondering if this might be a julia gtk issue. Everything I’ve seen says i should simply connect the “activate” signal to the menu item and it should work. but I’m not seeing it work. I’ve included a simple button that _does_ work.

Also, does anybody know if the gtkglarea widget would work through the julia-gtk package ??

code & glade file follows, the problem being that selecting file-\>new doesn’t do anything.

[Julia code](https://pastebin.com/S1msP70e)  
[glade file](https://pastebin.com/H4KTgVnC)

Thanks !

---

<div class="post-metadata">

**Author:** ![pixel27](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pixel27/32/8902_2.png) [@pixel27](https://discourse.julialang.org/u/pixel27)\
**Post date:** [July 1, 2019, 1:19pm UTC](https://discourse.julialang.org/t/gtk-menubar-and-gtkglarea-question/25876/2 "2019-07-01T13:19:40Z")

</div>

```julia
function file_new(w)
    println("File Menu")
end

```

You callback didn’t take the widget…

> [@purplishrock](#):
>
> I hate to ask this question here,

Out of curiosity do you hate asking questions? Or just hate asking here?

---

<div class="post-metadata">

**Author:** ![purplishrock](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/purplishrock/32/13451_2.png) [@purplishrock](https://discourse.julialang.org/u/purplishrock)\
**Post date:** [July 1, 2019, 6:35pm UTC](https://discourse.julialang.org/t/gtk-menubar-and-gtkglarea-question/25876/3 "2019-07-01T18:35:52Z")

</div>

Really amazing that I never noticed that, I stared at that code for well over an hour.

however, this little mistake does raise an interesting point, and does make this make my question julia relevant (as opposed to it being more of a gtk related question). it’s actually not obvious to me why the call didn’t work _without generating an error_.

either the compiler should be disappointed that I didn’t pass in a function that takes a widget argument, or, the dispatch should break since there was no function to call. It seems like some sort of bug that it silently failed.

p.s. lol, no i don’t hate asking questions. I thought this might be a gtk specific question as opposed to a julia specific question, i.e., didn’t really belong here. However, I had seen another post where, in fact, a widget in the Julia gtk interface was not working properly.

p.p.s yes, in fact adding the w argument does fix it. thank you !

---

<div class="post-metadata">

**Author:** ![pixel27](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pixel27/32/8902_2.png) [@pixel27](https://discourse.julialang.org/u/pixel27)\
**Post date:** [July 1, 2019, 6:45pm UTC](https://discourse.julialang.org/t/gtk-menubar-and-gtkglarea-question/25876/4 "2019-07-01T18:45:51Z")

</div>

> [@purplishrock](#):
>
> however, this little mistake does raise an interesting point, and does make this make my question julia relevant (as opposed to it being more of a gtk related question).

I agree with you that this is fricken annoying…I suspect it might be a julia to C library issue. i.e. Julia is just passing a function pointer to the GTK C library, and ultimately the GTK library is calling it back. It appears if the number of parameter are wrong, GTK doesn’t call it, which to me, brings up the question “What did it really call?”, “How did it know the parameters were wrong?”, and “Did this just cause memory corruption?”.

I suspect to fix this issue would require GTK.jl to either verify the callback functions (which I don’t think it possible) or for each notification type provide a “trampoline” function with the correct parameters which then calls “your” function. The trampoline function would keep stuff in the Julia space so Julia could detect the parameter mismatch and report an error.

---

<div class="post-metadata">

**Author:** ![purplishrock](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/purplishrock/32/13451_2.png) [@purplishrock](https://discourse.julialang.org/u/purplishrock)\
**Post date:** [July 1, 2019, 8:31pm UTC](https://discourse.julialang.org/t/gtk-menubar-and-gtkglarea-question/25876/5 "2019-07-01T20:31:16Z")

</div>

> [@pixel27](#):
>
> “What did it really call?”, “How did it know the parameters were wrong?”, and “Did this just cause memory corruption?”.

yeah- those various thoughts crossed my mind too.

I just looked at the Gtk source. It simply takes the julia callback function that you supplied, turns it into a cfunction\_, which wraps it into another function (so - i thikn similar to your trampoline idea). The original function just keeps propagating all the way through so it’s not at all obvious why it should not be called, it seems like regardless of the arguments the function should still be invoked. There’s almost certainly something wrong…

However it _is_ obvious why I don’t get a compiler error. The cb is defined as a “Function” without any argument specification at all. so it doesn’t matter if the function takes 0 arguments or 10 arguments, it’s still a function and will satisfy the argument type of “Function”.
