3

我正在尝试在 SciLab 中设计一个 GUI,根据复选标记更新它的属性。例如:一个复选框可能会在回调期间启用和更改多个文本框的背景;或者一个按钮可能需要选择一定数量的复选框。

我的问题是,我似乎无法根据回调期间的复选框状态开发用于运行指令的流控制语句。我当前的 UIControl 元素如下所示:

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)')

当我选中复选框时运行的回调是这样的:

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

这段代码的问题似乎是第二条路径(Value = 1)似乎永远不会运行,即使我不断切换复选框也是如此。我得到这样的输出:

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

为了重新加载检查元素,我做错了什么吗?我希望能够同时运行这两条路径,但是我似乎永远无法从复选框元素中获得 1 的值。有人对此有解决方案吗?谢谢!

4

2 回答 2

1

如果有人想知道并通过谷歌或其他东西找到这个,这就是我修复它的方法:

事实证明,当表单关闭且脚本正在运行时,SciLab 有时不会清除所有 UI 变量。

解决方案是在每个程序的顶部添加几行,以清除所有变量、关闭所有表单并初始化变量。

基本上,添加这个:

// /////////////
// Lemon Pledge
// /////////////
mprintf("\n!!!!!!!!!!!!!!!!!!!\nCLEARING ALL VARIABLES\n!!!!!!!!!!!!!!!!!!!\n")
xdel(winsid());
clear;
clearglobal;
于 2012-10-29T17:55:09.720 回答
0

另一个不太复杂的解决方案是:使用相同的复选框,我将最后一个属性留空。

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','')

然后我进行回调

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

瞧,无需清理您的工作区。

于 2020-08-21T13:10:06.163 回答