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