source: trunk/src/msgbox_uvmat.m @ 1160

Last change on this file since 1160 was 1157, checked in by sommeria, 3 months ago

filter_time added

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