Main thread yield to graphics events
    Flemming Nyboe 
    flemming at nyboe.net
       
    Wed Aug 12 08:35:41 CEST 2009
    
    
  
Hello,
I have an infinite while loop processing graphics in a figure. I'm trying to
break the loop when the user closes the figure, but it seems that the
execution thread never yields to the graphics events.
The below code does not end (print "done") when I close the figure.
1) is there a way to force a "do-events" where graphics events are given
time to fire?
2) alternatively, is there a way to detect if a keyboard key has been
pressed without waiting if not.
Regards
Flemming, Denmark
----------------
// detecting closed figure
function my_eventhandler(win,x,y,ibut)
  global run
  if ibut==-1000 then 
    run=0;
  end
endfunction
global run
run=1;
plot2d()
seteventhandler('my_eventhandler')
fh=gcf();
while run,
 if (length(winsid())==0) then
    run=0;
 end
 if ~is_handle_valid(fh) then
   run=0;
 end
 drawnow();
 sleep(2);
end
seteventhandler('') //suppress the event handler
printf('done\n');
----------------
    
    
More information about the users
mailing list