11# -*- coding: utf-8 -*-
2-
32from smile .common import *
43from smile .scale import scale as s
54from .inst .computer import computer_list
109
1110import os
1211
12+ def get_is_first (run_num ):
13+ return run_num == 0
14+
15+ def get_practice_inst (config , run_num ):
16+ if len (config .CONT_KEY ) > 1 :
17+ cont_key_str = str (config .CONT_KEY [0 ]) + " or " + str (config .CONT_KEY [- 1 ])
18+ else :
19+ cont_key_str = str (config .CONT_KEY [0 ])
20+ practice_inst = "You will now have a short practice bag of balloons.\n " \
21+ "Please note how the money in the bank drops until you" \
22+ " make a decision.\n Press %s to continue." % (cont_key_str )
23+ if run_num > 0 :
24+ practice_inst += "\n You may press the button in the lower right " \
25+ f"corner to skip the practice."
1326
27+ return practice_inst
1428@Subroutine
1529def Instruct (self , config , run_num , sub_dir , task_dir = None ,
1630 full_instructions = True , practice = True , lang = "E" ,):
31+ is_first = Func (get_is_first , run_num ).result
1732
1833 if len (config .CONT_KEY ) > 1 :
1934 cont_key_str = str (config .CONT_KEY [0 ]) + " or " + str (config .CONT_KEY [- 1 ])
2035 else :
2136 cont_key_str = str (config .CONT_KEY [0 ])
2237
38+ practice_inst = Func (get_practice_inst , config , run_num ).result
39+
2340 if config .TOUCH :
2441 with Loop (computer_list ) as instruction :
2542 txt = instruction .current
@@ -51,106 +68,200 @@ def Instruct(self, config, run_num, sub_dir, task_dir=None,
5168 GetResponse (keys = config .CONT_KEY )
5269
5370 else :
54- with Parallel ():
55- MouseCursor (blocking = False )
56- with Serial (blocking = False ):
57- with If (full_instructions ):
58- with Loop (computer_list ) as instruction :
59- txt = instruction .current
60- with Parallel ():
61- with If ((instruction .i == 2 )):
62- with Parallel ():
63- img2 = Image (source = config .INST2_IMG_PATH ,
64- bottom = (self .exp .screen .height / 2. ) + s (50 ),
65- keep_ratio = True , allow_stretch = True ,
66- height = s (400 ))
67- lbl2 = Label (text = txt % (config .KEY_TEXT [0 ],
68- config .KEY_TEXT [- 1 ]),
69- halign = 'left' , top = img2 .bottom - s (10 ),
70- font_size = s (config .LABEL_FONT_SIZE ))
71- Label (text = 'Press %s to continue' % (config .CONT_KEY_STR ),
72- halign = 'left' ,
73- top = lbl2 .bottom ,
74- font_size = s (config .LABEL_FONT_SIZE ))
75- with Else ():
76- with Parallel ():
77- lbl1 = Label (text = txt ,
78- halign = 'left' ,
79- font_size = s (config .LABEL_FONT_SIZE ))
80- Label (text = 'Press %s to continue' % (config .CONT_KEY_STR ),
81- halign = 'left' ,
82- top = lbl1 .bottom - s (75 ),
83- font_size = s (config .LABEL_FONT_SIZE ))
71+ with If (is_first ):
72+ with Parallel ():
73+ MouseCursor (blocking = False )
74+ with Serial (blocking = True ):
75+ with If (full_instructions ):
76+ with Loop (computer_list ) as instruction :
77+ txt = instruction .current
78+ with Parallel ():
79+ with If ((instruction .i == 2 )):
80+ with Parallel ():
81+ img2 = Image (source = config .INST2_IMG_PATH ,
82+ bottom = (self .exp .screen .height / 2. ) + s (50 ),
83+ keep_ratio = True , allow_stretch = True ,
84+ height = s (400 ))
85+ lbl2 = Label (text = txt % (config .KEY_TEXT [0 ],
86+ config .KEY_TEXT [- 1 ]),
87+ halign = 'left' , top = img2 .bottom - s (10 ),
88+ font_size = s (config .LABEL_FONT_SIZE ))
89+ Label (text = 'Press %s to continue' % (config .CONT_KEY_STR ),
90+ halign = 'left' ,
91+ top = lbl2 .bottom ,
92+ font_size = s (config .LABEL_FONT_SIZE ))
93+ with Else ():
94+ with Parallel ():
95+ lbl1 = Label (text = txt ,
96+ halign = 'left' ,
97+ font_size = s (config .LABEL_FONT_SIZE ))
98+ Label (text = 'Press %s to continue' % (config .CONT_KEY_STR ),
99+ halign = 'left' ,
100+ top = lbl1 .bottom - s (75 ),
101+ font_size = s (config .LABEL_FONT_SIZE ))
102+ with UntilDone ():
103+ Wait (.5 )
104+ GetResponse (keys = config .CONT_KEY )
105+
106+ with If (practice ):
107+
108+ Label (text = practice_inst ,
109+ halign = 'center' ,
110+ font_size = s (config .LABEL_FONT_SIZE ))
84111 with UntilDone ():
85112 Wait (.5 )
86113 GetResponse (keys = config .CONT_KEY )
87114
88- with If (practice ):
115+ number_of_sets = 1
116+ self .set_number = 0
117+ self .grand_total = config .GRAND_TOTAL
118+ self .balloon_number_session = 0
119+ self .trkp_press_time = None
120+
121+ Wait (1. )
122+ # Loop over practice blocks
123+ with Loop (number_of_sets ):
124+ Wait (.5 , jitter = .5 )
125+
126+ # Calling listgen as 'bags'
127+ bg = Func (add_air ,
128+ total_number_of_balloons = len (config .PRACTICE_SETUP ) * 2 ,
129+ num_ranges = len (config .PRACTICE_SETUP ),
130+ balloon_setup = config .PRACTICE_SETUP ,
131+ randomize = config .RANDOMIZE_BALLOON_NUM ,
132+ reward_low = config .REWARD_LOW ,
133+ reward_high = config .REWARD_HIGH ,
134+ subject_directory = sub_dir ,
135+ practice = True ,
136+ shuffle_bags = config .SHUFFLE_BAGS )
137+ bags = bg .result
138+ self .block_tic = 0
139+
140+ # with Loop(bag.current) as balloon:
141+ with Loop (bags ) as balloon :
142+ Balloon = BARTSub (config ,
143+ log_name = 'bart_practice' ,
144+ balloon = balloon .current ,
145+ block = self .block_tic ,
146+ set_number = self .set_number ,
147+ grand_total = self .grand_total ,
148+ balloon_number_session = self .balloon_number_session ,
149+ subject = self ._exp .subject ,
150+ run_num = run_num ,
151+ trkp_press_time = self .trkp_press_time )
152+ self .balloon_number_session += 1
153+ self .grand_total = Balloon .grand_total
154+ self .block_tic += 1
155+
156+ self .set_number += 1
89157
90- Label (text = "You will now have a short practice bag of balloons.\n " +
91- "Please note how the money in the bank drops until you" +
92- " make a decision.\n Press %s to continue." % (cont_key_str ),
93- halign = 'center' ,
94- font_size = s (config .LABEL_FONT_SIZE ))
95- with UntilDone ():
96158 Wait (.5 )
97- GetResponse (keys = config .CONT_KEY )
98-
99- number_of_sets = 1
100- self .set_number = 0
101- self .grand_total = config .GRAND_TOTAL
102- self .balloon_number_session = 0
103- self .trkp_press_time = None
104-
105- Wait (1. )
106- # Loop over practice blocks
107- with Loop (number_of_sets ):
108- Wait (.5 , jitter = .5 )
109-
110- # Calling listgen as 'bags'
111- bg = Func (add_air ,
112- total_number_of_balloons = len (config .PRACTICE_SETUP ),
113- num_ranges = len (config .PRACTICE_SETUP ),
114- balloon_setup = config .PRACTICE_SETUP ,
115- randomize = config .RANDOMIZE_BALLOON_NUM ,
116- reward_low = config .REWARD_LOW ,
117- reward_high = config .REWARD_HIGH ,
118- subject_directory = sub_dir ,
119- practice = True ,
120- shuffle_bags = config .SHUFFLE_BAGS )
121- bags = bg .result
122-
123- self .block_tic = 0
124-
125- # with Loop(bag.current) as balloon:
126- with Loop (bags ) as balloon :
127- Balloon = BARTSub (config ,
128- log_name = 'bart_practice' ,
129- balloon = balloon .current ,
130- block = self .block_tic ,
131- set_number = self .set_number ,
132- grand_total = self .grand_total ,
133- balloon_number_session = self .balloon_number_session ,
134- subject = self ._exp .subject ,
135- run_num = run_num ,
136- trkp_press_time = self .trkp_press_time )
137- self .balloon_number_session += 1
138- self .grand_total = Balloon .grand_total
139- self .block_tic += 1
140-
141- self .set_number += 1
142-
143- Wait (.5 )
144- Label (text = 'You have completed the practice.\n ' +
145- 'Press %s to continue.' % (cont_key_str ),
146- halign = 'center' ,
147- font_size = s (config .LABEL_FONT_SIZE ))
148- with UntilDone ():
149- Wait (1.5 )
150- GetResponse (keys = config .CONT_KEY )
151- with Serial (blocking = False ):
152- with ButtonPress ():
153- Button (text = "Skip Practice" , width = s (config .SKIP_SIZE [0 ]),
154- bottom = 0 , right = self .exp .screen .width ,
155- height = s (config .SKIP_SIZE [1 ]),
156- font_size = s (config .SKIP_FONT_SIZE ))
159+ Label (text = 'You have completed the practice.\n ' +
160+ 'Press %s to continue.' % (cont_key_str ),
161+ halign = 'center' ,
162+ font_size = s (config .LABEL_FONT_SIZE ))
163+ with UntilDone ():
164+ Wait (0.5 )
165+ GetResponse (keys = config .CONT_KEY )
166+
167+ with Else ():
168+ with If (is_first ):
169+ with Parallel ():
170+ MouseCursor (blocking = False )
171+ with Serial (blocking = False ):
172+ with If (full_instructions ):
173+ with Loop (computer_list ) as instruction :
174+ txt = instruction .current
175+ with Parallel ():
176+ with If ((instruction .i == 2 )):
177+ with Parallel ():
178+ img2 = Image (source = config .INST2_IMG_PATH ,
179+ bottom = (self .exp .screen .height / 2. ) + s (50 ),
180+ keep_ratio = True , allow_stretch = True ,
181+ height = s (400 ))
182+ lbl2 = Label (text = txt % (config .KEY_TEXT [0 ],
183+ config .KEY_TEXT [- 1 ]),
184+ halign = 'left' , top = img2 .bottom - s (10 ),
185+ font_size = s (config .LABEL_FONT_SIZE ))
186+ Label (text = 'Press %s to continue' % (config .CONT_KEY_STR ),
187+ halign = 'left' ,
188+ top = lbl2 .bottom ,
189+ font_size = s (config .LABEL_FONT_SIZE ))
190+ with Else ():
191+ with Parallel ():
192+ lbl1 = Label (text = txt ,
193+ halign = 'left' ,
194+ font_size = s (config .LABEL_FONT_SIZE ))
195+ Label (text = 'Press %s to continue' % (config .CONT_KEY_STR ),
196+ halign = 'left' ,
197+ top = lbl1 .bottom - s (75 ),
198+ font_size = s (config .LABEL_FONT_SIZE ))
199+ with UntilDone ():
200+ Wait (.5 )
201+ GetResponse (keys = config .CONT_KEY )
202+
203+ with If (practice ):
204+ Label (text = practice_inst ,
205+ halign = 'center' ,
206+ font_size = s (config .LABEL_FONT_SIZE ))
207+ with UntilDone ():
208+ Wait (.5 )
209+ GetResponse (keys = config .CONT_KEY )
210+
211+ number_of_sets = 1
212+ self .set_number = 0
213+ self .grand_total = config .GRAND_TOTAL
214+ self .balloon_number_session = 0
215+ self .trkp_press_time = None
216+
217+ Wait (1. )
218+ # Loop over practice blocks
219+ with Loop (number_of_sets ):
220+ Wait (.5 , jitter = .5 )
221+
222+ # Calling listgen as 'bags'
223+ bg = Func (add_air ,
224+ total_number_of_balloons = len (config .PRACTICE_SETUP ) * 2 ,
225+ num_ranges = len (config .PRACTICE_SETUP ),
226+ balloon_setup = config .PRACTICE_SETUP ,
227+ randomize = config .RANDOMIZE_BALLOON_NUM ,
228+ reward_low = config .REWARD_LOW ,
229+ reward_high = config .REWARD_HIGH ,
230+ subject_directory = sub_dir ,
231+ practice = True ,
232+ shuffle_bags = config .SHUFFLE_BAGS )
233+ bags = bg .result
234+ self .block_tic = 0
235+
236+ # with Loop(bag.current) as balloon:
237+ with Loop (bags ) as balloon :
238+ Balloon = BARTSub (config ,
239+ log_name = 'bart_practice' ,
240+ balloon = balloon .current ,
241+ block = self .block_tic ,
242+ set_number = self .set_number ,
243+ grand_total = self .grand_total ,
244+ balloon_number_session = self .balloon_number_session ,
245+ subject = self ._exp .subject ,
246+ run_num = run_num ,
247+ trkp_press_time = self .trkp_press_time )
248+ self .balloon_number_session += 1
249+ self .grand_total = Balloon .grand_total
250+ self .block_tic += 1
251+
252+ self .set_number += 1
253+
254+ Wait (.5 )
255+ Label (text = 'You have completed the practice.\n ' +
256+ 'Press %s to continue.' % (cont_key_str ),
257+ halign = 'center' ,
258+ font_size = s (config .LABEL_FONT_SIZE ))
259+ with UntilDone ():
260+ Wait (0.5 )
261+ GetResponse (keys = config .CONT_KEY )
262+ with Serial (blocking = False ):
263+ with ButtonPress ():
264+ Button (text = "Skip Practice" , width = s (config .SKIP_SIZE [0 ]),
265+ bottom = 0 , right = self .exp .screen .width ,
266+ height = s (config .SKIP_SIZE [1 ]),
267+ font_size = s (config .SKIP_FONT_SIZE ))
0 commit comments