Quick question GUI AppDesigner

1 次查看(过去 30 天)
Good evening,
I have a very simple question to ask you: I've got a main figure "MainFigure" with just one "GoTo SecondFig" pushbutton and when pressed it opens a new figure "SecondFigure" with a "Return to MainFig" pushbutton.
Goal to achieve:
1) When the user clicks on the "GoTo SecondFig" pushbutton and the new figure appears, the user cannot push again the button on the "MainFigure". Also, the user is forced to close the second figure if he wants to return to the main one (the behaviour is like the one we experience on a database form. Until you do not quit a form, you could not perform other action on other forms).
2) When the user clicks on the "Return to MainFig" pushbutton, "SecondFigure" closes and focus return to the main one. (How do I link these two figures in the callback of the "Return to MainFig" pushbutton?)
3) Do all this stuff with appDesigner.
Thank you for your help. Hope I was clear enough.
Best regards

采纳的回答

Adam Danz
Adam Danz 2020-6-15
编辑:Adam Danz 2020-6-16
1) When the user clicks on the "GoTo SecondFig" pushbutton and the new figure appears, the user cannot push again the button on the "MainFigure".
As part of the push button's callback function, disable the button using
app.Button1.Enable = 'off';
...Also, the user is forced to close the second figure if he wants to return to the main one
How are you hiding the first figure? Is the figure embedded within the app or is it external to the app? Either way, within the callback function of the push button from fig 1,
fig1.Visible = 'off'; % to turn off visibility of figure "fig1"
% or
ax.Visibility = 'off'; % to control the axes (it's not clear if "figure" is really a figure or axes)
Then, set the callback function for Button2 (in fig2) to turn the visibility back on for fig 1.
app.Button1.Visible = 'on';
However, fig2 needs to have access to fig1 handle. Is Fig2 created from the callback function of the button in Fig 1? If so, you could pass the handle there. You may also be able to use find(). Also, see my answer to your question "How do I link these two figures...".
2) When the user clicks on the "Return to MainFig" pushbutton, "SecondFigure" closes and focus return to the main one.
The callback function for Button 2 (in fig 2) will do two things in this order.
- set the Visible property of fig 1 (shown above)
- close the figure using close(f) or delete(f) where f is the handle to figure 2.
(How do I link these two figures in the callback of the "Return to MainFig" pushbutton?)
It depends how they are being created. Figure have a propery UserData where you can store anything you want. You could store the figure handles there. For example,
fig1 = figure();
fig2 = figure('UserData', fig1);
fig1.UserData = fig2;
Now access the figure handles using
fig1.UserData % handle to fig2
fig2.UserData % handle to fig1
3) Do all this stuff with appDesigner.
It's not clear what you mean here. App Designer is a figure so if you're creating additional figures, those figures must be external. When you say "figure" do you mean "axes" or "tab"?
  2 个评论
MZ123
MZ123 2020-6-16
Dear Adam,
first of all, thank you for the exhaustive answer to my vague question. It helped a lot.
I made two separate .mlapp GUIs using AppDesigner. The GUIs are composed of a figure (of course) and just one pushbutton (no axes).
Reading your answer and learning a bit about handles, I solved in this way:
1) during mainGUI initialization function I set the name with
app.UIFigure1.Name = "Main"
2) the same was done with the second GUI
app.UIFigure2.Name = "Secondary"
3) pressing Button1 in Figure1 I did as you wrote me:
app.Button1.Enable = 'off';
and invoked GUI2 to appear.
4) in GUI2, pressing the Button2 I refered to the Main GUI thanks to handles via:
h_MainFigure = findall(0,'Type','uifigure','Name','Main');
enabling again the PushButton1 and deleting the second GUI.
Hope this was correct enough. It works for the moment!! :)
Adam Danz
Adam Danz 2020-6-17
编辑:Adam Danz 2020-6-18
It looks OK. You can also name the GUI from the DesignView within AppDesigner by selecting the main figure and setting the "name" value in the component browser. But there's nothing wrong with naming it the way you did, within the startup fcn.
One word of caution. The figure name "Main" is not unique enough. There's a non-zero chance that some day you'll have another uifigure named "main" while your app is running and the findall() function will return both handles which may cause an error. To get around this you can do two things. 1) change the main figure name to something more descriptive of whatever the app does. Something like "MainSalesApp" or "BaseAppForFileReformatting". The second thing you can do to further decrease the chances of ever "finding" the wrong figure is to use a "Tag" value, too. A tag can be assigned to the figure either in the startup fcn or within the DesignView. For example,
h_MainFigure = findall(0,'Type','uifigure','Name','MainSalesApp', 'Tag', 'PrimaryApp_Sales');

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Interactive Control and Callbacks 的更多信息

产品


版本

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by