[visionegg] Re: Question about removal/hiding of already displayed text in a viewport.
- From: Mark Halko <mhalko@xxxxxx>
- To: visionegg@xxxxxxxxxxxxx
- Date: Mon, 9 Jul 2007 20:38:37 -0400
Hi Ethan ,
Text( text = "Position1 ",
position = (15,20),
anchor='left',
color = (0.0,0.0,0.0,1.0))
You want to assign the text object to a variable, so you can access
it's parameters later:
mytext=Text( text = "Position1 ",position =
(15,20),anchor='left',color = (0.0,0.0,0.0,1.0))
1. Would you put the text in a separate viewport, and then turn it on
and off?
Probably the easiest thing to do is to just turn it off and on:
mytext.parameters.on = True
mytext.parameters.on = False
Although you could put it in a separate viewport if you like.
2. Is there some sort of a command switch for the opacity of the text,
like there is for text texture backgrounds?
Use the max_alpha parameter:
mytext=Text( text = "Position1 ",position =
(15,20),anchor='left',color = (0.0, 0.0, 0.0, 1.0), max_alpha=0.5)
or
mytext.parameters.max_alpha=0.5 #half transparent
3. Can you replace the "text" with nothing....if fear blank spaces
might
make something you could see on the screen?
Sure. See my attached file for typing text to screen. It might
answer most of your questions. Space bar turns the text on and off,
typing adds letters, return prints the text to terminal and clears
the text, backspace deletes the last letter. Escape quits.
Mark
#!/usr/bin/env python
"""Display text strings."""
import VisionEgg
VisionEgg.start_default_logging(); VisionEgg.watch_exceptions()
from VisionEgg.Core import *
from VisionEgg.FlowControl import Presentation
from VisionEgg.Text import *
import sys
screen = get_default_screen()
screen.parameters.bgcolor = (0.0,0.0,1.0) # background blue (RGB)
text =
Text(text="",anchor='center',position=(screen.size[0]/2,screen.size[1]/2))
viewport = Viewport(screen=screen,size=screen.size,stimuli=[text])
def keydown(event) :
global text
if event.key == pygame.locals.K_ESCAPE :
sys.exit()
elif event.key == pygame.locals.K_SPACE :
text.parameters.on = not text.parameters.on #False if True, True if
False
elif event.key == pygame.locals.K_RETURN :
print text.parameters.text
text.parameters.text=""
elif event.key == pygame.locals.K_BACKSPACE :
text.parameters.text=text.parameters.text[:-1]
else :
text.parameters.text+=event.unicode
p = Presentation(go_duration=('forever',),viewports=[viewport])
p.parameters.handle_event_callbacks = [(pygame.locals.QUIT, sys.exit),
(pygame.locals.KEYDOWN, keydown)]
p.go()
- References:
Other related posts:
- » [visionegg] Question about removal/hiding of already displayed text in a viewport.
- » [visionegg] Re: Question about removal/hiding of already displayed text in a viewport.
Text( text = "Position1 ",
position = (15,20),
anchor='left',
color = (0.0,0.0,0.0,1.0))
1. Would you put the text in a separate viewport, and then turn it on and off?
2. Is there some sort of a command switch for the opacity of the text, like there is for text texture backgrounds?
make something you could see on the screen?