<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/264877</link>
    <title>MATLAB Central Newsreader - Gui multiple instances</title>
    <description>Feed for thread: Gui multiple instances</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>Tue, 03 Nov 2009 21:00:20 -0500</pubDate>
      <title>Gui multiple instances</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/264877#691841</link>
      <author>Jane </author>
      <description>Is there a way of preventing the user from opening the same GUI multiple times?&lt;br&gt;
&lt;br&gt;
Is there a way of determining that a GUI of that name is already running and hence set the focus to the one already open instead of creating a new version?&lt;br&gt;
&lt;br&gt;
Thanks</description>
    </item>
    <item>
      <pubDate>Tue, 03 Nov 2009 21:59:04 -0500</pubDate>
      <title>Re: Gui multiple instances</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/264877#691858</link>
      <author>Matt Fig</author>
      <description>Yes, many ways.&lt;br&gt;
&lt;br&gt;
One way is to have the first part of your GUI look for a figure with the tag 'MYGUI' and if it doesn't find such a figure, create the GUI (with tag 'MYGUI' of course).  If the first code does find a figure with the tag 'MYGUI' it just returns.</description>
    </item>
    <item>
      <pubDate>Wed, 04 Nov 2009 18:01:05 -0500</pubDate>
      <title>Re: Gui multiple instances</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/264877#692139</link>
      <author>Jane </author>
      <description>I haven't been able to find a method to search for the figure.  &lt;br&gt;
&lt;br&gt;
I think perhaps this is bacause I have the 'handlevisibilty' to callback.  Is there a way of finding an instance of the GUI with this property set?&lt;br&gt;
&lt;br&gt;
In the meantime I have set the 'windowstyle' to modal, which does prevent multiple instances but is far from a perfect solution.&lt;br&gt;
&lt;br&gt;
I'ld be grateful of further suggestions&lt;br&gt;
&lt;br&gt;
Thanks</description>
    </item>
    <item>
      <pubDate>Wed, 04 Nov 2009 18:42:04 -0500</pubDate>
      <title>Re: Gui multiple instances</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/264877#692147</link>
      <author>someone </author>
      <description>&quot;Jane &quot; &amp;lt;j.l.terry@hotmail.co.uk&amp;gt; wrote in message &amp;lt;hcsfh0$7ag$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; I haven't been able to find a method to search for the figure.  &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; I think perhaps this is bacause I have the 'handlevisibilty' to callback.  Is there a way of finding an instance of the GUI with this property set?&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; In the meantime I have set the 'windowstyle' to modal, which does prevent multiple instances but is far from a perfect solution.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; I'ld be grateful of further suggestions&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Thanks&lt;br&gt;
&lt;br&gt;
You can try setting the 'ShowHiddenHandles' root property to 'on', &lt;br&gt;
do your figure search test (by 'Tag' or whatever), &lt;br&gt;
then set the 'ShowHiddenHandles' root property back to 'off'.</description>
    </item>
    <item>
      <pubDate>Wed, 04 Nov 2009 19:24:03 -0500</pubDate>
      <title>Re: Gui multiple instances</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/264877#692166</link>
      <author>Jane </author>
      <description>Thankyou,&lt;br&gt;
&lt;br&gt;
I used the following code at the beginning of my GUI function&lt;br&gt;
&lt;br&gt;
% Check to see if an instance of GUI is already running -----------------&lt;br&gt;
set(0,'showhiddenhandles','on');&lt;br&gt;
p = findobj(gcf,'tag','uis');&lt;br&gt;
set(0,'showhiddenhandles','off');&lt;br&gt;
if ~isempty(p)&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;figure(p);&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;msgbox('Simulate Data is already open.');&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return;&lt;br&gt;
end&lt;br&gt;
&lt;br&gt;
Which seems to work fine in 2008a, but causes a new figure to be opened on the first run in 7.0.1.&lt;br&gt;
&lt;br&gt;
Is this the type of code you meant?  And can I prevent a new window opening in 7.0.1?</description>
    </item>
    <item>
      <pubDate>Wed, 04 Nov 2009 19:52:03 -0500</pubDate>
      <title>Re: Gui multiple instances</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/264877#692172</link>
      <author>someone </author>
      <description>&quot;Jane &quot; &amp;lt;j.l.terry@hotmail.co.uk&amp;gt; wrote in message &amp;lt;hcskcj$ao9$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; Thankyou,&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; I used the following code at the beginning of my GUI function&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; % Check to see if an instance of GUI is already running -----------------&lt;br&gt;
&amp;gt; set(0,'showhiddenhandles','on');&lt;br&gt;
&amp;gt; p = findobj(gcf,'tag','uis');&lt;br&gt;
&amp;gt; set(0,'showhiddenhandles','off');&lt;br&gt;
&amp;gt; if ~isempty(p)&lt;br&gt;
&amp;gt;     figure(p);&lt;br&gt;
&amp;gt;     msgbox('Simulate Data is already open.');&lt;br&gt;
&amp;gt;     return;&lt;br&gt;
&amp;gt; end&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Which seems to work fine in 2008a, but causes a new figure to be opened on the first run in 7.0.1.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Is this the type of code you meant?&lt;br&gt;
&lt;br&gt;
Yes&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;And can I prevent a new window opening in 7.0.1?&lt;br&gt;
&lt;br&gt;
% Maybe instead of:&lt;br&gt;
if ~isempty(p)&lt;br&gt;
% you can try:&lt;br&gt;
if ishandle(p)&lt;br&gt;
&lt;br&gt;
% And if you are really paranoid, you can test if p is ONLY a&lt;br&gt;
% figure handle by testing whether the 'Parent' property is root.</description>
    </item>
    <item>
      <pubDate>Wed, 04 Nov 2009 20:35:06 -0500</pubDate>
      <title>Re: Gui multiple instances</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/264877#692186</link>
      <author>Jane </author>
      <description>&amp;gt;   And can I prevent a new window opening in 7.0.1?&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; % Maybe instead of:&lt;br&gt;
&amp;gt; if ~isempty(p)&lt;br&gt;
&amp;gt; % you can try:&lt;br&gt;
&amp;gt; if ishandle(p)&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; % And if you are really paranoid, you can test if p is ONLY a&lt;br&gt;
&amp;gt; % figure handle by testing whether the 'Parent' property is root.&lt;br&gt;
&lt;br&gt;
Thanks,&lt;br&gt;
I have changed my condition to ishandle.  &lt;br&gt;
The new figure window in 7.0.1 was caused by the way I had findobj.  I have now changed this to:&lt;br&gt;
&lt;br&gt;
p=findobj('tag','uis','parent',0)&lt;br&gt;
&lt;br&gt;
and it seems to be working fine in both versions of Matlab.&lt;br&gt;
&lt;br&gt;
Thanks agin for your time, it's much appreciated.</description>
    </item>
    <item>
      <pubDate>Wed, 04 Nov 2009 20:53:03 -0500</pubDate>
      <title>Re: Gui multiple instances</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/264877#692190</link>
      <author>someone </author>
      <description>&quot;Jane &quot; &amp;lt;j.l.terry@hotmail.co.uk&amp;gt; wrote in message &amp;lt;hcsohp$4lb$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &amp;gt;   And can I prevent a new window opening in 7.0.1?&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; % Maybe instead of:&lt;br&gt;
&amp;gt; &amp;gt; if ~isempty(p)&lt;br&gt;
&amp;gt; &amp;gt; % you can try:&lt;br&gt;
&amp;gt; &amp;gt; if ishandle(p)&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; % And if you are really paranoid, you can test if p is ONLY a&lt;br&gt;
&amp;gt; &amp;gt; % figure handle by testing whether the 'Parent' property is root.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Thanks,&lt;br&gt;
&amp;gt; I have changed my condition to ishandle.  &lt;br&gt;
&amp;gt; The new figure window in 7.0.1 was caused by the way I had findobj.  I have now changed this to:&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; p=findobj('tag','uis','parent',0)&lt;br&gt;
&lt;br&gt;
% Ah, yes!&lt;br&gt;
&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; and it seems to be working fine in both versions of Matlab.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Thanks agin for your time, it's much appreciated.&lt;br&gt;
&lt;br&gt;
% BTW, I noticed that ishandle returns a vector, not a scalar.&lt;br&gt;
% So you may want to use something like:&lt;br&gt;
&lt;br&gt;
if any(ishandle(p))&lt;br&gt;
&lt;br&gt;
doc if&lt;br&gt;
&lt;br&gt;
Remarks&lt;br&gt;
Nonscalar Expressions&lt;br&gt;
If the evaluated expression yields a nonscalar value,&lt;br&gt;
then every element of this value must be true or nonzero &lt;br&gt;
for the entire expression to be considered true.</description>
    </item>
    <item>
      <pubDate>Wed, 04 Nov 2009 21:16:20 -0500</pubDate>
      <title>Re: Gui multiple instances</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/264877#692193</link>
      <author>Jane </author>
      <description>I've made that change thanks code now looks like:&lt;br&gt;
&lt;br&gt;
% Check to see if an instance of GUI is already running -----------------&lt;br&gt;
set(0,'showhiddenhandles','on');&lt;br&gt;
p = findobj('tag','uis','parent',0);&lt;br&gt;
set(0,'showhiddenhandles','off');&lt;br&gt;
if any(ishandle(p))&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;figure(p);&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;msgbox('Simulate Data is already open.','createMode','modal');&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return;&lt;br&gt;
end&lt;br&gt;
&lt;br&gt;
and is working :D</description>
    </item>
    <item>
      <pubDate>Thu, 05 Nov 2009 05:55:03 -0500</pubDate>
      <title>Re: Gui multiple instances</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/264877#692286</link>
      <author>Matt Fig</author>
      <description>Just a note, you can use findall instead of having to set the root property for findobj.</description>
    </item>
  </channel>
</rss>

