SciLab checkbox UIControl value not changing with state?

1.2k Views Asked by At

I'm trying to design a GUI in SciLab that updates it's properties depending on a checkmark. For example: A checkbox might enable and change the backrounds of several text boxes during a callback; or a pushbutton may require a certain number of checkboxes to be selected.

My problem is that I can't seem to develop a flow control statement for running instructions depending on the checkboxes state during a callback. My current UIControl element looks like this:

handles.chkS11En=uicontrol(f,'unit','normalized','BackgroundColor',[0.8,0.8,0.8],'Enable','on','FontAngle','normal','FontName','helvetica','FontSize',[12],'FontUnits','points','FontWeight','normal','ForegroundColor',[0,0,0],'HorizontalAlignment','center','ListboxTop',[],'Max',[1],'Min',[0],'Position',[0.02140625,0.791119360625398,0.0803125,0.0369667],'Relief','flat','SliderStep',[0.01,0.1],'String','S11','Style','checkbox','Value',[0],'VerticalAlignment','middle','Visible','on','Tag','chkS11En','Callback','chkS11En_callback(handles)')

And my callback that runs when I check the checkbox is this:

cS11En = findobj('tag', 'chkS11En');     // checkbox option
tS11MagUpperBound = findobj('tag', 'txtS11MagUpperBound');  //edit box that is controlled

mprintf("%d\n",cS11En.Value);
if cS11En.Value == [1] then
    mprintf("Checked = on \n");
    set(tS11MagUpperBound,'BackgroundColor',[1,1,1]);
    set(tS11MagUpperBound,"Enable",'on');
    set(cS11Save,"Enable",'on');
elseif cS11En.Value == [0] then
    mprintf("Checked = off \n");
    set(tS11MagUpperBound,'BackgroundColor',[0.8,0.8,0.8]);
    set(tS11MagUpperBound,'Enable','off');
    set(cS11Save,"Enable",'off');
end

The problem with this code seems to be that the second path (Value = 1) never seems to run, even when i continually toggle the checkbox. I get an output like so:

0
Checked = off 
0
Checked = off 
0
Checked = off 
0
Checked = off 

Is there something I'm doing wrong in order to reload checking the element? I want to be able to run both paths, however I can never seem to get a value of 1 from the checkbox element. Does anyone have a solution to this? Thanks!

2

There are 2 best solutions below

0
On

IF anyone is wondering and finds this through the googles or something, this is how I fixed it:

It turns out that SciLab sometimes doesn't clear all UI variables when the form is closed and a script is running.

The solution is to add a few lines in the top of each of your program that clears all variables, closes all forms, and initializes your variables.

Basically, add this:

// /////////////
// Lemon Pledge
// /////////////
mprintf("\n!!!!!!!!!!!!!!!!!!!\nCLEARING ALL VARIABLES\n!!!!!!!!!!!!!!!!!!!\n")
xdel(winsid());
clear;
clearglobal;
0
On

Another less complex solution would be: Using the same checkbox I left the last attribute in blank.

handles.chkS11En=uicontrol(f,'unit','normalized','BackgroundColor',[0.8,0.8,0.8],'Enable','on','FontAngle','normal','FontName','helvetica','FontSize',[12],'FontUnits','points','FontWeight','normal','ForegroundColor',[0,0,0],'HorizontalAlignment','center','ListboxTop',[],'Max',[1],'Min',[0],'Position',[0.02140625,0.791119360625398,0.0803125,0.0369667],'Relief','flat','SliderStep',[0.01,0.1],'String','S11','Style','checkbox','Value',[0],'VerticalAlignment','middle','Visible','on','Tag','chkS11En','Callback','')

Then I make the callback

function chkS11En_callback(handles)
    if handles.chkS11En.Value == [1] then
        mprintf("Checked = on \n");
        set(tS11MagUpperBound,'BackgroundColor',[1,1,1]);
        set(tS11MagUpperBound,"Enable",'on');
        set(cS11Save,"Enable",'on');
    else
        mprintf("Checked = off \n");
        set(tS11MagUpperBound,'BackgroundColor',[0.8,0.8,0.8]);
        set(tS11MagUpperBound,'Enable','off');
        set(cS11Save,"Enable",'off');
    end

And voilà, no need to clear your workspace.