source: trunk/src/msgbox_uvmat.m @ 785

Last change on this file since 785 was 747, checked in by sommeria, 11 years ago

adpatations to 3D fields

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