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