Locking All Other GUI Windows While Another is Up
古いコメントを表示
I have a GUI which controls hardware. The GUI creates multiple new GUI's from it which change aspects of how the original GUI interacts with this hardware. While a user is changing settings of how the original GUI functions, I do not want the original GUI to be able to function. Ensuring the button to configure the GUI is unusable is easy as I simply make the button to do so invisible while the user is waiting on results. However, I have not been able to find a simple way of making the original GUI unusable.
I've tried uiwait with a simple example, but it has not worked as the "fail test" still displays text on the original GUI (under handles1.GUI) if I change my focus back to the original GUI after creating the second (handles2.GUI).
handles1=struct();
handles1.GUI=figure();
handles1.UI1=uicontrol('style','text',...
'parent',handles1.GUI,...
'units','normalized',...
'position',[0.2 0.2 0.1 0.1]);
handles1.UI2=uicontrol('style','pushbutton',...
'Callback',@Lock_Me,...
'parent',handles1.GUI,...
'String','Lock Test',...
'Units','Normalized',...
'position',[0.4 0.4 0.1 0.1]);
handles1.UI3=uicontrol('style','pushbutton',...
'Callback',@Fail_Me,...
'parent',handles1.GUI,...
'String','Fail Test',...
'Units','Normalized',...
'position',[0.6 0.6 0.1 0.1]);
function Lock_Me(hObject,~,~)
handles2=struct();
handles2.GUI=figure();
handles2.UI1=uicontrol('style','pushbutton',...
'Parent',handles2.GUI,...
'Callback',@Unlock_Me);
setappdata(handles2.GUI,'lockedfig',hObject.Parent)
uiwait(hObject.Parent);
end
function Unlock_Me(hObject,~,~)
uiresume(getappdata(handles2.GUI,'lockedfig'))
close(hObject.Parent)
end
function Fail_Me(hObject,~,~)
GUI1children=hObject.Parent.Children;
for i=1:length(GUI1children)
if strcmp(GUI1children(i).Style,'text')
GUI1children(i).String='Failure';
end
end
end
I'm not super familiar with uiwait and uiresume while using multiple figures, so I may be incorrect in using appdata to transfer the handle of the original figure which needs to be resumed.
This is not the exact structure of my GUI, it is much more complex with a few pushbuttons, and popupmenus I would like to disable. The GUI window which is spawned to configure the original GUI also has multiple GUI's it can create to change advanced settings of the original GUI. However, if the above code works the way it should, then I should be okay.
I'm using MATLAB 2017b and am not using GUIDE, but I'm sure if you submit something with how GUIDE does something I can figure out how to do it manually.
6 件のコメント
Adam Danz
2018 年 8 月 3 日
What if you turn off the visibility of the original GUI during period when you don't want users to use that GUI? Note that the visibility property does not block access to the object's components. It just makes the object not visible.
If guiHand is the handle to your GUI.
guiHand.Visible = 'off';
guiHand.Visible = 'on';
Luke Perry
2018 年 8 月 3 日
編集済み: Luke Perry
2018 年 8 月 3 日
OCDER
2018 年 8 月 3 日
I like @Adam's answer. If you're worried about crashing, etc, perhaps a try/catch statement could work.
handles.GUI.Visible = 'off';
try
Out = NewGUI(handles.GUI.Position, ...); %Open your new GUI
%As bonus, perhaps you could draw this NewGUI RIGHT ABOVE the current
%GUI's position. Just so it looks like you're in the same GUI.
%You'd have to feed in the position of the current GUI and use that
%to resize the GUI's position.
catch E
disp(E);
end
handles.GUI.Visible = 'on'; %Restore your GUI Visibility
Luke Perry
2018 年 8 月 3 日
OCDER
2018 年 8 月 3 日
If you put the handles.GUI.Visible 'on', in the catch statement, then your original GUI will reappear ONLY WHEN there's an error from the New GUI - as in, normal-working New GUI will just forever hide the original GUI.
The New GUI should have uiwait and uiresume in it, so the the original GUI is waiting for the New GUI to complete and return an output. Without the uiwait and uiresume in NewGUI, you're right - it'll just open New GUI + reshow Orig GUI.
Luke Perry
2018 年 8 月 3 日
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で View and Analyze Simulation Results についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!