source: trunk/src/msgbox_uvmat.m @ 746

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