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