The list that "pops up" from a Popupmenus in Igor7 has a vertical bar down it, with an empty space on the left side. For color table popup menu (and possibly other popup modes), this space contains a checkmark for the currently selected item. Are there any (perhaps undocumented) hooks to use this left side space with user defined menu list popup menus? Like being able to populate it with checks or bullets for selected items? I currently do something like this:
function/S NQ_ChanSelectList (chanVarStr, nChans)
string chanVarStr
variable nChans
NVAR chanVar = $"root:Packages:twoP:Acquire:" + chanVarStr
string chanSelList = ""
variable iChan
for (ichan =0; iChan < nChans; iChan +=1)
if ((2^ichan) & chanVar)
chanSelList += "\\M1" + num2char(7) + " "
else
chanSelList += " "
endif
chanSelList += num2str (iCHan) + ";"
endfor
return chanSelList
end
Function testChan_PopMenuProc(pa) : PopupMenuControl
STRUCT WMPopupAction &pa
switch( pa.eventCode )
case 2: // mouse up
NVAR chanVar = root:Packages:twoP:Acquire:scanChans
String popStr = pa.popStr
if (char2num (popStr[0]) != 7) // adding a new channel
chanVar+= 2^(pa.popNum -1)
else
chanVar -=2^(pa.popNum -1)
endif
Variable popNum = pa.popNum
break
case -1: // control being killed
break
endswitch
//print chanVar
return 0
End
DisplayHelpTopic "Special Characters in Menu Item Strings"
But be aware that a PopupMenu control requires that special character interpretation be enabled, so you need to add "\\M1" to your menu items. DisplayHelpTopic "Enabling and Disabling Special Character Interpretation".
johnweeks wrote: DisplayHelpTopic "Special Characters in Menu Item Strings"
But be aware that a PopupMenu control requires that special character interpretation be enabled, so you need to add "\\M1" to your menu items. DisplayHelpTopic "Enabling and Disabling Special Character Interpretation".
Thanks John, that works, puts the checkmark in the intended location. It looks so much better.
Note that with this method of marking selections you can't use something like
if (char2num (popStr[0]) != 7)
to see if an item is selected; the checkmarks are not part of the string. It is easy to redo the functions so they work properly, though.
This code uses a variable for a bitwise channel selection (0 =1, 1-2, 2=4, 3=8, etc) and a string containing the list of channels. The popmenu shows the list of channels with selected channels checked. Selecting a currently unselected channel from the popmenu selects it, selecting a selected channel deselects it.
PopupMenu popup0,pos={1.00,1.00},size={135.00,23.00},proc=ChanPopMenuProc,title="Selected Channels"
PopupMenu popup0,mode=0,value= #"ChanSelectList ()"
string/G root:chanStr = "ch0-test1;ch1-test2;ch2-test3;ch3-test4;"
variable/G root:chanVar = 0
PopupMenu popup0,pos={1.00,1.00},size={135.00,23.00},proc=ChanPopMenuProc,title="Selected Channels"
PopupMenu popup0,mode=0,value= #"ChanSelectList ()"
function/S ChanSelectList ()
SVAR chanStr = root:chanStr
NVAR chanVar = root:chanVar
string chanSelList = ""
variable iChan, nchans = ItemsInList(chanStr, ";")
for (ichan =0; iChan < nChans; iChan +=1)
if ((2^ichan) & chanVar)
chanSelList += "\\M1" + StringFromList(iChan, chanStr, ";") + "!*;"
else
chanSelList += StringFromList(iChan, chanStr, ";") + ";"
endif
endfor
return chanSelList
end
Function ChanPopMenuProc(pa) : PopupMenuControl
STRUCT WMPopupAction &pa
switch( pa.eventCode )
case 2: // mouse up
NVAR chanVar = root:chanVar
variable chanPos = 2^(pa.popnum-1)
if (chanPos & chanVar) // deselecting a new channel
chanVar-= chanPos
else // selecting a channel
chanVar += chanPos
endif
break
case -1: // control being killed
break
endswitch
return 0
End
But be aware that a PopupMenu control requires that special character interpretation be enabled, so you need to add "\\M1" to your menu items. DisplayHelpTopic "Enabling and Disabling Special Character Interpretation".
John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
October 24, 2016 at 10:07 am - Permalink
Thanks John, that works, puts the checkmark in the intended location. It looks so much better.
Note that with this method of marking selections you can't use something like
to see if an item is selected; the checkmarks are not part of the string. It is easy to redo the functions so they work properly, though.
This code uses a variable for a bitwise channel selection (0 =1, 1-2, 2=4, 3=8, etc) and a string containing the list of channels. The popmenu shows the list of channels with selected channels checked. Selecting a currently unselected channel from the popmenu selects it, selecting a selected channel deselects it.
October 26, 2016 at 10:42 am - Permalink