source: trunk/src/msgbox_uvmat.m @ 746

Last change on this file since 746 was 746, checked in by sommeria, 10 years ago
File size: 10.5 KB
RevLine 
[733]1
[2]2%'msgbox_uvmat': associated with GUI msgbox_uvmat.fig to display message boxes, for error, warning or input calls
3%
[654]4% answer=msgbox_uvmat(title,display,default_answer,Position)
5%
[2]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:
[581]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).
[2]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',   []);
[121]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
[2]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
[581]41%------------------------------------------------------------------------
[2]42% --- Executes just before msgbox_uvmat is made visible.
[421]43function msgbox_uvmat_OpeningFcn(hObject, eventdata, handles,title,display_str,default_answer,Position)
[581]44%------------------------------------------------------------------------
[2]45% This function has no output args, see OutputFcn.
46
47% Choose default command line output for msgbox_uvmat
48handles.output = 'Cancel';
[244]49set(handles.figure1,'Units','pixels')
50FigPos=[100 150 500 50];%default position
[472]51if exist('Position','var') && numel(Position)>=2
[244]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)
[726]65% set(hObject,'WindowKeyPressFcn',{'keyboard_callback',handles})%set keyboard action function
[2]66
67% Update handles structure
68guidata(hObject, handles);
69testNo=0;
[246]70testCancel=0;
[746]71testOK=1;
[2]72testinputstring=0;
73icontype='quest';%default question icon (text input asked)
74if exist('title','var')
[156]75    set(hObject, 'Name', title);
76    switch title
77        case {'CONFIRMATION'}
78            icontype='';
79        case 'ERROR'
80            icontype='error';
[421]81            if exist('display_str','var')
82                disp(display_str); %display the error message in the Matlab command window
83            end
[156]84        case 'WARNING'
85            icontype='warn';
86        case 'INPUT_Y-N'
87            icontype='quest';
[246]88            testCancel=1; %no cancel button
[156]89            testNo=1; % button No activated
90        case {'RULER'}
91            icontype='';
92            testinputstring=1;
[244]93        case 'INPUT_TXT'
94            testinputstring=1;
[246]95            testCancel=1; %no cancel button
[581]96        case 'INPUT_MENU'
97            testinputstring=2;
98            testCancel=1; %no cancel button
[746]99        case 'INFO'
100            icontype='';
101            testOK=0;
[156]102        otherwise
[244]103          %  testinputstring=1;
104            icontype='';
105            testinputstring=exist('default_answer','var');
[156]106    end
[2]107end
[421]108if exist('display_str','var')
109    set(handles.text1, 'String', display_str);
[2]110end
[581]111
112if testinputstring==1
[2]113    set(handles.edit_box, 'Visible', 'on');
[244]114    if ~exist('default_answer','var');
115        default_answer='';
116    end
117    set(handles.edit_box, 'String', default_answer);
[733]118    if exist('Position','var')&&numel(Position)>=2
[581]119        if iscell(default_answer)
120            widthstring=max(max(cellfun('length',default_answer)),length(display_str));
121            heightstring=size(default_answer,1);%nbre of expected lines
122            set(handles.edit_box,'Max',2);
123        else
124            widthstring=max(length(default_answer),length(display_str));
125            heightstring=1;
126        end
127        widthstring=max(widthstring,length(title)+20);
128        boxsize=[10*widthstring 20*heightstring];%size of the display edit box
129        set(handles.edit_box,'Units','pixels')
130        set(handles.edit_box,'FontUnits','pixels')
131        set(handles.edit_box,'FontSize',12)
132        set(handles.edit_box,'Position',[5,34,boxsize(1),boxsize(2)])
133        FigPos(3)=10+boxsize(1);
134        FigPos(4)=56+boxsize(2);
135        FigPos(2)=Position(2)-FigPos(4)-25;
136        set(handles.figure1,'Position',FigPos)
[244]137    end
[581]138elseif testinputstring==2
139    set(handles.edit_box,'style','listbox')
140    set(handles.edit_box, 'Visible', 'on');
141    set(handles.edit_box,'String', default_answer)
[2]142else
143    set(handles.text1, 'Position', [0.15 0.3 0.85 0.7]);
144end
145
146% Show a question icon from dialogicons.mat - variables questIconData and questIconMap
147if isequal(icontype,'')
148    hima=findobj(handles.axes1,'Type','image');
149    if ~isempty(hima)
150        delete(hima)
151    end
152else
153    load dialogicons.mat
154    eval(['IconData=' icontype 'IconData;'])
155    eval(['IconCMap=' icontype 'IconMap;'])
156    questIconMap(256,:) = get(handles.figure1, 'Color');
157    Img=image(IconData, 'Parent', handles.axes1);
158    set(handles.figure1, 'Colormap', IconCMap);
159    set(handles.axes1, ...
160        'Visible', 'off', ...
161        'YDir'   , 'reverse'       , ...
162        'XLim'   , get(Img,'XData'), ...
163        'YLim'   , get(Img,'YData')  ...
164        );
165end
166if testCancel
167     set(handles.Cancel,'Visible','on')
168else
169    set(handles.Cancel,'Visible','off')
170end
171if testNo
172     set(handles.No,'Visible','on')
173else
174    set(handles.No,'Visible','off')
175end   
[296]176set(handles.figure1,'Units','normalized')
177set(handles.edit_box,'Units','normalized')
[746]178if testOK
[2]179set(handles.figure1,'WindowStyle','modal')% Make% Make the GUI modal
[746]180set(handles.OK,'Visible','on')
[2]181% UIWAIT makes msgbox_uvmat wait for user response (see UIRESUME)
182uiwait(handles.figure1);
[746]183else
184   set(handles.OK,'Visible','off')
185end
[2]186
[746]187
[581]188%------------------------------------------------------------------------
[2]189% --- Outputs from this function are returned to the command line.
190function varargout = msgbox_uvmat_OutputFcn(hObject, eventdata, handles)
[581]191%------------------------------------------------------------------------
[599]192varargout{1}='Cancel';%deg
[2]193% Get default command line output from handles structure
[246]194if isfield(handles,'output')
195    if isequal(handles.output,'Cancel')
196        varargout{1}='Cancel';
197    elseif isequal(handles.output,'No')
198        varargout{1}='No';
199    else
[581]200        if strcmp(get(handles.edit_box,'Style'),'listbox')
[713]201            varargout{1}=get(handles.edit_box,'Value');
[581]202        else
[713]203            varargout{1}=get(handles.edit_box,'String');
[581]204        end
[713]205        if isempty(varargout{1})
[246]206            varargout{1}='Yes';
207        end
[2]208    end
[713]209    if strcmp(get(handles.edit_box, 'Visible'), 'on')
210        varargout{2}=get(handles.edit_box,'String');
211    end
[246]212    % The figure can be deleted now
[746]213    if strcmp(get(handles.OK,'Visible'),'on')
[599]214    delete(handles.figure1);
[746]215    else %case of INFO display (non modal)
216        varargout{1}=hObject;
217    end
[2]218end
[713]219
[599]220%  delete(handles.figure1);
[581]221
222%------------------------------------------------------------------------
[2]223% --- Executes on button press in OK.
224function OK_Callback(hObject, eventdata, handles)
[581]225%------------------------------------------------------------------------
[2]226handles.output = get(hObject,'String');
227guidata(hObject, handles);% Update handles structure
228uiresume(handles.figure1);
229
[581]230%------------------------------------------------------------------------
[2]231% --- Executes on button press in No.
232function No_Callback(hObject, eventdata, handles)
[581]233%------------------------------------------------------------------------
[2]234handles.output='No';
235guidata(hObject, handles);
236uiresume(handles.figure1);
237
[581]238%------------------------------------------------------------------------
[2]239% --- Executes on button press in Cancel.
240function Cancel_Callback(hObject, eventdata, handles)
[581]241%------------------------------------------------------------------------
[2]242handles.output = get(hObject,'String');
243%handles.output = 'Cancel'
244guidata(hObject, handles); % Update handles structure
245% Use UIRESUME instead of delete because the OutputFcn needs
246% to get the updated handles structure.
247uiresume(handles.figure1);
248
[581]249%------------------------------------------------------------------------
[2]250% --- Executes when user attempts to close figure1.
251function figure1_CloseRequestFcn(hObject, eventdata, handles)
[581]252%------------------------------------------------------------------------
[733]253% Cancel_Callback(hObject, eventdata, handles)
254% if isequal(get(handles.figure1, 'waitstatus'), 'waiting')
255%     % The GUI is still in UIWAIT, us UIRESUME
256%     uiresume(handles.figure1);
257% else
[2]258    % The GUI is no longer waiting, just close it
[733]259%     delete(handles.figure1);
260% end
261% handles.output = get(hObject,'String');
262% %handles.output = 'Cancel'
263% guidata(hObject, handles); % Update handles structure
264% Use UIRESUME instead of delete because the OutputFcn needs
265% to get the updated handles structure.
266% uiresume(handles.figure1);
[2]267
[733]268
[581]269%------------------------------------------------------------------------
[2]270% --- Executes on key press over figure1 with no controls selected.
271function figure1_KeyPressFcn(hObject, eventdata, handles)
[581]272%------------------------------------------------------------------------
[2]273% Check for "enter" or "escape"
274if isequal(get(hObject,'CurrentKey'),'escape')
275    % User said no by hitting escape
276    handles.output = 'No';
277   
278    % Update handles structure
279    guidata(hObject, handles);
280   
281    uiresume(handles.figure1);
282end
283if isequal(get(hObject,'CurrentKey'),'return')
284    uiresume(handles.figure1);
285end   
286
287
288
289
Note: See TracBrowser for help on using the repository browser.