Setting a Matlab GUI apps main figure to invisble

조회 수: 41 (최근 30일)
Mat
Mat 2020년 7월 21일
댓글: Adam Danz 2020년 7월 21일
I was interested in trying to break up my GUI app in to a set of smaller GUIs, all made in app creator, but using only a single app window and allowing the user to switch between them. I made a parent app with a button that when pressed started a second app containing a panel. The second app has a startup function that sets the parent of the panel to the figure window of the first app, which behaves as expected, but the second app window is still present. So then I added another line in the start up function to set its own uifigure to invisible:
% Code that executes after component creation
function startupFcn(app, parent)
app.Panel.Parent = parent;
app.UIFigure.Visible = false;
end
The argument 'parent' is the UIFigure from the first app.
This seems to work as expected, but what happens to the instance of app 2? The figure window is invisible, but it seems the app is still running. If so can it be closed without making it visible to user? What happens to its instance if I close the first app? Can I delete the instance from either app?
  댓글 수: 5
Mat
Mat 2020년 7월 21일
Would it be better to create a handle subclass for each section and use an input argument in their creation functions to pass a handle to the parent app? This would avoid having to subclass matlab.apps.AppBase while allowing the GUI to be written in small manageable sections.
Adam Danz
Adam Danz 2020년 7월 21일
The parent app should get the other app handles when the secondary apps are created. For example,
app.SecondaryAppHandle = secondaryApp;
where SecondaryAppHandle is a property of the primary app (instructions).

댓글을 달려면 로그인하십시오.

답변 (2개)

Mehmed Saad
Mehmed Saad 2020년 7월 21일
편집: Mehmed Saad 2020년 7월 21일
Run Test2.mlapp.
Press To Plot, it will take you automatically to Test1
Test1 and Test2 must be in the same directory

How it works

  댓글 수: 2
Mat
Mat 2020년 7월 21일
I am doing something very similar to this but I am using the UIFigure of the first app to plot the GUI components of the second. Assigning the second app to a property in the first should ensure proper deletion of both apps when I close the first apps window, but what happens if I don't assign the second app instance to a varaible? Does it just go out of scope and get deleted after the pushButton call back has run?
Mat
Mat 2020년 7월 21일
Here is my version. It allows all the components to be drawn in the same uifigure. Assigning the second app to a property in the first should ensure that it is deleted correctly when the first app is closed. Assigning the calling app to a property of the callee exposes all the public properties and methods of the caller to the callee. I'm not sure whether it it better for the second app to be created and deleted on the button presses or for the first app to just check if the second app has been instantiated and use visibilty to hide/show the panel. This may be better as the second app can then be used to store data.

댓글을 달려면 로그인하십시오.


Mat
Mat 2020년 7월 21일
I found part of my answer here. Using
h = findall(0,'Type','figure');
I found I had a number of orphaned invisible figures!

카테고리

Help CenterFile Exchange에서 Develop uifigure-Based Apps에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by