Thread Subject: Visible figure has no gui handle. Why?

Subject: Visible figure has no gui handle. Why?

From: G.A.M.

Date: 27 Aug, 2007 18:43:58

Message: 1 of 8

Hello. I have an application that creates and displays a
figure (as the main window for the GUI). The figure is
displayed on screen, but the gui handle doesn't exist
immediately after the figure is created.

Executing h=findobj shows me that the figure and all its
uicontrols are not among the existing objects even though
the figure is currently visible on the screen.

Where can I find basic information about why a gui handle
would be cleared or removed and how to prevent this from
happening?

I posted a related question here:
http://www.mathworks.cn/matlabcentral/newsreader/view_thread/155215

That question has more details and replies there would also
help, but I think this question is really the heart of my
issue. Thank you.


Subject: Visible figure has no gui handle. Why?

From: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)

Date: 27 Aug, 2007 19:14:14

Message: 2 of 8

In article <fav61d$7a5$1@fred.mathworks.com>, G.A.M. <x0zero@gmail.com> wrote:
>Hello. I have an application that creates and displays a
>figure (as the main window for the GUI). The figure is
>displayed on screen, but the gui handle doesn't exist
>immediately after the figure is created.

>Executing h=findobj shows me that the figure and all its
>uicontrols are not among the existing objects even though
>the figure is currently visible on the screen.

The HandleVisibility property of the figure has been set to 'off'.

See findall() and allchild()
--
   Okay, buzzwords only. Two syllables, tops. -- Laurie Anderson

Subject: Visible figure has no gui handle. Why?

From: G.A.M.

Date: 27 Aug, 2007 19:33:44

Message: 3 of 8

Hi. Thank you for your tips. I now understand a bit about
handle visibility (and I now have some clues about what to
search for in help).

Using the property inspector I saw that the figure's
HandleVisibility property was set to 'callback'. I changed
it to 'on', as advised here:
http://www.mathworks.cn/matlabcentral/newsreader/view_thread/155215

However, that did not change the fact that my code cannot
find the handle. Apparently the HandleVisibility property is
 later being set to 'off' by some process I'm not aware of.

What built-in functions would set HandleVisibility to off? I
haven't written any code to do that, so I'm not sure why it
is happening. I appreciate any other tips.

roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson) wrote in
message <fav7q6$d5g$1@canopus.cc.umanitoba.ca>...
> In article <fav61d$7a5$1@fred.mathworks.com>, G.A.M.
<x0zero@gmail.com> wrote:
> >Hello. I have an application that creates and displays a
> >figure (as the main window for the GUI). The figure is
> >displayed on screen, but the gui handle doesn't exist
> >immediately after the figure is created.
>
> >Executing h=findobj shows me that the figure and all its
> >uicontrols are not among the existing objects even though
> >the figure is currently visible on the screen.
>
> The HandleVisibility property of the figure has been set
to 'off'.
>
> See findall() and allchild()
> --
> Okay, buzzwords only. Two syllables, tops. -- Laurie
Anderson

Subject: Visible figure has no gui handle. Why?

From: G.A.M.

Date: 29 Aug, 2007 20:32:54

Message: 4 of 8

Hello. I have been stumped by this problem for several days
now. Using the tips provided previously, I have been
debugging the problem. However, I still get an 'Invalid
handle' error when using get('Tag', 'figureM').

Below is some interesting info that shows the figure exists
and HandleVisibility = on. At the moment I execute these
statements, the figure is visible on screen. Yet I still get
an 'Invalid handle' error as shown below. Any tips?


K>> h1 = findall(0, 'Tag', 'figureM')

h1 =

  399.0098

K>> get(h1)
Alphamap = [ (1 by 64) double array]
BackingStore = on
CloseRequestFcn = closereq
Color = [0.709804 0.807843 0.909804]
Colormap = [ (64 by 3) double array]
CurrentAxes = [406.01]
CurrentCharacter =
CurrentObject = [32.0095]
CurrentPoint = [230 22]
DockControls = off
DoubleBuffer = on
FileName = [ (1 by 84) char array]
FixedColors = [ (12 by 3) double array]
IntegerHandle = off
InvertHardcopy = on
KeyPressFcn = [ (1 by 1) function_handle array]
KeyReleaseFcn =
MenuBar = none
MinColormap = [64]
Name = Figure_M
NextPlot = add
NumberTitle = off
PaperUnits = inches
PaperOrientation = portrait
PaperPosition = [0.25 2.5 8 6]
PaperPositionMode = manual
PaperSize = [8.5 11]
PaperType = usletter
Pointer = arrow
PointerShapeCData = [ (16 by 16) double array]
PointerShapeHotSpot = [1 1]
Position = [72 34 1494 1031]
Renderer = painters
RendererMode = auto
Resize = on
ResizeFcn =
SelectionType = normal
ShareColors = on
ToolBar = auto
Units = pixels
WindowButtonDownFcn =
WindowButtonMotionFcn =
WindowButtonUpFcn =
WindowScrollWheelFcn =
WindowStyle = normal
WVisual = 00 (RGB 32 GDI, Bitmap, Window)
WVisualMode = auto

BeingDeleted = off
ButtonDownFcn =
Children = [ (16 by 1) double array]
Clipping = on
CreateFcn =
DeleteFcn =
BusyAction = queue
HandleVisibility = on
HitTest = on
Interruptible = on
Parent = [0]
Selected = off
SelectionHighlight = on
Tag = figureM
Type = figure
UIContextMenu = []
UserData = []
Visible = on

K>> get('Tag', 'figureM')
??? Error using ==> get
Invalid handle.

K>>

"G.A.M. " <x0zero@gmail.com> wrote in message
<fav8uo$5oc$1@fred.mathworks.com>...
> Hi. Thank you for your tips. I now understand a bit about
> handle visibility (and I now have some clues about what to
> search for in help).
>
> Using the property inspector I saw that the figure's
> HandleVisibility property was set to 'callback'. I changed
> it to 'on', as advised here:
>
http://www.mathworks.cn/matlabcentral/newsreader/view_thread/155215
>
> However, that did not change the fact that my code cannot
> find the handle. Apparently the HandleVisibility property is
> later being set to 'off' by some process I'm not aware of.
>
> What built-in functions would set HandleVisibility to off? I
> haven't written any code to do that, so I'm not sure why it
> is happening. I appreciate any other tips.
>
> roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson) wrote in
> message <fav7q6$d5g$1@canopus.cc.umanitoba.ca>...
> > In article <fav61d$7a5$1@fred.mathworks.com>, G.A.M.
> <x0zero@gmail.com> wrote:
> > >Hello. I have an application that creates and displays a
> > >figure (as the main window for the GUI). The figure is
> > >displayed on screen, but the gui handle doesn't exist
> > >immediately after the figure is created.
> >
> > >Executing h=findobj shows me that the figure and all its
> > >uicontrols are not among the existing objects even though
> > >the figure is currently visible on the screen.
> >
> > The HandleVisibility property of the figure has been set
> to 'off'.
> >
> > See findall() and allchild()
> > --
> > Okay, buzzwords only. Two syllables, tops. -- Laurie
> Anderson
>

Subject: Visible figure has no gui handle. Why?

From: Loren Shure

Date: 29 Aug, 2007 21:10:04

Message: 5 of 8

In article <fb4l5m$4u4$1@fred.mathworks.com>, x0zero@gmail.com says...
> Hello. I have been stumped by this problem for several days
> now. Using the tips provided previously, I have been
> debugging the problem. However, I still get an 'Invalid
> handle' error when using get('Tag', 'figureM').
>
> Below is some interesting info that shows the figure exists
> and HandleVisibility = on. At the moment I execute these
> statements, the figure is visible on screen. Yet I still get
> an 'Invalid handle' error as shown below. Any tips?
>
>
> K>> h1 = findall(0, 'Tag', 'figureM')
>
> h1 =
>
> 399.0098
>
> K>> get(h1)
> Alphamap = [ (1 by 64) double array]
> BackingStore = on
> CloseRequestFcn = closereq
> Color = [0.709804 0.807843 0.909804]
> Colormap = [ (64 by 3) double array]
> CurrentAxes = [406.01]
> CurrentCharacter =
> CurrentObject = [32.0095]
> CurrentPoint = [230 22]
> DockControls = off
> DoubleBuffer = on
> FileName = [ (1 by 84) char array]
> FixedColors = [ (12 by 3) double array]
> IntegerHandle = off
> InvertHardcopy = on
> KeyPressFcn = [ (1 by 1) function_handle array]
> KeyReleaseFcn =
> MenuBar = none
> MinColormap = [64]
> Name = Figure_M
> NextPlot = add
> NumberTitle = off
> PaperUnits = inches
> PaperOrientation = portrait
> PaperPosition = [0.25 2.5 8 6]
> PaperPositionMode = manual
> PaperSize = [8.5 11]
> PaperType = usletter
> Pointer = arrow
> PointerShapeCData = [ (16 by 16) double array]
> PointerShapeHotSpot = [1 1]
> Position = [72 34 1494 1031]
> Renderer = painters
> RendererMode = auto
> Resize = on
> ResizeFcn =
> SelectionType = normal
> ShareColors = on
> ToolBar = auto
> Units = pixels
> WindowButtonDownFcn =
> WindowButtonMotionFcn =
> WindowButtonUpFcn =
> WindowScrollWheelFcn =
> WindowStyle = normal
> WVisual = 00 (RGB 32 GDI, Bitmap, Window)
> WVisualMode = auto
>
> BeingDeleted = off
> ButtonDownFcn =
> Children = [ (16 by 1) double array]
> Clipping = on
> CreateFcn =
> DeleteFcn =
> BusyAction = queue
> HandleVisibility = on
> HitTest = on
> Interruptible = on
> Parent = [0]
> Selected = off
> SelectionHighlight = on
> Tag = figureM
> Type = figure
> UIContextMenu = []
> UserData = []
> Visible = on
>
> K>> get('Tag', 'figureM')
> ??? Error using ==> get
> Invalid handle.
>
> K>>
>
> "G.A.M. " <x0zero@gmail.com> wrote in message
> <fav8uo$5oc$1@fred.mathworks.com>...
> > Hi. Thank you for your tips. I now understand a bit about
> > handle visibility (and I now have some clues about what to
> > search for in help).
> >
> > Using the property inspector I saw that the figure's
> > HandleVisibility property was set to 'callback'. I changed
> > it to 'on', as advised here:
> >
> http://www.mathworks.cn/matlabcentral/newsreader/view_thread/155215
> >
> > However, that did not change the fact that my code cannot
> > find the handle. Apparently the HandleVisibility property is
> > later being set to 'off' by some process I'm not aware of.
> >
> > What built-in functions would set HandleVisibility to off? I
> > haven't written any code to do that, so I'm not sure why it
> > is happening. I appreciate any other tips.
> >
> > roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson) wrote in
> > message <fav7q6$d5g$1@canopus.cc.umanitoba.ca>...
> > > In article <fav61d$7a5$1@fred.mathworks.com>, G.A.M.
> > <x0zero@gmail.com> wrote:
> > > >Hello. I have an application that creates and displays a
> > > >figure (as the main window for the GUI). The figure is
> > > >displayed on screen, but the gui handle doesn't exist
> > > >immediately after the figure is created.
> > >
> > > >Executing h=findobj shows me that the figure and all its
> > > >uicontrols are not among the existing objects even though
> > > >the figure is currently visible on the screen.
> > >
> > > The HandleVisibility property of the figure has been set
> > to 'off'.
> > >
> > > See findall() and allchild()
> > > --
> > > Okay, buzzwords only. Two syllables, tops. -- Laurie
> > Anderson
> >
>
>

You have to pass possible handles or ancestors into findall. These all
worked for me as I expected:

h = figure('Tag','figureM');
h(2) = figure;

>>findall(h,'tag','figureM')
   1
>>findall(0,'tag','figureM')
   1
>>findall(h(2),'tag','figureM')
   Empty matrix: 0-by-1


--
Loren
http://blogs.mathworks.com/loren/

Subject: Visible figure has no gui handle. Why?

From: G.A.M.

Date: 29 Aug, 2007 21:38:17

Message: 6 of 8

Hi Loren,
Thanks for your reply. Unfortunately, I don't quite
understand it yet. I appreciate a clarification :)

My issue is that my main gui is displayed on the screen but
when I attempt to get a handle to it in my m-file code I get
an error that indicates the value returned by findobj('Tag',
'figureM') isn't valid. This seems very strange.

I simply want to have a gui figure display on the screen and
remain accessible/valid while the user clicks buttons and
causes various plots to be displayed. This seems like the
normal behavior one would expect, so I'm baffled that I'm
getting invalid handle errors - especially because I can see
the figure on the screen at the time of the errors.

The code I pasted was executed in the workspace as an
attempt to help me debug the problem. However, the problem
occurs in the m-file code. I simply can't seem to use
findobj('Tag', 'figureM') as one would expect it to be used.

> You have to pass possible handles or ancestors into
findall. These all
> worked for me as I expected:
>
> h = figure('Tag','figureM');
> h(2) = figure;
>
> >>findall(h,'tag','figureM')
> 1
> >>findall(0,'tag','figureM')
> 1
> >>findall(h(2),'tag','figureM')
> Empty matrix: 0-by-1
>
>
> --
> Loren
> http://blogs.mathworks.com/loren/

Subject: Visible figure has no gui handle. Why?

From: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)

Date: 29 Aug, 2007 23:14:24

Message: 7 of 8

In article <fb4l5m$4u4$1@fred.mathworks.com>, G.A.M. <x0zero@gmail.com> wrote:
>Hello. I have been stumped by this problem for several days
>now. Using the tips provided previously, I have been
>debugging the problem. However, I still get an 'Invalid
>handle' error when using get('Tag', 'figureM').

You can't get('Tag', 'figureM'). You can, though,

get(findobj('Tag', 'figureM'))

get() must be passed a handle (or list of handles) to operate on.
--
   I was very young in those days, but I was also rather dim.
   -- Christopher Priest

Subject: Visible figure has no gui handle. Why?

From: G.A.M.

Date: 30 Aug, 2007 21:22:05

Message: 8 of 8

Hi. Thank you for pointing out my mistake. Unfortunately,
that was only a mistake in what I posted here, not in my
code. I still have the problem in my code where it seems
like figures have handle visibility off when it is set to
on. I cannot figure it out... the code seems correct.

roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson) wrote in
message <fb4ukg$g6q$1@canopus.cc.umanitoba.ca>...
> In article <fb4l5m$4u4$1@fred.mathworks.com>, G.A.M.
<x0zero@gmail.com> wrote:
> >Hello. I have been stumped by this problem for several days
> >now. Using the tips provided previously, I have been
> >debugging the problem. However, I still get an 'Invalid
> >handle' error when using get('Tag', 'figureM').
>
> You can't get('Tag', 'figureM'). You can, though,
>
> get(findobj('Tag', 'figureM'))
>
> get() must be passed a handle (or list of handles) to
operate on.
> --
> I was very young in those days, but I was also rather dim.
> -- Christopher Priest

Tags for this Thread

Everyone's Tags:

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
guihandle G.A.M. 27 Aug, 2007 14:45:07
guihandles G.A.M. 27 Aug, 2007 14:45:07
gui G.A.M. 27 Aug, 2007 14:45:07
figure G.A.M. 27 Aug, 2007 14:45:07
rssFeed for this Thread
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com