|
"Steven Lord" <slord@mathworks.com> wrote in message <ghrd59$9vb$1@fred.mathworks.com>...
>
> "Chris " <chris.crawshaw@gmail.com> wrote in message
> news:ghpjqu$7jn$1@fred.mathworks.com...
> > Hi all,
> > I've been trying to learn about the 'handles' thing that appears in GUIDE
> > scripts I've downloaded and in scripts I've downloaded from here. I just
> > can't seem to get my head around it.
> > I have uploaded an example of my script where I haven't used this at all
> > but it needs to be reviewed - I'll add the link when it becomes available.
> >
> > However, in the meantime, an example of a function nested within my GUI
> > is:
> > m3=uicontrol(fig,...
> > 'style','pop');
> > function calcbutton(source,eventdata); %push to calculate button
> > str3=get(m3,'string');
> > val3=get(m3,'value');
> > end
> >
> > I assume, using handles provides benifits which aren't apparent at the
> > moment. Any advice on where to use this or where to research it would be
> > greatly appreciated.
> >
> > An example of the code I'm struggling to understand:
> > function pushbutton1_Callback(hObject, eventdata, handles)
> > % hObject handle to pushbutton1 (see GCBO)
> > % eventdata reserved - to be defined in a future version of MATLAB
> > % handles structure with handles and user data (see GUIDATA)
> > saveState(handles)
> >
> > I have read the help files on GUIDATA and GUIHANDLES but still don't
> > understand it I'm afraid.
>
> Don't worry about GUIDATA and GUIHANDLES for right now. First, have you
> read the section in the Getting Started guide that deals with Handle
> Graphics objects?
>
> http://www.mathworks.com/access/helpdesk/help/techdoc/learn_matlab/f3-15974.html
>
> One metaphor that I find useful is to think of an object's handle as its
> telephone number. Using the handle/phone number, you can communicate with
> the object using either GET (which allows you to ask the object questions,
> like "What is your Position property?") or SET (which allows you to give the
> object an order, like "Change your Position property to this vector.").
>
> The way GUIDE defines the callback functions for the objects, it passes in a
> handles structure (a telephone book) listing the handles for all the objects
> in the GUI. Just like a phone book, a handles structure makes it easier to
> find an object's handle/phone number. As the comment says, the handles
> structure not only contains handles to objects, but it can also contain user
> data (like a note you write inside the phone book.)
>
> If you don't have a copy of the handles structure/phone book in your
> function, you can retrieve one with GUIDATA or GUIHANDLES, and if you want
> to copy the additional data/notes you've made in your local copy of the
> handles structure to the main handles structure that the figure keeps for
> its reference, you can also use GUIDATA and GUIHANDLES for that purpose.
>
> It's not a perfect metaphor (for instance, you can change your telephone
> number but you can't really change an object's handle) but as metaphors go,
> it's not half bad if I do say so myself.
>
> --
> Steve Lord
> slord@mathworks.com
>
Hi,
I think I'm starting to understand this now - your phone number/book analogy really explains it well.
At the moment I don't mind creating GUIs by coding them directly so I don't need to use the handles structure, however I could see it being very useful if you could create more than one (such as a phone book for business contacts and one for personal contacts - perhaps with some contacts in both?) if this is possible it could be useful, for example pushing button_a sets the 3 drop down menu's in handles_a to value 2 without having to type the set function for each menu.
Just a thought but I have a feeling its not possible to group widgets in this way.
Thanks for your advice, and Jiro. The documentation sections are handy, and the video tutorials are always interesting and I always learn something from them.
As a side question, are there other benifits to creating GUIs in GUIDE other than the speed of drag+drop and positioning? And are there any significant draw-backs to using GUIDE?
What are people's general preference?
Cheers,
Chris
|