Ejemplo n.º 1
0
 def test_font_manager(self):
     # Create a font manager
     mgr = FontManager()
     # Check that it finds fonts which should be pre-packaged with PsychoPy in the resources folder
     assert bool(mgr.getFontNamesSimilar("Open Sans"))
     # Check that it doesn't find fonts which aren't installed as default
     assert not bool(mgr.getFontNamesSimilar("Dancing Script"))
     # Check that it can install fonts from Google
     mgr.addGoogleFont("Hanalei")
     # Check that these fonts are found once installed
     assert bool(mgr.getFontNamesSimilar("Hanalei"))
Ejemplo n.º 2
0
import ast
import re

from numpy import array
from esprima import parseScript

from psychopy.tools import monitorunittools
from psychopy.alerts._alerts import alert
from psychopy.visual.textbox2.fontmanager import FontManager

fontMGR = FontManager()


class TestWin(object):
    """
    Creates a false window with necessary attributes for converting component
    Parameters to pixels.
    """
    def __init__(self, exp):
        self.useRetina = True
        self.exp = exp
        self.monitor = self.exp.settings.monitor
        winSize = self.exp.settings.params['Window size (pixels)'].val

        if winSize and isinstance(winSize, str):
            self.size = ast.literal_eval(winSize)
        elif winSize and (isinstance(winSize, list)
                          or isinstance(winSize, tuple)):
            self.size = winSize
        else:
            self.size = (1024, 768)
Ejemplo n.º 3
0
"""
This demo produces a handy diagram showing how the metrics of a PsychoPy GLFont object affect the layout of rows in a textbox. A textbox is drawn such that the baseline of the first line is at the vertical coordinate 0, meaning that all other lines and shapes can be laid out relative to this line.
"""


from psychopy import visual, event
from psychopy.visual.textbox2.fontmanager import FontManager

# Create window
win = visual.Window(size=(500, 200), units="pix", color="white")

# Create a list to store objects for easy drawing
drawList = []

# Get a font with consistent proportions that are easy to spot
allFonts = FontManager()
font = allFonts.getFont("Outfit", size=50, lineSpacing=1.3)

# Create a textbox using this font, whose vertical position is such that the baseline of the first line of text is at 0
text = visual.TextBox2(
    win=win, text="My text has an È!\nMy text has an È!", font=font,
    pos=(-50, font.ascender), size=(400, font.height), padding=0,
    color="black", anchor="top center", alignment="top left"
)
drawList += [text]

# Draw the baseline
baseline = visual.Line(win, start=(-250, 0), end=(250, 0), lineColor="green")
baselineLbl = visual.TextBox2(win, "baseline (0)", "Outfit", color="green", letterHeight=12, pos=(160, 8), size=(50, 10), padding=0)
drawList += [baseline, baselineLbl]
# Draw the descent line