Bug in popupContextualMenu?
josh.liptonduffin_1
Hi all, I have experienced a weird behavior in popuContextualMenu where the value of the returned S_selection variable does not match what was in the menu's custom string in the case where an exclamation point is included in the menu list.
Example non-working code below: if the user clicks on a trace, a single-item popup menu displays, but the stringswitch statement returns nothing.
function fitContextMenuHook(hs)
STRUCT WMWinHookStruct &hs
variable ret=0
strswitch(hs.eventName)
case "mousedown":
Variable isContextualMenu = hs.eventMod %& 0x10 //did the usr right click?
if(!isContextualMenu)
break //do nothing if it was a left click
endif
string clickedTraceName = tracefrompixel(hs.mouseLoc.h, hs.mouseLoc.v,"")
print clickedTraceName
if (strlen(clickedTraceName)) //if there was no trace evaluates to zero (ie false)
popupContextualMenu/C=(hs.mouseLoc.h, hs.mouseLoc.v) "Fit me!;"
print s_selection
StrSwitch(S_selection)
case "Fit me!": ///////DOES NOT RETURN TRUE WHEN USER SELECTS FROM THE SINGLE-ITEM MENU
print "fit me baby one more time"
break
endswitch
ret=1
endif
break
endswitch
return ret
end
STRUCT WMWinHookStruct &hs
variable ret=0
strswitch(hs.eventName)
case "mousedown":
Variable isContextualMenu = hs.eventMod %& 0x10 //did the usr right click?
if(!isContextualMenu)
break //do nothing if it was a left click
endif
string clickedTraceName = tracefrompixel(hs.mouseLoc.h, hs.mouseLoc.v,"")
print clickedTraceName
if (strlen(clickedTraceName)) //if there was no trace evaluates to zero (ie false)
popupContextualMenu/C=(hs.mouseLoc.h, hs.mouseLoc.v) "Fit me!;"
print s_selection
StrSwitch(S_selection)
case "Fit me!": ///////DOES NOT RETURN TRUE WHEN USER SELECTS FROM THE SINGLE-ITEM MENU
print "fit me baby one more time"
break
endswitch
ret=1
endif
break
endswitch
return ret
end
However, the following code works:
function fitContextMenuHook(hs)
STRUCT WMWinHookStruct &hs
variable ret=0
strswitch(hs.eventName)
case "mousedown":
Variable isContextualMenu = hs.eventMod %& 0x10 //did the usr right click?
if(!isContextualMenu)
break //do nothing if it was a left click
endif
string clickedTraceName = tracefrompixel(hs.mouseLoc.h, hs.mouseLoc.v,"")
print clickedTraceName
if (strlen(clickedTraceName)) //if there was no trace evaluates to zero (ie false)
popupContextualMenu/C=(hs.mouseLoc.h, hs.mouseLoc.v) "Fit me!;"
print s_selection
StrSwitch(S_selection)
case "Fit me": ///THIS RETURNS TRUE
print "fit me baby one more time"
break
endswitch
ret=1
endif
break
endswitch
return ret
end
STRUCT WMWinHookStruct &hs
variable ret=0
strswitch(hs.eventName)
case "mousedown":
Variable isContextualMenu = hs.eventMod %& 0x10 //did the usr right click?
if(!isContextualMenu)
break //do nothing if it was a left click
endif
string clickedTraceName = tracefrompixel(hs.mouseLoc.h, hs.mouseLoc.v,"")
print clickedTraceName
if (strlen(clickedTraceName)) //if there was no trace evaluates to zero (ie false)
popupContextualMenu/C=(hs.mouseLoc.h, hs.mouseLoc.v) "Fit me!;"
print s_selection
StrSwitch(S_selection)
case "Fit me": ///THIS RETURNS TRUE
print "fit me baby one more time"
break
endswitch
ret=1
endif
break
endswitch
return ret
end
So it seems that while the popup menu contains just one item, the string "Fit me!", s_selection seems to return "Fit me", without the exclamation point.
Is this a bug? I haven't tested it with other non alphanumeric variables.
Your menu item ends with "!", which is a special character in a menu (it adds a check mark to the menu item). This is described in:
DisplayHelpTopic "Special Characters in Menu Item Strings"
You can get the behavior you expect if you tell Igor to turn off special character interpretation using this command instead of the one you were using:
popupContextualMenu/C=(hs.mouseLoc.h, hs.mouseLoc.v) "\\M0Fit me!;"
For more details, execute:
DisplayHelpTopic "Enabling and Disabling Special Character Interpretation"
August 6, 2021 at 08:38 pm - Permalink
Thank you for that - should have RTFM'ed better....
August 8, 2021 at 05:06 am - Permalink