samer@4
|
1 function iterate_gui(stfn,S0,varargin)
|
samer@4
|
2 % iterate_gui - iterate state transformer under GUI control
|
samer@4
|
3 %
|
samer@4
|
4 % iterate_gui ::
|
samer@4
|
5 % (A->A,handle) ~'state transformer function',
|
samer@4
|
6 % A ~'initial state'
|
samer@4
|
7 % -> gui.
|
samer@4
|
8 %
|
samer@4
|
9 % The idea is that the state transformer returns a handle to a
|
samer@4
|
10 % GUI element to be used for advancing the sequence. You click
|
samer@4
|
11 % on that element to move to the next element of the sequence.
|
samer@4
|
12 % Button 2 rewinds to the beginning of the sequence.
|
samer@4
|
13
|
samer@4
|
14 % to do: user configurable keys to allow multiple plotseqs
|
samer@4
|
15 % in same figure, each watching different keys.
|
samer@4
|
16
|
samer@37
|
17 opts=options('keyctl','set',varargin{:});
|
samer@4
|
18
|
samer@4
|
19 [S,h]=stfn(S0);
|
samer@4
|
20 set(h,'ButtonDownFcn',@btndn);
|
samer@4
|
21 switch opts.keyctl
|
samer@4
|
22 case 'set', addkbcallback(gcf), addkbcallback(gcf,@keypress);
|
samer@4
|
23 case 'add', addkbcallback(gcf,@keypress);
|
samer@4
|
24 end
|
samer@4
|
25
|
samer@4
|
26 function next()
|
samer@4
|
27 if isempty(S), beep;
|
samer@4
|
28 else
|
samer@4
|
29 [S,h]=stfn(S);
|
samer@4
|
30 set(h,'ButtonDownFcn',@btndn);
|
samer@4
|
31 end
|
samer@4
|
32 end
|
samer@4
|
33
|
samer@4
|
34 function rewind(), [S,h]=stfn(S0); set(h,'ButtonDownFcn',@btndn); end
|
samer@4
|
35 function btndn(a,b)
|
samer@4
|
36 if strcmp(get(gcf,'SelectionType'),'alt'), rewind();
|
samer@4
|
37 else next(); end
|
samer@4
|
38 end
|
samer@4
|
39
|
samer@4
|
40 function keypress(b)
|
samer@4
|
41 switch b.Character
|
samer@4
|
42 case {'b','r'}, rewind();
|
samer@4
|
43 case {' ','n'}, next();
|
samer@4
|
44 end
|
samer@4
|
45 end
|
samer@4
|
46 end % of main function
|
samer@4
|
47
|