Skip to content

Commit 8287674

Browse files
committed
BF: FormComponent crashes if non-ascii chracters are used as items on Python2
1 parent 417c9f4 commit 8287674

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

psychopy/visual/form.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
ColorMixin)
1616
from random import shuffle
1717

18+
from psychopy.constants import PY3
19+
1820
__author__ = 'Jon Peirce, David Bridges, Anthony Haffey'
1921

2022

@@ -171,8 +173,12 @@ def _checkHeaders(fields):
171173
_checkHeaders(item.keys())
172174
# Convert options to list of strings
173175
for idx, item in enumerate(items):
174-
if isinstance(item['options'], str):
175-
items[idx]['options'] = item['options'].split(',')
176+
if PY3:
177+
if isinstance(item['options'], str):
178+
items[idx]['options'] = item['options'].split(',')
179+
else: # Python2
180+
if isinstance(item['options'], unicode):
181+
items[idx]['options'] = item['options'].split(',')
176182
# Check types
177183
[_checkTypes(item['type']) for item in items]
178184
# Check N options > 1
@@ -266,7 +272,7 @@ def _setQuestion(self, item):
266272
The width of the question bounding box as type float
267273
"""
268274
if self.autoLog:
269-
psychopy.logging.exp("Question text: {}".format(item['questionText']))
275+
psychopy.logging.exp(u"Question text: {}".format(item['questionText']))
270276

271277
question = psychopy.visual.TextStim(self.win,
272278
text=item['questionText'],
@@ -310,7 +316,7 @@ def _setResponse(self, item, question):
310316
if self.autoLog:
311317
psychopy.logging.exp("Response type: {}".format(item['type']))
312318
psychopy.logging.exp("Response layout: {}".format(item['layout']))
313-
psychopy.logging.exp("Response options: {}".format(item['options']))
319+
psychopy.logging.exp(u"Response options: {}".format(item['options']))
314320

315321
# Create position of response object
316322
pos = self._getResponsePos(item, question)

0 commit comments

Comments
 (0)