lecture (7) introduction to gui eng. osama talaat 1

Download Lecture (7) Introduction to GUI Eng. Osama Talaat 1

If you can't read please download the document

Upload: mervin-gregory

Post on 18-Jan-2018

214 views

Category:

Documents


0 download

DESCRIPTION

Predefined Dialogs 3 Message Box

TRANSCRIPT

Lecture (7) Introduction to GUI Eng. Osama Talaat 1 Predefined Dialogs 2 Help Dialog Warning Dialog Error Dialog Predefined Dialogs 3 Message Box Predefined Dialogs 4 Input Dialog: Predefined Dialogs 5 Question Dialog: Predefined Dialogs 6 Menu: Predefined Dialogs 7 Wait Bar: clear all; close all; clc; waitbar(0/10,'Please wait'); for k = 1:10 pause(1) % computations here waitbar(k/10); end Customize New GUI Create new folder for each new GUI in the current directory and enter it. Open the GUI Design Environment (Editor): >> guide 8 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. 9 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. 10 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)) 11 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)) 12 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. 13 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 14 Button Callback BEST WISHES Eng. Osama Talaat 15