source: trunk/src/msgbox_uvmat.m @ 1157

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

filter_time added

File size: 12.0 KB
RevLine 
[2]1%'msgbox_uvmat': associated with GUI msgbox_uvmat.fig to display message boxes, for error, warning or input calls
2%
[654]3% answer=msgbox_uvmat(title,display,default_answer,Position)
4%
[2]5% OUTPUT:
6% answer  (text string)= 'yes', 'No', 'cancel', or the text string introduced as input
[747]7% for title='WAITING...', the output is the handle of the figure, to allow deletion by the calling program.
[2]8%
9%INPUT:
[851]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
[1157]12%                = 'INPUT_MENU', input data must be selected from  a menu choice
[851]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
[747]18% display: displayed text
[1157]19% default_answer: default answer in the edit box (only used with title='INPUT_TXT' or 'INPUT_MENU')
[2]20
[809]21%=======================================================================
[1126]22% Copyright 2008-2024, LEGI UMR 5519 / CNRS UGA G-INP, Grenoble, France
[809]23%   http://www.legi.grenoble-inp.fr
[1127]24%   Joel.Sommeria - Joel.Sommeria (A) univ-grenoble-alpes.fr
[809]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
[2]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',   []);
[121]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
[2]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
[581]62%------------------------------------------------------------------------
[2]63% --- Executes just before msgbox_uvmat is made visible.
[421]64function msgbox_uvmat_OpeningFcn(hObject, eventdata, handles,title,display_str,default_answer,Position)
[581]65%------------------------------------------------------------------------
[2]66% This function has no output args, see OutputFcn.
67
68% Choose default command line output for msgbox_uvmat
69handles.output = 'Cancel';
[244]70set(handles.figure1,'Units','pixels')
71FigPos=[100 150 500 50];%default position
[1157]72if strcmp(title,'INPUT_MENU')
73    FigPos=[100 150 500 200];%default position
74end
[472]75if exist('Position','var') && numel(Position)>=2
[244]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)
[726]89% set(hObject,'WindowKeyPressFcn',{'keyboard_callback',handles})%set keyboard action function
[2]90
91% Update handles structure
92guidata(hObject, handles);
93testNo=0;
[246]94testCancel=0;
[746]95testOK=1;
[2]96testinputstring=0;
97icontype='quest';%default question icon (text input asked)
98if exist('title','var')
[156]99    set(hObject, 'Name', title);
100    switch title
101        case {'CONFIRMATION'}
102            icontype='';
103        case 'ERROR'
104            icontype='error';
[421]105            if exist('display_str','var')
106                disp(display_str); %display the error message in the Matlab command window
107            end
[156]108        case 'WARNING'
109            icontype='warn';
110        case 'INPUT_Y-N'
111            icontype='quest';
[847]112            testCancel=0; %no cancel button
[156]113            testNo=1; % button No activated
[851]114        case 'INPUT_Y-N-Cancel'
115            icontype='quest';
116            testCancel=1; % cancel button introduced
117            testNo=1; % button No activated
[747]118        case 'RULER'
[156]119            icontype='';
120            testinputstring=1;
[244]121        case 'INPUT_TXT'
122            testinputstring=1;
[246]123            testCancel=1; %no cancel button
[581]124        case 'INPUT_MENU'
125            testinputstring=2;
126            testCancel=1; %no cancel button
[747]127        case 'WAITING...'
[746]128            icontype='';
129            testOK=0;
[156]130        otherwise
[244]131          %  testinputstring=1;
132            icontype='';
133            testinputstring=exist('default_answer','var');
[156]134    end
[2]135end
[421]136if exist('display_str','var')
137    set(handles.text1, 'String', display_str);
[2]138end
[581]139
140if testinputstring==1
[2]141    set(handles.edit_box, 'Visible', 'on');
[244]142    if ~exist('default_answer','var');
143        default_answer='';
144    end
145    set(handles.edit_box, 'String', default_answer);
[733]146    if exist('Position','var')&&numel(Position)>=2
[581]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)
[244]165    end
[581]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)
[1157]170    set(handles.edit_box,'Max',2);% allows for multiple selection
[2]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   
[296]205set(handles.figure1,'Units','normalized')
206set(handles.edit_box,'Units','normalized')
[746]207if testOK
[2]208set(handles.figure1,'WindowStyle','modal')% Make% Make the GUI modal
[746]209set(handles.OK,'Visible','on')
[2]210% UIWAIT makes msgbox_uvmat wait for user response (see UIRESUME)
211uiwait(handles.figure1);
[746]212else
213   set(handles.OK,'Visible','off')
214end
[2]215
[746]216
[581]217%------------------------------------------------------------------------
[2]218% --- Outputs from this function are returned to the command line.
219function varargout = msgbox_uvmat_OutputFcn(hObject, eventdata, handles)
[581]220%------------------------------------------------------------------------
[599]221varargout{1}='Cancel';%deg
[2]222% Get default command line output from handles structure
[246]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
[581]229        if strcmp(get(handles.edit_box,'Style'),'listbox')
[713]230            varargout{1}=get(handles.edit_box,'Value');
[581]231        else
[713]232            varargout{1}=get(handles.edit_box,'String');
[581]233        end
[713]234        if isempty(varargout{1})
[246]235            varargout{1}='Yes';
236        end
[2]237    end
[713]238    if strcmp(get(handles.edit_box, 'Visible'), 'on')
239        varargout{2}=get(handles.edit_box,'String');
240    end
[246]241    % The figure can be deleted now
[746]242    if strcmp(get(handles.OK,'Visible'),'on')
[599]243    delete(handles.figure1);
[747]244    else %case of WAITING... display (non modal)
[746]245        varargout{1}=hObject;
246    end
[2]247end
[713]248
[599]249%  delete(handles.figure1);
[581]250
251%------------------------------------------------------------------------
[2]252% --- Executes on button press in OK.
253function OK_Callback(hObject, eventdata, handles)
[581]254%------------------------------------------------------------------------
[2]255handles.output = get(hObject,'String');
256guidata(hObject, handles);% Update handles structure
257uiresume(handles.figure1);
258
[581]259%------------------------------------------------------------------------
[2]260% --- Executes on button press in No.
261function No_Callback(hObject, eventdata, handles)
[581]262%------------------------------------------------------------------------
[2]263handles.output='No';
264guidata(hObject, handles);
265uiresume(handles.figure1);
266
[581]267%------------------------------------------------------------------------
[2]268% --- Executes on button press in Cancel.
269function Cancel_Callback(hObject, eventdata, handles)
[581]270%------------------------------------------------------------------------
[2]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
[581]278%------------------------------------------------------------------------
[2]279% --- Executes when user attempts to close figure1.
280function figure1_CloseRequestFcn(hObject, eventdata, handles)
[581]281%------------------------------------------------------------------------
[733]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
[2]287    % The GUI is no longer waiting, just close it
[733]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);
[2]296
[733]297
[581]298%------------------------------------------------------------------------
[2]299% --- Executes on key press over figure1 with no controls selected.
300function figure1_KeyPressFcn(hObject, eventdata, handles)
[581]301%------------------------------------------------------------------------
[2]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.