SetVariable control not responding

I created a panel with a SetVariable control and a refresh button.

The refresh button is used to kill and recreate the panel.

Once I click the refresh button, the SetVariable control stops responding. The text I typed in the SetVariable control will be rejected.

Is there anything wrong with this code?

Thank you for your help.

#pragma TextEncoding = "UTF-8"
#pragma rtGlobals=3             // Use modern global access method and strict wave access
#pragma DefaultTab={3,20,4}     // Set default tab width in Igor Pro 9 and later

Function testfunc()
    String/G str
    KillWindow/Z test
    NewPanel/K=1/N=test/W=(100,100,500,200)
    Button button0 title="Refresh",size={120,25},pos={15,10},proc=ButtonProc
    SetVariable setvar0 title="string input", value=str, size={280,25},pos={15,60}, fSize=13
End

Function ButtonProc(ba) : ButtonControl
    STRUCT WMButtonAction &ba

    switch( ba.eventCode )
        case 2: // mouse up
            // click code here
            testfunc()
            break
        case -1: // control being killed
            break
    endswitch

    return 0
End

 

Your code is working fine here on Windows both in Igor 8 (build 37948) and Igor 9 (build 38378). With 'stop responding' you mean that your string variable 'str' is not updated anymore? Or is the text you type just disappearing?

By the way, maybe it is not such a great idea to kill / rebuild the panel while code with associated with the panel runs. To prevent that for sure, I would push the call to testfunc() into the operations queue via

Execute/P/Q "testfunc()"

 

Good advice on using Execute/P. chozo is a real Igor pro!

I would also like to suggest that you use data folder paths and window names in code like this:

Function testfunc()
    String/G root:str
    KillWindow/Z test
    NewPanel/K=1/N=test/W=(100,100,500,200)
    Button button0 title="Refresh", win=test,size={120,25},pos={15,10},proc=ButtonProc
    SetVariable setvar0,win=test,title="string input",value=str,size={280,25},pos={15,60},fSize=13
End

Function ButtonProc(ba) : ButtonControl
    STRUCT WMButtonAction &ba

    switch( ba.eventCode )
        case 2: // mouse up
            // click code here
            testfunc()
            break
        case -1: // control being killed
            break
    endswitch

    return 0
End

After you click the Refresh button, does the Refresh button work?

In reply to by chozo

chozo wrote:

Your code is working fine here on Windows both in Igor 8 (build 37948) and Igor 9 (build 38378). With 'stop responding' you mean that your string variable 'str' is not updated anymore? Or is the text you type just disappearing?

By the way, maybe it is not such a great idea to kill / rebuild the panel while code with associated with the panel runs. To prevent that for sure, I would push the call to testfunc() into the operations queue via

Execute/P/Q "testfunc()"

Thank you for the comments. My environment is Igor 9 (Build 37840) on macOS 12.2.1. I have used this procedure for a few months but for the first time noticed this issue.

 

With 'stop responding', I meant that the string variable 'str' is not updated anymore.

For example,

1. Type 'test' in SetVariable Control

2. Click the Refresh button

3. Type 'testtest' in SetVariable Control or delete 'test'

4. SetVariable Control forcedly changes back to 'test'

Here is a link to the screen record.

https://www.dropbox.com/t/UT724uac7cYv1mt8

 

I will use Execute/P in my procedure. Thank you!

Before you kill the panel (with a /Z flag), do a test for weather the panel exists. If so, capture the set variable input to your str global. Then, kill the panel and rebuild. If the panel does not exist, exit.

I have to wonder also whether you are getting caught by an issue that you enter text but do not type a return keystroke in the setvariable input field.

 

Just some additional 2 cents from my side: Putting aside the code issue, I don't know your reason for this approach, but I think usually it is not necessary to rebuild a panel (especially with a button click). How about just updating the relevant controls or data instead?

I have tried the first posted code on Igor Pro 8.04 in the same macOS system, and the SetVariable control worked fine even after 'kill and rebuild' the panel.

 

I followed the suggestions and created a code without killing and rebuilding.

However, the SetVariable stops responding after clicking the refresh button.

Here is the code I used.

Function testfunc()
    String/G root:str
//    KillWindow/Z test
    DoWindow test
    If(V_flag == 0)
        NewPanel/K=1/N=test/W=(100,100,500,200)
    Endif
    Button button0 title="Refresh", win=test,size={120,25},pos={15,10},proc=ButtonProc
    SetVariable setvar0,win=test,title="string input",value=str,size={280,25},pos={15,60},fSize=13
End

Function ButtonProc(ba) : ButtonControl
    STRUCT WMButtonAction &ba

    switch( ba.eventCode )
        case 2: // mouse up
            // click code here
            Execute/P/Q "testfunc()"
            break
        case -1: // control being killed
            break
    endswitch

    return 0
End

Of course, I can do the same thing without clicking the Refresh button.

So, I

1. Typed the testfunc() in the command window

2. Entered an 'abc' text in the SetVariable Control and confirmed the global str contains the 'abc.'

3. Then, closed the panel

4. Typed testfunc() in command window again

5. SetVariable control stops responding

 

Now, I wonder the SetVariable issue might not be a problem with the code but a bug of Igor 9.

 

 

I guess you make sure that you press enter every time after inputting something into the SetVariable control. Then this is maybe a macOS related bug and probably has nothing to do with button control. Does this also happen when you remove the button+code? Like this (by the way, you should probably define the full path to the string variable when assigning to the control):

Function testfunc()
    String/G root:str
    DoWindow test
    If(V_flag == 0)
        NewPanel/K=1/N=test/W=(100,100,500,200)
    Endif
    SetVariable setvar0,win=test,title="string input",value=root:str,size={280,25},pos={15,60}
End

 

I just tried Maru's latest code in Igor 9 on my Macintosh running 10.14.6 (yes, pretty old!). I think I'm seeing the problem- after pressing the Refresh button, I enter some new text in the SetVariable. When I press Return, I get a beep and nothing happens. Apparently something has gone wrong with the SetVariable, but I don't know what. I'm working on it.

And the latest build of Igor 9 makes the code work as expected. The only change to SetVariable I see has a commit message 

Added setting of the isString member when attaching a string global variable or wave. This fixes a problem in which you can't change the text of a floating panel with global string variable in a panel made with /FLT=2. Don't know why it makes a difference in such a corner case! Fixes #4075: SetVariable with global string doesn't work in a floating panel
 

Seems now that the floating panel part of this isn't required to trigger the bug. I'm not sure why it is, but I think this fixes your problem. You can get the latest build by selecting Help->Igor Pro Nightly Builds

> chozo

Thank you for the advices.

I have tried your modified code without the button part. But the SetVariable stopped responding after I close and reopen the panel.

As suggested by johnweeks, it seems a problem with current Igor 9.

 

> johnweeks

I am happy to know this issue will be solved in the future updates. I have tried the Nightly Builds and the SetVariable works fine!