-
Notifications
You must be signed in to change notification settings - Fork 890
/
launchHub.py
162 lines (128 loc) · 6.23 KB
/
launchHub.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Testing the iohub.launchHubServer function
illustrating the different ways it can be used.
No PsychoPy Window is created for this demo; results are
printed to stdout.
Initial Version: May 6th, 2013, Sol Simpson
"""
from __future__ import absolute_import, division, print_function
from psychopy.iohub import launchHubServer
def testWithNoKwargs():
"""
testWithNoKwargs illustrates using the launchHubServer function with no
parameters at all. Considerations:
* A Keyboard, Mouse, Monitor, and Experiment device are created by default.
* All devices use their default parameter settings. Therefore,
not very useful in real studies.
* ioHub DataStore is not enabled.
"""
io = launchHubServer()
# Get the default keyboard device created.
keyboard = io.devices.keyboard
print()
print(" ** PRESS A KEY TO CONTINUE.....")
# Check for new events every 1/4 second.
# By using the io.wait() function, the ioHub Process is checked for
# events every 50 msec or so, and they are cached in the PsychoPy process
# until the next getEvents() call is made. On Windows, messagePump() is also
# called periodically so that any Window you have created does not lock up.
#
while not keyboard.getEvents():
io.wait(0.25)
print("A Keyboard Event was Detected; exiting Test.")
io.quit()
def testUsingPsychoPyMonitorConfig():
"""
testUsingPsychoPyMonitorConfig illustrates using the launchHubServer function
and providing a PsychoPy monitor configuration file name.
Considerations:
* A Keyboard, Mouse, Monitor, and Experiment device are created by default.
* If the psychopy_monitor_name is valid, the ioHub Display is updated to
use the display size and viewing distance specified in the psychopy monitor config.
* ioHub DataStore is not enabled.
"""
io = launchHubServer(psychopy_monitor_name='testMonitor')
# Get the default display device created.
display = io.devices.display
# print(the display's physical characteristics, showing they have
# been updated based on the settings in the PsychoPy monitor config.
print('Display Psychopy Monitor Name: ', display.getPsychopyMonitorName())
print('Display Default Eye Distance: ', display.getDefaultEyeDistance())
print('Display Physical Dimensions: ', display.getPhysicalDimensions())
# That's it, shut down the ioHub Process and exit. ;)
io.quit()
def testEnabledDataStore():
"""
testEnabledDataStore is the same as testUsingPsychoPyMonitorConfig above,
but by adding an experiment_code parameter the ioHub DataStore will
be enabled, using a auto generated session_code each time it is run.
Experiment and session metadata is printed at the end of the demo.
Considerations:
* A Keyboard, Mouse, Monitor, and Experiment device are created by default.
* If the psychopy_monitor_name is valid, the ioHub Display is updated to
use the display size and viewing distance specified in the psychopy monitor config.
* ioHub DataStore is enabled because experiment_code is provided.
session_code will be auto generated using the current time.
"""
psychopy_mon_name = 'testMonitor'
exp_code = 'gap_endo_que'
io = launchHubServer(psychopy_monitor_name=psychopy_mon_name,
experiment_code=exp_code)
display = io.devices.display
print('Display Psychopy Monitor Name: ', display.getPsychopyMonitorName())
print('Display Default Eye Distance: ', display.getDefaultEyeDistance())
print('Display Physical Dimensions: ', display.getPhysicalDimensions())
from pprint import pprint
print('Experiment Metadata: ')
pprint(io.getExperimentMetaData())
print('\nSession Metadata: ')
pprint(io.getSessionMetaData())
io.quit()
def testEnabledDataStoreAutoSessionCode():
"""
testEnabledDataStoreAutoSessionCode is the same as testEnabledDataStore
above, but session_code is provided by the script instead of being
auto-generated. The ioHub DataStore will be enabled, using the
experiment and session_code provided each time it is run. Experiment
and session metadata is printed at the end of the demo.
Considerations:
* A Keyboard, Mouse, Monitor, and Experiment device are created by
default.
* If the psychopy_monitor_name is valid, the ioHub Display is
updated to use the display size and viewing distance specified
in the psychopy monitor config.
* ioHub DataStore is enabled because experiment_code and
session_code are provided.
"""
import time
from pprint import pprint
psychopy_mon_name = 'testMonitor'
exp_code = 'gap_endo_que'
sess_code = 'S_{0}'.format(int(time.mktime(time.localtime())))
print('Current Session Code will be: ', sess_code)
io = launchHubServer(psychopy_monitor_name=psychopy_mon_name,
experiment_code=exp_code,
session_code=sess_code)
display = io.devices.display
print('Display Psychopy Monitor Name: ', display.getPsychopyMonitorName())
print('Display Default Eye Distance: ', display.getDefaultEyeDistance())
print('Display Physical Dimensions: ', display.getPhysicalDimensions())
print('Experiment Metadata: ')
pprint(io.getExperimentMetaData())
print('\nSession Metadata: ')
pprint(io.getSessionMetaData())
io.quit()
test_list = ['testWithNoKwargs', 'testUsingPsychoPyMonitorConfig',
'testEnabledDataStore', 'testEnabledDataStoreAutoSessionCode']
if __name__ == '__main__':
for test in test_list:
print('\n------------------------------------\n')
print('Running %s Test:'%(test))
for namespace in (locals(), globals()):
if test in namespace:
result = namespace[test]()
print('Test Result: ', result)
break
# The contents of this file are in the public domain.