open-cogsci / OpenSesame

Graphical experiment builder for the social sciences
http://osdoc.cogsci.nl/
GNU General Public License v3.0
236 stars 112 forks source link

Program Crash when entering non-ascii characters in text input form with psychoPy backend #680

Open LeonardoJost opened 4 years ago

LeonardoJost commented 4 years ago

Hi, I have raised this issue on the forum and it seems to be a bug: https://forum.cogsci.nl/index.php?p=/discussion/5607/problem-with-entering-non-ascii-characters-in-text-input-form-with-psychopy-backend#latest I have also found this bug in closed issues for 3.2.7 https://github.com/smathot/OpenSesame/issues/651 but recreated it in 3.2.8.

When creating custom text input forms using OpenSesame with psychoPy backend and entering any special character (e.g. äöüß), the program ends with

TypeError: unsupported operand type(s) for &: 'float' and 'int'

The program ends as soon as the character is entered and I cannot avoid this by defining key_filters. This is with psychoPy backend, with xpyriment no errors occur. A working simple program recreating this problem on my computer (using a german keyboard) is below.

---
API: 2.1
OpenSesame: 3.2.8
Platform: nt
---
set width 1024
set uniform_coordinates yes
set title "New experiment"
set subject_parity even
set subject_nr 0
set start experiment
set sound_sample_size -16
set sound_freq 48000
set sound_channels 2
set sound_buf_size 1024
set sampler_backend legacy
set round_decimals 2
set mouse_backend psycho
set keyboard_backend psycho
set height 768
set fullscreen no
set form_clicks no
set foreground white
set font_underline no
set font_size 18
set font_italic no
set font_family mono
set font_bold no
set experiment_path "c:\\Program Files (x86)\\OpenSesame\\share\\opensesame_resources\\templates"
set disable_garbage_collection yes
set description "The main experiment item"
set coordinates uniform
set compensation 0
set color_backend psycho
set clock_backend psycho
set canvas_backend psycho
set background black

define sequence experiment
   set flush_keyboard yes
   set description "Runs a number of items in sequence"
   run new_inline_script always

define inline_script new_inline_script
   set description "Executes Python code"
   ___run__
   #parameters
   thisQuestion=u'Please enter your answer'
   # Create a form
   form = Form(
      cols=[1], rows=[2,1],
      margins=(50,100,50,100), spacing=25
   )

   #add widgets
   form.set_widget(Label(text=thisQuestion, center=False), (0,0))
   textInput=TextInput(return_accepts=True, stub=u'Answer')
   form.set_widget(textInput, (0,1))   
   form._exec(textInput)
   __end__
   set _prepare ""
smathot commented 4 years ago

Thanks for reporting this. In the debug window there should be a more elaborate error message, i.e. a traceback. Could you post that here?

LeonardoJost commented 4 years ago

Sure, I have run the program and entered 'abcdä' into the text field and it crashed upon entering 'ä'. Here is the traceback:

File "C:\Program Files (x86)\OpenSesame\lib\site-packages\libopensesame\inline_script.py", line 116, in run
    self.workspace._exec(self.crun)
  File "C:\Program Files (x86)\OpenSesame\lib\site-packages\libopensesame\base_python_workspace.py", line 124, in _exec
    exec(bytecode, self._globals)
  Inline script, line 13, in <module>
  File "C:\Program Files (x86)\OpenSesame\lib\site-packages\libopensesame\widgets\_form.py", line 233, in _exec
    key, timestamp = kb.get_key()
  File "C:\Program Files (x86)\OpenSesame\lib\site-packages\openexp\backend.py", line 180, in inner
    retval = fnc(self, *arglist, **kwdict)
  File "C:\Program Files (x86)\OpenSesame\lib\site-packages\openexp\_keyboard\psycho.py", line 93, in get_key
    keys = event.getKeys(keylist, modifiers=True)
  File "C:\Program Files (x86)\OpenSesame\lib\site-packages\psychopy\event.py", line 329, in getKeys
    keyNames = [(k[0], modifiers_dict(k[1])) for k in targets]
  File "C:\Program Files (x86)\OpenSesame\lib\site-packages\psychopy\event.py", line 253, in modifiers_dict
    'MOD_SCROLLLOCK'
  File "C:\Program Files (x86)\OpenSesame\lib\site-packages\psychopy\event.py", line 244, in <dictcomp>
    return {(mod[4:].lower()): modifiers & getattr(sys.modules[__name__], mod) > 0 for mod in [
TypeError: unsupported operand type(s) for &: 'float' and 'int'