SetVar and active setvar proc functions
daggaz
I tried to do the same thing with a SetVar, but I cant even get it to run a print statement. Ive used SetVar to initiate variables before in a user-interface, but I used a second function to read all those variable and then feed them into the main function. This time, I would just like the proc function to run some code if the user pushes the up/down arrows or enters a new value into the field. Is it possible or have I misunderstood the functionality here?
function setvar_proc(setvar_z, z, varStr, varName) :setVariableControl
string setvar_z // name of my control
variable z // the variable being manipulated
string varStr // not sure what this is for
string varName // again, not entirely sure what you would use this for
do a whole bunch of stuff like load some new images in my fancy panels based on the new z value
print "Oh Igor, why don't you love me anymore?"
end
string setvar_z // name of my control
variable z // the variable being manipulated
string varStr // not sure what this is for
string varName // again, not entirely sure what you would use this for
do a whole bunch of stuff like load some new images in my fancy panels based on the new z value
print "Oh Igor, why don't you love me anymore?"
end
My button shows up with the correct variable value inside (and moving the slider keyed to the same variable changes this value, as well the opposite, changing the value here moves my slider), but nothing else happens. Igor refuses to print even.
Variable/G root:MyValue
NVAR vMyValue=root:MyValue
vMyValue=1
NewPanel /W=(150,77,450,277)
SetVariable setvar0,pos={2,2},size={120,16},proc=SetVarProc,title="This is my value:"
SetVariable setvar0,limits={0,10,1},value= root:MyValue
End
Function SetVarProc(sva) : SetVariableControl
STRUCT WMSetVariableAction &sva
switch( sva.eventCode )
case 1: // mouse up
print "Mouse Up event"
break
case 2: // Enter key
print "Enter Key Event"
break
case -1: // control being killed
break
endswitch
return 0
End
Hope this helps,
Kurt
May 13, 2013 at 02:08 am - Permalink
Im totally new to this structure stuff and unfortunately the help file "example" is too bare-bones for me to understand anything at all of what is actually happening.
EDIT: Your stand alone code does exactly what I am trying to do tho, so I will just play around with that for a while until I understand things. Thanks, man.
May 13, 2013 at 05:48 am - Permalink
For example, for the SetVariable control, you can have a non-structure based procedure looking like this:
String ctrlName
Variable varNum
String varStr
String varName
End
which is much the same as you had in your original posting, or the same functionality (and the additional event handler) in a structure based function as this:
STRUCT WMSetVariableAction &sva
String ctrlName = sva.ctrlName
Variable varNum = sva.dval
String varStr = sva.sval
String varName = sva.vName
switch( sva.eventCode )
case 1: // mouse up
case 2: // Enter key
case 3: // Live update
Variable dval = sva.dval
String sval = sva.sval
break
case -1: // control being killed
break
endswitch
return 0
End
I tend to look for the details by going to Help...Command Help, which opens up a Help Browser, and then scrolling down the list to select WMSetVariableAction in the left hand listbox, or choosing SetVariable in the left hand listbox, and then scrolling down to look at the Details section.
Hope this helps!
Kurt
May 13, 2013 at 06:14 am - Permalink
In your example, it would seem that, unless the "do a whole bunch of stuff..." causes the function to exit before the print statement is encountered, setvar_proc isn't being called as a result of user interaction with the setvar control. In the control definition is there a part that reads "proc=setvar_proc"?
Have you tried using the debugger? Although the print statement in setvar_proc is helpful, setting a break point in that function and stepping through it line by line after it has been called might be even more enlightening.
May 13, 2013 at 06:20 am - Permalink
Vagueness regarding input parameters is often a source of frustration. For example, I will often find a short sentence describing what a parameter is, but nothing at all as to what it does. Perhaps to a more experienced person, the functionality is obvious from the definition, but to somebody like me its a frustrating cyclical argument. Most of the time the definitions are very helpful, but not always. String varName = "the name of the variable" for example.. Obviously its a string containing the variable name, I can see that without the definition which tells me nothing new. But since when do I need a string to name a variable, isn't that what the variable command is for? And is the exception so important that there is a specific parameter for this? What happens if I leave it out? etc.. etc..
Obviously you guys cant be expected to write an in-depth introductory course for the newbies. And actually the IGOR documentation already comes wonderfully close, one of the reasons I love this program. One way to improve things would be to allow access to the code in the examples. The help files pointed me straight to a great slider example, but for the love of Igor I just couldn't find the code running the panel, which is what I really needed to see. It already exists, so having it pop up when you run the examples would be an easy and very practical addition to the documentation.
Thanks again, will plug away at this structure stuff now for a few days =)
EDIT: "In the control definition is there a part that reads "proc=setvar_proc"? Yes, and I use liberal print lines to test code for bugs. I havent played with the debugger yet actually, I will have to look into that. I'm sure I was doing something wrong with the whole structure mumbojumbo in this case..
May 15, 2013 at 12:18 am - Permalink
We try to make our documentation helpful... I admit that one sounds just a bit on the, um, cryptic side :) Perhaps the explanations here will help:
DisplayHelpTopic "Built-in Structure Reference"
I expect that you meant "vname" instead of "varname" but that's probably a result of frustration...
Such a member would be aimed at using a single action procedure for more than one control. In such a case, you might well need a programmatic way to find out the particular variable that is connected to the particular control that triggered your action procedure.
But it is our intention to make the documentation helpful. If you have suggestions to improve it, please feel free to e-mail support@wavemetrics.com. We do actually listen!
A couple of things that can help:
If you put the panel into Draw mode (Show Tools) click a control to select it, then right click you will get a contextual menu that includes Go To xxx which will take you to the action procedure for the control.
In the code, if you right-click on the action structure name, it will take you to the documentation for the structure members. Which may be of limited help :)
In Igor code in general, if you right-click on an Igor command you will get a menu that includes Help For xxx and Insert xxx Template.
That's really the only way to learn it. It can be painful, though.
You really want to do that. I can't imagine doing anything more than the most basic coding without it.
John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
May 15, 2013 at 10:21 am - Permalink