Comments (3)
Basically, the problem is how to do this as easy as possible. The beauty of the constants module approach was really simple: just define everything that needs to remain constant in a single file, and then import that file. Of course I do see the problem that occurs with the keyword arguments. Bloody object oriented programmers redefining all sorts of crap at runtime... ;)
I've been thinking about a almost the exact approach as you propose for a while. Basically, the idea is to keep a dict (lets call it settings
) that contains all of the values used in PyGaze's modules. It could be accessible via pygaze.settings
, and when PyGaze is initialized it would contain all default values (possibly imported from defaults
and constants
, for backwards compatibility).
import pygaze
# print the default option, or the option set in constants.py, e.g. "pygame"
print(pygaze.settings['disptype'])
# set a new value
pygaze.settings['disptype'] = "psychopy"
I suppose that if settings
is a global variable in the modules, this should work. Your approach in OpenSesame is more advanced, in that it's a class. I suppose that settings.disptype = "pygame"
is a more sensible syntax than settings['disptype'] = "pygame"
, so I think I prefer your option.
from pygaze.
Yes, a dict
will work equally well. The benefit of using a class, and override the __setattr__()
and __getattr()__
methods is, in addition to providing a clean syntax, that you can implement some extra functionality. For example you could raise informative Exception
s if settings are missing or load settings from constants.py
on startup. But of course, all of these things are also possible using a dict
, so it's a matter of taste.
I would suggest to put the settings object (be it a custom class or a dict
) in a separate submodule though, because it's a conceptually distinct chunk of functionality. If you still want to be able to access it as pygaze.settings
(which makes sense), you can use a redirect import in pygaze/__init__.py
. For example like so:
# Redirect import
from pygaze.settings import settings
Btw, I removed all the other redirect imports from pygaze/__init__.py
, so at the moment you cannot do from pygaze import Screen
etc. anymore. This is not because I think this is a bad idea, but because these imports caused all modules to be loaded as soon as anything from pygaze
was imported, thus causing the settings-copying issue described above. As soon as there is a better settings mechanism they can go back.
from pygaze.
I noticed they went missing, and figured this was the reason. My preference
goes out to using a class, due to the clearer syntax, that has the added
bonus of resembling a Matlab struct (which means Matlab/PsychToolbox users
will potentially adopt to PyGaze easier).
I agree on keeping the init as clean as possible; this seems like a
thing for the misc module. This would still need to be one of the very
first things to import in init, though! I'll see if I can whip up
something this weekend; shouldn't be too difficult, but will require a lot
testing to make sure everything runs smoothly, and backwards compatibility
isn't compromised.
On Thu, Jan 9, 2014 at 9:32 AM, Sebastiaan Mathot
[email protected]:
Yes, a dict will work equally well. The benefit of using a class, and
override the setattr() and getattr() methods is, in addition to
providing a clean syntax, that you can implement some extra functionality.
For example you could raise informative Exceptions if settings are
missing or load settings from constants.py on startup. But of course, all
of these things are also possible using a dict, so it's a matter of taste.I would suggest to put the settings object (be it a custom class or a dict)
in a separate submodule though, because it's a conceptually distinct chunk
of functionality. If you still want to be able to access it as
pygaze.settings (which makes sense), you can use a redirect import in
pygaze/init.py. For example like so:Redirect importfrom pygaze.settings import settings
Btw, I removed all the other redirect imports from pygaze/init.py, so
at the moment you cannot do from pygaze import Screen etc. anymore. This
is not because I think this is a bad idea, but because these imports caused
all modules to be loaded as soon as anything from pygaze was imported,
thus causing the settings-copying issue described above. As soon as there
is a better settings mechanism they can go back.—
Reply to this email directly or view it on GitHubhttps://github.com//issues/13#issuecomment-31914897
.
from pygaze.
Related Issues (20)
- libsmi HOT 1
- Can PyGaze use in Tobii EyeTracker 4C(Consumer Eye Trackers)?
- Exception: The setting "TRACKERSERIALNUMBER" does not exist HOT 1
- Inescapable frozen grey screen on eyetracking examples HOT 1
- Eyelink fixations map to unexpected values with 2560x1440p display HOT 2
- Add PyGaze to Open Neuroscience
- Eyelink 1000+ feed not shown in Eyelink menu / opensesame pygaze init item HOT 3
- time.clock depreciated HOT 2
- How to produce eye data file HOT 5
- FileNotFoundError: Could not find module 'iViewXAPI.dll' (or one of its dependencies). Try using the full path with constructor syntax. HOT 1
- Does PyGaze support tobii eye tracker 5? HOT 1
- AttributeError: module 'pylink.__version__' has no attribute 'split' HOT 2
- Could not find module 'iViewXAPI.dll' (or one of its dependencies). Try using the full path with constructor syntax. HOT 1
- Log messages in OpenGaze / GazePoint HOT 5
- Working example for Mac using webcam HOT 2
- tobii eyetrackers
- PyGaze missing package lxml for GazePoint
- PyGaze error in OpenSesame using GazePoint
- Tobii eye tracker has lots of temporal noise and missing samples HOT 2
- Converting Eyelink / Pygaze coordinates to be "compatible" with OS coordinate system
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pygaze.