Callback not working properly.
12 views (last 30 days)
Show older comments
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 Comments
Answers (1)
Walter Roberson
on 18 Sep 2015
cmp_import_pshbttn_callback should not be calling cmp_button_Callback.
2 Comments
Walter Roberson
on 28 Sep 2015
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);
See Also
Categories
Find more on Interactive Control and Callbacks in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!