esdalmaijer / PyGaze

an open-source, cross-platform toolbox for minimal-effort programming of eye tracking experiments
www.pygaze.org
GNU General Public License v3.0
671 stars 211 forks source link

Specifying `disptype` through keyword gives exception #5

Closed smathot closed 10 years ago

smathot commented 10 years ago

Most of the settings can be overridden by creating constants.py or by passing keyword arguments to the constructor. However, the keyword way gave me some trouble. For example, I would expect this to work:

from pygaze import libscreen
screen = libscreen.Screen(disptype='pygame')

Instead it gives an Exception, because pygame has not been imported. The problem appears to be due to the fact that the import statements are based only on the values set in either defaults.py or constants.py, but not based on the keywords. I'm not sure what the best solution would be. One option would be to create a function that ascertains that pygame is imported, and call this function in the constructor of Display, Screen, and wherever we need to make sure that pygame is available. An analogous function would need to be created for psychopy, of course.

def importPygame():

    """Make sure that PyGame is imported."""

    if 'pygame' not in globals():
        global pygame
        import pygame
esdalmaijer commented 10 years ago

Good point, that applies to some of the other libraries as well. I'm pondering over it... Will report back if I figure something out (your way seems like a good approach, I'll see if I can find a way to integrate it within all of the libs).

smathot commented 10 years ago

Closing due to #12.