Callback not working properly.
12 ビュー (過去 30 日間)
古いコメントを表示
Hey, I ham having problems call the function
cmp_button_Callback(hObject, eventdata, handles)
but when I do it tells me
Error in ThermaGUI>cmp_import_pshbttn_callback (line 126)
cmp_button_Callback
Error while evaluating DestroyedObject Callback
so I am not sure how to fix this... It worked initially but something just broke. Here is the part of the code that had problems.
function cmp_button_Callback(hObject, eventdata, handles)
global cmp_created
if cmp_created == 1
imshow('check.png','Parent',handles.intro_chckbx_cmp)
else
imshow('cross.png','Parent',handles.intro_chckbx_cmp)
%Creates components gui with options
cmp_fig = figure(...
'Color',[.94 .94 .94],...
'Position',[500,500,165,130],...
'Resize','Off',...
'MenuBar','none',...
'Name','Conditions',...
'tag','cmp_fig',...
'WindowStyle','modal');
%Creates text in option to guide the user
uicontrol(...
'Parent',cmp_fig,...
'Position',[10 90 150 30],...
'String','Choose Option',...
'Style','text',...
'TooltipString','Default');
%Creates button to import a .cmp file
cmp_import_pshbttn = uicontrol(...
'Parent',cmp_fig,...
'Position',[10 70 150 30],...
'String','Import existing .cmp file',...
'Style','pushbutton',...
'Tag','cmp_import_pshbttn',...
'Callback',@cmp_import_pshbttn_callback,...
'TooltipString','Default');
%Create a button to open the gui for custom creation of .cmp
cmp_custom_pshbttn = uicontrol(...
'Parent',cmp_fig,...
'Position',[10 40 150 30],...
'String','Create custom .cmp file',...
'Style','pushbutton',...
'Tag','cnd_custom_pshbttn',...
'Callback',@cmp_custom_pshbttn_Callback,...
'TooltipString','Default');
%Creates pushbutton to cancel process
cpd_cancel_pshbttn = uicontrol(...
'Parent',cmp_fig,...
'Position',[10 10 150 30],...
'String','Cancel',...
'Style','pushbutton',...
'Tag','cmp_cancel_pshbttn',...
'TooltipString','Default');
end
function cmp_import_pshbttn_callback(hObject, eventdata, handles)
% delete(gcf)
[FileName,PathName] = uigetfile({'*.cmp',...
'Component Files (*.cmp)';'*.txt', 'Text Files (*.txt)';...
'*.*','All Files (*.*)'},'Select the Components File');
pathn = fullfile(PathName,FileName);
curpath = fullfile(pwd,FileName);
if isequal(FileName,0) %if no file is chosen or canceled then display Cancel
disp('User selected Cancel')
else % else continue
disp(['User selected ', fullfile(PathName, FileName)])
disp(['asd', fullfile(pwd, FileName)])
if isequal(curpath,pathn) % determine if file is in current directory or not
movefile(FileName,'test.cmp')
else
copyfile(fullfile(PathName, FileName)); % copy file into directory for Matlab
movefile(FileName,'test.cmp')
end
end
global cmp_created
cmp_created = 1;
%imshow('check.png','Parent',handles.intro_chckbx_cmp)
cmp_button_Callback(hObject, eventdata, handles)
additionally, there is an imshow because instead of calling the function that would then execute that function, but it does not work properly when executed in this function, which is why I tried calling the other function where imshow properly works.
0 件のコメント
回答 (1 件)
Walter Roberson
2015 年 9 月 18 日
cmp_import_pshbttn_callback should not be calling cmp_button_Callback.
2 件のコメント
Walter Roberson
2015 年 9 月 28 日
function do_the_cmp_work(hObject, eventdata, handles)
imshow('check.png','Parent',handles.intro_chckbx_cmp);
end
function cmp_button_Callback(hObject, eventdata, handles)
%Creates components gui with options
cmp_fig = figure(...
'Color',[.94 .94 .94],...
'Position',[500,500,165,130],...
'Resize','Off',...
'MenuBar','none',...
'Name','Conditions',...
'tag','cmp_fig',...
'WindowStyle','modal');
%Creates text in option to guide the user
uicontrol(...
'Parent',cmp_fig,...
'Position',[10 90 150 30],...
'String','Choose Option',...
'Style','text',...
'TooltipString','Default');
%Creates button to import a .cmp file
cmp_import_pshbttn = uicontrol(...
'Parent',cmp_fig,...
'Position',[10 70 150 30],...
'String','Import existing .cmp file',...
'Style','pushbutton',...
'Tag','cmp_import_pshbttn',...
'Callback',@cmp_import_pshbttn_callback,...
'TooltipString','Default');
%Create a button to open the gui for custom creation of .cmp
cmp_custom_pshbttn = uicontrol(...
'Parent',cmp_fig,...
'Position',[10 40 150 30],...
'String','Create custom .cmp file',...
'Style','pushbutton',...
'Tag','cnd_custom_pshbttn',...
'Callback',@cmp_custom_pshbttn_Callback,...
'TooltipString','Default');
%Creates pushbutton to cancel process
cpd_cancel_pshbttn = uicontrol(...
'Parent',cmp_fig,...
'Position',[10 10 150 30],...
'String','Cancel',...
'Style','pushbutton',...
'Tag','cmp_cancel_pshbttn',...
'TooltipString','Default');
do_the_cmp_work(hObject, eventdata, handles);
function cmp_import_pshbttn_callback(hObject, eventdata, handles)
[FileName,PathName] = uigetfile({'*.cmp',...
'Component Files (*.cmp)';'*.txt', 'Text Files (*.txt)';...
'*.*','All Files (*.*)'},'Select the Components File');
pathn = fullfile(PathName,FileName);
curpath = fullfile(pwd,FileName);
if isequal(FileName,0) %if no file is chosen or canceled then display Cancel
disp('User selected Cancel')
else % else continue
disp(['User selected ', fullfile(PathName, FileName)])
disp(['asd', fullfile(pwd, FileName)])
if isequal(curpath,pathn) % determine if file is in current directory or not
movefile(FileName,'test.cmp')
else
copyfile(fullfile(PathName, FileName)); % copy file into directory for Matlab
movefile(FileName,'test.cmp')
end
end
do_the_cmp_work(hObject, eventdata, handles);
参考
カテゴリ
Help Center および File Exchange で Interactive Control and Callbacks についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!