source: trunk/src/msgbox_uvmat.m @ 244

Last change on this file since 244 was 244, checked in by sommeria, 13 years ago

various bug repair, improved display of msgbox_uvmat

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