while 循环阻止从 gui 读取回调
while loop blocks reading callbacks from gui
我正在尝试向 GUI 添加一个停止按钮,该按钮可用于中止 gui 和后台 while 循环的执行。考虑代码:
function pushFun(button)
disp("Push!")
endfunction
h = figure(1);
set(h,'UserData',1);
button = uicontrol(h, 'Style', 'pushbutton', 'String', 'Stop',..
'Position', [0 0 60 25], 'callback', 'pushFun',..
"callback_type", 2);
效果很好。但是代码:
function stopgui()
global guistop;
guistop = %t;
endfunction
h = figure(1);
set(h,'UserData',1);
global guistop
guistop = %f;
button = uicontrol(h, 'Style', 'pushbutton', 'String', 'Stop',..
'Position', [0 0 60 25], 'callback', 'stopgui',..
"callback_type", 2);
while ~guistop
// some code here
sleep(100)
end
不响应按钮交互。如果您能帮助我知道哪里出了问题以及我该如何解决,我将不胜感激。
您必须使用回调类型 10(优先(或不可中断)Scilab 指令):
button = uicontrol(h, 'Style', 'pushbutton', 'String', 'Stop',..
'Position', [0 0 60 25], 'callback', 'stopgui',..
'callback_type', 10);
我正在尝试向 GUI 添加一个停止按钮,该按钮可用于中止 gui 和后台 while 循环的执行。考虑代码:
function pushFun(button)
disp("Push!")
endfunction
h = figure(1);
set(h,'UserData',1);
button = uicontrol(h, 'Style', 'pushbutton', 'String', 'Stop',..
'Position', [0 0 60 25], 'callback', 'pushFun',..
"callback_type", 2);
效果很好。但是代码:
function stopgui()
global guistop;
guistop = %t;
endfunction
h = figure(1);
set(h,'UserData',1);
global guistop
guistop = %f;
button = uicontrol(h, 'Style', 'pushbutton', 'String', 'Stop',..
'Position', [0 0 60 25], 'callback', 'stopgui',..
"callback_type", 2);
while ~guistop
// some code here
sleep(100)
end
不响应按钮交互。如果您能帮助我知道哪里出了问题以及我该如何解决,我将不胜感激。
您必须使用回调类型 10(优先(或不可中断)Scilab 指令):
button = uicontrol(h, 'Style', 'pushbutton', 'String', 'Stop',..
'Position', [0 0 60 25], 'callback', 'stopgui',..
'callback_type', 10);