|
1 | 1 | #!/usr/bin/env python |
2 | 2 | # -*- coding: utf-8 -*- |
3 | 3 |
|
4 | | - |
| 4 | +import psychopy |
5 | 5 | from psychopy import visual, core, event, logging |
| 6 | +import numpy as np |
6 | 7 |
|
7 | | -logging.console.setLevel(logging.DEBUG) |
| 8 | +logging.console.setLevel(logging.EXP) |
8 | 9 | c = core.Clock() |
9 | 10 |
|
10 | 11 | from psychopy.visual.textbox2 import TextBox2, allFonts |
11 | 12 |
|
12 | | -win = visual.Window([800, 800], monitor='testMonitor', backend='glfw') |
| 13 | +win = visual.Window([800, 800], monitor='testMonitor') |
13 | 14 | logging.exp("{:.3f}: created window".format(c.getTime())) |
14 | 15 |
|
15 | | -text = u"<i>The quick</i> brown <b>fox</b> jumped" |
16 | | -loremIpsum = u"PsychoPy is an open-source Python application allowing you to run a supercali-fragilisticexpeilidocious wide range of neuroscience, psychology and psychophysics experiments. It’s a free, powerful alternative to Presentation™ or e-Prime™, written in Python (a free alternative to Matlab™ g)." |
| 16 | +psychopyInfo = u"<b>PsychoPy</b> is an <i>open-source</i> Python application allowing you to run a supercali-fragilisticexpeilidocious wide range of neuroscience, psychology and psychophysics experiments. It’s a free, powerful alternative to Presentation™ or e-Prime™, written in Python (a free alternative to Matlab™ g)." |
17 | 17 |
|
18 | | -fontSize = 16 |
19 | 18 | # preload some chars into a font to see how long it takes |
20 | | -nChars = 256 |
| 19 | +fontSize = 16 |
21 | 20 | arial = allFonts.getFont("Arial", fontSize) |
22 | 21 | logging.exp("{:.3f}: created font".format(c.getTime())) |
23 | | -arial.preload(nChars) |
| 22 | +nChars = 256 |
| 23 | +arial.preload(nChars) # or set to preload specific string of chars |
24 | 24 | logging.exp("{:.3f}: preloaded {} chars".format(c.getTime(), nChars)) |
25 | | -# arial.saveToCache() # can't yet retrieve the font but it's interesting to see! |
26 | 25 |
|
27 | | - |
28 | | -txt1 = TextBox2(win, color='black', colorSpace='named', text='Toptastic', font='Times', |
29 | | - pos=(0, 0.0), letterHeight=0.1, units='height', |
30 | | - size=[1, 1], |
31 | | - anchor='right-bottom', |
32 | | - borderColor='red', |
| 26 | +txt1 = TextBox2(win, text="Type here, it's toptastic", font='Times', |
| 27 | + color='black', colorSpace='named', |
| 28 | + pos=(0, 0.4), letterHeight=0.05, units='height', |
| 29 | + size=[0.8, 0.2], |
| 30 | + anchor='center-top', |
| 31 | + borderColor='lightgrey', |
33 | 32 | fillColor='slategrey', |
34 | 33 | editable=True) |
35 | | -txt1.draw() |
36 | | - |
37 | | -x, y = 0, -5 |
38 | 34 |
|
39 | | -txt2 = TextBox2(win, color='blue', text=loremIpsum, font='Arial', |
40 | | - pos=(x, y), anchor='bottom', size=(20, None), units='cm', |
| 35 | +txt2 = TextBox2(win, text=psychopyInfo, font='Arial', |
| 36 | + pos=(0, -5), anchor='middle', size=(20, None), units='cm', |
41 | 37 | lineSpacing=1.1, |
42 | 38 | letterHeight=1., |
43 | | - borderColor='white', |
44 | | - fillColor=None, |
| 39 | + color='LightGrey', borderColor='Moccasin', fillColor=None, |
45 | 40 | editable=True) |
46 | | -txt2.draw() |
47 | | - |
48 | | -logging.exp("{:.3f}: drew altered Arial text".format(c.getTime())) |
49 | | - |
50 | | -win.flip() |
51 | | -logging.exp("{:.3f}: drew TextBox Times (no preload)".format(c.getTime())) |
52 | 41 |
|
53 | | -stims = [txt1, txt2] |
54 | | -win.flip() |
55 | | -for frame in range(1000): |
56 | | - txt2.pos += 0.01 |
57 | | - for stim in stims: |
58 | | - stim.draw() |
| 42 | +txt3 = TextBox2(win, text='Good for non-editable text (Esc to quit)', |
| 43 | + font='Arial', |
| 44 | + borderColor=None, fillColor=None, |
| 45 | + pos=(-0.5,-0.5), units='height', anchor='bottom-left', |
| 46 | + letterHeight=0.02, |
| 47 | + editable=False) |
| 48 | + |
| 49 | +clock = core.Clock() |
| 50 | +t=0 |
| 51 | +while t<20: |
| 52 | + t= clock.getTime() |
| 53 | + |
| 54 | + txt1.draw() |
| 55 | + |
| 56 | + txt2.pos = (0.2*np.sin(t), 0.2*np.cos(t)) |
| 57 | + txt2.draw() |
| 58 | + |
| 59 | + txt3.draw() |
59 | 60 | if 'escape' in event.getKeys(): |
60 | 61 | core.quit() |
61 | 62 |
|
|
0 commit comments