1 |
function theResult = again(varargin) |
---|
2 |
|
---|
3 |
% again -- Button for "Again" actions. |
---|
4 |
% again('theCallback') adds an "Again" pushbutton |
---|
5 |
% to the current figure, to evaluate 'theCallback' |
---|
6 |
% when pressed. The button handle is returned. |
---|
7 |
% again('s1', 's2', ...) joins the string-arguments |
---|
8 |
% with blank-separators to form the actual |
---|
9 |
% callback. The word 'then' causes a comma |
---|
10 |
% separator to be used. |
---|
11 |
% h = again (no argument) returns the handle of |
---|
12 |
% the existing "Again" pushbutton. |
---|
13 |
% again('demo') demonstrates itself by plotting |
---|
14 |
% random numbers each time the button is pressed. |
---|
15 |
% |
---|
16 |
% Note: this code needs some work to prevent |
---|
17 |
% run-away recursions when it is called from |
---|
18 |
% another routine as part of a demo. |
---|
19 |
|
---|
20 |
% Copyright (C) 2000 Dr. Charles R. Denham, ZYDECO. |
---|
21 |
% All Rights Reserved. |
---|
22 |
% Disclosure without explicit written consent from the |
---|
23 |
% copyright owner does not constitute publication. |
---|
24 |
|
---|
25 |
% Version of 17-Feb-2000 23:41:04. |
---|
26 |
% Updated 24-Mar-2000 09:59:05. |
---|
27 |
|
---|
28 |
% Process the callback. |
---|
29 |
|
---|
30 |
if any(gcbo) |
---|
31 |
oldPointer = get(gcbf, 'Pointer'); |
---|
32 |
set(gcbf, 'Pointer', 'watch') |
---|
33 |
drawnow |
---|
34 |
eval(get(gcbo, 'Tag')) |
---|
35 |
set(gcbf, 'Pointer', oldPointer) |
---|
36 |
return |
---|
37 |
end |
---|
38 |
|
---|
39 |
% Return the existing handle. |
---|
40 |
|
---|
41 |
props = {'Style', 'pushbutton', 'String', 'Again', ... |
---|
42 |
'Position', [20 10 60 20]}; |
---|
43 |
h = findobj(gcf, props{:}); |
---|
44 |
if any(h) & nargin < 1 & nargout > 0 |
---|
45 |
theResult = h; |
---|
46 |
return |
---|
47 |
end |
---|
48 |
|
---|
49 |
% Create or update the button. |
---|
50 |
|
---|
51 |
if nargin < 1, varargin{1} = 'demo'; help(mfilename), end |
---|
52 |
|
---|
53 |
theCallback = ''; |
---|
54 |
for i = 1:length(varargin) |
---|
55 |
if i > 1, theCallback = [theCallback ' ']; end |
---|
56 |
if isequal(varargin{i}, 'then') |
---|
57 |
varargin{i} = ','; |
---|
58 |
end |
---|
59 |
theCallback = [theCallback varargin{i}]; |
---|
60 |
end |
---|
61 |
|
---|
62 |
if isequal(theCallback, 'demo') |
---|
63 |
theCallback = 'n=ceil(50*rand(1,1))+1;plot(fft(eye(n,n)),''-o''),axis equal'; |
---|
64 |
eval(theCallback) |
---|
65 |
end |
---|
66 |
|
---|
67 |
if isempty(h) & ~isempty(theCallback) |
---|
68 |
h = uicontrol(props{:}); |
---|
69 |
set(h, 'Callback', mfilename, 'Tag', theCallback, ... |
---|
70 |
'ToolTipString', theCallback) |
---|
71 |
elseif ~isempty(theCallback) |
---|
72 |
set(h, 'Callback', mfilename, 'Tag', theCallback, ... |
---|
73 |
'ToolTipString', theCallback) |
---|
74 |
end |
---|
75 |
|
---|
76 |
figure(gcf) |
---|
77 |
|
---|
78 |
if nargout > 0, theResult = h; end |
---|