Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "Lecture (7) Introduction to GUI Eng. Osama Talaat 1."— Presentation transcript:

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

2 Predefined Dialogs 2 Help Dialog Warning Dialog Error Dialog

3 Predefined Dialogs 3 Message Box

4 Predefined Dialogs 4  Input Dialog:

5 Predefined Dialogs 5  Question Dialog:

6 Predefined Dialogs 6  Menu:

7 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

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 8

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. 9

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. 10

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)) 11

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)) 12

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. 13

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 14 Button Callback

15 BEST WISHES Eng. Osama Talaat 15


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

Similar presentations


Ads by Google