Upload
sook
View
37
Download
0
Embed Size (px)
DESCRIPTION
Lecture (7). Introduction to GUI Eng. Osama Talaat. Predefined Dialogs. Predefined Dialogs. Predefined Dialogs. Predefined Dialogs. Predefined Dialogs. Menu :. Predefined Dialogs. clear all ; close all ; clc ; waitbar (0/10 , 'Please wait' ); for k = 1:10 - PowerPoint PPT Presentation
Citation preview
1Lecture (7)Introduction to GUI
Eng. Osama Talaat
2 Predefined DialogsHelp Dialog Warning Dialog Error
Dialog
3 Predefined DialogsMessage Box
4 Predefined Dialogs Input Dialog:
5 Predefined Dialogs Question Dialog:
6 Predefined Dialogs Menu:
7 Predefined Dialogs Wait Bar:
clear all; close all; clc; waitbar(0/10,'Please wait');for k = 1:10 pause(1) % computations here waitbar(k/10);end
8 Customize New GUI Create new folder for each new GUI in the
current directory and enter it. Open the GUI Design Environment (Editor):
>> guide
9 Length Converter Insert the components from the left vertical
panel. Arrange them as you like. Double Click any component to change its
properties such as string and name. Save and run.
10 String & Tag Change the tag of each element to a
meaningful name to be used in programming. convert_button, m_edit, cm_edit, mm_edit,
in_edit.
11 Button Callback Program the event of button click.
Right click it >> view callbacks >> callback.
The structure handles is used to handle any element: handles.convert_button, handles.m_edit,
handles.cm_edit, handles.mm_edit, handles.in_edit
To get any element property use this function:
m = get(handles.m_edit,'string');
m = str2num(get(handles.m_edit,'string')); To set any element property use this function:
set(handles.mm_edit,'string',num2str(m*1000))
12 Button Callback% --- Executes on button press in convert_button.
function convert_button_Callback(hObject, eventdata, handles)
% hObject handle to convert_button (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
m=str2num(get(handles.m_edit,'string'));
set(handles.mm_edit,'string',num2str(m*1000))
set(handles.cm_edit,'string',num2str(m*100))
set(handles.in_edit,'string',num2str(m/0.0254))
13 Several Source Units Resize the window to contain the new
elemnts. Add another edit and static for the input
and rearrange the layout to bring the meter into bottom.
Add a pop-up menu, with tag: unit_menu. String it with the units in separate lines. The index of the selected item is stored in
the property ‘value’ of the pop-up menu.
14
unit=get(handles.unit_menu,'value');in=str2num(get(handles.input_edit,'string'));
if unit==1 %meter set(handles.m_edit,'string',num2str(in)) set(handles.mm_edit,'string',num2str(in*1000)) set(handles.cm_edit,'string',num2str(in*100)) set(handles.in_edit,'string',num2str(in/0.0254))elseif unit==2 %millimeter set(handles.m_edit,'string',num2str(in/1000)) set(handles.mm_edit,'string',num2str(in)) set(handles.cm_edit,'string',num2str(in/10)) set(handles.in_edit,'string',num2str(in/25.4))elseif unit==3 %centimeter set(handles.m_edit,'string',num2str(in/100)) set(handles.mm_edit,'string',num2str(in*10)) set(handles.cm_edit,'string',num2str(in)) set(handles.in_edit,'string',num2str(in/2.54))elseif unit==4 %inch set(handles.m_edit,'string',num2str(in*0.0254)) set(handles.mm_edit,'string',num2str(in*25.4)) set(handles.cm_edit,'string',num2str(in*2.54)) set(handles.in_edit,'string',num2str(in))end
Button Callback
15 BEST WISHESEng. Osama Talaat