Info

此问题已关闭。 请重新打开它进行编辑或回答。

Strange behavior of GUI with GUIDE

1 次查看(过去 30 天)
Julien
Julien 2013-9-26
关闭: MATLAB Answer Bot 2021-8-20
Hello,
I'm trying to build a GUI by combining GUIDE and the GUI Layout Toolbox. I would like to build a multitab GUI very quickly, but with a large amount of components. It takes a long time to write the code, and I would like to focus on the callback's and not on the components positionning.
To do so, I found a way that could work :
  • build each tab content wrapped in a panel in separate GUIDE figure,
  • write a main script that open figures in invisible mode
  • add the panels in each tabs
The process is working well if we take care to change units of all components to "normalized" (it is also a tip to resize easyly GUI's created with GUIDE)
For the moment I see three ways to do this : In the following code, create_Pipe is a nested function that opens the fig PipePanel created with GUIDE, get the handles structure A
  • 1) generate the mfile that include the handles of each components and use copyobj(panel,tab).
function create_Pipe()
[~,A]=PipePanel('visible','off');
newPipe=copyobj(A.PipePan,h.mainTab);
end
  • 2) Change the Parent of the panel:
function create_Pipe()
[~,A]=PipePanel('visible','off');
set(A.PipePan,'Parent',double(h.mainTab));
end
It works, my components (all children of the panel) are well transferred, I have acces to all components properties with struc A.
But when I close and reload, it doesent work (invalid object/handles)
When I launch PipePanel with the code of GUIDE, nothings appears. When I reload GUIDE, all become OK
I really don't understand what happens !
  • 3) Generate only the figure, and retrieve all components using findobj. It works but not the more efficient way
Do you have any Idea about the bug, or an other solution to import components with handles ?
Thank you in advance

回答(1 个)

Julien
Julien 2013-9-26
I found a solution, it seems well working. It could be a process to create multitab GUI's with GUIDE.
  • - Put all the components of the tab wrapped in a panel within GUIDE
  • - Place the components as you want and change all the units to "normalized"
  • - Create a new figure with a tabpanel container (the same size of your panel is better. If you put all to normalized, all components will keep the defined ratio)
  • - open in invisible mode the GUI figure corresponding to the current tab,
  • - copy the main panel object and set the tab panel as the new parent (copyobj)
Now we need to retrieve all components handles to acces their properties. this can be done with a simple function:
function handles=childHandles(hParent)
%Find all the children handles
handVal=findobj(hParent);
%Find all the children name defined within GUIDE
handTag=get(handVal,'Tag');
%Create a new handle structure
for i=1:length(handVal)
handles.(char(handTag(i))=handVal(i);
end
end
this will output a new handles structure of all cloned components.
I don't know if there is most simple solution, but it is a good way for me to save time when building complex GUI. (GUI Layout is very usefull, but the number of command lines become veeeery long when you have a lot of components). If somebody is interresed by a complete example, I could provide one on file exchange when I will have some free time.
  1 个评论
Julien
Julien 2013-9-26
I precise that you will need to download the great GUI Layout toolbox on file exchange to acces tabpanels: GUI Layout toolbox

此问题已关闭。

产品

Community Treasure Hunt

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

Start Hunting!

Translated by