psychopy.org | Reference | Downloads | Github

Pyglet error when presenting text

Hi Everyone,

I am unable to display text using my code, and am getting a strange pyglet error. I saw that someone posted about this when working on a windows system, however, I am working from a Mac laptop. Below are the details of the issue as well as demo code that works (to display text). I would love to hear if anyone has suggestions for debugging this.

I am working from a MacBook Pro, macOS 11.6 (20G165).

I wrote this code in PychoPy v2021.2.3 Coder window.

Code:

# Importing libraries
from __future__ import absolute_import, division, print_function
from psychopy import visual, event, gui, data, core, logging
from psychopy.visual import ShapeStim
from psychopy.hardware import keyboard
from psychopy.tools.attributetools import attributeSetter, setAttribute
import glob
import random as rn
import numpy as np
import csv
from numpy import random

# Define global variables
root_path = '/Users/arkadiymaksimovskiy/' # root path, set as needed
win = visual.Window(color = 'grey', fullscr=True) #Create our window object
kb = keyboard.Keyboard() # Define a keyboard object
myDialogueBox = gui.Dlg(title = "Participant Info", pos = (0,0))
LArrow= visual.ImageStim(win, image = root_path + '/LArrow.png', pos = [-190,-280])
RArrow= visual.ImageStim(win, image = root_path + '/RArrow.png', pos = [190,-280])
Accuracy = int
KeyPress = ''

## Presenting stimuli

# Dialogue Box
def ShowDialogue():
    myDialogueBox.addField('Participant ID:')
    myDialogueBox.show()

## Instructions and Practice

# Text instructions Function
def input_txt(words):
    global KeyPress
    txt = visual.TextStim(win, text = words, height=25, pos=(0, -0.2))
    txt.draw()
    win.flip()
    KeyPress = event.waitKeys()
    return KeyPress

# All Instructions
def show_instr():
    inst_resp = 'r'
    while 'r' in inst_resp:
        KeyPress= input_txt('''We are often bombarded by a continuous stream of information. Some of it is relevant to our tasks, while a lot of it can be distracting. As we transition from one emotional event to another, it can be easy to lose track of how our feelings change throughout the day.''')
        KeyPress= input_txt('''In this task we will simulate situations in which emotional events rapidly change. To do that, we will show you a series of emotional pictures (positive, negative, and neutral) and ask you to keep track of your emotional responses to each picture. This is much like scrolling through a newsfeed, but with directed effort towards noticing your feelings.''')
        KeyPress= input_txt('''In order to simulate irrelevant distrators, we will show you a bunch of abstract images. These images don't have any meaning and are there to fill the space in-between the relevant pictures.''')
        KeyPress= input_txt('''In order to identify when you are viewing a meaningful picutre, press the RIGHT arrow. In order to identify when you are viewing a meaningless abstract picutre, press the Left arrow.''')
        KeyPress= input_txt('''Try to register how each picture makes you feel. To do that, you will need to first report whether an image is a picture, by pressing the RIGHT arrow. Then, try your best to focus on your emotional response to the picture for as long as it remains on the screen. Since abstract do not carry the same emotional charge, just press the LEFT arrow as soon as you see an abstract images, and simply wait for the next image to come up on the screen.''')
        KeyPress= input_txt('''In order to keep your attention focused on the center of the screen, you will see a white cross-hair between all images. Whenever you see this white cross-hair, simply keep looking at the center of the screen and wait for the next image to appear. You don't have to press anything during this time.''')
        inst_resp= input_txt('''If these instructions make sense, press the spacebar to see a few examples. Otherwise, press "r" if you would like to review the instructions again.''')

show_instr()

win.close()
core.quit()

Error:

## Running: /Users/arkadiymaksimovskiy/
##
3.2332     WARNING     Monitor specification not found. Creating a temporary one...
3.2404     WARNING     User requested fullscreen with size [800 600], but screen is actually [1680, 1050]. Using actual size
2021-09-16 15:19:08.919 python[22726:418913] ApplePersistenceIgnoreState: Existing state will not be touched. New state will be written to /var/folders/8k/ccw394fd7r756wkmlrt849sc0000gn/T/org.opensciencetools.psychopy.savedState
Traceback (most recent call last):
  File "/Users/arkadiymaksimovskiy/Oddball_EEG_Enc_New.py", line 63, in <module>
    show_instr()
  File "/Users/arkadiymaksimovskiy/Oddball_EEG_Enc_New.py", line 63, in <module>, line 55, in show_instr
    KeyPress= input_txt('''We are often bombarded by a continuous stream of information. Some of it is relevant to our tasks, while a lot of it can be distracting. As we transition from one emotional event to another, it can be easy to lose track of how our feelings change throughout the day.''')
  File "/Users/arkadiymaksimovskiy/Oddball_EEG_Enc_New.py", line 45, in input_txt
    txt = visual.TextStim(win, text = words, height=25, pos=(0, -0.2))
  File "/Applications/PsychoPy.app/Contents/Resources/lib/python3.6/psychopy/visual/text.py", line 226, in __init__
    self.setText(text, log=False)
  File "/Applications/PsychoPy.app/Contents/Resources/lib/python3.6/psychopy/visual/text.py", line 374, in setText
    setAttribute(self, 'text', text, log)
  File "/Applications/PsychoPy.app/Contents/Resources/lib/python3.6/psychopy/tools/attributetools.py", line 141, in setAttribute
    setattr(self, attrib, value)
  File "/Applications/PsychoPy.app/Contents/Resources/lib/python3.6/psychopy/tools/attributetools.py", line 32, in __set__
    newValue = self.func(obj, value)
  File "/Applications/PsychoPy.app/Contents/Resources/lib/python3.6/psychopy/visual/text.py", line 365, in text
    self._setTextShaders(text)
  File "/Applications/PsychoPy.app/Contents/Resources/lib/python3.6/psychopy/visual/text.py", line 391, in _setTextShaders
    multiline=True, width=self._wrapWidthPix)  # width of the frame
  File "/Applications/PsychoPy.app/Contents/Resources/lib/python3.6/pyglet/text/__init__.py", line 457, in __init__
    'align': align,
  File "/Applications/PsychoPy.app/Contents/Resources/lib/python3.6/pyglet/text/document.py", line 598, in set_style
    0, len(self.text), attributes)
  File "/Applications/PsychoPy.app/Contents/Resources/lib/python3.6/pyglet/text/document.py", line 506, in set_style
    self.dispatch_event('on_style_text', start, end, attributes)
  File "/Applications/PsychoPy.app/Contents/Resources/lib/python3.6/pyglet/event.py", line 408, in dispatch_event
    if handler(*args):
  File "/Applications/PsychoPy.app/Contents/Resources/lib/python3.6/pyglet/text/layout.py", line 1064, in on_style_text
    self._init_document()
  File "/Applications/PsychoPy.app/Contents/Resources/lib/python3.6/pyglet/text/layout.py", line 1034, in _init_document
    self._update()
  File "/Applications/PsychoPy.app/Contents/Resources/lib/python3.6/pyglet/text/layout.py", line 957, in _update
    lines = self._get_lines()
  File "/Applications/PsychoPy.app/Contents/Resources/lib/python3.6/pyglet/text/layout.py", line 933, in _get_lines
    glyphs = self._get_glyphs()
  File "/Applications/PsychoPy.app/Contents/Resources/lib/python3.6/pyglet/text/layout.py", line 1076, in _get_glyphs
    glyphs.extend(font.get_glyphs(text[start:end]))
  File "/Applications/PsychoPy.app/Contents/Resources/lib/python3.6/pyglet/font/base.py", line 386, in get_glyphs
    self.glyphs[c] = glyph_renderer.render(c)
  File "/Applications/PsychoPy.app/Contents/Resources/lib/python3.6/pyglet/font/quartz.py", line 133, in render
    glyph = self.font.create_glyph(glyph_image)
  File "/Applications/PsychoPy.app/Contents/Resources/lib/python3.6/pyglet/font/base.py", line 354, in create_glyph
    self.texture_mag_filter)
  File "/Applications/PsychoPy.app/Contents/Resources/lib/python3.6/pyglet/image/__init__.py", line 1549, in create_for_size
    blank)
  File "/Applications/PsychoPy.app/Contents/Resources/lib/python3.6/pyglet/gl/lib.py", line 107, in errcheck
    raise GLException(msg)
pyglet.gl.lib.GLException: b'invalid value'
##### Experiment ended. #####

For some reason, when I run the ‘hello_world.py’ demo provided with Psychopy, that works okay. Not sure why my text presentation keeps crashing and would be really grateful for any input.

Much appreciated,
Arkadiy

Why are you enclosing your input text in triple quotes?

@wakecarter Thank you for taking a look at this! I’m using triple quotes to encapsulate quotations into text, and not keep having to use escape keys.

However, I replicated the code without triple quotes (below) as well as simplified text, and am unfortunately still getting an error.

# Importing libraries
from __future__ import absolute_import, division, print_function
from psychopy import visual, event, gui, data, core, logging
from psychopy.visual import ShapeStim
from psychopy.hardware import keyboard
from psychopy.tools.attributetools import attributeSetter, setAttribute
import glob
import random as rn
import numpy as np
import csv
from numpy import random

# Define global variables
win = visual.Window(color = 'grey', fullscr=True) #Create our window object
kb = keyboard.Keyboard() # Define a keyboard object
KeyPress = ''


# Text instructions Function
def input_txt(words):
    global KeyPress
    txt = visual.TextStim(win, text = words, height=25, pos=(0, -0.2))
    txt.draw()
    win.flip()
    KeyPress = event.waitKeys()
    return KeyPress

# All Instructions
def show_instr():
    inst_resp = 'r'
    while 'r' in inst_resp:
        KeyPress= input_txt('txt')

show_instr()

win.close()
core.quit()

Error:

3.2562     WARNING     Monitor specification not found. Creating a temporary one...
3.2653     WARNING     User requested fullscreen with size [800 600], but screen is actually [1680, 1050]. Using actual size
2021-09-17 04:25:16.300 python[27674:540052] ApplePersistenceIgnoreState: Existing state will not be touched. New state will be written to /var/folders/8k/ccw394fd7r756wkmlrt849sc0000gn/T/org.opensciencetools.psychopy.savedState
Traceback (most recent call last):
  File "/Users/arkadiy/test.py", line 34, in <module>
    show_instr()
  File "/Users/arkadiy/test.py", line 32, in show_instr
    KeyPress= input_txt('txt')
  File "/Users/arkadiy/test.py", line 22, in input_txt
    txt = visual.TextStim(win, text = words, height=25, pos=(0, -0.2))
  File "/Applications/PsychoPy.app/Contents/Resources/lib/python3.6/psychopy/visual/text.py", line 226, in __init__
    self.setText(text, log=False)
  File "/Applications/PsychoPy.app/Contents/Resources/lib/python3.6/psychopy/visual/text.py", line 374, in setText
    setAttribute(self, 'text', text, log)
  File "/Applications/PsychoPy.app/Contents/Resources/lib/python3.6/psychopy/tools/attributetools.py", line 141, in setAttribute
    setattr(self, attrib, value)
  File "/Applications/PsychoPy.app/Contents/Resources/lib/python3.6/psychopy/tools/attributetools.py", line 32, in __set__
    newValue = self.func(obj, value)
  File "/Applications/PsychoPy.app/Contents/Resources/lib/python3.6/psychopy/visual/text.py", line 365, in text
    self._setTextShaders(text)
  File "/Applications/PsychoPy.app/Contents/Resources/lib/python3.6/psychopy/visual/text.py", line 391, in _setTextShaders
    multiline=True, width=self._wrapWidthPix)  # width of the frame
  File "/Applications/PsychoPy.app/Contents/Resources/lib/python3.6/pyglet/text/__init__.py", line 457, in __init__
    'align': align,
  File "/Applications/PsychoPy.app/Contents/Resources/lib/python3.6/pyglet/text/document.py", line 598, in set_style
    0, len(self.text), attributes)
  File "/Applications/PsychoPy.app/Contents/Resources/lib/python3.6/pyglet/text/document.py", line 506, in set_style
    self.dispatch_event('on_style_text', start, end, attributes)
  File "/Applications/PsychoPy.app/Contents/Resources/lib/python3.6/pyglet/event.py", line 408, in dispatch_event
    if handler(*args):
  File "/Applications/PsychoPy.app/Contents/Resources/lib/python3.6/pyglet/text/layout.py", line 1064, in on_style_text
    self._init_document()
  File "/Applications/PsychoPy.app/Contents/Resources/lib/python3.6/pyglet/text/layout.py", line 1034, in _init_document
    self._update()
  File "/Applications/PsychoPy.app/Contents/Resources/lib/python3.6/pyglet/text/layout.py", line 957, in _update
    lines = self._get_lines()
  File "/Applications/PsychoPy.app/Contents/Resources/lib/python3.6/pyglet/text/layout.py", line 933, in _get_lines
    glyphs = self._get_glyphs()
  File "/Applications/PsychoPy.app/Contents/Resources/lib/python3.6/pyglet/text/layout.py", line 1076, in _get_glyphs
    glyphs.extend(font.get_glyphs(text[start:end]))
  File "/Applications/PsychoPy.app/Contents/Resources/lib/python3.6/pyglet/font/base.py", line 386, in get_glyphs
    self.glyphs[c] = glyph_renderer.render(c)
  File "/Applications/PsychoPy.app/Contents/Resources/lib/python3.6/pyglet/font/quartz.py", line 133, in render
    glyph = self.font.create_glyph(glyph_image)
  File "/Applications/PsychoPy.app/Contents/Resources/lib/python3.6/pyglet/font/base.py", line 354, in create_glyph
    self.texture_mag_filter)
  File "/Applications/PsychoPy.app/Contents/Resources/lib/python3.6/pyglet/image/__init__.py", line 1549, in create_for_size
    blank)
  File "/Applications/PsychoPy.app/Contents/Resources/lib/python3.6/pyglet/gl/lib.py", line 107, in errcheck
    raise GLException(msg)
pyglet.gl.lib.GLException: b'invalid value'
##### Experiment ended. #####