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
0 个评论
采纳的回答
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 个评论
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 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!