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