esdalmaijer/opensesame_eyetracker — pull request #1 by smathot (2013-07-30 16:03:04+00:00)
Title: Some bits and ideas

I couldn't resist playing around with this right away, and made some minor modifications.

- I moved the `lib[tracker]` modules to a separate `tracker` package. That looks cleaner to me, but whatever you prefer. There is no technical reason not to structure the code with packages within OpenSesame plug-ins.
- I changed the import statements to avoid `exec()` statements. Although it's unlikely to happen in this particular case, I've sometimes had issues with using `exec()` in this way, when parts of the string get interpreted in an unintended way. And usually it's possible to rewrite the code so that you don't need `exec()` at all.

And some ideas came to mind:

- What do you think about defining an abstract `libbasetracker` class (or some name like that), which has all the docstrings, describes the API, and is inherited by all the other tracker classes? It wouldn't add any functionality, but it might make things more transparent.
- Right now all the constructors take a whole range of keywords, some of which are specific to a particular eye tracker. For example the `ip` keyword, which is only applicable to `libsmi.__init__()`. This is not very elegant, and if more brands are supported, there might be more and more of those brand-specific keywords. One solution would be to have only a few, universally applicable keywords (like `data_file`, etc.) and pass the rest of the keywords as extras in [dictionary style](http://docs.python.org/2/tutorial/controlflow.html#keyword-arguments). The example below shows the general idea. `kw1` and `kw2` would then be the standard keywords, that are applicable to all eye trackers. The brand-specific keywords, like `kw3`, would be passed into `kw_dict`.

~~~ .python
def my_func(kw1=0, kw2=1, **kw_dict):
if u'kw3' in kw_dict:
print 'kw3 =', kw_dict[u'kw3']
else:
print 'No kw3'

kw_dict = {u'kw3' : 2}
my_func(kw2=1, **kw_dict)
my_func(kw3=2)
my_func(kw2=1)
~~~

Right now I only tried the dummy functionality (I didn't encounter any issues), but tomorrow I'll try it on the EyeLink as well!