source: trunk/src/msgbox_uvmat.m @ 823

Last change on this file since 823 was 809, checked in by g7moreau, 10 years ago
  • Add license
File size: 11.6 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:
11%          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).
12%          if title='INPUT_TXT', input data is asked in an edit box
13%          if title='CONFIMATION'', 'ERROR', 'WARNING','RULER' the figure remains  opened until a button 'OK' is pressed
14%             title='RULER' is used for display of length and angle from the ruler tool.
15%          if title='INPUT_Y-N', an answer Yes/No is requested
16%          if title='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=1; %no cancel button
109            testNo=1; % button No activated
110        case 'RULER'
111            icontype='';
112            testinputstring=1;
113        case 'INPUT_TXT'
114            testinputstring=1;
115            testCancel=1; %no cancel button
116        case 'INPUT_MENU'
117            testinputstring=2;
118            testCancel=1; %no cancel button
119        case 'WAITING...'
120            icontype='';
121            testOK=0;
122        otherwise
123          %  testinputstring=1;
124            icontype='';
125            testinputstring=exist('default_answer','var');
126    end
127end
128if exist('display_str','var')
129    set(handles.text1, 'String', display_str);
130end
131
132if testinputstring==1
133    set(handles.edit_box, 'Visible', 'on');
134    if ~exist('default_answer','var');
135        default_answer='';
136    end
137    set(handles.edit_box, 'String', default_answer);
138    if exist('Position','var')&&numel(Position)>=2
139        if iscell(default_answer)
140            widthstring=max(max(cellfun('length',default_answer)),length(display_str));
141            heightstring=size(default_answer,1);%nbre of expected lines
142            set(handles.edit_box,'Max',2);
143        else
144            widthstring=max(length(default_answer),length(display_str));
145            heightstring=1;
146        end
147        widthstring=max(widthstring,length(title)+20);
148        boxsize=[10*widthstring 20*heightstring];%size of the display edit box
149        set(handles.edit_box,'Units','pixels')
150        set(handles.edit_box,'FontUnits','pixels')
151        set(handles.edit_box,'FontSize',12)
152        set(handles.edit_box,'Position',[5,34,boxsize(1),boxsize(2)])
153        FigPos(3)=10+boxsize(1);
154        FigPos(4)=56+boxsize(2);
155        FigPos(2)=Position(2)-FigPos(4)-25;
156        set(handles.figure1,'Position',FigPos)
157    end
158elseif testinputstring==2
159    set(handles.edit_box,'style','listbox')
160    set(handles.edit_box, 'Visible', 'on');
161    set(handles.edit_box,'String', default_answer)
162else
163    set(handles.text1, 'Position', [0.15 0.3 0.85 0.7]);
164end
165
166% Show a question icon from dialogicons.mat - variables questIconData and questIconMap
167if isequal(icontype,'')
168    hima=findobj(handles.axes1,'Type','image');
169    if ~isempty(hima)
170        delete(hima)
171    end
172else
173    load dialogicons.mat
174    eval(['IconData=' icontype 'IconData;'])
175    eval(['IconCMap=' icontype 'IconMap;'])
176    questIconMap(256,:) = get(handles.figure1, 'Color');
177    Img=image(IconData, 'Parent', handles.axes1);
178    set(handles.figure1, 'Colormap', IconCMap);
179    set(handles.axes1, ...
180        'Visible', 'off', ...
181        'YDir'   , 'reverse'       , ...
182        'XLim'   , get(Img,'XData'), ...
183        'YLim'   , get(Img,'YData')  ...
184        );
185end
186if testCancel
187     set(handles.Cancel,'Visible','on')
188else
189    set(handles.Cancel,'Visible','off')
190end
191if testNo
192     set(handles.No,'Visible','on')
193else
194    set(handles.No,'Visible','off')
195end   
196set(handles.figure1,'Units','normalized')
197set(handles.edit_box,'Units','normalized')
198if testOK
199set(handles.figure1,'WindowStyle','modal')% Make% Make the GUI modal
200set(handles.OK,'Visible','on')
201% UIWAIT makes msgbox_uvmat wait for user response (see UIRESUME)
202uiwait(handles.figure1);
203else
204   set(handles.OK,'Visible','off')
205end
206
207
208%------------------------------------------------------------------------
209% --- Outputs from this function are returned to the command line.
210function varargout = msgbox_uvmat_OutputFcn(hObject, eventdata, handles)
211%------------------------------------------------------------------------
212varargout{1}='Cancel';%deg
213% Get default command line output from handles structure
214if isfield(handles,'output')
215    if isequal(handles.output,'Cancel')
216        varargout{1}='Cancel';
217    elseif isequal(handles.output,'No')
218        varargout{1}='No';
219    else
220        if strcmp(get(handles.edit_box,'Style'),'listbox')
221            varargout{1}=get(handles.edit_box,'Value');
222        else
223            varargout{1}=get(handles.edit_box,'String');
224        end
225        if isempty(varargout{1})
226            varargout{1}='Yes';
227        end
228    end
229    if strcmp(get(handles.edit_box, 'Visible'), 'on')
230        varargout{2}=get(handles.edit_box,'String');
231    end
232    % The figure can be deleted now
233    if strcmp(get(handles.OK,'Visible'),'on')
234    delete(handles.figure1);
235    else %case of WAITING... display (non modal)
236        varargout{1}=hObject;
237    end
238end
239
240%  delete(handles.figure1);
241
242%------------------------------------------------------------------------
243% --- Executes on button press in OK.
244function OK_Callback(hObject, eventdata, handles)
245%------------------------------------------------------------------------
246handles.output = get(hObject,'String');
247guidata(hObject, handles);% Update handles structure
248uiresume(handles.figure1);
249
250%------------------------------------------------------------------------
251% --- Executes on button press in No.
252function No_Callback(hObject, eventdata, handles)
253%------------------------------------------------------------------------
254handles.output='No';
255guidata(hObject, handles);
256uiresume(handles.figure1);
257
258%------------------------------------------------------------------------
259% --- Executes on button press in Cancel.
260function Cancel_Callback(hObject, eventdata, handles)
261%------------------------------------------------------------------------
262handles.output = get(hObject,'String');
263%handles.output = 'Cancel'
264guidata(hObject, handles); % Update handles structure
265% Use UIRESUME instead of delete because the OutputFcn needs
266% to get the updated handles structure.
267uiresume(handles.figure1);
268
269%------------------------------------------------------------------------
270% --- Executes when user attempts to close figure1.
271function figure1_CloseRequestFcn(hObject, eventdata, handles)
272%------------------------------------------------------------------------
273% Cancel_Callback(hObject, eventdata, handles)
274% if isequal(get(handles.figure1, 'waitstatus'), 'waiting')
275%     % The GUI is still in UIWAIT, us UIRESUME
276%     uiresume(handles.figure1);
277% else
278    % The GUI is no longer waiting, just close it
279%     delete(handles.figure1);
280% end
281% handles.output = get(hObject,'String');
282% %handles.output = 'Cancel'
283% guidata(hObject, handles); % Update handles structure
284% Use UIRESUME instead of delete because the OutputFcn needs
285% to get the updated handles structure.
286% uiresume(handles.figure1);
287
288
289%------------------------------------------------------------------------
290% --- Executes on key press over figure1 with no controls selected.
291function figure1_KeyPressFcn(hObject, eventdata, handles)
292%------------------------------------------------------------------------
293% Check for "enter" or "escape"
294if isequal(get(hObject,'CurrentKey'),'escape')
295    % User said no by hitting escape
296    handles.output = 'No';
297   
298    % Update handles structure
299    guidata(hObject, handles);
300   
301    uiresume(handles.figure1);
302end
303if isequal(get(hObject,'CurrentKey'),'return')
304    uiresume(handles.figure1);
305end   
306
307
308
309
Note: See TracBrowser for help on using the repository browser.