samer@4: function iterate_gui(stfn,S0,varargin) samer@4: % iterate_gui - iterate state transformer under GUI control samer@4: % samer@4: % iterate_gui :: samer@4: % (A->A,handle) ~'state transformer function', samer@4: % A ~'initial state' samer@4: % -> gui. samer@4: % samer@4: % The idea is that the state transformer returns a handle to a samer@4: % GUI element to be used for advancing the sequence. You click samer@4: % on that element to move to the next element of the sequence. samer@4: % Button 2 rewinds to the beginning of the sequence. samer@4: samer@4: % to do: user configurable keys to allow multiple plotseqs samer@4: % in same figure, each watching different keys. samer@4: samer@37: opts=options('keyctl','set',varargin{:}); samer@4: samer@4: [S,h]=stfn(S0); samer@4: set(h,'ButtonDownFcn',@btndn); samer@4: switch opts.keyctl samer@4: case 'set', addkbcallback(gcf), addkbcallback(gcf,@keypress); samer@4: case 'add', addkbcallback(gcf,@keypress); samer@4: end samer@4: samer@4: function next() samer@4: if isempty(S), beep; samer@4: else samer@4: [S,h]=stfn(S); samer@4: set(h,'ButtonDownFcn',@btndn); samer@4: end samer@4: end samer@4: samer@4: function rewind(), [S,h]=stfn(S0); set(h,'ButtonDownFcn',@btndn); end samer@4: function btndn(a,b) samer@4: if strcmp(get(gcf,'SelectionType'),'alt'), rewind(); samer@4: else next(); end samer@4: end samer@4: samer@4: function keypress(b) samer@4: switch b.Character samer@4: case {'b','r'}, rewind(); samer@4: case {' ','n'}, next(); samer@4: end samer@4: end samer@4: end % of main function samer@4: