[visionegg] Re: the attachments...

Hi Christoph,

It looks like your program should work with one minor change. A few 
other pointers and tips below.

> photo = []
> photoX = []
>
> # present them in random order
> for filename in os.listdir(path):
>     photo.append(filename)
> length = len(photo)
> for i in range(0, length):
>     ran = randint(0, len(photo)-1)
>     file = photo[ran]
>     photoX.append(file)
>     photo.pop(ran)

You can do all of this with "photo.shuffle()", I believe.

> #############################################
> #  Create event handler callback functions  #
> #############################################
>
> # mouse state global variables
> pressed = 0
> released = 0
> button_press_time = []
>
> def mousebuttondown(event):
>     global pressed
>     if event.type == pygame.locals.MOUSEBUTTONDOWN:
>         pressed = 1
>         button_press_time.append(VisionEgg.timing_func())
>
> handle_event_callbacks = [(pygame.locals.MOUSEBUTTONDOWN,
> mousebuttondown),
>                           (pygame.locals.MOUSEBUTTONUP, mousebuttonup)]

If only events of type pygame.locals.MOUSEBUTTONDOWN trigger a callback 
to mousebuttondown(), there's no point in checking event.type in that 
callback.  (Maybe you want to check if "event.button==1", though?) Same 
for mouse up.


You got the error:

> NotImplementedError: <__main__.MouseButtonController instance at
> 0x8fe53fc>: Definition in abstract base class Controller must be
> overriden.

 From the following code:

> ########################
> #  Define controllers  #
> ########################
> class MouseButtonController( Controller ):
>     def __init__(self):
>         Controller.__init__(self,
>                             return_type=type(None),
>                             eval_frequency=Controller.EVERY_FRAME)
>
>     def during_go_eval(self,t=None):
>         # do the following ...
>         return None
>
> p.add_controller(None, None, MouseButtonController() )

There's no reason for this code.  A controller attached to nothing (the 
first two parameters to add_controller() set to None), but called every 
on frame executes the during_go_eval() function on every frame during 
the go loop (and between_go_eval on every frame not during a go loop).  
If there's nothing in these functions, it's pointless to have such a 
controller.  Nevertheless, the exception you got is from not overriding 
the "between_go_eval()" method. I've updated the source to make that 
exception more explicit in the future.

Cheers!
Andrew

======================================
The Vision Egg mailing list
Archives: http://www.freelists.org/archives/visionegg
Website: http://www.visionegg.org/mailinglist.html

Other related posts: