Presentation is loading. Please wait.

Presentation is loading. Please wait.

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.

Similar presentations


Presentation on theme: "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."— 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 ExamplePropertyValuePropertyName ‘ Example ’ string ‘ name ’ ‘ none ’ { ‘ figure ’ } ‘ MenuBar ’ ‘ on ’ { ‘ on ’ } ‘ off ’ ‘ NumberTitle ’ [0.5, 0.9, 0.7][R, G, B] ‘ color ’ ‘ inches ’ { ‘ pixels ’ } ‘ normalized ’ ‘ inches ’ ‘ centimeters ’ ‘ points ’ ‘ characters ’ ‘ units ’ [2, 3, 2, 1][x, y, w, l] ‘ position ’

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

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

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

11 0.45 0.25 0.45

12 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

13

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

15 UICONTROL Property: ‘ Style ’ ‘ style ’ property specifies the UICONTROL type and can have one of the following as its value: 1-pushbutton7- slider 2- toggle button8- frame 3- radio button9-listbox 4-checkbox10- pop up menu 5-edit 6-text

16 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]

17

18

19 UICONTROL Properties ExplanationExamplePropertyVal ue PropertyNam e Writes string in UICONTROL ‘ Enter Number ’ string ‘ string ’ Font colour[0, 0, 0][R, G, B] ‘ foregroundcol or ’ UICONTROL colour [1, 1, 1][R, G, B] ‘ backgroundcol or ’ Sets UICONTROL to visible/invisible ‘ off ’ { ‘ on ’ } ‘ off ’ ‘ visible ’ Execute specified function on UICONTROL interaction @myfunc1String or function handle ‘ callback ’

20 Another uicontrol

21 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 ’ )

22 Examples

23 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 ” )

24

25

26

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

28

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

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

31

32

33 Pushbutton

34 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”.

35 “ varargin ” stand for variable arguments This is due to the fact that the function has no inputs to it.

36

37 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

38

39

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

41

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

43

44

45 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

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

47

48 Listbox Its function is very similar to the popupmenu.

49

50

51

52 WELCOME TO second SESSION

53 LETS HAVE QUICK REVIEW

54

55 Slider Important slider properties include MIN, MAX, VALUE and SLIDERSTEP properties. MIN and MAX properties take the values of the minimum and maximum of the slider, respectively. SLIDERSTEP is a two element vector that controls how much the slider VALUE changes with each click. The first value of SLIDERSTEP controls how much the slider moves when one of the arrows on its far sides is clicked. The second element governs the change of slider value when clicking on an empty space in the slider itself. Both SLIDERSTEP element are scaled to the MIN to MAX scale, meaning they are to be in the range [0, 1].

56

57 Using the slider to its full potential What we want to do is make the slider control the number to be inputted. To do this, we give the slider a callback. When interacting with the slider, its value will be placed in the edit box.

58

59

60 Or using another function to squre it:

61

62 What if we want the edit box to control the slider?

63 Just like any other UICONTROL, the edit box can be given a callback as well. In the edit box callback, we change the value of the slider accordingly

64

65

66 What do you think? Remember how we have set the MAX property of the SLIDER to 10? Well what if this value is exceeded in the edit box, what should happen?

67

68 If the value to be set in the slider is higher than its MAX property or lower than it MIN property, then the SLIDER wouldn ’ t be created. A solution to this problem is to create an error dialog box whenever this happens, and then proceed to reset the slider.

69 ERRORDLG Function The function ERRORDLG produces an error dialog box with two input parameters. The second input is the box title, while the first is the error message itself. Syntax: errordlg(title,message)

70 Example

71

72 Checkbox UICONTROL The checkbox UICONTROL is similar to the listbox and popupmenu in which it has a defining VALUE property. The value for each checkbox can either be “ 1 ” (i.e. checked) or “ 0 ”. Another handy property is the ‘ string ’ property.

73

74

75 Radiobutton The radiobutton is very similar to the checkbox. You can create a radiobutton group. That way, only one of the buttons in the group can be selected “on” (i.e. has the value of “1”)

76

77

78 Events activating the key board >> a = waitforbuttonpress In response, Matlab displays a figure window. when you place the cursor inside the window and press down the mouse, the variable is set to 0 and the window is minimized. instead, if you press a key, a is set to 1, and you can also extract that key using >> get(gcf, ‘CurrentChar’)

79

80 Menus and other choices items = {‘Car’, ‘Truck’, ‘Motorcycle’, ‘delete’, ‘QUIT’}; menu (‘Next vehicle:’, items) Clicking on car returns 1, truck 2 etc. QUIT closes the menu.

81

82

83 questdlg(‘Does this make sense?’, ‘A question for you’) generates the following dialog box: Clicking on Yes (No) generates a string ‘Yes’ (‘No’).

84 Text Box inputs Here is a way to create a text box: Suppose the user enters the information as follows: Then, a becomes: a = 'Joe' '1/1/2010' '8'5''

85 Input from mouse You can use ginput function to get the position of mouse.

86

87 Refrences: Husam Aldahiyat ‘s power point Dr. ravikumar ‘s power points


Download ppt "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."

Similar presentations


Ads by Google