setBorderColor not working correctly

Hi everyone,

Thanks in advance to whom will contribute to this discussion :smiley:

OS: MacOS Ventura 13.1

What is the problem?
The border line (property .setBorderColor) of the imageStim object doesn’t show.

The task
I want to highlight the selected image in the screen by changing the color of the image border.

What did I try?
This is my function. After a left or right key is pressed, the corresponding image should be highlighted by a green border line.

def present_symbols(symbols, text):
    global event_log, last_event

    event_symbols = {
        'trial_type': 'symbols & instruction',
        'onset': globalClock.getTime(),
        'filename': [symbol1_image, symbol2_image, instruction_text],
        'corrAns': corr_ans,
        'symbolPos': [symbol1_position, symbol2_position],
        'block nr': block_num, 
        'trial nr': trial_num
    }
    record_event(event_symbols)

    kb.clock.reset()  # start the timer 
    print('And I print again the block nr:', block_num)

    while True:
        keys_sym = [] # empty list from previous events

        # Draw stimuli
        for stimulus in [image_symbol1, image_symbol2, instruction]: 
            stimulus.draw()
        win.flip()

        # Check keypresses
        keys_sym = kb.getKeys(waitRelease=True)
        if keys_sym:
            print(keys_sym)
            for key in keys_sym:
                key_symbols = {'block nr': block_num, 'trial nr': trial_num, 'trial_type': 'key_press_sym', 'onset': globalClock.getTime(), 'duration': key.duration, 'response': key.name}
                record_event(key_symbols)
            
            if 'escape' in keys_sym:
                core.quit()

            if 'left' in keys_sym:
                if symbol1_position == (-0.35, 0):
                    image_symbol1.setBorderColor('green')
                    image_symbol1.lineWidth = 4
                    print('Entering the loop but not showing')
                else:
                    image_symbol2.setBorderColor('green')
                    image_symbol2.lineWidth = 4
                    print('Entering the loop but not showing')

                for stimulus in [image_symbol1, image_symbol2, instruction]: 
                    stimulus.draw()
                win.flip()
                core.wait(0.5)  # give time to ppn to see chosen image
                break

            if 'right' in keys_sym:
                if symbol1_position == (0.35, 0):
                    image_symbol1.setBorderColor('green')
                    image_symbol1.lineWidth = 4
                    print('Entering the loop but not showing')
                    for stimulus in [image_symbol1, image_symbol2, instruction]: 
                        stimulus.draw()
                    win.flip()
                    core.wait(0.5)  # give time to ppn to see chosen image
                    break

                else:
                    image_symbol2.setBorderColor('green')
                    image_symbol2.lineWidth = 4  
                    print('Entering the loop but not showing')
                    for stimulus in [image_symbol1, image_symbol2, instruction]: 
                        stimulus.draw()
                    win.flip()
                    core.wait(0.5)  # give time to ppn to see chosen image
                    break 

    return keys_sym  # Return the keys_sym list

Extra
If anyone knows how to make this function more efficient (i.e. currently losing time on recording events), it would be appreciated :slight_smile:

Thank you!

Odd that it’s not working, but as an alternative you can simply draw a visual.Rect behind the image that is slightly larger than the image itself and the appearance will be the same.

Hi Jonathan,

Actually I think the .setBorderColor function is not properly defined. This is the code:

def setBorderColor(self, color, colorSpace=None, operation='', log=None):
        """Hard setter for `fillColor`, allows suppression of the log message,
        simultaneous colorSpace setting and calls update methods.
        """
        setColor(obj=self, colorAttrib="borderColor", color=color, colorSpace=colorSpace or self.colorSpace, operation=operation, log=log)
        # Trigger color update for components like Textbox which have different behaviours for a hard setter
        self.updateColors()

And the eslf.updateColors() function code is empty:

def updateColors(self):
        """Placeholder method to update colours when set externally, for example updating the `pallette` attribute of
        a textbox"""
        return

But indeed what you’re suggesting is also what I thought would be the alternative solution.
Thanks!

Best,
Judit