source: trunk/src/msgbox_uvmat.m @ 575

Last change on this file since 575 was 507, checked in by sommeria, 12 years ago

various improvments and corrections
dtatatree_browser tested

File size: 8.9 KB
Line 
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
16function 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
21gui_Singleton = 1;
22gui_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',   []);
28if 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
30end
31
32if nargout
33    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
34else
35    gui_mainfcn(gui_State, varargin{:});
36end
37% End initialization code - DO NOT EDIT
38
39% --- Executes just before msgbox_uvmat is made visible.
40function msgbox_uvmat_OpeningFcn(hObject, eventdata, handles,title,display_str,default_answer,Position)
41% This function has no output args, see OutputFcn.
42
43% Choose default command line output for msgbox_uvmat
44handles.output = 'Cancel';
45set(handles.figure1,'Units','pixels')
46FigPos=[100 150 500 50];%default position
47if exist('Position','var') && numel(Position)>=2
48    FigPos(1)=Position(1);
49    FigPos(2)=Position(2)-FigPos(4);% upper left corner set by input Position
50    set(handles.figure1,'Position',FigPos)
51end
52set(handles.OK,'Units','pixels')
53set(handles.OK,'Position',[100 2 60 30])
54set(handles.OK,'FontSize',15)
55set(handles.No,'Units','pixels')
56set(handles.No,'Position',[200 2 60 30])
57set(handles.No,'FontSize',15)
58set(handles.Cancel,'Units','pixels')
59set(handles.Cancel,'Position',[300 2 60 30])
60set(handles.Cancel,'FontSize',15)
61
62
63% Update handles structure
64guidata(hObject, handles);
65testNo=0;
66testCancel=0;
67testinputstring=0;
68icontype='quest';%default question icon (text input asked)
69if exist('title','var')
70    set(hObject, 'Name', title);
71    switch title
72        case {'CONFIRMATION'}
73            icontype='';
74        case 'ERROR'
75            icontype='error';
76            if exist('display_str','var')
77                disp(display_str); %display the error message in the Matlab command window
78            end
79        case 'WARNING'
80            icontype='warn';
81        case 'INPUT_Y-N'
82            icontype='quest';
83            testCancel=1; %no cancel button
84            testNo=1; % button No activated
85        case {'RULER'}
86            icontype='';
87            testinputstring=1;
88        case 'INPUT_TXT'
89            testinputstring=1;
90            testCancel=1; %no cancel button
91        otherwise
92          %  testinputstring=1;
93            icontype='';
94            testinputstring=exist('default_answer','var');
95    end
96end
97if exist('display_str','var')
98    set(handles.text1, 'String', display_str);
99end
100% if testinputstring
101%     set(handles.edit_box, 'Visible', 'on');
102% else
103%     set(handles.text1, 'Position', [0.15 0.3 0.85 0.7]);
104% end
105if testinputstring
106    % set(handles.figure1,'Position',[40,80,20*length(default_answer),50])
107    set(handles.edit_box, 'Visible', 'on');
108    if ~exist('default_answer','var');
109        default_answer='';
110    end
111    set(handles.edit_box, 'String', default_answer);
112    if exist('Position','var')
113    if iscell(default_answer)
114        widthstring=max(max(cellfun('length',default_answer)),length(display_str));
115        heightstring=size(default_answer,1);%nbre of expected lines
116        set(handles.edit_box,'Max',2);
117    else
118        widthstring=max(length(default_answer),length(display_str));
119        heightstring=1;
120    end
121    widthstring=max(widthstring,length(title)+20);
122    boxsize=[10*widthstring 20*heightstring];%size of the display edit box
123    set(handles.edit_box,'Units','pixels')
124    set(handles.edit_box,'FontUnits','pixels')
125    set(handles.edit_box,'FontSize',12) 
126   set(handles.edit_box,'Position',[5,34,boxsize(1),boxsize(2)])
127   FigPos(3)=10+boxsize(1);
128   FigPos(4)=56+boxsize(2);
129   FigPos(2)=Position(2)-FigPos(4)-25;
130   set(handles.figure1,'Position',FigPos)
131    end
132%     set(handles.figure1,'Position',[40,40,20*length(default_answer),50])
133else
134    set(handles.text1, 'Position', [0.15 0.3 0.85 0.7]);
135end
136% Determine the position of the dialog - centered on the screen
137% FigPos=get(0,'DefaultFigurePosition');
138% OldUnits = get(hObject, 'Units');
139% set(hObject, 'Units', 'pixels');
140% OldPos = get(hObject,'Position');
141% FigWidth = OldPos(3);
142% FigHeight = OldPos(4);
143% ScreenUnits=get(0,'Units');
144% set(0,'Units','pixels');
145% ScreenSize=get(0,'ScreenSize');
146% set(0,'Units',ScreenUnits);
147%
148% FigPos(1)=1/2*(ScreenSize(3)-FigWidth);
149% FigPos(2)=2/3*(ScreenSize(4)-FigHeight);
150% FigPos(3:4)=[FigWidth FigHeight];
151% set(hObject, 'Position', FigPos);
152% set(hObject, 'Units', OldUnits);
153
154% Show a question icon from dialogicons.mat - variables questIconData and questIconMap
155if isequal(icontype,'')
156    hima=findobj(handles.axes1,'Type','image');
157    if ~isempty(hima)
158        delete(hima)
159    end
160else
161    load dialogicons.mat
162    eval(['IconData=' icontype 'IconData;'])
163    eval(['IconCMap=' icontype 'IconMap;'])
164    questIconMap(256,:) = get(handles.figure1, 'Color');
165    Img=image(IconData, 'Parent', handles.axes1);
166    set(handles.figure1, 'Colormap', IconCMap);
167    set(handles.axes1, ...
168        'Visible', 'off', ...
169        'YDir'   , 'reverse'       , ...
170        'XLim'   , get(Img,'XData'), ...
171        'YLim'   , get(Img,'YData')  ...
172        );
173end
174if testCancel
175     set(handles.Cancel,'Visible','on')
176else
177    set(handles.Cancel,'Visible','off')
178end
179if testNo
180     set(handles.No,'Visible','on')
181else
182    set(handles.No,'Visible','off')
183end   
184set(handles.figure1,'Units','normalized')
185set(handles.edit_box,'Units','normalized')
186
187set(handles.figure1,'WindowStyle','modal')% Make% Make the GUI modal
188% UIWAIT makes msgbox_uvmat wait for user response (see UIRESUME)
189uiwait(handles.figure1);
190
191
192% --- Outputs from this function are returned to the command line.
193function varargout = msgbox_uvmat_OutputFcn(hObject, eventdata, handles)
194
195% Get default command line output from handles structure
196if isfield(handles,'output')
197    if isequal(handles.output,'Cancel')
198        varargout{1}='Cancel';
199    elseif isequal(handles.output,'No')
200        varargout{1}='No';
201    else
202        varargout{1}=get(handles.edit_box,'String');
203        if isempty(varargout{1}) || isequal(varargout{1},'')
204            varargout{1}='Yes';
205        end
206    end
207    % The figure can be deleted now
208end
209 delete(handles.figure1);
210 
211% --- Executes on button press in OK.
212function OK_Callback(hObject, eventdata, handles)
213handles.output = get(hObject,'String');
214guidata(hObject, handles);% Update handles structure
215uiresume(handles.figure1);
216
217% --- Executes on button press in No.
218function No_Callback(hObject, eventdata, handles)
219handles.output='No';
220guidata(hObject, handles);
221uiresume(handles.figure1);
222
223% --- Executes on button press in Cancel.
224function Cancel_Callback(hObject, eventdata, handles)
225handles.output = get(hObject,'String');
226%handles.output = 'Cancel'
227guidata(hObject, handles); % Update handles structure
228% Use UIRESUME instead of delete because the OutputFcn needs
229% to get the updated handles structure.
230uiresume(handles.figure1);
231
232
233% --- Executes when user attempts to close figure1.
234function figure1_CloseRequestFcn(hObject, eventdata, handles)
235if isequal(get(handles.figure1, 'waitstatus'), 'waiting')
236    % The GUI is still in UIWAIT, us UIRESUME
237    uiresume(handles.figure1);
238else
239    % The GUI is no longer waiting, just close it
240    delete(handles.figure1);
241end
242
243% --- Executes on key press over figure1 with no controls selected.
244function figure1_KeyPressFcn(hObject, eventdata, handles)
245% Check for "enter" or "escape"
246if isequal(get(hObject,'CurrentKey'),'escape')
247    % User said no by hitting escape
248    handles.output = 'No';
249   
250    % Update handles structure
251    guidata(hObject, handles);
252   
253    uiresume(handles.figure1);
254end
255if isequal(get(hObject,'CurrentKey'),'return')
256    uiresume(handles.figure1);
257end   
258
259
260
261
262
Note: See TracBrowser for help on using the repository browser.