禁用Matlab gui项目

时间:2014-01-29 02:00:07

标签: matlab matlab-figure

我们正在编写一个包含多个下拉菜单的程序来对数据进行排序。它是一个体面的数据集,下拉动态生成。因此,当您更改下拉菜单时,您必须等待一两秒钟才能选择下一个下拉菜单,否则它会将整个内容拧紧。所以,我编写了一个小函数来禁用所有UI元素(将enable属性设置为off)。

问题是它在下拉回调函数中无法可靠地工作。

function deactivate_pulldowns(handles)

set(handles.first_data_field_pulldown,'enable','off');
set(handles.first_key_data_list_pulldown,'enable','off');
set(handles.second_data_field_pulldown,'enable','off');


function first_data_field_pulldown_Callback(hObject, eventdata, handles)

%deactivate the pulldowns until processing is complete
deactivate_pulldowns(handles);

%wipe out the old pull down if it exists
try
    [dummy, dummy] = size(handles.first_field_reduced_key_data);
    handles.first_field_reduced_key_data = '';
    clear handles.first_field_reduced_key_data
catch

% ... This is pretty long and does a bunch of processing and takes time

所以,上面的方法不起作用。但是,如果我在deactivate_pulldowns调用之后添加一个消息框,它可以正常工作。

function first_data_field_pulldown_Callback(hObject, eventdata, handles)

%deactivate the pulldowns until processing is complete
deactivate_pulldowns(handles);
msgbox('test1');

%wipe out the old pull down if it exists
try
    [dummy, dummy] = size(handles.first_field_reduced_key_data);
    handles.first_field_reduced_key_data = '';
    clear handles.first_field_reduced_key_data
catch

% ... This is pretty long and does a bunch of processing and takes time

这将取消我所期望的所有下拉菜单。这是怎么回事??

1 个答案:

答案 0 :(得分:1)

看起来您需要强制更新用户界面对象。尝试使用drawnow代替虚拟消息框:

drawnow('update')

或者可能是一个完整的事件队列,只有drawnow