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 | testinputstring=0;
|
---|
72 | icontype='quest';%default question icon (text input asked)
|
---|
73 | if exist('title','var')
|
---|
74 | set(hObject, 'Name', title);
|
---|
75 | switch title
|
---|
76 | case {'CONFIRMATION'}
|
---|
77 | icontype='';
|
---|
78 | case 'ERROR'
|
---|
79 | icontype='error';
|
---|
80 | if exist('display_str','var')
|
---|
81 | disp(display_str); %display the error message in the Matlab command window
|
---|
82 | end
|
---|
83 | case 'WARNING'
|
---|
84 | icontype='warn';
|
---|
85 | case 'INPUT_Y-N'
|
---|
86 | icontype='quest';
|
---|
87 | testCancel=1; %no cancel button
|
---|
88 | testNo=1; % button No activated
|
---|
89 | case {'RULER'}
|
---|
90 | icontype='';
|
---|
91 | testinputstring=1;
|
---|
92 | case 'INPUT_TXT'
|
---|
93 | testinputstring=1;
|
---|
94 | testCancel=1; %no cancel button
|
---|
95 | case 'INPUT_MENU'
|
---|
96 | testinputstring=2;
|
---|
97 | testCancel=1; %no cancel button
|
---|
98 | otherwise
|
---|
99 | % testinputstring=1;
|
---|
100 | icontype='';
|
---|
101 | testinputstring=exist('default_answer','var');
|
---|
102 | end
|
---|
103 | end
|
---|
104 | if exist('display_str','var')
|
---|
105 | set(handles.text1, 'String', display_str);
|
---|
106 | end
|
---|
107 |
|
---|
108 | if testinputstring==1
|
---|
109 | set(handles.edit_box, 'Visible', 'on');
|
---|
110 | if ~exist('default_answer','var');
|
---|
111 | default_answer='';
|
---|
112 | end
|
---|
113 | set(handles.edit_box, 'String', default_answer);
|
---|
114 | if exist('Position','var')&&numel(Position)>=2
|
---|
115 | if iscell(default_answer)
|
---|
116 | widthstring=max(max(cellfun('length',default_answer)),length(display_str));
|
---|
117 | heightstring=size(default_answer,1);%nbre of expected lines
|
---|
118 | set(handles.edit_box,'Max',2);
|
---|
119 | else
|
---|
120 | widthstring=max(length(default_answer),length(display_str));
|
---|
121 | heightstring=1;
|
---|
122 | end
|
---|
123 | widthstring=max(widthstring,length(title)+20);
|
---|
124 | boxsize=[10*widthstring 20*heightstring];%size of the display edit box
|
---|
125 | set(handles.edit_box,'Units','pixels')
|
---|
126 | set(handles.edit_box,'FontUnits','pixels')
|
---|
127 | set(handles.edit_box,'FontSize',12)
|
---|
128 | set(handles.edit_box,'Position',[5,34,boxsize(1),boxsize(2)])
|
---|
129 | FigPos(3)=10+boxsize(1);
|
---|
130 | FigPos(4)=56+boxsize(2);
|
---|
131 | FigPos(2)=Position(2)-FigPos(4)-25;
|
---|
132 | set(handles.figure1,'Position',FigPos)
|
---|
133 | end
|
---|
134 | elseif testinputstring==2
|
---|
135 | set(handles.edit_box,'style','listbox')
|
---|
136 | set(handles.edit_box, 'Visible', 'on');
|
---|
137 | set(handles.edit_box,'String', default_answer)
|
---|
138 | else
|
---|
139 | set(handles.text1, 'Position', [0.15 0.3 0.85 0.7]);
|
---|
140 | end
|
---|
141 |
|
---|
142 | % Show a question icon from dialogicons.mat - variables questIconData and questIconMap
|
---|
143 | if isequal(icontype,'')
|
---|
144 | hima=findobj(handles.axes1,'Type','image');
|
---|
145 | if ~isempty(hima)
|
---|
146 | delete(hima)
|
---|
147 | end
|
---|
148 | else
|
---|
149 | load dialogicons.mat
|
---|
150 | eval(['IconData=' icontype 'IconData;'])
|
---|
151 | eval(['IconCMap=' icontype 'IconMap;'])
|
---|
152 | questIconMap(256,:) = get(handles.figure1, 'Color');
|
---|
153 | Img=image(IconData, 'Parent', handles.axes1);
|
---|
154 | set(handles.figure1, 'Colormap', IconCMap);
|
---|
155 | set(handles.axes1, ...
|
---|
156 | 'Visible', 'off', ...
|
---|
157 | 'YDir' , 'reverse' , ...
|
---|
158 | 'XLim' , get(Img,'XData'), ...
|
---|
159 | 'YLim' , get(Img,'YData') ...
|
---|
160 | );
|
---|
161 | end
|
---|
162 | if testCancel
|
---|
163 | set(handles.Cancel,'Visible','on')
|
---|
164 | else
|
---|
165 | set(handles.Cancel,'Visible','off')
|
---|
166 | end
|
---|
167 | if testNo
|
---|
168 | set(handles.No,'Visible','on')
|
---|
169 | else
|
---|
170 | set(handles.No,'Visible','off')
|
---|
171 | end
|
---|
172 | set(handles.figure1,'Units','normalized')
|
---|
173 | set(handles.edit_box,'Units','normalized')
|
---|
174 |
|
---|
175 | set(handles.figure1,'WindowStyle','modal')% Make% Make the GUI modal
|
---|
176 | % UIWAIT makes msgbox_uvmat wait for user response (see UIRESUME)
|
---|
177 | uiwait(handles.figure1);
|
---|
178 |
|
---|
179 | %------------------------------------------------------------------------
|
---|
180 | % --- Outputs from this function are returned to the command line.
|
---|
181 | function varargout = msgbox_uvmat_OutputFcn(hObject, eventdata, handles)
|
---|
182 | %------------------------------------------------------------------------
|
---|
183 | varargout{1}='Cancel';%deg
|
---|
184 | % Get default command line output from handles structure
|
---|
185 | if isfield(handles,'output')
|
---|
186 | if isequal(handles.output,'Cancel')
|
---|
187 | varargout{1}='Cancel';
|
---|
188 | elseif isequal(handles.output,'No')
|
---|
189 | varargout{1}='No';
|
---|
190 | else
|
---|
191 | if strcmp(get(handles.edit_box,'Style'),'listbox')
|
---|
192 | varargout{1}=get(handles.edit_box,'Value');
|
---|
193 | else
|
---|
194 | varargout{1}=get(handles.edit_box,'String');
|
---|
195 | end
|
---|
196 | if isempty(varargout{1})
|
---|
197 | varargout{1}='Yes';
|
---|
198 | end
|
---|
199 | end
|
---|
200 | if strcmp(get(handles.edit_box, 'Visible'), 'on')
|
---|
201 | varargout{2}=get(handles.edit_box,'String');
|
---|
202 | end
|
---|
203 | % The figure can be deleted now
|
---|
204 | delete(handles.figure1);
|
---|
205 | end
|
---|
206 |
|
---|
207 | % delete(handles.figure1);
|
---|
208 |
|
---|
209 | %------------------------------------------------------------------------
|
---|
210 | % --- Executes on button press in OK.
|
---|
211 | function OK_Callback(hObject, eventdata, handles)
|
---|
212 | %------------------------------------------------------------------------
|
---|
213 | handles.output = get(hObject,'String');
|
---|
214 | guidata(hObject, handles);% Update handles structure
|
---|
215 | uiresume(handles.figure1);
|
---|
216 |
|
---|
217 | %------------------------------------------------------------------------
|
---|
218 | % --- Executes on button press in No.
|
---|
219 | function No_Callback(hObject, eventdata, handles)
|
---|
220 | %------------------------------------------------------------------------
|
---|
221 | handles.output='No';
|
---|
222 | guidata(hObject, handles);
|
---|
223 | uiresume(handles.figure1);
|
---|
224 |
|
---|
225 | %------------------------------------------------------------------------
|
---|
226 | % --- Executes on button press in Cancel.
|
---|
227 | function Cancel_Callback(hObject, eventdata, handles)
|
---|
228 | %------------------------------------------------------------------------
|
---|
229 | handles.output = get(hObject,'String');
|
---|
230 | %handles.output = 'Cancel'
|
---|
231 | guidata(hObject, handles); % Update handles structure
|
---|
232 | % Use UIRESUME instead of delete because the OutputFcn needs
|
---|
233 | % to get the updated handles structure.
|
---|
234 | uiresume(handles.figure1);
|
---|
235 |
|
---|
236 | %------------------------------------------------------------------------
|
---|
237 | % --- Executes when user attempts to close figure1.
|
---|
238 | function figure1_CloseRequestFcn(hObject, eventdata, handles)
|
---|
239 | %------------------------------------------------------------------------
|
---|
240 | % Cancel_Callback(hObject, eventdata, handles)
|
---|
241 | % if isequal(get(handles.figure1, 'waitstatus'), 'waiting')
|
---|
242 | % % The GUI is still in UIWAIT, us UIRESUME
|
---|
243 | % uiresume(handles.figure1);
|
---|
244 | % else
|
---|
245 | % The GUI is no longer waiting, just close it
|
---|
246 | % delete(handles.figure1);
|
---|
247 | % end
|
---|
248 | % handles.output = get(hObject,'String');
|
---|
249 | % %handles.output = 'Cancel'
|
---|
250 | % guidata(hObject, handles); % Update handles structure
|
---|
251 | % Use UIRESUME instead of delete because the OutputFcn needs
|
---|
252 | % to get the updated handles structure.
|
---|
253 | % uiresume(handles.figure1);
|
---|
254 |
|
---|
255 |
|
---|
256 | %------------------------------------------------------------------------
|
---|
257 | % --- Executes on key press over figure1 with no controls selected.
|
---|
258 | function figure1_KeyPressFcn(hObject, eventdata, handles)
|
---|
259 | %------------------------------------------------------------------------
|
---|
260 | % Check for "enter" or "escape"
|
---|
261 | if isequal(get(hObject,'CurrentKey'),'escape')
|
---|
262 | % User said no by hitting escape
|
---|
263 | handles.output = 'No';
|
---|
264 |
|
---|
265 | % Update handles structure
|
---|
266 | guidata(hObject, handles);
|
---|
267 |
|
---|
268 | uiresume(handles.figure1);
|
---|
269 | end
|
---|
270 | if isequal(get(hObject,'CurrentKey'),'return')
|
---|
271 | uiresume(handles.figure1);
|
---|
272 | end
|
---|
273 |
|
---|
274 |
|
---|
275 |
|
---|
276 |
|
---|