psychopy.org | Reference | Downloads | Github

Text BoundingBox Issues

I’m displaying a rectangular box around text when a response is made using the text.boundBox option. On my Windows computer the box fits nicely around the text, but when I try to run this on a Mac, the box does not fit around the entire text. The monitor resolution of my PC is 1366x768 and the Mac resolution is 2560x1600. My hunch is the issue is with the different aspect ratios, but I’m not sure how to address it.

This is what I’ve been doing:

> #Determine Monitor Resolution:
> if platform.system() == "Windows":
>     from win32api import GetSystemMetrics
>     width, height = GetSystemMetrics(0), GetSystemMetrics(1)
> elif platform.system() == "Darwin":
>     p = subp.Popen(shlex.split("system_profiler SPDisplaysDataType"), stdout=subp.PIPE)
>     output = subp.check_output(('grep', 'Resolution'), stdin=p.stdout)
>     width, height = [int(x.strip(' ')) for x in output.split(':')[-1].split(' x ')]  
> choice1 = visual.TextStim(win, text='',height=0.08, pos=(0,0), wrapWidth=0.5, color="White")
> choice2 = visual.TextStim(win, text='',height=0.08, pos=(0,0), wrapWidth=0.5, color="White")
> resp_box = visual.Rect(win, width = 0.3, height = 0.1, pos = (0,0))
> while True:
>     if event.getKeys(keyList = ["escape"]):
>         core.quit()           
>     response = event.getKeys(keyList = ["left","right"])
>     if len(response):
>         if response[0] == "left":
>             resp_box.pos = (-0.5, -0.5)
>             resp_box.width = (choice1.boundingBox[0]/width)*2 + 0.05
>             resp_box.height = (choice1.boundingBox[1]/height)*2 + 0.05
>             resp_box.draw()
>         elif response[0] == "right":
>             resp_box.pos = (0.5, -0.5)
>             resp_box.width = (choice2.boundingBox[0]/width)*2 + 0.05
>             resp_box.height = (choice2.boundingBox[1]/height)*2 + 0.05
>             resp_box.draw()
>         else:
>             pass
>         win.flip()

Thanks for any help.