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