source: trunk/src/msgbox_uvmat.m @ 827

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