PageRenderTime 27ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/src/utils/gui_active.m

http://slac-lucretia.googlecode.com/
MATLAB | 38 lines | 19 code | 5 blank | 14 comment | 4 complexity | 530bc26663cb385de34adc663a7fdbb9 MD5 | raw file
Possible License(s): BSD-2-Clause
  1. function ret = gui_active(optional_input)
  2. %
  3. % gui_active - used to implement an abort function in a GUI
  4. %
  5. % initially : gui_active(1)
  6. %
  7. % in the aplication, occaisionally
  8. % EITHER 1) if (~gui_active) then ... do abort action
  9. % OR 2) polling gui_active(-1) will cause an error with the value 'abort_requested'
  10. % that can be caught with a "try-catch" block
  11. %
  12. % to initiate the abort (for both cases) call: gui_active(0)
  13. %
  14. % the call to drawnow enable other controls to "patch-in" before the
  15. % rest of this code execute and possibly change the "is_active" state
  16. persistent is_active;
  17. if (nargin > 0)
  18. if (optional_input == -1)
  19. drawnow;
  20. if (~is_active)
  21. error('abort_requested');
  22. end
  23. else
  24. prev_is_active = is_active;
  25. is_active = optional_input;
  26. if ((prev_is_active > 0) & (is_active == 0))
  27. disp('operation aborted');
  28. end
  29. end
  30. else
  31. drawnow('expose');
  32. end
  33. ret = is_active;