[visionegg] Re: falling out of a go() loop which is set to run_forever so that a second go() loop can be allowed to run
- From: Andrew Straw <andrew.straw@xxxxxxxxxxxxxxx>
- To: visionegg@xxxxxxxxxxxxx
- Date: Thu, 24 Jul 2003 11:32:50 +0200
Hi Mark,
I'm also wondering if there are timing (or other) issues in
organizing my stimulus presentation in this way (is it better to
simply have
one main loop, rather than a number of loops in sequence)?
I don't think there are timing or other issues involved. I think its
largely a matter of personal preference. For your task I think it
might be conceptually cleaner to write your own main loop rather than
using the Presentation class.
(When I first wrote the Vision Egg, I was using it mainly for
electrophysiology experiments where the go loop paradigm is very
useful. The ephys_server and GUI is built on that paradigm. But for
psychophysics I think it's generally less useful.)
I'm still in the process of adding more demos that show use of your own
main loop, and I think the ones that do exist are only in the bleeding
edge release so far.
How do I quit prematurely out of a go() loop (say, as a result of a
mouse
button press), without exiting the VisionEgg script entirely?
It is possible to do it this way, so here's the answer to your question:
If you have an instance of Presentation called p, setting
p.parameters.go_duration = (0,'frames') would stop the go loop before
drawing another frame.
So, your event handlers will have have a reference to the instance of
Presentation you want to quit. Therefore, you might need to define
your instances of Presentation as before, but then modify the event
handler:
class ButtonDown:
def set_presentation_instance(self, p):
self.p = p
def click(self, event):
if event.button == 1:
self.p.parameters.go_duration = (0,'frames')
button_down = ButtonDown()
handle_event_callbacks = [(pygame.locals.QUIT, quit),
(pygame.locals.MOUSEBUTTONDOWN,button_down.click),
(pygame.locals.MOUSEBUTTONUP,
mouse_button_up),
(pygame.locals.KEYDOWN, keydown)]
p = Presentation(go_duration=('forever',), viewports=[view],
handle_event_callbacks=handle_event_callbacks)
q = ...
r = ...
button_down.set_presentation_instance(p)
p.go()
button_down.set_presentation_instance(q)
q.go()
button_down.set_presentation_instance(r)
r.go()
Something like that should do what you want. But, as I said, it may be
cleaner to write your own control flow rather than resort to object
oriented trickery like this.
Cheers!
Andrew
======================================
The Vision Egg mailing list
Archives: http://www.freelists.org/archives/visionegg
Website: http://www.visionegg.org/mailinglist.html
- Follow-Ups:
- References:
Other related posts:
- » [visionegg] Re: falling out of a go() loop which is set to run_forever so that a second go() loop can be allowed to run
- » [visionegg] Re: falling out of a go() loop which is set to run_forever so that a second go() loop can be allowed to run
organizing my stimulus presentation in this way (is it better to simply have
one main loop, rather than a number of loops in sequence)?
button press), without exiting the VisionEgg script entirely?