[733] | 1 |
|
---|
[2] | 2 | %'msgbox_uvmat': associated with GUI msgbox_uvmat.fig to display message boxes, for error, warning or input calls
|
---|
| 3 | %
|
---|
[654] | 4 | % answer=msgbox_uvmat(title,display,default_answer,Position)
|
---|
| 5 | %
|
---|
[2] | 6 | % OUTPUT:
|
---|
| 7 | % answer (text string)= 'yes', 'No', 'cancel', or the text string introduced as input
|
---|
[747] | 8 | % for title='WAITING...', the output is the handle of the figure, to allow deletion by the calling program.
|
---|
[2] | 9 | %
|
---|
| 10 | %INPUT:
|
---|
| 11 | % title: string indicating the type of message box:
|
---|
[747] | 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).
|
---|
[2] | 13 | % if title='INPUT_TXT', input data is asked in an edit box
|
---|
[747] | 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.
|
---|
[2] | 16 | % if title='INPUT_Y-N', an answer Yes/No is requested
|
---|
[747] | 17 | % if title='WAITING...' the figure remains open until the program deletes it
|
---|
| 18 | % display: displayed text
|
---|
[2] | 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', []);
|
---|
[121] | 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
|
---|
[2] | 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 |
|
---|
[581] | 44 | %------------------------------------------------------------------------
|
---|
[2] | 45 | % --- Executes just before msgbox_uvmat is made visible.
|
---|
[421] | 46 | function msgbox_uvmat_OpeningFcn(hObject, eventdata, handles,title,display_str,default_answer,Position)
|
---|
[581] | 47 | %------------------------------------------------------------------------
|
---|
[2] | 48 | % This function has no output args, see OutputFcn.
|
---|
| 49 |
|
---|
| 50 | % Choose default command line output for msgbox_uvmat
|
---|
| 51 | handles.output = 'Cancel';
|
---|
[244] | 52 | set(handles.figure1,'Units','pixels')
|
---|
| 53 | FigPos=[100 150 500 50];%default position
|
---|
[472] | 54 | if exist('Position','var') && numel(Position)>=2
|
---|
[244] | 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)
|
---|
[726] | 68 | % set(hObject,'WindowKeyPressFcn',{'keyboard_callback',handles})%set keyboard action function
|
---|
[2] | 69 |
|
---|
| 70 | % Update handles structure
|
---|
| 71 | guidata(hObject, handles);
|
---|
| 72 | testNo=0;
|
---|
[246] | 73 | testCancel=0;
|
---|
[746] | 74 | testOK=1;
|
---|
[2] | 75 | testinputstring=0;
|
---|
| 76 | icontype='quest';%default question icon (text input asked)
|
---|
| 77 | if exist('title','var')
|
---|
[156] | 78 | set(hObject, 'Name', title);
|
---|
| 79 | switch title
|
---|
| 80 | case {'CONFIRMATION'}
|
---|
| 81 | icontype='';
|
---|
| 82 | case 'ERROR'
|
---|
| 83 | icontype='error';
|
---|
[421] | 84 | if exist('display_str','var')
|
---|
| 85 | disp(display_str); %display the error message in the Matlab command window
|
---|
| 86 | end
|
---|
[156] | 87 | case 'WARNING'
|
---|
| 88 | icontype='warn';
|
---|
| 89 | case 'INPUT_Y-N'
|
---|
| 90 | icontype='quest';
|
---|
[246] | 91 | testCancel=1; %no cancel button
|
---|
[156] | 92 | testNo=1; % button No activated
|
---|
[747] | 93 | case 'RULER'
|
---|
[156] | 94 | icontype='';
|
---|
| 95 | testinputstring=1;
|
---|
[244] | 96 | case 'INPUT_TXT'
|
---|
| 97 | testinputstring=1;
|
---|
[246] | 98 | testCancel=1; %no cancel button
|
---|
[581] | 99 | case 'INPUT_MENU'
|
---|
| 100 | testinputstring=2;
|
---|
| 101 | testCancel=1; %no cancel button
|
---|
[747] | 102 | case 'WAITING...'
|
---|
[746] | 103 | icontype='';
|
---|
| 104 | testOK=0;
|
---|
[156] | 105 | otherwise
|
---|
[244] | 106 | % testinputstring=1;
|
---|
| 107 | icontype='';
|
---|
| 108 | testinputstring=exist('default_answer','var');
|
---|
[156] | 109 | end
|
---|
[2] | 110 | end
|
---|
[421] | 111 | if exist('display_str','var')
|
---|
| 112 | set(handles.text1, 'String', display_str);
|
---|
[2] | 113 | end
|
---|
[581] | 114 |
|
---|
| 115 | if testinputstring==1
|
---|
[2] | 116 | set(handles.edit_box, 'Visible', 'on');
|
---|
[244] | 117 | if ~exist('default_answer','var');
|
---|
| 118 | default_answer='';
|
---|
| 119 | end
|
---|
| 120 | set(handles.edit_box, 'String', default_answer);
|
---|
[733] | 121 | if exist('Position','var')&&numel(Position)>=2
|
---|
[581] | 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)
|
---|
[244] | 140 | end
|
---|
[581] | 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)
|
---|
[2] | 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
|
---|
[296] | 179 | set(handles.figure1,'Units','normalized')
|
---|
| 180 | set(handles.edit_box,'Units','normalized')
|
---|
[746] | 181 | if testOK
|
---|
[2] | 182 | set(handles.figure1,'WindowStyle','modal')% Make% Make the GUI modal
|
---|
[746] | 183 | set(handles.OK,'Visible','on')
|
---|
[2] | 184 | % UIWAIT makes msgbox_uvmat wait for user response (see UIRESUME)
|
---|
| 185 | uiwait(handles.figure1);
|
---|
[746] | 186 | else
|
---|
| 187 | set(handles.OK,'Visible','off')
|
---|
| 188 | end
|
---|
[2] | 189 |
|
---|
[746] | 190 |
|
---|
[581] | 191 | %------------------------------------------------------------------------
|
---|
[2] | 192 | % --- Outputs from this function are returned to the command line.
|
---|
| 193 | function varargout = msgbox_uvmat_OutputFcn(hObject, eventdata, handles)
|
---|
[581] | 194 | %------------------------------------------------------------------------
|
---|
[599] | 195 | varargout{1}='Cancel';%deg
|
---|
[2] | 196 | % Get default command line output from handles structure
|
---|
[246] | 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
|
---|
[581] | 203 | if strcmp(get(handles.edit_box,'Style'),'listbox')
|
---|
[713] | 204 | varargout{1}=get(handles.edit_box,'Value');
|
---|
[581] | 205 | else
|
---|
[713] | 206 | varargout{1}=get(handles.edit_box,'String');
|
---|
[581] | 207 | end
|
---|
[713] | 208 | if isempty(varargout{1})
|
---|
[246] | 209 | varargout{1}='Yes';
|
---|
| 210 | end
|
---|
[2] | 211 | end
|
---|
[713] | 212 | if strcmp(get(handles.edit_box, 'Visible'), 'on')
|
---|
| 213 | varargout{2}=get(handles.edit_box,'String');
|
---|
| 214 | end
|
---|
[246] | 215 | % The figure can be deleted now
|
---|
[746] | 216 | if strcmp(get(handles.OK,'Visible'),'on')
|
---|
[599] | 217 | delete(handles.figure1);
|
---|
[747] | 218 | else %case of WAITING... display (non modal)
|
---|
[746] | 219 | varargout{1}=hObject;
|
---|
| 220 | end
|
---|
[2] | 221 | end
|
---|
[713] | 222 |
|
---|
[599] | 223 | % delete(handles.figure1);
|
---|
[581] | 224 |
|
---|
| 225 | %------------------------------------------------------------------------
|
---|
[2] | 226 | % --- Executes on button press in OK.
|
---|
| 227 | function OK_Callback(hObject, eventdata, handles)
|
---|
[581] | 228 | %------------------------------------------------------------------------
|
---|
[2] | 229 | handles.output = get(hObject,'String');
|
---|
| 230 | guidata(hObject, handles);% Update handles structure
|
---|
| 231 | uiresume(handles.figure1);
|
---|
| 232 |
|
---|
[581] | 233 | %------------------------------------------------------------------------
|
---|
[2] | 234 | % --- Executes on button press in No.
|
---|
| 235 | function No_Callback(hObject, eventdata, handles)
|
---|
[581] | 236 | %------------------------------------------------------------------------
|
---|
[2] | 237 | handles.output='No';
|
---|
| 238 | guidata(hObject, handles);
|
---|
| 239 | uiresume(handles.figure1);
|
---|
| 240 |
|
---|
[581] | 241 | %------------------------------------------------------------------------
|
---|
[2] | 242 | % --- Executes on button press in Cancel.
|
---|
| 243 | function Cancel_Callback(hObject, eventdata, handles)
|
---|
[581] | 244 | %------------------------------------------------------------------------
|
---|
[2] | 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 |
|
---|
[581] | 252 | %------------------------------------------------------------------------
|
---|
[2] | 253 | % --- Executes when user attempts to close figure1.
|
---|
| 254 | function figure1_CloseRequestFcn(hObject, eventdata, handles)
|
---|
[581] | 255 | %------------------------------------------------------------------------
|
---|
[733] | 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
|
---|
[2] | 261 | % The GUI is no longer waiting, just close it
|
---|
[733] | 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);
|
---|
[2] | 270 |
|
---|
[733] | 271 |
|
---|
[581] | 272 | %------------------------------------------------------------------------
|
---|
[2] | 273 | % --- Executes on key press over figure1 with no controls selected.
|
---|
| 274 | function figure1_KeyPressFcn(hObject, eventdata, handles)
|
---|
[581] | 275 | %------------------------------------------------------------------------
|
---|
[2] | 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 |
|
---|