Domanda

We're writing a program with several pull downs to sort through data. It's a decent sized dataset, and the pulldowns are generated dynamically. As a result, when you change a pulldown you have to wait a second or five before selecting the next pulldown, or it screws the whole thing up. So, I wrote a small function that disables all the UI elements (sets enable property to off).

The problem is that it isn't working reliably in pulldown callback functions.

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

So, the above doesn't work. But, if I add a message box just after the deactivate_pulldowns call, it works fine.

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

This will deactivate all the pulldowns like I expect. Whats going on here!?

È stato utile?

Soluzione

It looks like you need to force the user-interface objects to update. Try drawnow in place of the dummy message box:

drawnow('update')

Or perhaps a full event queue flush with just drawnow on its own.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top