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