
popupmenus in Igor7

jamie
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
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