[visionegg] Re: stimulus

  • From: Dave Bissig <dbissig@xxxxxxxxx>
  • To: visionegg@xxxxxxxxxxxxx
  • Date: Mon, 24 Aug 2009 01:02:59 -0400

OOPS!
(1) I missed the point about starting with a text-only viewport, and
switching from that to a second one...
(2) there were a couple goofs in the script I sent anyways (including
repeated misspelling of "boilerplate").
...so try this:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
####### import stuff
## (boilerplate)
import VisionEgg
from VisionEgg import *
VisionEgg.start_default_logging(); VisionEgg.watch_exceptions()
from VisionEgg.Core import *
from VisionEgg.Textures import *
from VisionEgg.Text import *
import pygame

####### open a Vision Egg window
## (boilerplate)
refresh_rate = 120
screen_width = 921
screen_height = 606
bits_per_pixel = 16
def __VEggConfig():
    VisionEgg.start_default_logging(); VisionEgg.watch_exceptions()
    VisionEgg.config.VISIONEGG_GUI_INIT = 0
    VisionEgg.config.VISIONEGG_FRAMELESS_WINDOW = 1
    VisionEgg.config.VISIONEGG_FULLSCREEN = 0
    VisionEgg.config.VISIONEGG_MONITOR_REFRESH_HZ = refresh_rate
    VisionEgg.config.VISIONEGG_SCREEN_W = screen_width
    VisionEgg.config.VISIONEGG_SCREEN_H = screen_height
    VisionEgg.config.VISIONEGG_PREFERRED_BPP = bits_per_pixel

###### make a couple of simple modules
## WaitAround, here, just closes the window when you hit ESC, or
## (owing to its use of CheckMousePosition(xpos,ypos) ) when you
## click on the image with your mouse.

def WaitAround():
    waiting=0
    while waiting != 1:
        for event in pygame.event.get():
            if event.type == pygame.locals.MOUSEBUTTONDOWN:
                xpos,ypos = pygame.mouse.get_pos()
                CheckMousePosition(xpos,ypos) # given the coordinates and
command set up in CheckMousePosition
                                              # this causes the display to
switch to (or from) the
                                              # text-only or text+image
display (depending on the
                                              #  global value of
STARTSCREEN).
                waiting=1
            elif event.type == pygame.locals.KEYDOWN:
                if event.key == pygame.locals.K_ESCAPE:
                    screen.close()
                    screen.close()
                    raise SystemExit

def CheckMousePosition(xpos,ypos):
    ## you could add different locations here (with elif) to define several
functions, based
    ## on the location of mousedown.  (like a simple imagemap of old website
design fame).
    if xpos >= 0 and xpos <=600 and ypos >= 0 and ypos <=921:
        if STARTSCREEN == 1:
            STARTSCREEN = 0  ## if 1, switch to 0,
            global STARTSCREEN
        elif STARTSCREEN == 0:
            STARTSCREEN = 1 ## if 0, switch to 1,
            global STARTSCREEN

########### Next four lines are boilerplate.
__VEggConfig()
screen = get_default_screen()
screen.parameters.bgcolor = (0.0,0.0,0.0)
pygame.mouse.set_cursor(*pygame.cursors.arrow)

STARTSCREEN=1

## OK, now set up the main loop.
mk=0
while mk != 1:
    if STARTSCREEN == 1:
        ## make some text stimuli
        bunchOtext1 = Text(text="Click text
to",color=(1,1,0.8),position=(150,(screen_height-230)),font_size=40,anchor='center')
        bunchOtext2 = Text(text="engage
facepalm",color=(1,1,0.8),position=(150,(screen_height-270)),font_size=40,anchor='center')
        ## make the viewport.
        textPort = VisionEgg.Core.Viewport(screen=screen, size=screen.size,
stimuli=[bunchOtext1,bunchOtext2])

        ## first clear anything in the buffer already.
        screen.clear()

        ## draw the text on the black background.
        textPort.draw()

        ## now, swap the buffers (whatever is on screen now goes to buffer,
and the stuff we
        ##                      just drew to the buffer is shown on screen).
        VisionEgg.Core.swap_buffers()
        pygame.mouse.set_visible(True)
        WaitAround()

    elif STARTSCREEN == 0:

        ## basic TextureStimulus command for showing an image.

back=TextureStimulus(texture=Texture('picard-facepalm.jpg'),position=(0,(screen_height-0)),anchor='upperleft')
        ## draw the viewport.

background=VisionEgg.Core.Viewport(screen=screen,size=screen.size,stimuli=[back])
        bunchOtext1 = Text(text="Click image
to",color=(1,1,0.8),position=(150,(screen_height-230)),font_size=40,anchor='center')
        bunchOtext2 = Text(text="disengage
facepalm",color=(1,1,0.8),position=(150,(screen_height-270)),font_size=40,anchor='center')
        ## we alread called VisionEgg.Core.Viewport() to make the background
image veiwport
        ## , and we'll now use it again to make the text viewport.  ...not
sure what the consequences
        ##   are for having "overlapping" things crammed into the same
viewport... I suggest avoiding it.
        ##   and anyways, splitting things into different viewports gives
you control over what's drawn first,
        ##   or if you're drawing something over a consistent background,
may let you run things
        ##   a bit quicker (just defining the background viewport once, in
stead of over
        ##   and over again in a loop).
        ### anyways...
        ### make the text's viewport:
        textPort = VisionEgg.Core.Viewport(screen=screen, size=screen.size,
stimuli=[bunchOtext1,bunchOtext2])

        ##
        ##
        ########## now, we draw everything to the buffer.##########
        ## first clear anything in the buffer already.
        screen.clear()

        ## draw the background
        background.draw()

        ## draw with text
        textPort.draw()

    ########  NOTE:  if you changed the order, like this:
    #   textPort.draw()
    #   background.draw()
    ######## you would have drawn the text, then drawn the image on top, so
no text would show up.

        ## now, swap the buffers (whatever is on screen now goes to buffer,
and the stuff we
        ##                      just drew to the buffer is shown on screen).
        VisionEgg.Core.swap_buffers()
        pygame.mouse.set_visible(True)
        WaitAround()



~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


On Sun, Aug 23, 2009 at 4:08 PM, Maja K <maja_ka@xxxxxxxxxxx> wrote:

>  Hello Everybody, :-)
> I am having some troubles with displaying of my viewports and would really
> appreciate if someone could help me.
> My problem is that I made presentation which includes text viewport. I also
> created another presentation which includes two viewports - one with the
> stimulus (of some object I created) and second of another text viewport.
>
> Each of the viewports when run separately work well, however when I try to
> run first presentation and after it the second one, the second one runs, but
> it does not display on the screen. Also when i run the presentation with two
> viewports only the one added as the second one displays on the screen.
> I would really appreciate if someone could tell me what I am doing wrong.
>
> best wishes to you all,
> Maja
>
> ------------------------------
> With Windows Live, you can organize, edit, and share your photos. Click
> here. <http://www.windowslive.com/Desktop/PhotoGallery>
>

Other related posts: