Callback not working properly.
7 次查看(过去 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!