source: trunk/src/msgbox_uvmat.m @ 295

Last change on this file since 295 was 246, checked in by sommeria, 10 years ago

thin plate shell (patch) introduced

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=0;
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        case 'ERROR'
74            icontype='error';
75        case 'WARNING'
76            icontype='warn';
77        case 'INPUT_Y-N'
78            icontype='quest';
79            testCancel=1; %no cancel button
80            testNo=1; % button No activated
81        case {'RULER'}
82            icontype='';
83            testinputstring=1;
84        case 'INPUT_TXT'
85            testinputstring=1;
86            testCancel=1; %no cancel button
87        otherwise
88          %  testinputstring=1;
89            icontype='';
90            testinputstring=exist('default_answer','var');
91    end
92end
93if exist('display','var')
94    set(handles.text1, 'String', display);
95end
96% if testinputstring
97%     set(handles.edit_box, 'Visible', 'on');
98% else
99%     set(handles.text1, 'Position', [0.15 0.3 0.85 0.7]);
100% end
101if testinputstring
102    % set(handles.figure1,'Position',[40,80,20*length(default_answer),50])
103    set(handles.edit_box, 'Visible', 'on');
104    if ~exist('default_answer','var');
105        default_answer='';
106    end
107    set(handles.edit_box, 'String', default_answer);
108    if exist('Position','var')
109    if iscell(default_answer)
110        widthstring=max(cellfun('length',default_answer));
111        heightstring=size(default_answer,1);
112        set(handles.edit_box,'Max',2);
113    else
114        widthstring=length(default_answer);
115        heightstring=1;
116    end
117    widthstring=max(widthstring,length(title));
118    boxsize=[10*widthstring 20*heightstring];%size of the display edit box
119    set(handles.edit_box,'Units','pixels')
120    set(handles.edit_box,'FontUnits','pixels')
121    set(handles.edit_box,'FontSize',12) 
122   set(handles.edit_box,'Position',[5,34,boxsize(1),boxsize(2)])
123   FigPos(3)=10+boxsize(1);
124   FigPos(4)=36+boxsize(2);
125   FigPos(2)=Position(2)-FigPos(4)-25;
126   set(handles.figure1,'Position',FigPos)
127    end
128%     set(handles.figure1,'Position',[40,40,20*length(default_answer),50])
129else
130    set(handles.text1, 'Position', [0.15 0.3 0.85 0.7]);
131end
132% Determine the position of the dialog - centered on the screen
133% FigPos=get(0,'DefaultFigurePosition');
134% OldUnits = get(hObject, 'Units');
135% set(hObject, 'Units', 'pixels');
136% OldPos = get(hObject,'Position');
137% FigWidth = OldPos(3);
138% FigHeight = OldPos(4);
139% ScreenUnits=get(0,'Units');
140% set(0,'Units','pixels');
141% ScreenSize=get(0,'ScreenSize');
142% set(0,'Units',ScreenUnits);
143%
144% FigPos(1)=1/2*(ScreenSize(3)-FigWidth);
145% FigPos(2)=2/3*(ScreenSize(4)-FigHeight);
146% FigPos(3:4)=[FigWidth FigHeight];
147% set(hObject, 'Position', FigPos);
148% set(hObject, 'Units', OldUnits);
149
150% Show a question icon from dialogicons.mat - variables questIconData and questIconMap
151if isequal(icontype,'')
152    hima=findobj(handles.axes1,'Type','image');
153    if ~isempty(hima)
154        delete(hima)
155    end
156else
157    load dialogicons.mat
158    eval(['IconData=' icontype 'IconData;'])
159    eval(['IconCMap=' icontype 'IconMap;'])
160    questIconMap(256,:) = get(handles.figure1, 'Color');
161    Img=image(IconData, 'Parent', handles.axes1);
162    set(handles.figure1, 'Colormap', IconCMap);
163    set(handles.axes1, ...
164        'Visible', 'off', ...
165        'YDir'   , 'reverse'       , ...
166        'XLim'   , get(Img,'XData'), ...
167        'YLim'   , get(Img,'YData')  ...
168        );
169end
170if testCancel
171     set(handles.Cancel,'Visible','on')
172else
173    set(handles.Cancel,'Visible','off')
174end
175if testNo
176     set(handles.No,'Visible','on')
177else
178    set(handles.No,'Visible','off')
179end   
180set(handles.figure1,'WindowStyle','modal')% Make% Make the GUI modal
181% UIWAIT makes msgbox_uvmat wait for user response (see UIRESUME)
182uiwait(handles.figure1);
183
184
185% --- Outputs from this function are returned to the command line.
186function varargout = msgbox_uvmat_OutputFcn(hObject, eventdata, handles)
187
188% Get default command line output from handles structure
189if isfield(handles,'output')
190    if isequal(handles.output,'Cancel')
191        varargout{1}='Cancel';
192    elseif isequal(handles.output,'No')
193        varargout{1}='No';
194    else
195        varargout{1}=get(handles.edit_box,'String');
196        if isempty(varargout{1}) || isequal(varargout{1},'')
197            varargout{1}='Yes';
198        end
199    end
200    % The figure can be deleted now
201end
202 delete(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.