source: trunk/src/msgbox_uvmat.m @ 200

Last change on this file since 200 was 156, checked in by sommeria, 14 years ago

many bug repairs and corrections for mouse action
create_grid: option for black marjkers for grid detection

File size: 6.7 KB
Line 
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:
9%          title= 'INPUT_TXT','CONFIMATION' ,'ERROR', 'WARNING', 'INPUT_Y-N', default = 'INPUT_TXT' (the title is displayed in the upper bar of the fig).
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',   []);
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
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
39% --- Executes just before msgbox_uvmat is made visible.
40function msgbox_uvmat_OpeningFcn(hObject, eventdata, handles,title,display,default_answer)
41% This function has no output args, see OutputFcn.
42
43% Choose default command line output for msgbox_uvmat
44handles.output = 'Cancel';
45
46% Update handles structure
47guidata(hObject, handles);
48testNo=0;
49testCancel=1;
50testinputstring=0;
51icontype='quest';%default question icon (text input asked)
52if exist('title','var')
53    set(hObject, 'Name', title);
54    switch title
55        case {'CONFIRMATION'}
56            icontype='';
57            testCancel=0; %no cancel button
58        case 'ERROR'
59            icontype='error';
60            testCancel=0; %no cancel button
61        case 'WARNING'
62            icontype='warn';
63            testCancel=0; %no cancel button
64        case 'INPUT_Y-N'
65            icontype='quest';
66            testNo=1; % button No activated
67        case {'RULER'}
68            icontype='';
69            testCancel=0; %no cancel button
70            testinputstring=1;
71        otherwise
72            testinputstring=1;
73    end
74end
75if exist('display','var')
76    set(handles.text1, 'String', display);
77end
78if testinputstring
79    set(handles.edit_box, 'Visible', 'on');
80else
81    set(handles.text1, 'Position', [0.15 0.3 0.85 0.7]);
82end
83if exist('default_answer','var') &&  testinputstring
84    set(handles.edit_box, 'String', default_answer);
85end
86% Determine the position of the dialog - centered on the screen
87FigPos=get(0,'DefaultFigurePosition');
88OldUnits = get(hObject, 'Units');
89set(hObject, 'Units', 'pixels');
90OldPos = get(hObject,'Position');
91FigWidth = OldPos(3);
92FigHeight = OldPos(4);
93ScreenUnits=get(0,'Units');
94set(0,'Units','pixels');
95ScreenSize=get(0,'ScreenSize');
96set(0,'Units',ScreenUnits);
97
98FigPos(1)=1/2*(ScreenSize(3)-FigWidth);
99FigPos(2)=2/3*(ScreenSize(4)-FigHeight);
100FigPos(3:4)=[FigWidth FigHeight];
101set(hObject, 'Position', FigPos);
102set(hObject, 'Units', OldUnits);
103
104% Show a question icon from dialogicons.mat - variables questIconData and questIconMap
105if isequal(icontype,'')
106    hima=findobj(handles.axes1,'Type','image');
107    if ~isempty(hima)
108        delete(hima)
109    end
110else
111    load dialogicons.mat
112    eval(['IconData=' icontype 'IconData;'])
113    eval(['IconCMap=' icontype 'IconMap;'])
114    questIconMap(256,:) = get(handles.figure1, 'Color');
115    Img=image(IconData, 'Parent', handles.axes1);
116    set(handles.figure1, 'Colormap', IconCMap);
117    set(handles.axes1, ...
118        'Visible', 'off', ...
119        'YDir'   , 'reverse'       , ...
120        'XLim'   , get(Img,'XData'), ...
121        'YLim'   , get(Img,'YData')  ...
122        );
123end
124if testCancel
125     set(handles.Cancel,'Visible','on')
126else
127    set(handles.Cancel,'Visible','off')
128end
129if testNo
130     set(handles.No,'Visible','on')
131else
132    set(handles.No,'Visible','off')
133end   
134set(handles.figure1,'WindowStyle','modal')% Make% Make the GUI modal
135% UIWAIT makes msgbox_uvmat wait for user response (see UIRESUME)
136uiwait(handles.figure1);
137
138
139% --- Outputs from this function are returned to the command line.
140function varargout = msgbox_uvmat_OutputFcn(hObject, eventdata, handles)
141
142% Get default command line output from handles structure
143if isequal(handles.output,'Cancel')
144    varargout{1}='Cancel';
145elseif isequal(handles.output,'No')
146    varargout{1}='No';
147else
148    varargout{1}=get(handles.edit_box,'String');
149    if isempty(varargout{1}) || isequal(varargout{1},'')
150        varargout{1}='Yes';
151    end
152end
153% The figure can be deleted now
154delete(handles.figure1);
155
156% --- Executes on button press in OK.
157function OK_Callback(hObject, eventdata, handles)
158handles.output = get(hObject,'String');
159guidata(hObject, handles);% Update handles structure
160uiresume(handles.figure1);
161
162% --- Executes on button press in No.
163function No_Callback(hObject, eventdata, handles)
164handles.output='No';
165guidata(hObject, handles);
166uiresume(handles.figure1);
167
168% --- Executes on button press in Cancel.
169function Cancel_Callback(hObject, eventdata, handles)
170handles.output = get(hObject,'String');
171%handles.output = 'Cancel'
172guidata(hObject, handles); % Update handles structure
173% Use UIRESUME instead of delete because the OutputFcn needs
174% to get the updated handles structure.
175uiresume(handles.figure1);
176
177
178% --- Executes when user attempts to close figure1.
179function figure1_CloseRequestFcn(hObject, eventdata, handles)
180if isequal(get(handles.figure1, 'waitstatus'), 'waiting')
181    % The GUI is still in UIWAIT, us UIRESUME
182    uiresume(handles.figure1);
183else
184    % The GUI is no longer waiting, just close it
185    delete(handles.figure1);
186end
187
188% --- Executes on key press over figure1 with no controls selected.
189function figure1_KeyPressFcn(hObject, eventdata, handles)
190% Check for "enter" or "escape"
191if isequal(get(hObject,'CurrentKey'),'escape')
192    % User said no by hitting escape
193    handles.output = 'No';
194   
195    % Update handles structure
196    guidata(hObject, handles);
197   
198    uiresume(handles.figure1);
199end
200if isequal(get(hObject,'CurrentKey'),'return')
201    uiresume(handles.figure1);
202end   
203
204
205
206
207
Note: See TracBrowser for help on using the repository browser.