Reusable Graphics Objects UC Berkeley Fall 2004, E77 me

Slides:



Advertisements
Similar presentations
Chapter 16 Graphical User Interfaces John Keyser’s Modifications of Slides by Bjarne Stroustrup
Advertisements

BMP Hide ‘n’ Seek What is BMP Hide ‘n’ Seek ? –It’s a tool that lets you hide text messages in BMP files without much visible change in the picture. –Change.
Microsoft Visual Basic: Reloaded Chapter Seven More on the Repetition Structure.
A graphical user interface (GUI) is a pictorial interface to a program. A good GUI can make programs easier to use by providing them with a consistent.
Functions UC Berkeley Fall 2004, E77 Copyright 2005, Andy Packard. This work is licensed under the Creative Commons.
Introduction to Graphical User Interfaces. Objectives * Students should understand what a procedural program is. * Students should understand what an.
Chapter 6 Understanding the Structure of an Application: Procedures, Modules, and Classes.
A short intermission about function handles and cell arrays A MATLAB function may be referenced by a handle. >> sphere(100)
Matlab GUIs GUIDE.
1 JavaScript. 2 What’s wrong with JavaScript? A very powerful language, yet –Often hated –Browser inconsistencies –Misunderstood –Developers find it painful.
Introduction to Matlab & Data Analysis
Debugging UC Berkeley Fall 2004, E77 Copyright 2005, Andy Packard. This work is licensed under the Creative Commons.
Simulink SubSystems and Masking April 22, Copyright , Andy Packard. This work is licensed under the.
Cell Arrays UC Berkeley Fall 2004, E77 Copyright 2005, Andy Packard. This work is licensed under the Creative Commons.
INTRODUCTION TO JAVASCRIPT AND DOM Internet Engineering Spring 2012.
Recursion and Induction UC Berkeley Fall 2004, E77 Copyright 2005, Andy Packard. This work is licensed under the.
Black Box Software Testing Copyright © 2003 Cem Kaner & James Bach 1 Black Box Software Testing Spring 2005 PART 7 -- FUNCTION TESTING by Cem Kaner, J.D.,
Fundamentals of GUI Programming. Objectives: At the end of the session, you should be able to: describe the guidelines that are used for creating user-friendly.
HandleGraphics Intro UC Berkeley Fall 2004, E77 Copyright 2005, Andy Packard. This work is licensed under the Creative.
Script Files UC Berkeley Fall 2004, E77 Copyright 2005, Andy Packard. This work is licensed under the Creative.
IEEE Arithmetic UC Berkeley Fall 2004, E77 Copyright 2005, Andy Packard. This work is licensed under the Creative.
Struct Arrays UC Berkeley Fall 2004, E77 Copyright 2005, Andy Packard. This work is licensed under the Creative.
Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 13 GUI Programming.
Visual Basic for Application - Microsoft Access 2003 Programming applications using Objects.
Intro to Simulink April 15, Copyright , Andy Packard. This work is licensed under the Creative Commons.
Inheritance in Matlab Classes E177 February 14, Copyright , Andy Packard. This work is licensed.
Introduction to Matlab Module #10 Page 1 Introduction to Matlab Module #10 – Creating Graphical User Interfaces Topics 1.Overview of GUI Development using.
Root Finding UC Berkeley Fall 2004, E77 Copyright 2005, Andy Packard. This work is licensed under the Creative.
Get/Set Methods UC Berkeley Fall 2004, E77 Copyright 2005, Andy Packard. This work is licensed under the Creative.
Intro to Simulink Modified by Gary Balas 20 Feb 2011 Copyright , Andy Packard. This work is licensed under.
MATLAB and SimulinkLecture 61 To days Outline Graphical User Interface (GUI) Exercise on this days topics.
Overview of Previous Lesson(s) Over View VP is the methodology in which development allows the user to grab and use the desired tools like menus, buttons,
Introduction to CMex E177 April 25, Copyright 2005, Andy Packard. This work is licensed under the Creative.
E177, Rules of Interruptibility of Callbacks March 4, Copyright , Andy Packard. This work is licensed.
Unit 2 Technology Systems
Lecture 3 (UNIT -1) SUNIL KUMAR CIT-UPES.
OOP: Creating a Class Topics More OOP concepts
EGR 2261 Unit 11 Pointers and Dynamic Variables
Topics Graphical User Interfaces Using the tkinter Module
IS 350 Application Structure
Introduction to Java E177 April 29, me. berkeley
Andy Wang Object Oriented Programming in C++ COP 3330
Multiple Classes and Inheritance
For/Switch/While/Try UC Berkeley Fall 2004, E77 me
CSC461 Lecture 8: Input Devices
Basic operations in Matlab
Functions CIS 40 – Introduction to Programming in Python
New Structure Recall “average.cpp” program
More on Graphical User Interfaces
Chapter 16 – Programming your App’s Memory
Class Info E177 January 22, me. berkeley
Regular Expressions: Searching strings for patterns April 24, 2008 Copyright , Andy Packard and Trent Russi. This work is licensed under the Creative.
E177, Graphics Objects in Matlab February 26, me
@ReferAssignGetSet February 21, me. berkeley
Black Box Software Testing Fall 2004
Black Box Software Testing Fall 2005 Overview – Part 1 of 3
Classes and Objects.
CS285 Introduction - Visual Basic
INFO/CSE 100, Spring 2006 Fluency in Information Technology
Class Intro/TDD Intro 8/23/2005
Whatcha doin'? Aims: Begin to create GUI applications. Objectives:
Pointers The C programming language gives us the ability to directly manipulate the contents of memory addresses via pointers. Unfortunately, this power.
E177, Reference/Assignment for Classes: Intro February 12, Copyright , Andy Packard. This work.
Function Handles UC Berkeley Fall 2004, E Copyright 2005, Andy Packard
Model, View, Controller design pattern
C – Programming Language
Arrays in Matlab UC Berkeley Fall 2004, E Copyright 2005, Andy Packard
CHAPTER FOUR VARIABLES AND CONSTANTS
Web Programming and Design
Basics of Matlab UC Berkeley Fall 2004, E Copyright 2005, Andy Packard
Presentation transcript:

Reusable Graphics Objects UC Berkeley Fall 2004, E77 http://jagger. me Reusable Graphics Objects UC Berkeley Fall 2004, E77 http://jagger.me.berkeley.edu/~pack/e77 Copyright 2005, Andy Packard. This work is licensed under the Creative Commons Attribution-ShareAlike License. To view a copy of this license, visit http://creativecommons.org/licenses/by-sa/2.0/ or send a letter to Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.

Writing reusable graphical based applications In order to write a reusable, graphical based application using Matlab HandleGraphics, the “application” should mimic the attributes of the basic Matlab HandleGraphics objects referred to by a handle get/set interface by which its properties (“state”) are accessed store hidden, globally accessible data have events associated with changes in its state This is relatively straightforward to do, but beyond the scope of the last 50 minute lecture of E77. Perhaps we need one last 18 page lab… By example, we partial overview of the strategy, minus the object oriented (user defined classes) wrapper.

Two more Matlab concepts We need two more Matlab concepts before starting subfunctions, also called Local functions Cell array callbacks (as opposed to char callbacks last time)

Subfunctions In a function m-file, it is legal to have two (or more) functions. The first function is the main function The second, third, etc are subfunctions Each use the same syntax (original) for function declaration line Name of subfunctions usually begins with LOCAL The subfunctions are visible to The main function in the same file Any subfunctions in the same file Convenience of functions without extra .m files All variables in a subfunction are local Like functions, use input and output arguments to pass variables “in” and “out” of the subfunction. Subfunctions can called by their function_handle The main function can (using @) access the function handle and pass that back to its caller…

Subfunctions Here is a simple example subex.m >> M = 9; >> [R,K] = subex(M,P); >> R R = 15 >> feval(K,2,8) ans = 4 function [A,H] = subex(B,C) A = B + LocalFcn1(B,C); H = @LocalFcn1; function Y = LocalFcn1(W,Q) Y = sqrt(W*Q); subex.m Every subfunction can be accessed anywhere through its handle.

Cell array callbacks Create (for example) a pushbutton PB = uicontrol(’style’,’pushb’); and a function, ARG5.m and a 1x4 cell array cb = {@ARG5 -14.1 ’e77’ [100;10;1]}; Set the callback of the pushbutton to be the cell array. set(PB,’Callback’,cb); What happens when the button is pressed? function ARG5(A1,A2,A3,A4,A5) ... % some code here

Cell array callbacks Setup is PB = uicontrol(’style’,’pushb’); cb = {@ARG5 -14.1 ’e77’ [100;10;1]}; set(PB,’Callback’,cb); Upon buttonpress, Matlab creates 2 variables, EventSrc and EventData, and executes an feval, without outputs feval(cb{1},EventSrc,EventData,cb{2:end}) equivalently ARG5(EventSrc,EventData,-14.1,’e77’,[100;10;1]) ARG5(A1, ,A2 ,A3 ,A4 ,A5 ) ARG5.m function ARG5(A1,A2,A3,A4,A5) ...

Cell array callback, common mistake Setup is PB = uicontrol(’style’,’pushb’); V = 17 cb = {@ARG5 -14.1 ’e77’ V}; set(PB,’Callback’,cb); V = 18; Now press button. What will the value of the 5th argument to the function ARG5 be? Remember, Matlab will execute feval(cb{1},EventSrc,EventData,cb{2:end}) Clarify: not actually the variable cb, but the contents of pushbutton’s CallBack property, get(PB,’Callback’))

PushButton/Counter ++ ++ 1 ++ 7 Let’s make a reusable object consisting of a counter (initialized at 0) pushbutton (to increment counter) text display of counter value Initial appearance After one buttonpress After 7 buttonpresses User should also be able to program additional actions to occur after a button press. pushbutton frame text uicontrol ++ ++ 1 ++ 7

Overview of Tool Code function ToolH = fname(arg) % Create objects which constitute the tool % These are the “subobjects” % Choose one subobject as the “tool handle” (ToolH) % Create ToolState struct which holds tool “state” % Hide ToolState in appdata of ToolH % Set subobject properties, event callbacks to subfcns % Input arg: ToolH (then subfcns can access ToolState) function subf1(Esrc,Edata,ToolH) % Ignore Esrc, Edata % Retrieve ToolState (from appdata of ToolH) % Do calcs, set properties of subobjects % Update and replace ToolState (appdata of ToolH) function subf2(Esrc,Edata,ToolH) function subf3(Esrc,Edata,ToolH)

PushButton/Counter State Graphics object is the counter/display What information do we need to keep track of everything? value of counter handle of text display function_handle that user wants to additionally execute when the value is incremented Hence, tool state will be a structure with 3 fields CntVal, integer counter value DispHan, the handle of the text display uicontrol IncCB, function_handle (plus additional arguments) of user defined increment callback ++ 1

function ToolHan = e77gui1(X,Y,IncCB) FrameH = uicontrol('style','frame',... 'position',[X Y 110 30]); PlusH = uicontrol('style','pushbutton',... 'position',[X+5 Y+5 40 20],'str','++'); DispH = uicontrol('style','text',... 'position',[X+50 Y+5 40 20]); ToolHan = DispH; ToolState.DispHan = DispH; ToolState.CntVal = 0; ToolState.IncCB = IncCB; setappdata(ToolHan,'ToolState',ToolState); set(PlusH,'callback',{@LOCALinc ToolHan}); set(DispH,'str',int2str(ToolState.CntVal)); function LOCALinc(ESrc, EData, TH) TS = getappdata(TH,'ToolState'); TS.CntVal = TS.CntVal + 1; set(TS.DispHan,'str',int2str(TS.CntVal)); setappdata(TH,'ToolState',TS); if ~isempty(TS.IncCB) feval(TS.IncCB{1},ESrc,EData,... TH,TS.IncCB{2:end}) end Create the objects that constitute the tool Designate toolhandle Create struct of Tool state (all relevant info) Hide state in ToolHan Set callback events & subobject properties Retrieve ToolState Do calculations, set subobject properties Update ToolState Run user callback if it exists, passing supplied arguments

function ToolHan = e77gui1(X,Y,IncCB) FrameH = uicontrol('style','frame',... 'position',[X Y 110 30]); PlusH = uicontrol('style','pushbutton',... 'position',[X+5 Y+5 40 20],'str','++'); DispH = uicontrol('style','text',... 'position',[X+50 Y+5 40 20]); ToolHan = DispH; ToolState.DispHan = DispH; ToolState.CntVal = 0; ToolState.IncCB = IncCB; setappdata(ToolHan,'ToolState',ToolState); set(PlusH,'callback',{@LOCALinc ToolHan}); set(DispH,'str',int2str(ToolState.CntVal));

function ToolHan = e77gui1(IncCB) % Omitted Code PlusH = uicontrol('style','pushbutton',... set(PlusH,'callback',{@LOCALinc ToolHan}); function LOCALinc(ESrc, EData, TH) TS = getappdata(TH,'ToolState'); TS.CntVal = TS.CntVal + 1; set(TS.DispHan,'str',int2str(TS.CntVal)); setappdata(TH,'ToolState',TS); if ~isempty(TS.IncCB) feval(TS.IncCB{1},ESrc,EData,TH,... TS.IncCB{2:end}) end