Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Apply callback to children
Date: Thu, 8 Jan 2009 20:38:02 +0000 (UTC)
Organization: Battelle Energy Alliance (INL)
Lines: 18
Message-ID: <gk5o7a$kap$1@fred.mathworks.com>
References: <gk3a05$9u7$1@fred.mathworks.com> <gk3bkm$oql$1@fred.mathworks.com> <gk5gle$l6j$1@fred.mathworks.com> <gk5h86$202$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-02-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1231447082 20825 172.30.248.37 (8 Jan 2009 20:38:02 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Thu, 8 Jan 2009 20:38:02 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 688530
Xref: news.mathworks.com comp.soft-sys.matlab:510499


"Jiro Doke" <jiro.doke@mathworks.com> wrote in message 
> You should set the WindowKeyPressFcn property of the figure. This gets called even if other components in your figure have focus.
> 
> 
> jiro

My version of Matlab doesn't have this as a property for figures.  I think this may not always work anyway, depending on the components of the GUI and what the keypressfcn does.  For example, if you have an edit box that has a callback which does something similar to what the figure's keypressfcn does, but lets you specify a value, will the windowkeypressfcn execute for every value entered into the edit box?  Even when you press return? 

The way I was thinking about would be simple enough:

ch = get(gcf,'chi'); % Get all the children.
ch = ch(strcmp(get(ch(:),'type'),'uicontrol')) % Take only uicontrols
ch = ch(strcmp(get(ch(:),'style'),'pushbutton'))  % Take only pushbuttons
set(ch,'keypressfcn',{@func})  % set their keypressfcn to the same as that of fig.

Note by changing the filtering operations above (lines 2 and 3), one could choose to set the keypressfcn for any children of the figure desired.

Just a thought.