Thread Subject: GUI Programming: clf vs. visible off for "next page"

Subject: GUI Programming: clf vs. visible off for "next page"

From: Rachel Laughs

Date: 9 Nov, 2009 22:31:03

Message: 1 of 6

My GUI that I am creating (not using GUIDE) has a large panel to encompass all the other components in the figure window.

There is a popup menu that allows the user to choose from the list, then a push button to submit the option.

What I would like to do is this:
Once the button is pushed, the components on top of the panel clears away, and new components show up based on the chosen option from the previous "page"'s popup menu.

So...should I use "clf" to clear the entire figure window and then make the panel again, and the next set of components? Or should the next step in the code turn off the visibility in the "old" components and turn on the visibility of the "new" components?

Or something else altogether?

Thanks so much!

Subject: GUI Programming: clf vs. visible off for "next page"

From: Rachel Laughs

Date: 9 Nov, 2009 23:03:03

Message: 2 of 6

Hm. So I guess "clf" won't work if I want to recall the choices selected from the popup menu.

I'll just play around with changing visibility and see what happens. My only concern is that I want to have lots of "pages", and each one dependent on the selection made on that first popup menu.

Subject: GUI Programming: clf vs. visible off for "next page"

From: Matt Fig

Date: 10 Nov, 2009 01:24:02

Message: 3 of 6

There are several ways of handling this problem, and it will somehow depend on the way your are storing your handles. One approach could be through the use of cell arrays to store the handles, as in this simple example:

function [] = mygui_p()

figure('units','pix',...
       'pos',[500 500 200 150],...
       'menub','none')
f{1} = uicontrol('style','edit',...
                 'string','empty',...
                 'pos',[10 70 100 30]);
f{2} = uicontrol('style','push',...
                 'units','pix',...
                 'pos',[10 10 100 40],...
                 'string','pushme');
g{1} = uicontrol('style','text',...
                 'string',{'static','text','does','not','disapear'},...
                 'pos',[120 10 70 140]);
             
set(f{2},'call',{@pb_call,f})
             
function [] = pb_call(varargin)

f = varargin{3};
set([f{:}],'visible','off')
pause(1)
set([f{:}],'visible','on')



Now if you already have your GUI built up and you are using a structure to store the handles, you could just group the handles which need to become invisible together into a cell array and store that cell array in the structure too. You can have as many different groups as you want.

Subject: GUI Programming: clf vs. visible off for "next page"

From: Rachel Laughs

Date: 10 Nov, 2009 16:20:18

Message: 4 of 6

"Matt Fig" <spamanon@yahoo.com> wrote in message <hdafbi$dp7$1@fred.mathworks.com>...
>
> Now if you already have your GUI built up and you are using a structure to store the handles, you could just group the handles which need to become invisible together into a cell array and store that cell array in the structure too. You can have as many different groups as you want.

--

I see what you are saying about grouping by cell array in your example. I like your idea of using structures though, but am not sure how to group by cell array and then storing the cell array in the structure.

So using your earlier example, this is how it would be run by using a structure, correct? How would you achieve the same effect by grouping and storing by cell array?

function [] = mygui_p()

figure('units','pix',...
       'pos',[500 500 200 150],...
       'menub','none')
S.ed = uicontrol('style','edit',...
                 'string','empty',...
                 'pos',[10 70 100 30]);
S.pb = uicontrol('style','push',...
                 'units','pix',...
                 'pos',[10 10 100 40],...
                 'string','pushme');
S.tx = uicontrol('style','text',...
                 'string',{'static','text','does','not','disapear'},...
                 'pos',[120 10 70 140]);
             
set(S.pb,'call',{@pb_call,S})
             
function [] = pb_call(varargin)

S = varargin{3};
set([S.ed,S.pb],'visible','off')
pause(1)
set([S.ed,S.pb],'visible','on')

Subject: GUI Programming: clf vs. visible off for "next page"

From: Rachel Laughs

Date: 10 Nov, 2009 16:33:02

Message: 5 of 6

Also, I tried to get the same result by grouping by expanding the structure to a [1 2], which totally failed, haha! This is what I ran:


function [] = mygui_p()

figure('units','pix',...
       'pos',[500 500 200 150],...
       'menub','none')
S(1).ed = uicontrol('style','edit',...
                 'string','empty',...
                 'pos',[10 70 100 30]);
S(1).pb = uicontrol('style','push',...
                 'units','pix',...
                 'pos',[10 10 100 40],...
                 'string','pushme');
S(2).tx = uicontrol('style','text',...
                 'string',{'static','text','does','not','disapear'},...
                 'pos',[120 10 70 140]);
             
set(S(1).pb,'call',{@pb_call,S(1)})
             
function [] = pb_call(varargin)

S = varargin{3};
set([S(1)],'visible','off')
pause(1)
set([S(1)],'visible','on')


....and the error that resulted, which is what I expected, but don't understand. Could someone explain, por favor? Thanks!


??? Error using ==> set
Conversion to double from struct is not possible.

Error in ==> mygui_p>pb_call at 22
set([S],'visible','off')

??? Error while evaluating uicontrol Callback

Subject: GUI Programming: clf vs. visible off for "next page"

From: Matt Fig

Date: 10 Nov, 2009 16:40:19

Message: 6 of 6

Add these lines right before setting the S.pb callback.

S.grp(1) = {[S.ed,S.pb]};
S.grp(2) = {S.tx};

Then in the callback

set([S.grp{1}],'visible','off')

Tags for this Thread

Everyone's Tags:

gui

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
gui Rachel Laughs 9 Nov, 2009 17:34:06
rssFeed for this Thread

Contact us at files@mathworks.com