Simple String Input for Panel

I've copied some code from this thread:

http://www.igorexchange.com/node/5588

and modified it a little, to have the below. It makes a simple panel with functional button and non-functional string input.

I'm not familiar with panel coding, and am not sure why the string gets erased after I type in the sample entry.


Menu "Analysis"
    "Open Calculate Panel",/Q, OpenCalculatePanel()
End
 
Function OpenCalculatePanel()
    DoWindow/K CalculatePanel
    Newpanel /W=(248,115,730,626)/N=CalculatePanel // apear the panel
    modifypanel cbRGB=(0,39168,39168),fixedsize=1 //color of panel
    showtools /A
    setdrawlayer/K userback
    Setdrawenv fsize=20,fstyle=1,textrgb=(65535,65535,65535)
    drawtext 115,32,"Load Files and Parameters"
    //drawpict 2,2,2,1,1    //no: 4 numbers and a picture name are needed here
    Button button1,pos={160,165},size={161,35},proc=buttonproc,title="Load Waves"
    SetVariable sample_name title="sample ",size={200,136},pos={136,100},proc=setvariableproc
Endmacro
 
Function ButtonProc(ctrlname) : ButtonControl
    string ctrlname
    Print "Button pressed"
    // Call your calculate routine here
End

Function setvariableproc(ctrlName) : setvariablecontrol
    String ctrlName
    Print "Button pressed"
    // Call your calculate routine here
End
I've modified the setvariableproc function to give this:

Menu "Analysis"
    "Open Calculate Panel",/Q, OpenCalculatePanel()
End
 
Function OpenCalculatePanel()
    DoWindow/K CalculatePanel
    Newpanel /W=(248,115,730,626)/N=CalculatePanel // apear the panel
    modifypanel cbRGB=(0,39168,39168),fixedsize=1 //color of panel
    showtools /A
    setdrawlayer/K userback
    Setdrawenv fsize=20,fstyle=1,textrgb=(65535,65535,65535)
    drawtext 115,32,"Load Files and Parameters"
    //drawpict 2,2,2,1,1    //no: 4 numbers and a picture name are needed here
    Button button1,pos={160,165},size={161,35},proc=buttonproc,title="Load Waves"
    SetVariable sample_name title="sample ",size={200,136},pos={136,100},proc=setvariableproc
Endmacro
 
Function ButtonProc(ctrlname) : ButtonControl
    string ctrlname
    Print "Button pressed"
    // Call your calculate routine here
End

Function setvariableproc(ctrlName) : setvariablecontrol
    String ctrlName
    controlinfo setvariableproc
    print s_value
   
    // Call your calculate routine here
End


The error is "expected right parenthesis." I can't find a left parenthesis that is unaccounted for...
Start with this instead ...

Menu "Analysis"
    "Open Calculate Panel",/Q, OpenCalculatePanel()
End
 
Function OpenCalculatePanel()
    DoWindow/K CalculatePanel
    Newpanel /W=(248,115,730,626)/N=CalculatePanel // apear the panel
    Button button1,pos={160,165},size={161,35},proc=ButtonProc,title="Load Waves"
    SetVariable sample_name title="sample ",size={200,136},pos={136,100},proc=SetVarProc, value=_STR:"Hello World!"
        return 0
end

Function SetVarProc(sva) : SetVariableControl
        STRUCT WMSetVariableAction &sva

        switch(sva.eventCode)
               case 1:
               case 2:
               case 3:
                     print sva.sval
                     break
        endswitch
        return 0
end


Function ButtonProc(ba) : ButtonControl
        STRUCT WMButtonAction &ba

        switch(ba.eventCode)
               case 2:
                     print "Button Pressed"
                     break
        endswitch
        return 0
end


Learn to use the new structure forms of the controller functions. They are generated automatically when you press the New button on the edit dialog box for the control itself.

Your code was missing an assignment for the value for the setvariable.

Edit: Fixed to show string variable not number value

--
J. J. Weimer
Chemistry / Chemical & Materials Engineering, UAH
This is great.

I've documented my understanding of some of the code. I've also simplified to get at what I would like my button to do: make a string in root and call another function. It works!

// creates selection in analysis pull down menu

Menu "Analysis"
    "Open Calculate Panel",/Q, OpenCalculatePanel()
End
 
// creates panel, defines operations
 
Function OpenCalculatePanel()

// make space for the pane to live, name it

    DoWindow/K CalculatePanel
    Newpanel /W=(248,115,730,626)/N=CalculatePanel
   
// create a button, with title "Load Waves" that execeutes the procedure ButtonProc when pressed   
   
    Button button1,pos={160,165},size={161,35},proc=ButtonProc,title="String Maker"
        return 0
end

 
// ButtonProc runs when the button is pressed.

// The action procedure, which may be a function or a macro, has the format:
//Function procName (ctrlName) : ButtonControl
//  String ctrlName
//  ...
//End
// The ": ButtonControl" designation tells Igor to include this procedure in the Procedure pop-up menu in the Button Control dialog.
//A Button action procedure using a structure has the format:
//Function newActionProcName(B_Struct) : ButtonControl
//  STRUCT WMButtonAction &B_Struct
//  ...
//End

// i suppose ba stands for "button action" and is the manner in which
// button is used
 
Function ButtonProc(ba) : ButtonControl

// why is WMButtonAction important? It isn't used elsewhere in the code

        STRUCT WMButtonAction &ba
 
        switch(ba.eventCode)
       
 // case 2 tells you that the mouse click has been released (click, then let go)
       
               case 2:
                     setdatafolder root:
                     string/g string1 = "string created"
                     youdiditalert()
// break is not strictly necessary but recommended and usually necessary
                     break
        endswitch
        return 0
end

function youdiditalert()
doalert 0, "you did it!"
return -1
end
Ok, I think I've gotten the variability I would like now to build a more complex panel.

Thanks a lot for the starter code and for pushing me to use STRUCT framework. The ability to pull values from the input is convenient!

// creates selection in analysis pull down menu

Menu "Analysis"
    "Open Calculate Panel",/Q, OpenCalculatePanel()
End
 
// creates panel, defines operations
 
Function OpenCalculatePanel()

// make space for the pane to live, name it

    DoWindow/K CalculatePanel
    Newpanel /W=(248,115,730,626)/N=CalculatePanel
   
// create a button, with title "Load Waves" that execeutes the procedure ButtonProc when pressed       
    Button button1,pos={160,165},size={161,35},proc=ButtonProc,title="String Maker"
//  
    SetVariable sample_name title="sample ",size={200,136},pos={136,100},proc=SetVarProc, value=_STR:"sample name"
    SetVariable ref_name title="reference ",size={200,136},pos={136,200},proc=SetVarProc, value=_STR:"reference name"
    SetVariable temp_list title="temperature list ",size={400,136},pos={40,300},proc=SetVarProc, value=_STR:"temperature list;separated by ; ex. 10;20 "
        return 0
end

Function SetVarProc(sva) : SetVariableControl
        STRUCT WMSetVariableAction &sva
 
        switch(sva.eventCode)
               case 1:
               case 2:
               case 3:
                     string/g sam = sva.sval
                  if(cmpstr(sva.ctrlname,"temp_list")==0)
                     print sva.ctrlname
                   endif
                     break
        endswitch
        return 0
end
Consider this instead ...

Function SetVarProc(sva) : SetVariableControl
    STRUCT WMSetVariableAction &sva

    switch( sva.eventCode )
        case 1: // mouse up
        case 2: // Enter key
        case 3: // Live update
            print "you have changed ", sva.ctrlname
            strswitch(sva.ctrlname)
                case "temp_list":
                    // do stuff here
                    break
                case "...":
                    // do stuff here
                    break
                ...
            endswitch
            break
        case -1: // control being killed
            break
    endswitch
    return 0
end


I recommend not to store switch values in globals when you can instead get their values as needed with ControlInfo.

--
J. J. Weimer
Chemistry / Chemical & Materials Engineering, UAH
> // why is WMButtonAction important? It isn't used elsewhere in the code

This is the WaveMetrics internal structure for button actions. Its storage location is "pointed to" by the reference &ba.

A pointer &ba is an address to the location of the WMButtonAction structure. The structure has all the values (strings, numbers, titles, mouse states ...) in it. The function call looks up the address &ba, goes to it, and reads the values in the (well-defined) WMButtonAction structure.

--
J. J. Weimer
Chemistry / Chemical & Materials Engineering, UAH
jjweimer wrote:
> // why is WMButtonAction important? It isn't used elsewhere in the code

This is the WaveMetrics internal structure for button actions. Its storage location is "pointed to" by the reference &ba.

A pointer &ba is an address to the location of the WMButtonAction structure. The structure has all the values (strings, numbers, titles, mouse states ...) in it. The function call looks up the address &ba, goes to it, and reads the values in the (well-defined) WMButtonAction structure.

--
J. J. Weimer
Chemistry / Chemical & Materials Engineering, UAH


Yeah, I've been learning about this today. I like this feature! I don't exactly understand the syntax, with the ampersand and stuff...but if I take it as a given, everything is going smoothly. And I've been able to extract other values as well.
jjweimer wrote:
Consider this instead ...

Function SetVarProc(sva) : SetVariableControl
    STRUCT WMSetVariableAction &sva

    switch( sva.eventCode )
        case 1: // mouse up
        case 2: // Enter key
        case 3: // Live update
            print "you have changed ", sva.ctrlname
            strswitch(sva.ctrlname)
                case "temp_list":
                    // do stuff here
                    break
                case "...":
                    // do stuff here
                    break
                ...
            endswitch
            break
        case -1: // control being killed
            break
    endswitch
    return 0
end


I recommend not to store switch values in globals when you can instead get their values as needed with ControlInfo.

--
J. J. Weimer
Chemistry / Chemical & Materials Engineering, UAH


I responded to this in a separate thread, because I think it's a separate topic: http://www.igorexchange.com/node/7118

Thanks for the advice...see what I did there and let me know if I'm headed towards a dead end with the way I use global strings and variables. I *think* I'm safe, but I'd like to hear what you guys think.