Trace Popup position, GetLastUserMenuInfo

If I add an item to the trace popup menu, it would be great to be able to figure out where the user (right) clicked to invoke the menu. Would it be possible to add that info, say, through GetLastUserMenuInfo? For a trace popup I would want to know the pixel in local coordinates. If I use GetMouse, I can find the position of the (left) click within the menu. My workaround for now is to click as far to the left as possible within the trace popup (I'm just trying to extract the x position of the first click that invoked the popup).
thomas_braun wrote:
Shouldn't AxisValFromPixel allow to convert from pixel coordinates into axis coordinates?


Yes, that's exactly what I'm using, but I wish to know the pixel value for the right click that precedes the left click that invokes my function, the one that caused the popup to be drawn at a particular location.
Adding a function to the trace popup is a great, low overhead way of being able to do useful things to a trace, but it would be even better if I had access to the click coordinates. I hope that makes sense.
sure

Menu "TracePopup"
    "click somewhere here", /Q, TraceClicker()
end

function TraceClicker()

    // figure out graph and trace names
    GetLastUserMenuInfo
   
    // figure out mouse position within graph on SECOND click
    getmouse /W=$S_graphName   
    string s_info=traceinfo(S_graphName, S_traceName, 0)
    variable x_pos=AxisValFromPixel(S_graphName, stringbykey("XAXIS",s_info) , v_left)
   
    string msg
    sprintf msg, "you clicked on %s in %s\r" S_traceName, S_graphname
    sprintf msg, "%s and then clicked at x = %g" msg, x_pos
    doalert 0, msg
    return 1
end
So what I'd like is for GetLastUserMenuInfo to create its own V_left
You'd need to set a window hook on your graph that either implements its own contextual menu (using PopupContextualMenu) instead of Igor's regular contextual menu, or perhaps just saves coordinates of a click to a variable in some specific data folder that your TraceClicker function can then access.
aclight wrote:
You'd need to set a window hook on your graph that either implements its own contextual menu (using PopupContextualMenu) instead of Igor's regular contextual menu, or perhaps just saves coordinates of a click to a variable in some specific data folder that your TraceClicker function can then access.


Right, I can achieve this with window hooks, and if I was building a GUI around a specific window that would be fine. In fact I've already done this for windows where I wanted to highlight traces as I mouse over them, etc. But if I just want to add a couple of utility functions to the trace popup that may rarely get used it seems like a lot of overhead for me to be keeping track of the mouse in every graph window. That's exactly why I would want to add a function to the trace popup and have Igor look after the mouse.
I've found a simple workaround that doesn't require a hook function:

If I use a string function to set the menu item name, I can get the mouse position and save in global variable. Since the menu item is updated each time the trace menu is populated, this gives me the position of the right click for use in the function that runs when I left click the menu item :)
Menu "TracePopup", dynamic
    TraceClickerPosition(), /Q, TraceClicker()
end

function /s TraceClickerPosition()
   
    getmouse /W=kwTopWin
    variable /G V_TraceMenuX=V_left
    return "click somewhere here"
end

function TraceClicker()
 
    // figure out graph and trace names
    GetLastUserMenuInfo
 
    // figure out mouse position within graph on SECOND click
    getmouse /W=$S_graphName   
    string s_info=traceinfo(S_graphName, S_traceName, 0)
    NVAR V_TraceMenuX=V_TraceMenuX
    variable x_pos1=AxisValFromPixel(S_graphName, stringbykey("XAXIS",s_info) , V_TraceMenuX)
    variable x_pos2=AxisValFromPixel(S_graphName, stringbykey("XAXIS",s_info) , v_left)
 
    string msg
    sprintf msg, "you clicked on %s in %s at x = %g\r" S_traceName, S_graphname, x_pos1
    sprintf msg, "%s and then clicked the menu item at x = %g" msg, x_pos2
    doalert 0, msg
    return 1
end
That is very clever! Don't forget to add the ", dynamic" bit to the menu definition.

--Jim Prouty
Software Engineer, WaveMetrics, Inc.
Cool! This is a nice a utility function for the cases where hooks are, as you say, potentially extraneous. But of course ...

tony wrote:
But if I just want to add a couple of utility functions to the trace popup that may rarely get used it seems like a lot of overhead for me to be keeping track of the mouse in every graph window.


I cannot see where the processing overhead of a window hook is an issue really ...

idle
idle
idle
(... repeat X billion times)
--> graph hook processing event
idle
idle
idle
...


OTOH, I can see where the nuances required to program hooks properly can be less transparent than what your approach is.

--
J. J. Weimer
Chemistry / Chemical & Materials Engineering, UAH
jjweimer wrote:
Cool! This is a nice a utility function for the cases where hooks are, as you say, potentially extraneous. But of course ...

tony wrote:
But if I just want to add a couple of utility functions to the trace popup that may rarely get used it seems like a lot of overhead for me to be keeping track of the mouse in every graph window.


I cannot see where the processing overhead of a window hook is an issue really ...



Maybe 'overhead' was an inappropriate choice of word.

I'm not even sure that I could achieve this with hooks. I could use AfterWindowCreatedHook to set a named hook for each new graph window. The named hook (which would be called for every mousemoved event in every graph window, so not exactly idle) could intercept a right click and decide whether the click was a trace click, and I could create a custom popup, but then I'd lose the trace popup.

All I was trying to do was to add an item to the trace popup that would allow me to do something based on the position on the trace. For instance, I use it with the all traces popup to tag each trace at that x position with the name of the wave in a font color that matches the trace color. A trivial application, but something I often do and that I dislike doing with dialogs.
You could use the Window hook to field the mouse-down event, and put up your own contextual menu at that spot. It would override Igor's trace contextual menu, not add to it.

John Weeks
WaveMetrics, Inc.
support@wavemetrics.com