OpeningFcn with GUI NOT created by GUIDE

2 次查看(过去 30 天)
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.

采纳的回答

Robert Cumming
Robert Cumming 2014-7-21
As joseph said - you dont need to.
One way around it is to create your figure with visible set to off - call your own OpeningFcn - then set visible to on!

更多回答(5 个)

Joseph Cheng
Joseph Cheng 2014-7-21
Do you need to? whatever you're using to create the GUI (not with GUIDE) is the OpeningFcn portion.
  1 个评论
Joseph Cheng
Joseph Cheng 2014-7-21
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.
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
George Lazaridis 2014-7-21
thanks for your answers guys. I am trying to incorporate into my GUI a splash screen because my executable's boot time is around 2 minutes! In every article i found online, it's mentioned to put some piece of code in the OpeningFcn function, but i don't have an OpeningFcn function as i created my GUI manually (i don't use GUIDE). What should i do?

George Lazaridis
George Lazaridis 2014-7-22
function HRVanalyzer11()
clc
clear all
s = SplashScreen( 'Splashscreen', 'example_splash.png', ...
'ProgressBar', 'on', ...
'ProgressPosition', 5, ...
'ProgressRatio', 0.4 );
s.addText( 30, 50, 'HRV_Analyzer', 'FontSize', 30, 'Color', [0 0 0.6] );
s.addText( 30, 80, 'v1.0', 'FontSize', 20, 'Color', [0.2 0.2 0.5] );
s.addText( 300, 270, 'Loading...', 'FontSize', 20, 'Color', 'white' );
if true
% code
end
hWinSize = 320;
vWinSize = 240;
warning off MATLAB:divideByZero
warning off MATLAB:singularMatrix
handles.flag = 0 ;
handles.srate=200;
handles.fsRR = 4;
handles.filterpointer = 0;
handles.rrflag = 0 ;
if true
% code
end
%Menu tabs
f = figure('Name','HRV_Analyzer','NumberTitle','off','Visible','off',...
'Position',[0,0,hWinSize,vWinSize],...
'menubar','none',...
'DockControls','off',...
'toolbar','none',...
'color',[0.9,0.9,0.9],...
'Units','normalized','CloseRequestFcn',@Exit_callback);
if true
% code
end
FileMenu = uimenu('Label','File',...
'parent', f,...
'visible', 'on');
and when I set the figure (f) visible then i delete(S).

George Lazaridis
George Lazaridis 2014-7-22
I just want to put something on the screen while the user is waiting for the matlab executable to load.
  1 个评论
Robert Cumming
Robert Cumming 2014-7-22
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).
For older versions of matlab you could try (its commercial) this method by Yair Altman.

请先登录,再进行评论。


George Lazaridis
George Lazaridis 2014-7-22
I am using 2013a. I believe you have to pay for Yair Altman's method :) As you can see i have my splash screen code in the first lines of my program. When i am running the program in Matlab environment it works as supposed to work, but of course, the delay is minimum, like 2-3seconds. When i deploy the .exe then, the delay time is 2minutes and the splash screen opens at the very last seconds before showing the GUI.
  7 个评论

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Environment and Settings 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by