Repository navigation
Expand file tree
/
Copy pathmw_instructions.py
More file actions
286 lines (253 loc) · 12 KB
/
Copy pathmw_instructions.py
File metadata and controls
286 lines (253 loc) · 12 KB
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
from psychopy import visual, core, event
from config_helpers import get_text_with_newlines
import experiment_utils as utils
from quiz_logic import run_comprehension_quiz
def show_mw_instructions_and_quiz(win, quit_experiment, RUN_COMPREHENSION_QUIZ, text_filename, riponda_port=None, fg_color='black', bg_color='white'):
"""
Displays all Mind Wandering instruction pages and runs the
comprehension quiz if it is enabled.
"""
mw_riponda_map = {
48: '1', # Button 1 Press
112: '2', # Button 2 Press
176: '3', # Button 3 Press
240: '4' # Button 4 Press
}
# --- Button Definition Helpers ---
# Q1 Buttons (1-4 scale)
q1_button_details = [
{'key': '1', 'label': get_text_with_newlines('MW_Probe_Content', 'q1_label_1', default="Not at all"), 'x': -300},
{'key': '2', 'label': get_text_with_newlines('MW_Probe_Content', 'q1_label_2', default=""), 'x': -100},
{'key': '3', 'label': get_text_with_newlines('MW_Probe_Content', 'q1_label_3', default=""), 'x': 100},
{'key': '4', 'label': get_text_with_newlines('MW_Probe_Content', 'q1_label_4', default="Completely"), 'x': 300}
]
# Q2 (Off-Task Content) Buttons
q2_mw_details = [
{'key': '1', 'label': get_text_with_newlines('MW_Probe_Content', 'q2_mw_label_1', default="I was thinking about nothing"), 'x': -300},
{'key': '2', 'label': get_text_with_newlines('MW_Probe_Content', 'q2_mw_label_2', default=""), 'x': -100},
{'key': '3', 'label': get_text_with_newlines('MW_Probe_Content', 'q2_mw_label_3', default=""), 'x': 100},
{'key': '4', 'label': get_text_with_newlines('MW_Probe_Content', 'q2_mw_label_4', default="I was thinking about something in particular"), 'x': 300}
]
# Q3 (Spontaneous/Deliberate) Buttons
q3_mw_details = [
{'key': '1', 'label': get_text_with_newlines('MW_Probe_Content', 'q3_mw_label_1', default="I was completely spontaneous"), 'x': -300},
{'key': '2', 'label': get_text_with_newlines('MW_Probe_Content', 'q3_mw_label_2', default=""), 'x': -100},
{'key': '3', 'label': get_text_with_newlines('MW_Probe_Content', 'q3_mw_label_3', default=""), 'x': 100},
{'key': '4', 'label': get_text_with_newlines('MW_Probe_Content', 'q3_mw_label_4', default="I was completely deliberate"), 'x': 300}
]
# Q4 (Affective Tone) Buttons
q4_mw_details = [
{'key': '1', 'label': get_text_with_newlines('MW_Probe_Content', 'q4_mw_label_1', default="Completely Negative"), 'x': -300},
{'key': '2', 'label': get_text_with_newlines('MW_Probe_Content', 'q4_mw_label_2', default=""), 'x': -100},
{'key': '3', 'label': get_text_with_newlines('MW_Probe_Content', 'q4_mw_label_3', default=""), 'x': 100},
{'key': '4', 'label': get_text_with_newlines('MW_Probe_Content', 'q4_mw_label_4', default="Completely Positive"), 'x': 300}
]
# --- INSTRUCTION PAGES DATA ---
mw_instruction_pages = [
# Intro
{'text': get_text_with_newlines('MW_Probes', 'mw_intro'), 'buttons': None},
# Q1 Explanation
{'text': get_text_with_newlines('MW_Probes', 'mw_q1'), 'buttons': q1_button_details},
# Q2 Off-Task Explanation
{'text': get_text_with_newlines('MW_Probes', 'mw_q2_off_task'), 'buttons': q2_mw_details},
# Q3 Spontaneous Explanation
{'text': get_text_with_newlines('MW_Probes', 'mw_q3_spontaneous'), 'buttons': q3_mw_details},
# Q4 Affective Explanation
{'text': get_text_with_newlines('MW_Probes', 'mw_q4_affective'), 'buttons': q4_mw_details},
# On-Task Intro
{'text': get_text_with_newlines('MW_Probes', 'mw_on_task_intro'), 'buttons': None},
# On-Task Follow-up Questions Explanation
{'text': get_text_with_newlines('MW_Probes', 'mw_on_task_follow_up'), 'buttons': None},
# Final Note
{'text': get_text_with_newlines('MW_Probes', 'mw_final_note'), 'buttons': None},
]
def draw_instruction_buttons(details):
if not details: return
for detail in details:
rect = visual.Rect(
win=win, width=150, height=100, pos=(detail['x'], -250),
fillColor='lightgrey', lineColor=fg_color, lineWidth=3
)
rect.draw()
number_stim = visual.TextStim(
win, text=detail['key'], color='black', height=50, pos=(detail['x'], -250),
font='Arial'
)
number_stim.draw()
label_stim = visual.TextStim(
win, text=detail['label'], color=fg_color, height=20, pos=(detail['x'], -350), wrapWidth=220,
font='Arial'
)
label_stim.draw()
# --- DISPLAY LOOP ---
for page in mw_instruction_pages:
text_stim = visual.TextStim(
win,
text=page['text'],
color=fg_color,
height=28,
pos=(0, 50),
wrapWidth=1600,
font='Arial'
)
prompt_text = get_text_with_newlines('Screens', 'prompt_continue', default="(Press any key to continue.)")
continue_stim = visual.TextStim(
win,
text=prompt_text,
color=fg_color,
height=20,
pos=(0, -450),
wrapWidth=1700,
font='Arial'
)
text_stim.draw()
continue_stim.draw()
if page['buttons']:
draw_instruction_buttons(page['buttons'])
win.flip()
event.clearEvents()
if riponda_port:
riponda_port.reset_input_buffer()
pressed_key = None
while pressed_key is None:
# 1. Check Keyboard
kb_responses = event.getKeys()
if kb_responses:
pressed_key = kb_responses[0]
break
# 2. Check Riponda
if riponda_port and riponda_port.in_waiting >= 6:
try:
packet = riponda_port.read(6)
if packet[0] == 0x6b: # Any key
pressed_key = 'riponda_press'
riponda_port.reset_input_buffer()
break
else:
riponda_port.reset_input_buffer()
except Exception as e:
print(f"Riponda read error: {e}")
riponda_port.reset_input_buffer()
core.wait(0.001)
if pressed_key == 'escape':
quit_experiment()
core.wait(0.5)
# --- COMPREHENSION QUIZ ---
if RUN_COMPREHENSION_QUIZ:
quiz_passed = False
attempts = 0
MAX_ATTEMPTS = 3
while not quiz_passed and attempts < MAX_ATTEMPTS:
attempts += 1
passed = run_comprehension_quiz(win, quit_experiment, text_filename, attempt_number=attempts, riponda_port=riponda_port, fg_color=fg_color, bg_color=bg_color)
if passed:
quiz_passed = True
#success_text = get_text_with_newlines('Quiz', 'quiz_passed_congrats')
#success_msg = visual.TextStim(
#win, text=success_text, color=fg_color, height=30, wrapWidth=1600, font='Arial'
#)
#success_msg.draw()
#win.flip()
#core.wait(2.0)
event.clearEvents()
if riponda_port:
riponda_port.reset_input_buffer()
pressed_key = None
while pressed_key is None:
# 1. Check Keyboard
kb_responses = event.getKeys()
if kb_responses:
pressed_key = kb_responses[0]
break
# 2. Check Riponda
if riponda_port and riponda_port.in_waiting >= 6:
try:
packet = riponda_port.read(6)
if packet[0] == 0x6b:
pressed_key = 'riponda_press'
riponda_port.reset_input_buffer()
break
else:
riponda_port.reset_input_buffer()
except Exception as e:
print(f"Riponda read error: {e}")
riponda_port.reset_input_buffer()
core.wait(0.001)
core.wait(0.5)
else:
if attempts < MAX_ATTEMPTS:
retry_text = get_text_with_newlines('Quiz', 'quiz_failed_retry')
retry_msg = visual.TextStim(
win, text=retry_text, color='white', height=30, wrapWidth=1600, font='Arial'
)
retry_msg.draw()
win.flip()
event.clearEvents()
if riponda_port:
riponda_port.reset_input_buffer()
pressed_key = None
while pressed_key is None:
# 1. Check Keyboard
kb_responses = event.getKeys()
if kb_responses:
pressed_key = kb_responses[0]
break
# 2. Check Riponda
if riponda_port and riponda_port.in_waiting >= 6:
try:
packet = riponda_port.read(6)
if packet[0] == 0x6b:
pressed_key = 'riponda_press'
riponda_port.reset_input_buffer()
break
else:
riponda_port.reset_input_buffer()
except Exception as e:
print(f"Riponda read error: {e}")
riponda_port.reset_input_buffer()
core.wait(0.001)
core.wait(0.5)
if not quiz_passed:
fail_text = get_text_with_newlines(
'Screens',
'quiz_failure_continue',
default="Unfortunately, you did not pass the comprehension quiz after 3 attempts.\nThe experiment will now continue.\n\n(Press any key to continue.)"
)
fail_message = visual.TextStim(
win,
text=fail_text,
color='red',
height=30,
wrapWidth=1600,
font='Arial'
)
fail_message.draw()
win.flip()
core.wait(0.5)
event.clearEvents()
if riponda_port:
riponda_port.reset_input_buffer()
pressed_key = None
while pressed_key is None:
# 1. Check Keyboard
kb_responses = event.getKeys()
if kb_responses:
pressed_key = kb_responses[0]
break
# 2. Check Riponda
if riponda_port and riponda_port.in_waiting >= 6:
try:
packet = riponda_port.read(6)
if packet[0] == 0x6b:
pressed_key = 'riponda_press'
riponda_port.reset_input_buffer()
break
else:
riponda_port.reset_input_buffer()
except Exception as e:
print(f"Riponda read error: {e}")
riponda_port.reset_input_buffer()
core.wait(0.001)
if pressed_key == 'escape':
quit_experiment()
core.wait(0.5)