1 / 87

Programming a GUI

Programming a GUI. Hanan sedaghat pisheh. For calling GUI, we need a function with no inputs or outputs First We create a m.file m file has the same name as the function. Creating the Function. Make sure the function name is the same as the m file ’ s. No input and No output.

jsnow
Download Presentation

Programming a GUI

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. Programming a GUI Hanan sedaghat pisheh

  2. For calling GUI, we need a function with no inputs or outputs First We create a m.file m file has the same name as the function

  3. Creating the Function Make sure the function name is the same as the m file’s. No input and No output

  4. You can use F5 or play buttton to run your rogram Write figure in your function and run it.

  5. Setting Figure Properties Syntax for setting figure properties is: figure('PropertyName',propertyvalue,…)

  6. Some Figure Properties

  7. Color vector value for [R, G, B], where each vector element takes a value in the range [0, 1]. Examples: [0, 1, 0] = GREEN [1, 1, 0] = YELLOW [1, 1, 1] = WHITE [0.5 0.5 0.5] = GRAY [0.5 0.2 0.75] = PURPLE

  8. Position Takes the vector value [x, y, w, l] Each element is a value in the units specified by the figure property ‘units’ x- Distance from left side of the screen y- Distance from bottom side of the screen w- Width of figure (horizontally) l- Length of figure (vertically)

  9. Units Safest bet is to use the property value ‘normalized’. With ‘normalized’ chosen, each element is relative to the screen and takes the value in the range of [0, 1]. [1, 1] [0, 0]

  10. 0.45 0.45 0.45 0.25

  11. RANDOM FUNCTION Creates a random number in the range [0, 1]. Can be used in [R, G, B] vector or even [x, y, w, l] vector

  12. UICONTROL Creates edit boxes, text boxes, pushbuttons, sliders, popup menus and more. Syntax: Uicontrol(‘propertyName’,propertyvalue)

  13. UICONTROL Property: ‘Style’ ‘style’ property specifies the UICONTROL type and can have one of the following as its value: 1-pushbutton 7- slider 2- toggle button 8- frame 3- radio button 9-listbox 4-checkbox 10- pop up menu 5-edit 6-text

  14. UICONTROL Property: Position ‘position’ behaves similarly to the FIGURE property, only here the position is taken relative to the figure window. Likewise, ‘units’ is treated in the same vein. [0,0]

  15. UICONTROL Properties

  16. Another uicontrol

  17. We need to give handles for objects so we could reference them later.important Command Get and set command are going to use alot. Syntax: get(handle,’propertName’)

  18. Examples

  19. Imagine we want to use the color of figure for the color of the text background So we should get the color of the created figure (with handle “f”)

  20. SET Command Gives pre-existing objects new values for properties. Syntax: set(handle,’propertyName’,propertyvalue) Lets change background color of first text box from green to random.

  21. What if we don’t want a dark background but we still want random one ? Remember: higher values brighter colors

  22. ANSWER: rand*0.5+0.5 gives us values in the range [0.5 1].

  23. Pushbutton

  24. Pushbutton Callback pushbutton has the ‘callback’ property name with the property value “@DO1”. This means that whenever the user interacts with the UICONTROL (in our case push the pushbutton), we will execute the function “DO1”.

  25. “varargin”stand for variable argumentsThis is due to the fact that the function has no inputs to it.

  26. Lets try this one : Add the number in the edit box with 5 and displayed on the text box1 Remember: 1-for convert string to numerical value, we use the command STR2NUM 2-use string in set command

  27. Popupmenu list of possibilities which user can choose from them.

  28. Lets try this one: we want to have a popupmenu string and we want the user to choose between squaring and cubing the value in the edit box. Thus when the pushbutton is pressed, the popupmenu value is checked and based on it, the operation performed will be different.

  29. What do you think? Assume we want to have same example as before but this time in addition of pushing button we want an update when user changes the popupmenu

  30. This means we should give the popupmenu a callback function which is the same as pushbutton callback function.

  31. Listbox Its function is very similar to the popupmenu.

More Related