source: trunk/src/msgbox_uvmat.m @ 747

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

adpatations to 3D fields

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