Package psychopy :: Module visual :: Class Window
[frames] | no frames]

Class Window

source code

Used to set up a context in which to draw objects, using either PyGame (python's SDL binding) or pyglet.

The pyglet backend allows multiple windows to be created, allows the user to specify which screen to use (if more than one is available, duh!) and allows movies to be rendered.

Pygame has fewer bells and whistles, but does seem a little faster in text rendering. Pygame is used for all sound production and for monitoring the joystick.

Instance Methods
 
__init__(self, size=(800, 600), pos=None, color=(0, 0, 0), colorSpace='rgb', rgb=None, dkl=None, lms=None, fullscr=None, allowGUI=None, monitor={}, bitsMode=None, winType=None, units=None, gamma=None, blendMode='avg', screen=0, viewScale=None, viewPos=None, viewOri=0.0, waitBlanking=True)
:Parameters:
source code
 
setRecordFrameIntervals(self, value=True)
To provide accurate measures of frame intervals, to determine whether frames are being dropped.
source code
 
saveFrameIntervals(self, fileName=None, clear=True)
Save recorded screen frame intervals to disk, as comma-separated values.
source code
 
whenIdle(self, func)
Defines the function to use during idling (GLUT only)
source code
 
onResize(self, width, height)
A default resize event handler.
source code
 
flip(self, clearBuffer=True)
Flip the front and back buffers after drawing everything for your frame.
source code
 
update(self)
Deprecated: use Window.flip() instead
source code
 
clearBuffer(self)
Clear the back buffer (to which you are currently drawing) without flipping the window.
source code
 
getMovieFrame(self, buffer='front')
Capture the current Window as an image.
source code
 
saveMovieFrames(self, fileName, mpgCodec='mpeg1video', fps=30)
Writes any captured frames to disk.
source code
 
fullScr(self)
Toggles fullscreen mode (GLUT only).
source code
 
close(self)
Close the window (and reset the Bits++ if necess).
source code
 
go(self)
start the display loop (GLUT only)
source code
 
fps(self)
Report the frames per second since the last call to this function (or since the window was created if this is first call)
source code
 
setColor(self, color, colorSpace=None, operation='')
Set the color of the window.
source code
 
setRGB(self, newRGB)
Deprecated: As of v1.61.00 please use setColor() instead
source code
 
setScale(self, units, font='dummyFont', prevScale=(1.0, 1.0))
This method is called from within the draw routine and sets the scale of the OpenGL context to map between units.
source code
 
setGamma(self, gamma)
Set the monitor gamma, using Bits++ if possible
source code
 
setMouseVisible(self, visibility)
Sets the visibility of the mouse cursor.
source code
Method Details

__init__(self, size=(800, 600), pos=None, color=(0, 0, 0), colorSpace='rgb', rgb=None, dkl=None, lms=None, fullscr=None, allowGUI=None, monitor={}, bitsMode=None, winType=None, units=None, gamma=None, blendMode='avg', screen=0, viewScale=None, viewPos=None, viewOri=0.0, waitBlanking=True)
(Constructor)

source code 

:Parameters:

    size : (800,600)
        Size of the window in pixels (X,Y)
    pos : *None* or (x,y)
        Location of the window on the screen
    rgb : [0,0,0]
        Color of background as [r,g,b] list or single value. Each gun can take values betweeen -1 and 1
    fullscr : *None*, True or False
        Better timing can be achieved in full-screen mode            
    allowGUI :  *None*, True or False (if None prefs are used) 
        If set to False, window will be drawn with no frame and no buttons to close etc...
    winType :  *None*, 'pyglet', 'pygame'
        If None then PsychoPy will revert to user/site preferences
    monitor : *None*, string or a `~psychopy.monitors.Monitor` object
        The monitor to be used during the experiment
    units :  *None*, 'norm' (normalised),'deg','cm','pix'
        Defines the default units of stimuli drawn in the window (can be overridden by each stimulus)
        See :ref:`units` for explanation of options.
    screen : *0*, 1 (or higher if you have many screens)
        Specifies the physical screen that stimuli will appear on (pyglet winType only)
    viewScale : *None* or [x,y]
        Can be used to apply a custom scaling to the current units of the :class:`~psychopy.visual.Window`.  
    viewPos : *None*, or [x,y]
        If not None, redefines the origin for the window
    viewOri : *0* or any numeric value
        A single value determining the orientation of the view in degs
    waitBlanking : *None*, True or False. 
        After a call to flip() should we wait for the blank before the script continues
    gamma : 1.0, 
        Monitor gamma for linearisation (will use Bits++ if possible). Overrides monitor settings
    bitsMode : None, 'fast', ('slow' mode is deprecated). 
        Defines how (and if) the Bits++ box will be used. 'fast' updates every frame by drawing a hidden line on the top of the screen.
    
    :note: Preferences. Some parameters (e.g. units) can now be given default values in the user/site preferences and these will be used if None is given here. If you do specify a value here it will take precedence over preferences.

setRecordFrameIntervals(self, value=True)

source code 

To provide accurate measures of frame intervals, to determine whether frames are being dropped. Set this to False while the screen is not being updated e.g. during event.waitkeys() and set to True during critical parts of the script

see also:
Window.saveFrameIntervals()

saveFrameIntervals(self, fileName=None, clear=True)

source code 

Save recorded screen frame intervals to disk, as comma-separated values.

fileName : None or the filename (including path if necessary) in which to store the data.
If None then 'lastFrameIntervals.log' will be used.

Parameters:  

onResize(self, width, height)

source code 
A default resize event handler.

This default handler updates the GL viewport to cover the entire
window and sets the ``GL_PROJECTION`` matrix to be orthagonal in
window space.  The bottom-left corner is (0, 0) and the top-right
corner is the width and height of the :class:`~psychopy.visual.Window` in pixels.

Override this event handler with your own to create another
projection, for example in perspective.

flip(self, clearBuffer=True)

source code 

Flip the front and back buffers after drawing everything for your frame. (This replaces the win.update() method, better reflecting what is happening underneath).

win.flip(clearBuffer=True)#results in a clear screen after flipping win.flip(clearBuffer=False)#the screen is not cleared (so represent the previous screen)

clearBuffer(self)

source code 
Clear the back buffer (to which you are currently drawing) without flipping the window. Useful if you want to generate movie sequences from the back buffer without actually taking the time to flip the window.

getMovieFrame(self, buffer='front')

source code 

Capture the current Window as an image. This can be done at any time (usually after a .update() command).

Frames are stored in memory until a .saveMovieFrames(filename) command is issued. You can issue getMovieFrame() as often as you like and then save them all in one go when finished.

saveMovieFrames(self, fileName, mpgCodec='mpeg1video', fps=30)

source code 

Writes any captured frames to disk. Will write any format that is understood by PIL (tif, jpg, bmp, png...)

Examples::
myWin.saveMovieFrames('frame.tif')#writes a series of static frames as frame001.tif, frame002.tif etc... myWin.saveMovieFrames('stimuli.mov', fps=25)#on OS X only myWin.saveMovieFrames('stimuli.gif')#but not great quality myWin.saveMovieFrames('stimuli.mpg')#not on OS X

parameters:

filename: name of file, including path (required)
The extension at the end of the file determines the type of file(s) created. If an image type is given the multiple static frames are created. If it is .gif then an animated GIF image is created (although you will get higher quality GIF by saving PNG files and then combining them in dedicated image manipulation software (e.g. GIMP). On windows and linux .mpeg files can be created if pymedia is installed. On OS X .mov files can be created if the pyobjc-frameworks-QTKit is installed.

mpgCodec: the code to be used by pymedia if the filename ends in .mpg

fps: the frame rate to be used throughout the movie only for quicktime (.mov) movies

fullScr(self)

source code 
Toggles fullscreen mode (GLUT only).

Fullscreen mode for PyGame contexts must be set during initialisation
of the :class:`~psychopy.visual.Window`

setColor(self, color, colorSpace=None, operation='')

source code 
Set the color of the window. 

NB This command sets the color that the blank screen will have on the next
clear operation. As a result it effectively takes TWO `flip()` operations to become 
visible (the first uses the color to create the new screen the second presents
that screen to the viewer).  

See :ref:`colorspaces` for further information about the ways to specify colors and their various implications.

:Parameters:

color : 
    Can be specified in one of many ways. If a string is given then it
    is interpreted as the name of the color. Any of the standard html/X11
    `color names <http://www.w3schools.com/html/html_colornames.asp>` 
    can be used. e.g.::
        
        myStim.setColor('white')
        myStim.setColor('RoyalBlue')#(the case is actually ignored)
    
    A hex value can be provided, also formatted as with web colors. This can be
    provided as a string that begins with # (not using python's usual 0x000000 format)::
        
        myStim.setColor('#DDA0DD')#DDA0DD is hexadecimal for plum
        
    You can also provide a triplet of values, which refer to the coordinates
    in one of the :ref:`colorspaces`. If no color space is specified then the color 
    space most recently used for this stimulus is used again.
    
        myStim.setColor([1.0,-1.0,-1.0], 'rgb')#a red color in rgb space
        myStim.setColor([0.0,45.0,1.0], 'dkl') #DKL space with elev=0, azimuth=45
        myStim.setColor([0,0,255], 'rgb255') #a blue stimulus using rgb255 space
    
    Lastly, a single number can be provided, x, which is equivalent to providing
    [x,x,x]. 
    
        myStim.setColor(255, 'rgb255') #all guns o max
    
colorSpace : string or None

    defining which of the :ref:`colorspaces` to use. For strings and hex
    values this is not needed. If None the default colorSpace for the stimulus is
    used (defined during initialisation). 
    
operation : one of '+','-','*','/', or '' for no operation (simply replace value)
    
    for colors specified as a triplet of values (or single intensity value)
    the new value will perform this operation on the previous color
    
        thisStim.setColor([1,1,1],'rgb255','+')#increment all guns by 1 value
        thisStim.setColor(-1, 'rgb', '*') #multiply the color by -1 (which in this space inverts the contrast)
        thisStim.setColor([10,0,0], 'dkl', '+')#raise the elevation from the isoluminant plane by 10 deg

setScale(self, units, font='dummyFont', prevScale=(1.0, 1.0))

source code 

This method is called from within the draw routine and sets the scale of the OpenGL context to map between units. Could potentially be called by the user in order to draw OpenGl objects manually in each frame.

The units can be 'norm'(normalised),'pix'(pixels),'cm' or 'stroke_font'. The font parameter is only used if units='stroke_font'

setMouseVisible(self, visibility)

source code 

Sets the visibility of the mouse cursor.

If Window was initilised with noGUI=True then the mouse is initially set to invisible, otherwise it will initially be visible.

Usage:
setMouseVisible(False) setMouseVisible(True)