Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
A question about pop-up menu in GUI

Subject: A question about pop-up menu in GUI

From: Squall Mania

Date: 19 Nov, 2009 16:37:20

Message: 1 of 12

Hello,

I have created a GUI and there is a pop-up menu in it. I want to know how I can generate an error dialogue when the pop-up menu is not open/used by a user. For the edit box, I use "isempty", but that doesn't work for the pop-up menu. My pop-up menu contains the following:
.....
A
B
C
D

*Please note that I don't want to assign anything at the opening function of my GUI.

Thanks and I look forward to hearing your solution.

Subject: A question about pop-up menu in GUI

From: Luis Ponce de Le?n Agust?n

Date: 19 Nov, 2009 16:55:12

Message: 2 of 12

Ciao Squall Mania:

Maybe you can define a condition (if, while, etc.) and put a warning message o something like this, the next code is a very simple example:
////////
if (n<4)
   warndlg('The typed number must be bigger than 4','WARNING');
   return
end
////////

Otherwise you can look for more info typing in the Command Window "help warndlg" and it will look something like this:

        f = warndlg('This is an warning string.', 'My Warn Dialog');
        f = warndlg('This is an warning string.', 'My Warn Dialog', 'modal');
 
  "See also dialog, errordlg, helpdlg, inputdlg, listdlg, msgbox, questdlg."

I hope this info support you.

Luis

Subject: A question about pop-up menu in GUI

From: Matt Fig

Date: 19 Nov, 2009 16:56:03

Message: 3 of 12

There are many ways this problem could be approached, and which to choose will depend somewhat on the way you wrote the GUI. You could make it so that the popup's callback sets a certain flag which is then read before the error message is issued/not issued. You could also put the top value of the popup to be an empty string, then check if it is still empty before the error message is issued/not issued. Etc, etc.

Subject: A question about pop-up menu in GUI

From: Squall Mania

Date: 19 Nov, 2009 17:19:21

Message: 4 of 12

"Luis Ponce de Le?n Agust?n" <poncedeleonagustin@yahoo.com.mx> wrote in message <he3t9g$9tv$1@fred.mathworks.com>...
> Ciao Squall Mania:
>
> Maybe you can define a condition (if, while, etc.) and put a warning message o something like this, the next code is a very simple example:
> ////////
> if (n<4)
> warndlg('The typed number must be bigger than 4','WARNING');
> return
> end
> ////////
>
> Otherwise you can look for more info typing in the Command Window "help warndlg" and it will look something like this:
>
> f = warndlg('This is an warning string.', 'My Warn Dialog');
> f = warndlg('This is an warning string.', 'My Warn Dialog', 'modal');
>
> "See also dialog, errordlg, helpdlg, inputdlg, listdlg, msgbox, questdlg."
>
> I hope this info support you.
>
> Luis

Luis,

Thanks for your response, but it seems you misunderstood what I had said. I know how to generate error dialogues with conditions; however, when I run my program that has a pop-up menu in it and the user doesn't use/open it or select anything from that menu, an error dialogue should generate saying "Please choose from the pop-up menu first". Do you know how I can do that?

Again, thanks for your response.

Subject: A question about pop-up menu in GUI

From: Nathan

Date: 19 Nov, 2009 17:39:19

Message: 5 of 12

On Nov 19, 9:19 am, "Squall Mania" <r_sk...@hotmail.com> wrote:
> "Luis Ponce de Le?n Agust?n" <poncedeleonagus...@yahoo.com.mx> wrote in message <he3t9g$9t...@fred.mathworks.com>...
>
>
>
> > Ciao Squall Mania:
>
> > Maybe you can define a condition (if, while, etc.) and put a warning message o something like this, the next code is a very simple example:
> > ////////
> > if (n<4)
> >    warndlg('The typed number must be bigger than 4','WARNING');
> >    return
> > end
> > ////////
>
> > Otherwise you can look for more info typing in the Command Window "help warndlg" and it will look something like this:
>
> >         f = warndlg('This is an warning string.', 'My Warn Dialog');
> >         f = warndlg('This is an warning string.', 'My Warn Dialog', 'modal');
>
> >   "See also dialog, errordlg, helpdlg, inputdlg, listdlg, msgbox, questdlg."
>
> > I hope this info support you.
>
> > Luis
>
> Luis,
>
> Thanks for your response, but it seems you misunderstood what I had said. I know how to generate error dialogues with conditions; however, when I run my program that has a pop-up menu in it and the user doesn't use/open it or select anything from that menu, an error dialogue should generate saying "Please choose from the pop-up menu first". Do you know how I can do that?
>
> Again, thanks for your response.

Set an error message if the pop-up menu value is 1 (the top of the
list) when the user tries to skip that step.

if get(handles.popupmenu1,'Value) == 1
 ERROR
end

or something of the sort.

-Nathan

Subject: A question about pop-up menu in GUI

From: Squall Mania

Date: 19 Nov, 2009 17:40:18

Message: 6 of 12

"Matt Fig" <spamanon@yahoo.com> wrote in message <he3tb3$d32$1@fred.mathworks.com>...
> There are many ways this problem could be approached, and which to choose will depend somewhat on the way you wrote the GUI. You could make it so that the popup's callback sets a certain flag which is then read before the error message is issued/not issued. You could also put the top value of the popup to be an empty string, then check if it is still empty before the error message is issued/not issued. Etc, etc.

Fig,

Thanks for your response, but none has solved my problem. I want it to be as easy as you would do it for the case of "edit box".

For example,

a = get(handles.ab,'string');

if (isempty(a))

errordlg('xxxxx')

end

The above one is for "edit box", is there any for pop-up menu?

Subject: A question about pop-up menu in GUI

From: Luis Ponce de Le?n Agust?n

Date: 19 Nov, 2009 17:47:04

Message: 7 of 12

Ciao again:

Ok, maybe you have a code something like this:

////////////////
function Popup_Callback(hObject, eventdata, handles)

% Find the value of the popup menu selection
activation=get(handles.Popup1,'Value')

% Now "activation" variable will get "0 or 1", 0= Not clicked and 1=Clicked
% After to give a value to "activation" you can use a condition

 if activation = 0
... sentences
else
... sentences
end

% Obviously the condition must be indicated just before run the next routines, calculus or opening dialog boxes.

% For example, if you have a GUI window where there is a pushbutton and it must work only if you select an option of your popup menu put the condition and the warning box after press the pushbutton and before make some calculus.

Subject: A question about pop-up menu in GUI

From: Nathan

Date: 19 Nov, 2009 17:57:11

Message: 8 of 12

On Nov 19, 9:47 am, "Luis Ponce de Le?n Agust?n"
<poncedeleonagus...@yahoo.com.mx> wrote:
> Ciao again:
>
> Ok, maybe you have a code something like this:
>
> ////////////////
> function Popup_Callback(hObject, eventdata, handles)
>
> % Find the value of the popup menu selection
> activation=get(handles.Popup1,'Value')
>
> % Now "activation" variable will get "0 or 1", 0= Not clicked and 1=Clicked
> % After to give a value to "activation" you can use a condition
>
>  if activation = 0
> ... sentences
> else
> ... sentences
> end
>
> % Obviously the condition must be indicated just before run the next routines, calculus or opening dialog boxes.
>
> % For example, if you have a GUI window where there is a pushbutton and it must work only if you select an option of your popup menu put the condition and the warning box after press the pushbutton and before make some calculus.

What makes you think Value will return either a 1 or 0 from a
popupmenu?

Value is the selected popup item. If you select item 2, assuming value
is initialized at 1, then Value will be 2. If you select item n, Value
will be n.

-Nathan

Subject: A question about pop-up menu in GUI

From: Squall Mania

Date: 19 Nov, 2009 18:05:19

Message: 9 of 12

Nathan <ngreco32@gmail.com> wrote in message <f9b5c79a-8f55-4244-8c8c-07c8971b6fed@v15g2000prn.googlegroups.com>...
> On Nov 19, 9:19?am, "Squall Mania" <r_sk...@hotmail.com> wrote:
> > "Luis Ponce de Le?n Agust?n" <poncedeleonagus...@yahoo.com.mx> wrote in message <he3t9g$9t...@fred.mathworks.com>...
> >
> >
> >
> > > Ciao Squall Mania:
> >
> > > Maybe you can define a condition (if, while, etc.) and put a warning message o something like this, the next code is a very simple example:
> > > ////////
> > > if (n<4)
> > > ? ?warndlg('The typed number must be bigger than 4','WARNING');
> > > ? ?return
> > > end
> > > ////////
> >
> > > Otherwise you can look for more info typing in the Command Window "help warndlg" and it will look something like this:
> >
> > > ? ? ? ? f = warndlg('This is an warning string.', 'My Warn Dialog');
> > > ? ? ? ? f = warndlg('This is an warning string.', 'My Warn Dialog', 'modal');
> >
> > > ? "See also dialog, errordlg, helpdlg, inputdlg, listdlg, msgbox, questdlg."
> >
> > > I hope this info support you.
> >
> > > Luis
> >
> > Luis,
> >
> > Thanks for your response, but it seems you misunderstood what I had said. I know how to generate error dialogues with conditions; however, when I run my program that has a pop-up menu in it and the user doesn't use/open it or select anything from that menu, an error dialogue should generate saying "Please choose from the pop-up menu first". Do you know how I can do that?
> >
> > Again, thanks for your response.
>
> Set an error message if the pop-up menu value is 1 (the top of the
> list) when the user tries to skip that step.
>
> if get(handles.popupmenu1,'Value) == 1
> ERROR
> end
>
> or something of the sort.
>
> -Nathan

Nathan,

Thanks a lot! That solved my problem :D

Subject: A question about pop-up menu in GUI

From: Matt Fig

Date: 19 Nov, 2009 18:26:16

Message: 10 of 12

> Set an error message if the pop-up menu value is 1 (the top of the
> list) when the user tries to skip that step.
>
> if get(handles.popupmenu1,'Value) == 1
> ERROR
> end
>
> or something of the sort.
>
> -Nathan


Just a note:
This only works if the first choice is made invalid, as in an empty string. If the user selects, or simply observes the valid first choice and agrees with it, then an error will be produced. Here is what I mean:



function [] = GUI_ex()
% How to tell if a popup choice has been made by the user.

S.fh = figure('units','pixels',...
              'position',[300 300 300 100],...
              'menubar','none',...
              'name','GUI_7',...
              'numbertitle','off',...
              'resize','off');
S.pp = uicontrol('style','pop',...
                 'unit','pix',...
                 'position',[10 60 280 20],...
                 'backgroundc',get(S.fh,'color'),...
                 'fontsize',12,'fontweight','bold',...
                 'string',{'','two','three','four'});
S.pb = uicontrol('style','push',...
                 'unit','pix',...
                 'position',[10 15 280 20],...
                 'backgroundcolor',get(S.fh,'color'),...
                 'fontsize',12,'fontweight','bold',...
                 'string','Push me to get choice',...
                 'callback',{@pb_call,S});

function [] = pb_call(varargin)
S = varargin{3};
str = get(S.pp,{'string','value'});

if isempty(str{1}{str{2}})
    errordlg('You must choose an item from the popupmenu')
else
    disp(str{1}{str{2}}) % Display on command line.
end

Subject: A question about pop-up menu in GUI

From: Nathan

Date: 19 Nov, 2009 18:34:53

Message: 11 of 12

On Nov 19, 10:26 am, "Matt Fig" <spama...@yahoo.com> wrote:
> > Set an error message if the pop-up menu value is 1 (the top of the
> > list) when the user tries to skip that step.
>
> > if get(handles.popupmenu1,'Value) == 1
> >  ERROR
> > end
>
> > or something of the sort.
>
> > -Nathan
>
> Just a note:
> This only works if the first choice is made invalid, as in an empty string.  If the user selects, or simply observes the valid first choice and agrees with it, then an error will be produced.  Here is what I mean:
>
> function [] = GUI_ex()
> % How to tell if a popup choice has been made by the user.
>
> S.fh = figure('units','pixels',...
>               'position',[300 300 300 100],...
>               'menubar','none',...
>               'name','GUI_7',...
>               'numbertitle','off',...
>               'resize','off');
> S.pp = uicontrol('style','pop',...
>                  'unit','pix',...
>                  'position',[10 60 280 20],...
>                  'backgroundc',get(S.fh,'color'),...
>                  'fontsize',12,'fontweight','bold',...
>                  'string',{'','two','three','four'});
> S.pb = uicontrol('style','push',...
>                  'unit','pix',...
>                  'position',[10 15 280 20],...
>                  'backgroundcolor',get(S.fh,'color'),...
>                  'fontsize',12,'fontweight','bold',...
>                  'string','Push me to get choice',...
>                  'callback',{@pb_call,S});            
>
> function [] = pb_call(varargin)
> S = varargin{3};
> str = get(S.pp,{'string','value'});
>
> if isempty(str{1}{str{2}})
>     errordlg('You must choose an item from the popupmenu')
> else
>     disp(str{1}{str{2}})  % Display on command line.
> end

Ah, yes, but the user specified that the Popupmenu was as follow:
.....
A
B
C
D

Meaning popupmenu Value 1 == '.....', which would seem to be an
invalid choice as is. But you're right to make it more robust by not
including any string in the first menu item.

-Nathan

Subject: A question about pop-up menu in GUI

From: Matt Fig

Date: 19 Nov, 2009 18:46:06

Message: 12 of 12

Nathan <ngreco32@gmail.com> wrote in message <205d4458-4dcc-47d4-b1be-
> Ah, yes, but the user specified that the Popupmenu was as follow:
> .....
> A
> B
> C
> D
>
> Meaning popupmenu Value 1 == '.....', which would seem to be an
> invalid choice as is. But you're right to make it more robust by not
> including any string in the first menu item.
>
> -Nathan

Oh, I see, I missed that ellipses. I thought that was just a break to set the choices off from the preceding sentence.

Tags for this Thread

No tags are associated with this thread.

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.

Contact us