source: trunk/src/msgbox_uvmat.m @ 622

Last change on this file since 622 was 599, checked in by sommeria, 11 years ago

various bug corrections. Steps further for civ_series (still development needed)

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