OpeningFcn with GUI NOT created by GUIDE
Mostrar comentarios más antiguos
Dear all, i have created a GUI without GUIDE and i am wondering how it's possible to call the OpeningFcn function like in GUIs created with GUIDE.
Respuesta aceptada
Más respuestas (5)
Joseph Cheng
el 21 de Jul. de 2014
1 voto
Do you need to? whatever you're using to create the GUI (not with GUIDE) is the OpeningFcn portion.
1 comentario
Joseph Cheng
el 21 de Jul. de 2014
well it looks like you're compiling it into a standalone exe? then i do not think putting it in the openingfcn equivalent is going to help as its taking 2min for matlab runtime to get everything straight before showing you anything.
http://www.mathworks.com/matlabcentral/answers/92901-how-can-i-show-a-splash-screen-when-the-mcr-is-loading-in-windows-standalone-application-mode is a thread i found that maybe relevant.
If you're not compiling to an executable then here is an example with the little details on why it takes 2 min (actual processing occurring or just displaying a simple GUI?). (come code or description of your startup sequence would have been nice):
function SplashScreen_Main()
fig_hand = figure; %figure handles
fig_size = get(fig_hand ,'Position');
I = imread('logo.tif');
AXES = axes;
imagesc(I),colormap(gray),set(AXES,'Position',[0 0 1 1])
set(fig_hand,'menubar','none');
Process_2minStartup(10)
YPos_offset=-65; %offset in y
%loop to generate popups.
for i=1:5
Type(i)=uicontrol('Style', 'popup',...
'String', '|1|2|3|4|5',...
'Position', [20 340+(i-1)*YPos_offset 100 50],'tag',['TYPE' num2str(i)]);
end
%setting some to enable off;
set(Type(1),'Enable','off');
set(Type(3),'Enable','off');
%disp(Type) %my debuging
%generate pushbutton.
Pbutton=uicontrol('Style', 'pushbutton',...
'String', 'check',...
'Position', [220 340 100 20],...
'Callback', {@check, fig_hand});
delete(AXES)
function Process_2minStartup(seconds)
pause(seconds)
function check(~,~,fig_hand)
TYPE=findobj(fig_hand,'Style','popup') %this is just to see if the popup numbers match what i have above for Type.
popup_tag = get(TYPE,'tag'); %get the tags
popup_enabled = get(TYPE,'Enable'); %get enabled
popup_stuff = get(TYPE,'String'); %get whats inside the pop up boxes
popup_select = get(TYPE,'Value'); %get which item was selected
for ind = 1:length(TYPE)
if strcmp(popup_enabled{ind},'on'); %check which popups are enabled
if strcmp(popup_stuff{ind}(popup_select{ind}),' ') %check if empty
fprintf(2, 'Problem: Empty string in: %s\n', popup_tag{ind});
else
fprintf(1,'Good: Valid string in: %s is %s\n', popup_tag{ind}, popup_stuff{ind}(popup_select{ind}));
end
else
fprintf(1,'Enable Off for Popup: %s\n', popup_tag{ind});
end
end
Pardon the not relevant code but to save some time i used an example i gave earlier today. So depending on whats taking the 2 min move the splash screen above.
George Lazaridis
el 21 de Jul. de 2014
0 votos
George Lazaridis
el 22 de Jul. de 2014
George Lazaridis
el 22 de Jul. de 2014
0 votos
1 comentario
Robert Cumming
el 22 de Jul. de 2014
what version of matlab are you using? In R2014a you can specify a splashscreen which Matlab will display while the MCR loads (which is most likely to be whats taking the majority of the time).
George Lazaridis
el 22 de Jul. de 2014
0 votos
7 comentarios
Robert Cumming
el 22 de Jul. de 2014
The delay you have sounds like its the time taken to load the MCR. There is nothing you can do in your m-code to solve this.
Its not a trivial problem to solve - hence why you have to pay for Yairs solution.
George Lazaridis
el 22 de Jul. de 2014
Robert Cumming
el 22 de Jul. de 2014
Of course its possible - thats what Yair did.
I assume a VS solution would you require loading your GUI as a DLL into the project - and all your VS solution does is to display your splashscreen - which is displayed while the DLL (+MCR) is loaded.
George Lazaridis
el 22 de Jul. de 2014
Robert Cumming
el 22 de Jul. de 2014
It doesn't require the openingfcn - that is just using it as an example.
It requires any function where you start your code - so put it just before you make your gui visible/interactive.
The creation of your splash screen is in the wrapper - all your doing is deleting it in your m-code.
George Lazaridis
el 22 de Jul. de 2014
George Lazaridis
el 22 de Jul. de 2014
Categorías
Más información sobre Startup and Shutdown en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!