1 / 15

Lecture (7)

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

sook
Download Presentation

Lecture (7)

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

  2. Predefined Dialogs

  3. Predefined Dialogs

  4. Predefined Dialogs

  5. Predefined Dialogs

  6. Predefined Dialogs • Menu:

  7. Predefined Dialogs 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. functionconvert_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. Button Callback unit=get(handles.unit_menu,'value'); in=str2num(get(handles.input_edit,'string')); ifunit==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

  15. BEST WISHES Eng. Osama Talaat

More Related