Correct @davide:
First example
The first example does not work at the moment. I think it is supposed to work, but the "button-press-event"
signal already has a connection in the InspectDR code. I think this is a bug with Gtk. I am almost certain you are supposed to be able to connect multiple callback functions to the same “signal”. I merely included the example in case you better understood how Gtk worked, and knew how to get around the problem.
Second example
As for the second example: that one will definitively work. I call it a “hack” because you actually have to add your code (or possibly a call to your user-defined function) directly in InspectDR’s src/gtk_input.jl
file.
Sightly less hack-y
…But since we are talking Julia here, I suppose you could use the “dynamic patching” (guerrilla patch/monkey patch) technique to overwrite the function from your own code, instead of directly modifying the InspectDR code:
using InspectDR
using Gtk
function InspectDR.handleevent_mousepress(::InspectDR.ISNormal, pwidget::InspectDR.PlotWidget, event::Gtk.GdkEventButton)
# @show event.state, event.button, event.event_type
InspectDR.focus_strip(pwidget, event.x, event.y)
InspectDR.set_focus(pwidget) #In case not in focus
if 3==event.button
InspectDR.boxzoom_setstart(pwidget, event.x, event.y) #Changes state
elseif 1==event.button
if InspectDR.modifiers_pressed(event.state, InspectDR.MODIFIER_SHIFT)
InspectDR.mousepan_setstart(pwidget, event.x, event.y) #Changes state
elseif !InspectDR.modifiers_pressed(event.state, InspectDR.MODIFIERS_SUPPORTED) #Un-modified
#!!! ADD CODE HERE !!!
@show pwidget.mouseover.pos #NOTE: Typically a Point2D struct, but might be nothing.
InspectDR.handleevent_mousepress(pwidget, InspectDR.CtrlElement, event.x, event.y)
end
end
end
Note that I now had to add a direct reference to InspectDR
for all function calls/structure definitions/etc defined in the InspectDR module. These functions/structures/… are not exported by InspectDR - so they are not otherwise available from your own function’s scope.
Hope that helps.