source: trunk/src/msgbox_uvmat.m @ 878

Last change on this file since 878 was 851, checked in by sommeria, 10 years ago

various

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