source: trunk/src/msgbox_uvmat.m @ 733

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

various improvements

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