-
Notifications
You must be signed in to change notification settings - Fork 1
/
UserWaitCommand.m
79 lines (61 loc) · 3.12 KB
/
UserWaitCommand.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
%#########################################################################
% UserWaitCommand
% ImagingStationController command to prompt the user with a dialogue box
% Written by Curtis Layton 10/2012
%#########################################################################
classdef UserWaitCommand < ControlCommand
properties % PROPERTIES
dialogHandle;
end % END PROPERTIES
properties (Access = private) % PRIVATE METHODS
dialogFlag; %flag to indicate whether dialog is currently open
end % END PRIVATE METHODS
methods % PUBLIC METHODS
function command = UserWaitCommand(hardware, message, timeout)
CheckParam.isString(message, 'UserWaitCommand:UserWaitCommand:badInputs');
if(~exist('timeout','var'))
timeout = 0; %0 is a flag to never timeout
else
CheckParam.isInteger(timeout, 'UserWaitCommand:UserWaitCommand:badInputs');
end
command = command@ControlCommand(hardware, 'userwait', 'prompt the user with a dialogue box and wait'); %call parent constructor
command.parameters.message = message; %message to be displayed in the dialogue box
command.parameters.timeout = timeout; %if provided, the dialogue box will automatically close and continue after this timeout period (in seconds)
command.dialogFlag = false;
end
function execute(command, scriptDepth, depthIndex)
if(~exist('depthIndex','var'))
depthIndex = 1;
end
%get a local copy of parameters that will be used
%the 'getParameter' method substitutes any loop variables for this iteration
message = command.getParameter('message', depthIndex);
timeout = command.getParameter('timeout', depthIndex);
command.dialogFlag = true;
command.dialogHandle = msgbox(message, 'User Wait', 'modal');
try
set(command.dialogHandle, 'DeleteFcn', @command.releaseDialogFlag);
if(timeout ~= 0)
timeoutTimer = timer('ExecutionMode','singleShot','StartDelay',timeout,'TimerFcn',@command.killDialog);
start(timeoutTimer);
end
uiwait(command.dialogHandle);
if(timeout ~= 0)
stop(timeoutTimer);
delete(timeoutTimer);
end
catch err
if(~strcmp(err.identifier, 'MATLAB:class:InvalidHandle') && ~strcmp(err.identifier, 'MATLAB:UndefinedFunction')) %errors associated with closing the window
rethrow(err);
end
end
end
function killDialog(command, timer, event)
close(command.dialogHandle);
end
function releaseDialogFlag(command, dialog, event)
command.dialogFlag = false;
delete(dialog);
end
end % END PUBLIC METHODS
end