[2] | 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', []);
|
---|
[121] | 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
|
---|
[2] | 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,default_answer)
|
---|
| 41 | % This function has no output args, see OutputFcn.
|
---|
| 42 |
|
---|
| 43 | % Choose default command line output for msgbox_uvmat
|
---|
| 44 | handles.output = 'Cancel';
|
---|
| 45 |
|
---|
| 46 | % Update handles structure
|
---|
| 47 | guidata(hObject, handles);
|
---|
| 48 | testNo=0;
|
---|
| 49 | testCancel=1;
|
---|
| 50 | testinputstring=0;
|
---|
| 51 | icontype='quest';%default question icon (text input asked)
|
---|
| 52 | if exist('title','var')
|
---|
[156] | 53 | set(hObject, 'Name', title);
|
---|
| 54 | switch title
|
---|
| 55 | case {'CONFIRMATION'}
|
---|
| 56 | icontype='';
|
---|
| 57 | testCancel=0; %no cancel button
|
---|
| 58 | case 'ERROR'
|
---|
| 59 | icontype='error';
|
---|
| 60 | testCancel=0; %no cancel button
|
---|
| 61 | case 'WARNING'
|
---|
| 62 | icontype='warn';
|
---|
| 63 | testCancel=0; %no cancel button
|
---|
| 64 | case 'INPUT_Y-N'
|
---|
| 65 | icontype='quest';
|
---|
| 66 | testNo=1; % button No activated
|
---|
| 67 | case {'RULER'}
|
---|
| 68 | icontype='';
|
---|
| 69 | testCancel=0; %no cancel button
|
---|
| 70 | testinputstring=1;
|
---|
| 71 | otherwise
|
---|
| 72 | testinputstring=1;
|
---|
| 73 | end
|
---|
[2] | 74 | end
|
---|
| 75 | if exist('display','var')
|
---|
| 76 | set(handles.text1, 'String', display);
|
---|
| 77 | end
|
---|
| 78 | if testinputstring
|
---|
| 79 | set(handles.edit_box, 'Visible', 'on');
|
---|
| 80 | else
|
---|
| 81 | set(handles.text1, 'Position', [0.15 0.3 0.85 0.7]);
|
---|
| 82 | end
|
---|
| 83 | if exist('default_answer','var') && testinputstring
|
---|
| 84 | set(handles.edit_box, 'String', default_answer);
|
---|
| 85 | end
|
---|
| 86 | % Determine the position of the dialog - centered on the screen
|
---|
| 87 | FigPos=get(0,'DefaultFigurePosition');
|
---|
| 88 | OldUnits = get(hObject, 'Units');
|
---|
| 89 | set(hObject, 'Units', 'pixels');
|
---|
| 90 | OldPos = get(hObject,'Position');
|
---|
| 91 | FigWidth = OldPos(3);
|
---|
| 92 | FigHeight = OldPos(4);
|
---|
| 93 | ScreenUnits=get(0,'Units');
|
---|
| 94 | set(0,'Units','pixels');
|
---|
| 95 | ScreenSize=get(0,'ScreenSize');
|
---|
| 96 | set(0,'Units',ScreenUnits);
|
---|
| 97 |
|
---|
| 98 | FigPos(1)=1/2*(ScreenSize(3)-FigWidth);
|
---|
| 99 | FigPos(2)=2/3*(ScreenSize(4)-FigHeight);
|
---|
| 100 | FigPos(3:4)=[FigWidth FigHeight];
|
---|
| 101 | set(hObject, 'Position', FigPos);
|
---|
| 102 | set(hObject, 'Units', OldUnits);
|
---|
| 103 |
|
---|
| 104 | % Show a question icon from dialogicons.mat - variables questIconData and questIconMap
|
---|
| 105 | if isequal(icontype,'')
|
---|
| 106 | hima=findobj(handles.axes1,'Type','image');
|
---|
| 107 | if ~isempty(hima)
|
---|
| 108 | delete(hima)
|
---|
| 109 | end
|
---|
| 110 | else
|
---|
| 111 | load dialogicons.mat
|
---|
| 112 | eval(['IconData=' icontype 'IconData;'])
|
---|
| 113 | eval(['IconCMap=' icontype 'IconMap;'])
|
---|
| 114 | questIconMap(256,:) = get(handles.figure1, 'Color');
|
---|
| 115 | Img=image(IconData, 'Parent', handles.axes1);
|
---|
| 116 | set(handles.figure1, 'Colormap', IconCMap);
|
---|
| 117 | set(handles.axes1, ...
|
---|
| 118 | 'Visible', 'off', ...
|
---|
| 119 | 'YDir' , 'reverse' , ...
|
---|
| 120 | 'XLim' , get(Img,'XData'), ...
|
---|
| 121 | 'YLim' , get(Img,'YData') ...
|
---|
| 122 | );
|
---|
| 123 | end
|
---|
| 124 | if testCancel
|
---|
| 125 | set(handles.Cancel,'Visible','on')
|
---|
| 126 | else
|
---|
| 127 | set(handles.Cancel,'Visible','off')
|
---|
| 128 | end
|
---|
| 129 | if testNo
|
---|
| 130 | set(handles.No,'Visible','on')
|
---|
| 131 | else
|
---|
| 132 | set(handles.No,'Visible','off')
|
---|
| 133 | end
|
---|
| 134 | set(handles.figure1,'WindowStyle','modal')% Make% Make the GUI modal
|
---|
| 135 | % UIWAIT makes msgbox_uvmat wait for user response (see UIRESUME)
|
---|
| 136 | uiwait(handles.figure1);
|
---|
| 137 |
|
---|
| 138 |
|
---|
| 139 | % --- Outputs from this function are returned to the command line.
|
---|
| 140 | function varargout = msgbox_uvmat_OutputFcn(hObject, eventdata, handles)
|
---|
| 141 |
|
---|
| 142 | % Get default command line output from handles structure
|
---|
| 143 | if isequal(handles.output,'Cancel')
|
---|
| 144 | varargout{1}='Cancel';
|
---|
| 145 | elseif isequal(handles.output,'No')
|
---|
| 146 | varargout{1}='No';
|
---|
| 147 | else
|
---|
| 148 | varargout{1}=get(handles.edit_box,'String');
|
---|
| 149 | if isempty(varargout{1}) || isequal(varargout{1},'')
|
---|
| 150 | varargout{1}='Yes';
|
---|
| 151 | end
|
---|
| 152 | end
|
---|
| 153 | % The figure can be deleted now
|
---|
| 154 | delete(handles.figure1);
|
---|
| 155 |
|
---|
| 156 | % --- Executes on button press in OK.
|
---|
| 157 | function OK_Callback(hObject, eventdata, handles)
|
---|
| 158 | handles.output = get(hObject,'String');
|
---|
| 159 | guidata(hObject, handles);% Update handles structure
|
---|
| 160 | uiresume(handles.figure1);
|
---|
| 161 |
|
---|
| 162 | % --- Executes on button press in No.
|
---|
| 163 | function No_Callback(hObject, eventdata, handles)
|
---|
| 164 | handles.output='No';
|
---|
| 165 | guidata(hObject, handles);
|
---|
| 166 | uiresume(handles.figure1);
|
---|
| 167 |
|
---|
| 168 | % --- Executes on button press in Cancel.
|
---|
| 169 | function Cancel_Callback(hObject, eventdata, handles)
|
---|
| 170 | handles.output = get(hObject,'String');
|
---|
| 171 | %handles.output = 'Cancel'
|
---|
| 172 | guidata(hObject, handles); % Update handles structure
|
---|
| 173 | % Use UIRESUME instead of delete because the OutputFcn needs
|
---|
| 174 | % to get the updated handles structure.
|
---|
| 175 | uiresume(handles.figure1);
|
---|
| 176 |
|
---|
| 177 |
|
---|
| 178 | % --- Executes when user attempts to close figure1.
|
---|
| 179 | function figure1_CloseRequestFcn(hObject, eventdata, handles)
|
---|
| 180 | if isequal(get(handles.figure1, 'waitstatus'), 'waiting')
|
---|
| 181 | % The GUI is still in UIWAIT, us UIRESUME
|
---|
| 182 | uiresume(handles.figure1);
|
---|
| 183 | else
|
---|
| 184 | % The GUI is no longer waiting, just close it
|
---|
| 185 | delete(handles.figure1);
|
---|
| 186 | end
|
---|
| 187 |
|
---|
| 188 | % --- Executes on key press over figure1 with no controls selected.
|
---|
| 189 | function figure1_KeyPressFcn(hObject, eventdata, handles)
|
---|
| 190 | % Check for "enter" or "escape"
|
---|
| 191 | if isequal(get(hObject,'CurrentKey'),'escape')
|
---|
| 192 | % User said no by hitting escape
|
---|
| 193 | handles.output = 'No';
|
---|
| 194 |
|
---|
| 195 | % Update handles structure
|
---|
| 196 | guidata(hObject, handles);
|
---|
| 197 |
|
---|
| 198 | uiresume(handles.figure1);
|
---|
| 199 | end
|
---|
| 200 | if isequal(get(hObject,'CurrentKey'),'return')
|
---|
| 201 | uiresume(handles.figure1);
|
---|
| 202 | end
|
---|
| 203 |
|
---|
| 204 |
|
---|
| 205 |
|
---|
| 206 |
|
---|
| 207 |
|
---|