The Math Forum

Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Math Forum » Discussions » Software » comp.soft-sys.matlab

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: automatically update editbox of one GUI with contents entered in 2nd GUI
Replies: 3   Last Post: Apr 11, 2012 11:04 PM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]

Posts: 64
Registered: 6/7/10
Re: automatically update editbox of one GUI with contents entered in 2nd GUI
Posted: Apr 11, 2012 11:04 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

This is the documentation you want to look at

The basic idea is that you create a handle object with properties with 'SetObservable'

%% object:
classdef test_obj < handle

properties (SetObservable, AbortSet)


function set.a(this,value)
if value > 10
fprintf('a cannot exceed 10');
this.a = value;



now create an instance of the object:


test = test_obj;


Now you can register listeners

% you can listen to an event, which you throw manually in the code:
%Whenever the overflow event is thrown, the callback is executed. The callback is
%always fed two parameters, the object sending the notification and event data

list{1} = test.addlistener('overflow',@(obj,event)fprintf('OVERFLOW\n'));

% you can also listen to individual properties in the same way. When the property
% changes, the callback is called. You can call use "PreSet", "PostSet", "PreGet' and
% "PostGet" to decide when the callback is triggered.

list{2} = t.addlistener('b','PostSet',@(obj,event)fprintf('B was just set\n'));


In a gui, I register my listeners like this:

handles.listeners{1} = handles.object.addlistener('property','PostSet',@(obj,event)updatedisplay(handles));

This causes the updatedisplay callback (in the gui) to be called every time is updated.

Then in your GUI, all you have to do is directly update the object and let the listeners do their thing. Since the object is a handle class, you can update any "copy" of it as all copies are just references to the same object. This lets you manipulate the object (and thus any attached GUIs) from a script or command line as well, and the GUI's will auto update to reflect the changes.

Just make sure you include a close function in your GUI that deletes the listeners or you will wind up with some odd "object deleted" errors if the listeners become orphaned.

Hope this helps.

"Alex " <> wrote in message <jm5dgp$fg1$>...
> Thanks Matthew, I think your suggestion about listeners is what I am looking for, however I am not familiar with listeners, and "help listener" doesn't return any results . Could you give me a brief example of code that would utilize listeners with respect to my problem?
> Thanks
> "Matthew" wrote in message <jm5cit$cdg$>...

> > you can use guidata:
> >
> >
> > However, the way I've approached this problem in the past is to write all of my processing code into a handle object. The GUI takes the handle to the object and registers listeners on any properties and events that it cares about with proper callbacks to deal with the change in data. So instead of having to write one GUI to talk to the other, you just write each GUI to update the base object and update itself when something it cares about in the base object changes.

Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© The Math Forum at NCTM 1994-2018. All Rights Reserved.