Detecting which subpanel & control was target of interaction

Hi everyone!

With the great help of some of you I have made a panel with different subpanels, all with the same set of controls.
I would now need to know the subpanel the user interacted with upon pressing a button, a checkbox or a popupmenu.

Using the Proc associated with checkboxes, I have been testing several operations to print to the console the results of my tests, but I don't seem to be able to print more than the name of the parent panel, instead of the subpanel.

Could anyone help?

Thanks in advance!
R.

The Panel looks like this:

Function MakePanel()
    NewPanel /W=(0,0,1200,600) /N=MyFunnyPanel/k=1
    //Define Vertical guides
    DefineGuide UGV0={FL,200},UGV1={UGV0,0.33333333,FR},UGV2={UGV0,0.66666666, FR}
    //Define Horizonzal guides
    DefineGuide UGH0={FB,0.5,FT}
   
    string quote = "\""
    String DataTypeList = quote + "Alpha;Beta;Delta;Gamma;Theta" + quote
    String SectionList = quote + "First;Second;Third;Fourth;" + quote
   
    //Create subpanels/subwindows where data will be displayed according to user input on controls
    Variable i
    for(i = 0; i < 6; i += 1)
        switch(i)
            case 0:
                NewPanel/FG=(UGV0,FT,UGV1,UGH0)/HOST=MyFunnyPanel
                break
            case 1:
                NewPanel/FG=(UGV1,FT,UGV2,UGH0)/HOST=MyFunnyPanel
                break
            case 2:
                NewPanel/FG=(UGV2,FT,FR,UGH0)/HOST=MyFunnyPanel
                break
            case 3:
                NewPanel/FG=(UGV0,UGH0,UGV1,FB)/HOST=MyFunnyPanel
                break
            case 4:
                NewPanel/FG=(UGV1,UGH0,UGV2,FB)/HOST=MyFunnyPanel
                break
            case 5:
                NewPanel/FG=(UGV2,UGH0,FR,FB)/HOST=MyFunnyPanel
                break
        endswitch
       
        //Names of Controls
        String SelectData = "SelectData"+num2str(i)
        String Selectsection = "SelectSection"+num2str(i)
        String CheckTS = "CheckTS"+num2str(i)
        String CheckHist = "CheckHist"+num2str(i)
        String CheckBar = "CheckBar"+num2str(i)
        String PopButton = "PopButton"+num2str(i)
       
        //Indicate controls needed             
        PopupMenu $SelectData, title="Data Type", bodyWidth=110, value=#DataTypeList, pos={120,10}     
        PopupMenu $SelectSection, title="Section", bodyWidth=100, value=#SectionList, pos={270,10}
       
        CheckBox $CheckTS,pos={5,30},size={75,15},title="Time Series",value=1,mode=1, proc=CheckPlotTypeProc
        CheckBox $CheckHist,pos={95,30},size={75,15},title="Histogram",value=0,mode=1, proc=CheckPlotTypeProc
        CheckBox $CheckBar,pos={185,30},size={75,15},title="Average",value=0,mode=1, proc=CheckPlotTypeProc
       
        Button $PopButton,title="pop",size={30,20}, pos={280,30}
        // add more controls here...
 
        RenameWindow #,$("P" + num2istr(i)) //Each subwindow has a name
    endfor
    SetActiveSubwindow ## //Go back to parent window
    String/G ListOFSubWindows = ChildWindowList("MYFunnyPanel")
End
The controls are on sub panels so they do not need unique names (only unique within each sub panel).
As an example, see below:
Function MakePanel()
    NewPanel /W=(0,0,1200,600) /N=MyFunnyPanel//k=1
    //Define Vertical guides
    DefineGuide UGV0={FL,200},UGV1={UGV0,0.33333333,FR},UGV2={UGV0,0.66666666, FR}
    //Define Horizonzal guides
    DefineGuide UGH0={FB,0.5,FT}
 
    string quote = "\""
    String DataTypeList = quote + "Alpha;Beta;Delta;Gamma;Theta" + quote
    String SectionList = quote + "First;Second;Third;Fourth;" + quote
   
    String sSubPanelName
 
    //Create subpanels/subwindows where data will be displayed according to user input on controls
    Variable i
    for(i = 0; i < 6; i += 1)
        switch(i)
            case 0:
                NewPanel/FG=(UGV0,FT,UGV1,UGH0)/HOST=MyFunnyPanel
                break
            case 1:
                NewPanel/FG=(UGV1,FT,UGV2,UGH0)/HOST=MyFunnyPanel
                break
            case 2:
                NewPanel/FG=(UGV2,FT,FR,UGH0)/HOST=MyFunnyPanel
                break
            case 3:
                NewPanel/FG=(UGV0,UGH0,UGV1,FB)/HOST=MyFunnyPanel
                break
            case 4:
                NewPanel/FG=(UGV1,UGH0,UGV2,FB)/HOST=MyFunnyPanel
                break
            case 5:
                NewPanel/FG=(UGV2,UGH0,FR,FB)/HOST=MyFunnyPanel
                break
        endswitch
       
        sSubPanelName = "P" + num2istr(i)
        RenameWindow #,$sSubPanelName //Each subwindow has a name
       
        //Names of Controls
 
        //Indicate controls needed             
        PopupMenu SelectData, title="Data Type", bodyWidth=110, value=#DataTypeList, pos={120,10}      
        PopupMenu SelectSection, title="Section", bodyWidth=100, value=#SectionList, pos={270,10}
 
        CheckBox CheckTS,pos={5,30},size={75,15},title="Time Series",value=1,mode=1, proc=CheckPlotTypeProc
        CheckBox CheckHist,pos={95,30},size={75,15},title="Histogram",value=0,mode=1, proc=CheckPlotTypeProc
        CheckBox CheckBar,pos={185,30},size={75,15},title="Average",value=0,mode=1, proc=CheckPlotTypeProc
 
        Button PopButton,title="pop",size={30,20}, pos={280,30}, proc=MyPopButtonProc
        // add more controls here...
 
        SetActiveSubwindow ## //Go back to parent window
    endfor
    String/G ListOFSubWindows = ChildWindowList("MYFunnyPanel")
End

Function MyPopButtonProc(B_Struct) : ButtonControl
    STRUCT WMButtonAction &B_Struct
   
    if(B_Struct.eventCode != 2) // ignore everything except mouse up
        return 0
    endif
   
    String sWin = B_Struct.win
   
    String sSubPanelNumber
    SplitString/E=("#P([[:digit:]]+)") sWin, sSubPanelNumber
    Variable vSubPanelNumber = str2num(sSubPanelNumber)
   
    String sSelectDataValue, sSelectSectionValue
   
    ControlInfo /W=$sWin SelectData
    sSelectDataValue    = S_Value
   
    ControlInfo /W=$sWin SelectSection
    sSelectSectionValue = S_Value
   
    printf "Panel = %g, DataValue = %s, SectionValue = %s\r", vSubPanelNumber, sSelectDataValue, sSelectSectionValue
   
    return 0
End


Hope this helps,
Kurt
Sorry John, could you please expand that a bit further?

From DisplayHelpTopic "WMButtonAction" i saw this: "char win[MAX_WIN_PATH+1] // Host window or subwindow name" sort of matching what you say but I have no idea of what to do with it.

I guess that I could use a swich-case-endswich approach combined with eventcode numbering (Case 2) to detect mouse click on control, but how do I go from that to extracting the subwindow name and control name is not entirely clear to me.

Thanks for the help!
Kurt, many thanks for this - I guess we were posting almost at the same time.
I'll have a look. As you can see your previous example for the overall panel design was very helpful.
Many thanks again!
Cheers,
R.
rhjpires wrote:
Sorry John, could you please expand that a bit further?

From DisplayHelpTopic "WMButtonAction" i saw this: "char win[MAX_WIN_PATH+1] // Host window or subwindow name" sort of matching what you say but I have no idea of what to do with it.

I guess that I could use a swich-case-endswich approach combined with eventcode numbering (Case 2) to detect mouse click on control, but how do I go from that to extracting the subwindow name and control name is not entirely clear to me.

Thanks for the help!

It looks like you are already doing it:
    ControlInfo /W=$sWin SelectData

So maybe I misunderstood what the present problem is. In my testing, bstruc.win contains the full subwindow path to the subwindow that owns the button that triggered your action proc.

John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
Thank you John. I needed a bit of studying, all is more clear now.

Cheers,
R.