Skip to content

Commit 9779579

Browse files
authored
Merge pull request #2460 from dvbridges/movieLoopFix
BF: Create JS videostim objects on each routine for looping variables
2 parents 12295f7 + 52d47ff commit 9779579

File tree

1 file changed

+33
-11
lines changed

1 file changed

+33
-11
lines changed

psychopy/experiment/components/movie/__init__.py

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -143,14 +143,14 @@ def _writeCreationCode(self, buff, useInits):
143143
" )\n")
144144
buff.writeIndentedLines(code % depth)
145145

146-
def writeInitCode(self, buff):
147-
# If needed then use _writeCreationCode()
148-
# Movie could be created here or in writeRoutineStart()
149-
if self.params['movie'].updates == 'constant':
150-
# create the code using init vals
151-
self._writeCreationCode(buff, useInits=True)
146+
def _writeCreationCodeJS(self, buff, useInits):
152147

153-
def writeInitCodeJS(self, buff):
148+
# If we're in writeInitCode then we need to convert params to initVals
149+
# because some (variable) params haven't been created yet.
150+
if useInits:
151+
inits = getInitVals(self.params)
152+
else:
153+
inits = self.params
154154

155155
if self.params['units'].val == 'from exp settings':
156156
unitsStr = "'height'"
@@ -160,13 +160,14 @@ def writeInitCodeJS(self, buff):
160160
else:
161161
unitsStr = "%(units)s" % self.params
162162

163-
inits = getInitVals(self.params)
163+
164164
noAudio = '{}'.format(inits['No audio'].val).lower()
165165
loop = '{}'.format(inits['loop'].val).lower()
166166

167-
for param in inits:
168-
if inits[param] in ['', None, 'None', 'none']:
169-
inits[param] = 'undefined'
167+
if useInits:
168+
for param in inits:
169+
if inits[param] in ['', None, 'None', 'none']:
170+
inits[param] = 'undefined'
170171

171172
code = "{name}Clock = new util.Clock();\n".format(**inits)
172173
buff.writeIndented(code)
@@ -193,13 +194,34 @@ def writeInitCodeJS(self, buff):
193194
noAudio=noAudio)
194195
buff.writeIndentedLines(code)
195196

197+
def writeInitCode(self, buff):
198+
# If needed then use _writeCreationCode()
199+
# Movie could be created here or in writeRoutineStart()
200+
if self.params['movie'].updates == 'constant':
201+
# create the code using init vals
202+
self._writeCreationCode(buff, useInits=True)
203+
204+
def writeInitCodeJS(self, buff):
205+
# If needed then use _writeCreationCodeJS()
206+
# Movie could be created here or in writeRoutineStart()
207+
if self.params['movie'].updates == 'constant':
208+
# create the code using init vals
209+
self._writeCreationCodeJS(buff, useInits=True)
210+
196211
def writeRoutineStartCode(self, buff):
197212
# If needed then use _writeCreationCode()
198213
# Movie could be created here or in writeInitCode()
199214
if self.params['movie'].updates != 'constant':
200215
# create the code using params, not vals
201216
self._writeCreationCode(buff, useInits=False)
202217

218+
def writeRoutineStartCodeJS(self, buff):
219+
# If needed then use _writeCreationCode()
220+
# Movie could be created here or in writeInitCode()
221+
if self.params['movie'].updates != 'constant':
222+
# create the code using params, not vals
223+
self._writeCreationCodeJS(buff, useInits=False)
224+
203225
def writeFrameCode(self, buff):
204226
"""Write the code that will be called every frame
205227
"""

0 commit comments

Comments
 (0)