我們正在編寫一個帶有幾個下拉菜單的程序來對數據進行排序。這是一個體面大小的數據集,並且下拉是動態生成的。因此,當您更改下拉菜單時,在選擇下一個下拉菜單之前,您必須等待一兩秒鐘,否則它會將整個事件擰緊。所以,我寫了一個小功能,禁用所有的UI元素(設置啓用屬性關閉)。禁用Matlab gui項目
問題是它在下拉回調函數中不能可靠工作。
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
這將停用所有的下拉菜單,就像我期望的那樣。這裏發生了什麼!?
雖然uicontrols可能看起來不像他們的殘疾人,但他們可能是 - 只有他們的視覺外觀沒有更新。您是否在處理過程中嘗試點擊它們?添加'msgbox'與@chappjc的答案具有相同的效果 - 即啓用重新繪製已更改的gui元素。 – sebastian
我能夠點擊它們。但我不確定它是否真的做了什麼。 chappjc的回答完全符合我的需要。 –
那麼,你顯然總是可以點擊 - 當然問題是,如果發生什麼事...... – sebastian