1 | %'msgbox_uvmat': associated with GUI msgbox_uvmat.fig to display message boxes, for error, warning or input calls
|
---|
2 | % msgbox_uvmat(title,display)
|
---|
3 | %
|
---|
4 | % OUTPUT:
|
---|
5 | % answer (text string)= 'yes', 'No', 'cancel', or the text string introduced as input
|
---|
6 | %
|
---|
7 | %INPUT:
|
---|
8 | % title: string indicating the type of message box:
|
---|
9 | % title= 'INPUT_TXT','CONFIMATION' ,'ERROR', 'WARNING', 'INPUT_Y-N', default = 'INPUT_TXT' (the title is displayed in the upper bar of the fig).
|
---|
10 | % if title='INPUT_TXT', input data is asked in an edit box
|
---|
11 | % if title='CONFIMATION'', 'ERROR', 'WARNING', the figure remains opened until a button 'OK' is pressed
|
---|
12 | % if title='INPUT_Y-N', an answer Yes/No is requested
|
---|
13 | % display, displayed text
|
---|
14 | % default_answer: default answer in the edit box (only used with title='INPUT_TXT')
|
---|
15 |
|
---|
16 | function varargout = msgbox_uvmat(varargin)
|
---|
17 |
|
---|
18 | % Last Modified by GUIDE v2.5 24-Oct-2009 21:55:17
|
---|
19 |
|
---|
20 | % Begin initialization code - DO NOT EDIT
|
---|
21 | gui_Singleton = 1;
|
---|
22 | gui_State = struct('gui_Name', mfilename, ...
|
---|
23 | 'gui_Singleton', gui_Singleton, ...
|
---|
24 | 'gui_OpeningFcn', @msgbox_uvmat_OpeningFcn, ...
|
---|
25 | 'gui_OutputFcn', @msgbox_uvmat_OutputFcn, ...
|
---|
26 | 'gui_LayoutFcn', [] , ...
|
---|
27 | 'gui_Callback', []);
|
---|
28 | if nargin && ischar(varargin{1}) && ~isempty(regexp(varargin{1},'_Callback','once'))
|
---|
29 | gui_State.gui_Callback = str2func(varargin{1});%for running msgbox_uvmat from a Callback
|
---|
30 | end
|
---|
31 |
|
---|
32 | if nargout
|
---|
33 | [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
|
---|
34 | else
|
---|
35 | gui_mainfcn(gui_State, varargin{:});
|
---|
36 | end
|
---|
37 | % End initialization code - DO NOT EDIT
|
---|
38 |
|
---|
39 | % --- Executes just before msgbox_uvmat is made visible.
|
---|
40 | function msgbox_uvmat_OpeningFcn(hObject, eventdata, handles,title,display,default_answer,Position)
|
---|
41 | % This function has no output args, see OutputFcn.
|
---|
42 |
|
---|
43 | % Choose default command line output for msgbox_uvmat
|
---|
44 | handles.output = 'Cancel';
|
---|
45 | set(handles.figure1,'Units','pixels')
|
---|
46 | FigPos=[100 150 500 50];%default position
|
---|
47 | if exist('Position','var')
|
---|
48 | FigPos(1)=Position(1);
|
---|
49 | FigPos(2)=Position(2)-FigPos(4);% upper left corner set by input Position
|
---|
50 | set(handles.figure1,'Position',FigPos)
|
---|
51 | end
|
---|
52 | set(handles.OK,'Units','pixels')
|
---|
53 | set(handles.OK,'Position',[100 2 60 30])
|
---|
54 | set(handles.OK,'FontSize',15)
|
---|
55 | set(handles.No,'Units','pixels')
|
---|
56 | set(handles.No,'Position',[200 2 60 30])
|
---|
57 | set(handles.No,'FontSize',15)
|
---|
58 | set(handles.Cancel,'Units','pixels')
|
---|
59 | set(handles.Cancel,'Position',[300 2 60 30])
|
---|
60 | set(handles.Cancel,'FontSize',15)
|
---|
61 |
|
---|
62 |
|
---|
63 | % Update handles structure
|
---|
64 | guidata(hObject, handles);
|
---|
65 | testNo=0;
|
---|
66 | testCancel=0;
|
---|
67 | testinputstring=0;
|
---|
68 | icontype='quest';%default question icon (text input asked)
|
---|
69 | if exist('title','var')
|
---|
70 | set(hObject, 'Name', title);
|
---|
71 | switch title
|
---|
72 | case {'CONFIRMATION'}
|
---|
73 | icontype='';
|
---|
74 | case 'ERROR'
|
---|
75 | icontype='error';
|
---|
76 | case 'WARNING'
|
---|
77 | icontype='warn';
|
---|
78 | case 'INPUT_Y-N'
|
---|
79 | icontype='quest';
|
---|
80 | testCancel=1; %no cancel button
|
---|
81 | testNo=1; % button No activated
|
---|
82 | case {'RULER'}
|
---|
83 | icontype='';
|
---|
84 | testinputstring=1;
|
---|
85 | case 'INPUT_TXT'
|
---|
86 | testinputstring=1;
|
---|
87 | testCancel=1; %no cancel button
|
---|
88 | otherwise
|
---|
89 | % testinputstring=1;
|
---|
90 | icontype='';
|
---|
91 | testinputstring=exist('default_answer','var');
|
---|
92 | end
|
---|
93 | end
|
---|
94 | if exist('display','var')
|
---|
95 | set(handles.text1, 'String', display);
|
---|
96 | end
|
---|
97 | % if testinputstring
|
---|
98 | % set(handles.edit_box, 'Visible', 'on');
|
---|
99 | % else
|
---|
100 | % set(handles.text1, 'Position', [0.15 0.3 0.85 0.7]);
|
---|
101 | % end
|
---|
102 | if testinputstring
|
---|
103 | % set(handles.figure1,'Position',[40,80,20*length(default_answer),50])
|
---|
104 | set(handles.edit_box, 'Visible', 'on');
|
---|
105 | if ~exist('default_answer','var');
|
---|
106 | default_answer='';
|
---|
107 | end
|
---|
108 | set(handles.edit_box, 'String', default_answer);
|
---|
109 | if exist('Position','var')
|
---|
110 | if iscell(default_answer)
|
---|
111 | widthstring=max(cellfun('length',default_answer));
|
---|
112 | heightstring=size(default_answer,1);
|
---|
113 | set(handles.edit_box,'Max',2);
|
---|
114 | else
|
---|
115 | widthstring=length(default_answer);
|
---|
116 | heightstring=1;
|
---|
117 | end
|
---|
118 | widthstring=max(widthstring,length(title));
|
---|
119 | boxsize=[10*widthstring 20*heightstring];%size of the display edit box
|
---|
120 | set(handles.edit_box,'Units','pixels')
|
---|
121 | set(handles.edit_box,'FontUnits','pixels')
|
---|
122 | set(handles.edit_box,'FontSize',12)
|
---|
123 | set(handles.edit_box,'Position',[5,34,boxsize(1),boxsize(2)])
|
---|
124 | FigPos(3)=10+boxsize(1);
|
---|
125 | FigPos(4)=36+boxsize(2);
|
---|
126 | FigPos(2)=Position(2)-FigPos(4)-25;
|
---|
127 | set(handles.figure1,'Position',FigPos)
|
---|
128 | end
|
---|
129 | % set(handles.figure1,'Position',[40,40,20*length(default_answer),50])
|
---|
130 | else
|
---|
131 | set(handles.text1, 'Position', [0.15 0.3 0.85 0.7]);
|
---|
132 | end
|
---|
133 | % Determine the position of the dialog - centered on the screen
|
---|
134 | % FigPos=get(0,'DefaultFigurePosition');
|
---|
135 | % OldUnits = get(hObject, 'Units');
|
---|
136 | % set(hObject, 'Units', 'pixels');
|
---|
137 | % OldPos = get(hObject,'Position');
|
---|
138 | % FigWidth = OldPos(3);
|
---|
139 | % FigHeight = OldPos(4);
|
---|
140 | % ScreenUnits=get(0,'Units');
|
---|
141 | % set(0,'Units','pixels');
|
---|
142 | % ScreenSize=get(0,'ScreenSize');
|
---|
143 | % set(0,'Units',ScreenUnits);
|
---|
144 | %
|
---|
145 | % FigPos(1)=1/2*(ScreenSize(3)-FigWidth);
|
---|
146 | % FigPos(2)=2/3*(ScreenSize(4)-FigHeight);
|
---|
147 | % FigPos(3:4)=[FigWidth FigHeight];
|
---|
148 | % set(hObject, 'Position', FigPos);
|
---|
149 | % set(hObject, 'Units', OldUnits);
|
---|
150 |
|
---|
151 | % Show a question icon from dialogicons.mat - variables questIconData and questIconMap
|
---|
152 | if isequal(icontype,'')
|
---|
153 | hima=findobj(handles.axes1,'Type','image');
|
---|
154 | if ~isempty(hima)
|
---|
155 | delete(hima)
|
---|
156 | end
|
---|
157 | else
|
---|
158 | load dialogicons.mat
|
---|
159 | eval(['IconData=' icontype 'IconData;'])
|
---|
160 | eval(['IconCMap=' icontype 'IconMap;'])
|
---|
161 | questIconMap(256,:) = get(handles.figure1, 'Color');
|
---|
162 | Img=image(IconData, 'Parent', handles.axes1);
|
---|
163 | set(handles.figure1, 'Colormap', IconCMap);
|
---|
164 | set(handles.axes1, ...
|
---|
165 | 'Visible', 'off', ...
|
---|
166 | 'YDir' , 'reverse' , ...
|
---|
167 | 'XLim' , get(Img,'XData'), ...
|
---|
168 | 'YLim' , get(Img,'YData') ...
|
---|
169 | );
|
---|
170 | end
|
---|
171 | if testCancel
|
---|
172 | set(handles.Cancel,'Visible','on')
|
---|
173 | else
|
---|
174 | set(handles.Cancel,'Visible','off')
|
---|
175 | end
|
---|
176 | if testNo
|
---|
177 | set(handles.No,'Visible','on')
|
---|
178 | else
|
---|
179 | set(handles.No,'Visible','off')
|
---|
180 | end
|
---|
181 | set(handles.figure1,'Units','normalized')
|
---|
182 | set(handles.edit_box,'Units','normalized')
|
---|
183 |
|
---|
184 | set(handles.figure1,'WindowStyle','modal')% Make% Make the GUI modal
|
---|
185 | % UIWAIT makes msgbox_uvmat wait for user response (see UIRESUME)
|
---|
186 | uiwait(handles.figure1);
|
---|
187 |
|
---|
188 |
|
---|
189 | % --- Outputs from this function are returned to the command line.
|
---|
190 | function varargout = msgbox_uvmat_OutputFcn(hObject, eventdata, handles)
|
---|
191 |
|
---|
192 | % Get default command line output from handles structure
|
---|
193 | if isfield(handles,'output')
|
---|
194 | if isequal(handles.output,'Cancel')
|
---|
195 | varargout{1}='Cancel';
|
---|
196 | elseif isequal(handles.output,'No')
|
---|
197 | varargout{1}='No';
|
---|
198 | else
|
---|
199 | varargout{1}=get(handles.edit_box,'String');
|
---|
200 | if isempty(varargout{1}) || isequal(varargout{1},'')
|
---|
201 | varargout{1}='Yes';
|
---|
202 | end
|
---|
203 | end
|
---|
204 | % The figure can be deleted now
|
---|
205 | end
|
---|
206 | delete(handles.figure1);
|
---|
207 |
|
---|
208 | % --- Executes on button press in OK.
|
---|
209 | function OK_Callback(hObject, eventdata, handles)
|
---|
210 | handles.output = get(hObject,'String');
|
---|
211 | guidata(hObject, handles);% Update handles structure
|
---|
212 | uiresume(handles.figure1);
|
---|
213 |
|
---|
214 | % --- Executes on button press in No.
|
---|
215 | function No_Callback(hObject, eventdata, handles)
|
---|
216 | handles.output='No';
|
---|
217 | guidata(hObject, handles);
|
---|
218 | uiresume(handles.figure1);
|
---|
219 |
|
---|
220 | % --- Executes on button press in Cancel.
|
---|
221 | function Cancel_Callback(hObject, eventdata, handles)
|
---|
222 | handles.output = get(hObject,'String');
|
---|
223 | %handles.output = 'Cancel'
|
---|
224 | guidata(hObject, handles); % Update handles structure
|
---|
225 | % Use UIRESUME instead of delete because the OutputFcn needs
|
---|
226 | % to get the updated handles structure.
|
---|
227 | uiresume(handles.figure1);
|
---|
228 |
|
---|
229 |
|
---|
230 | % --- Executes when user attempts to close figure1.
|
---|
231 | function figure1_CloseRequestFcn(hObject, eventdata, handles)
|
---|
232 | if isequal(get(handles.figure1, 'waitstatus'), 'waiting')
|
---|
233 | % The GUI is still in UIWAIT, us UIRESUME
|
---|
234 | uiresume(handles.figure1);
|
---|
235 | else
|
---|
236 | % The GUI is no longer waiting, just close it
|
---|
237 | delete(handles.figure1);
|
---|
238 | end
|
---|
239 |
|
---|
240 | % --- Executes on key press over figure1 with no controls selected.
|
---|
241 | function figure1_KeyPressFcn(hObject, eventdata, handles)
|
---|
242 | % Check for "enter" or "escape"
|
---|
243 | if isequal(get(hObject,'CurrentKey'),'escape')
|
---|
244 | % User said no by hitting escape
|
---|
245 | handles.output = 'No';
|
---|
246 |
|
---|
247 | % Update handles structure
|
---|
248 | guidata(hObject, handles);
|
---|
249 |
|
---|
250 | uiresume(handles.figure1);
|
---|
251 | end
|
---|
252 | if isequal(get(hObject,'CurrentKey'),'return')
|
---|
253 | uiresume(handles.figure1);
|
---|
254 | end
|
---|
255 |
|
---|
256 |
|
---|
257 |
|
---|
258 |
|
---|
259 |
|
---|