<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/242033</link>
    <title>MATLAB Central Newsreader - Apply callback to children</title>
    <description>Feed for thread: Apply callback to children</description>
    <language>en-us</language>
    <copyright>&amp;copy;1994-2012 by MathWorks, Inc.</copyright>
    <webmaster>webmaster@mathworks.com</webmaster>
    <generator>MATLAB Central Newsreader</generator>
    <docs>http://blogs.law.harvard.edu/tech/rss</docs>
    <ttl>60</ttl>
    <image>
      <title>MathWorks</title>
      <url>http://www.mathworks.com/images/membrane_icon.gif</url>
    </image>
    <item>
      <pubDate>Wed, 07 Jan 2009 22:23:01 -0500</pubDate>
      <title>Apply callback to children</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/242033#620367</link>
      <author>Erik </author>
      <description>Hi there I have a KeyPressFcn call back on a figure of mine and it works fine when only the figure is selected but the figure has buttons and if any of them are selected the KeyPressFcn no longer works is there any way around this?&lt;br&gt;
&lt;br&gt;
Thanks</description>
    </item>
    <item>
      <pubDate>Wed, 07 Jan 2009 22:51:02 -0500</pubDate>
      <title>Re: Apply callback to children</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/242033#620372</link>
      <author>Matt Fig</author>
      <description>&quot;Erik&quot; &amp;lt;Idont@wantSpam.co&amp;gt; wrote in message &amp;lt;gk3a05$9u7$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; Hi there I have a KeyPressFcn call back on a figure of mine and it works fine when only the figure is selected but the figure has buttons and if any of them are selected the KeyPressFcn no longer works is there any way around this?&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Thanks&lt;br&gt;
&lt;br&gt;
Why not set the keypressfcn of the buttons to the same function as the keypressfcn of the figure?</description>
    </item>
    <item>
      <pubDate>Thu, 08 Jan 2009 18:29:02 -0500</pubDate>
      <title>Re: Apply callback to children</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/242033#620529</link>
      <author>Erik </author>
      <description>I can apply them to all the buttons but there are many buttons and I was hoping that I wouldnt have to do that.</description>
    </item>
    <item>
      <pubDate>Thu, 08 Jan 2009 18:39:02 -0500</pubDate>
      <title>Re: Apply callback to children</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/242033#620534</link>
      <author>Jiro Doke</author>
      <description>&quot;Erik&quot; &amp;lt;Idont@wantSpam.co&amp;gt; wrote in message &amp;lt;gk5gle$l6j$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; I can apply them to all the buttons but there are many buttons and I was hoping that I wouldnt have to do that.&lt;br&gt;
&lt;br&gt;
Erik,&lt;br&gt;
&lt;br&gt;
You should set the WindowKeyPressFcn property of the figure. This gets called even if other components in your figure have focus.&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
jiro</description>
    </item>
    <item>
      <pubDate>Thu, 08 Jan 2009 20:38:02 -0500</pubDate>
      <title>Re: Apply callback to children</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/242033#620547</link>
      <author>Matt Fig</author>
      <description>&quot;Jiro Doke&quot; &amp;lt;jiro.doke@mathworks.com&amp;gt; wrote in message &lt;br&gt;
&amp;gt; You should set the WindowKeyPressFcn property of the figure. This gets called even if other components in your figure have focus.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; jiro&lt;br&gt;
&lt;br&gt;
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? &lt;br&gt;
&lt;br&gt;
The way I was thinking about would be simple enough:&lt;br&gt;
&lt;br&gt;
ch = get(gcf,'chi'); % Get all the children.&lt;br&gt;
ch = ch(strcmp(get(ch(:),'type'),'uicontrol')) % Take only uicontrols&lt;br&gt;
ch = ch(strcmp(get(ch(:),'style'),'pushbutton'))  % Take only pushbuttons&lt;br&gt;
set(ch,'keypressfcn',{@func})  % set their keypressfcn to the same as that of fig.&lt;br&gt;
&lt;br&gt;
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.&lt;br&gt;
&lt;br&gt;
Just a thought.</description>
    </item>
    <item>
      <pubDate>Thu, 08 Jan 2009 21:28:01 -0500</pubDate>
      <title>Re: Apply callback to children</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/242033#620551</link>
      <author>Jiro Doke</author>
      <description>&quot;Matt Fig&quot; &amp;lt;spamanon@yahoo.com&amp;gt; wrote in message &amp;lt;gk5o7a$kap$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &quot;Jiro Doke&quot; &amp;lt;jiro.doke@mathworks.com&amp;gt; wrote in message &lt;br&gt;
&amp;gt; &amp;gt; You should set the WindowKeyPressFcn property of the figure. This gets called even if other components in your figure have focus.&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; jiro&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; 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? &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; The way I was thinking about would be simple enough:&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; ch = get(gcf,'chi'); % Get all the children.&lt;br&gt;
&amp;gt; ch = ch(strcmp(get(ch(:),'type'),'uicontrol')) % Take only uicontrols&lt;br&gt;
&amp;gt; ch = ch(strcmp(get(ch(:),'style'),'pushbutton'))  % Take only pushbuttons&lt;br&gt;
&amp;gt; set(ch,'keypressfcn',{@func})  % set their keypressfcn to the same as that of fig.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; 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.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Just a thought.&lt;br&gt;
&lt;br&gt;
Yes, WindowKeyPressFcn would get called regardless of which control is in focus. You could do a check in the function to see if the component with focus is an edit box or not, but what you proposed should be fine as well. BTW, you can also use findobj to find the handles:&lt;br&gt;
&lt;br&gt;
ch = findobj(figH, 'type', 'uicontrol', 'style', 'pushbutton');&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
jiro</description>
    </item>
    <item>
      <pubDate>Thu, 08 Jan 2009 21:39:02 -0500</pubDate>
      <title>Re: Apply callback to children</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/242033#620554</link>
      <author>Matt Fig</author>
      <description>&quot;Jiro Doke&quot; &amp;lt;jiro.doke@mathworks.com&amp;gt; wrote in message &lt;br&gt;
&amp;gt;BTW, you can also use findobj to find the handles:&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; ch = findobj(figH, 'type', 'uicontrol', 'style', 'pushbutton');&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; jiro&lt;br&gt;
&lt;br&gt;
D-oh!&lt;br&gt;
When am I ever going to learn to use findobj!  :)&lt;br&gt;
I guess I am stuck with being a low-level kinda guy when it comes to handle graphics, I never think of findobj.  Maybe this will make me!  Thanks jiro.</description>
    </item>
  </channel>
</rss>

