OS (e.g. Win10): Win10
PsychoPy version (e.g. 1.84.x): v3.2.4
Standard Standalone? (y/n) If not then what?: n
What are you trying to achieve?: I had a class which inherited the TextStim class, but because TextStim is too slow for my purposes, I need to change my code to use TextBox. However, when I try to inherit Textbox in my Text class, and edit the parameters to match those of the TextBox syntax, I get these errors:
File “C:\Python36-32\lib\site-packages\BCPy2000\PsychoPyRenderer.py”, line 372, in
class Text(TextBox):
File “C:\Python36-32\lib\site-packages\psychopy\contrib\lazy_import.py”, line 195, in init
factory=cls._import)
File “C:\Python36-32\lib\site-packages\psychopy\contrib\lazy_import.py”, line 78, in init
scope[name] = self
TypeError: ‘str’ object does not support item assignment
I am currently working on wrapping the TextBox implementation, however I would like to keep the code the same so that I dont have to change much elsewhere. Here is my Text class:
class Text(TextBox):
def __init__(self, window=None, text='Hello world', font_name=None, font_size=32, position=(10,10), font_color=(0, 0, 0, 1), anchor='lower left', on=True, smooth=True):
if BciGenericRenderer.subclass().screen is None:
raise Exception('Stimuli can only be created after the screen is initialized!')
col, op = _colorFromBCItoPsyPy(color)
TextBox.__init__(self,BciGenericRenderer.subclass().screen,text,font_color=col,opacity=op)
if font_name is not None:
self.font_name=font_name
if 'center' in anchor:
self.align_vert='center'
if 'top' in anchor:
self.align_vert='top'
if 'bottom' in anchor:
self.align_vert='bottom'
if 'center' in anchor:
self.align_horz='center'
if 'left' in anchor:
self.align_horz='left'
if 'right' in anchor:
self.align_horz='right'
if position is not None: self.pos=Map2PsypyCoords(BciGenericRenderer.subclass().screen,position)
def _font_name_fget(self): return self.font
def _font_name_fset(self, val):
self.font=val
font_name = property(_font_name_fget, _font_name_fset, doc='font name')
def _font_size_fget(self): pass
def _font_size_fset(self, val):
pass
font_size = property(_font_size_fget, _font_size_fset, doc='font size')
# def _fget_angle(self): return self.angle
# def _fset_angle(self, val):
# try: val = float(val)
# except: raise TypeError('angle should be a floating-point scalar')
# self.ori = val % 360.0
# angle = property(_fget_angle, _fset_angle, doc='rotation angle in degrees')
def _fget_on(self): return self._on
def _fset_on(self, val):
try: val = bool(val)
except: raise TypeError('on should be a boolean')
self_on=on
on= property(_fget_on, _fset_on, doc='whether or not the stimulus is displayed')