GUI does not recognize existing handles after using addlistener

0 down vote favorite
I am quite new to MATLAB GUI programming (using GUIDE sorry) and I have an annoying issue: The GUI displays on an axis an image sequence stored in a cell array. I have a couple of pushbuttons and a slider to scroll through the sequence. In order to get a 'continuous slider' I use a listener object, which kind of works but creates some problems:
1) When I press the slider, a figure is created outside the GUI and the first frame of the sequence is displayed in it, but as I move the slider the sequence is displayed in the axis of my GUI (which is what I want) and the figure becomes empty. Can anybody tell me why this figure is created and how can I avoid it appearing?
2) Once I press the slider button and thus use the listener, all handles inside the GUI are not functionnal as Matlab does not recognize them and I'm stuck with a functionnal slider/display but I can't use the pushbuttons. In other words, it's like only the axis and the slider were in the GUI and every other elements (pushbuttons, text boxes, etc.) were non existent.
Any ideas on why this happens? Here is the code I use in the Create Function of the slider:
function slider_Frame_Video_Callback(hObject, eventdata, handles)
hListener = addlistener(hObject,'ContinuousValueChange',@(a,b) slider2_Frame_Video_Callback(hObject, eventdata, handles)); % a and b are dummy arguments
guidata(hObject,handles)
In the slider callback, the code looks like this (basically imshow in the current axis):
axes(hAxis)
imshow(Movie{frame},'parent',hAxis);
drawnow
% This does not work either as handles.edit_FrameNumber is not recognized by Matlab
set(handles.edit_FrameNumber, 'String', frame);
guidata(hObject,handles);
Thanks a lot for any hints/input!

댓글 수: 2

Can you attach it? What is _frame?
- frame is an integer calculated from the position of the slider:
frame = floor(get(hObject,'Value')*NumberFrames) % NumberFrames is the number of images in the cell array.
- Do you mean by attach the whole code for the slider callback?
thanks

댓글을 달려면 로그인하십시오.

 채택된 답변

Sean de Wolski
Sean de Wolski 2014년 6월 2일
편집: Sean de Wolski 2014년 6월 2일
More than likely the second figure is created because you use one of the get current * functions:
gcf
gca
gco
etc. These functions can't find the GUIDE figure because its 'HandleVisibility' is off and so they create a new one.

댓글 수: 2

Great the figure does not appear once I remove the code using 'gca' I had a few lines above.
However I used
set(handles.figure1,'HandleVisibility','on')
guidata(hObject,handles);
at the end of the slider callback but I still have the problem about invalid/deleted axes. Is there something I would need to add in the other callbacks of the GUI then?
Hi Sean,
I think I found a workaround for my problem: I changed the callback function in the addlistener definition in order to call an external function, called "ShowCurrentFrame", instead of the slider callback:
Before:
hListener = addlistener(hObject,'ContinuousValueChange',@(a,b) slider2_Frame_Video_Callback(hObject, eventdata, handles));
Now:
hListener = addlistener(hObject,'ContinuousValueChange',@(a,b) ShowCurrentFrame);
Using setappdata/getappdata I load the handles to the slider and I can now call other callbacks from the GUI.
Thanks for your help!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기

질문:

2014년 6월 2일

댓글:

2014년 6월 2일

Community Treasure Hunt

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

Start Hunting!

Translated by