Package pype :: Module sprite :: Class FrameBuffer
[frames] | no frames]

Class FrameBuffer

source code

object --+
         |
        FrameBuffer

Instance Methods
a new object with type S, a subtype of T
__new__(cls, *args, **kwargs)
This ensure a single instantation.
source code
 
__init__(self, dpy, width, height, fullscreen, bg=(128,128,128), sync=1, syncsize=50, syncx=None, syncy=None, synclevel=255, mouse=0, app=None, eyefn=None, fbw=None, fbh=None, xscale=1.0, yscale=1.0)
pygame+GL-based framebuffer class for pype.
source code
 
screen_open(self, init=0) source code
 
screen_close(self) source code
 
__del__(self)
FrameBuffer cleanup.
source code
 
calcfps(self, duration=250)
Estimate frames per second.
source code
 
set_gamma(self, r, g=None, b=None)
Set hardware gamma correction values (if possible).
source code
 
cursor(self, on=0)
Turn display of the mouse cursor on or off.
source code
 
cursorpos(self)
Query current mouse position and bar state (any button) in framebuffer window.
source code
 
togglefs(self, wait=0) source code
 
sync(self, state, flip=None)
Draw/set sync pulse sprite.
source code
 
sync_toggle(self, flip=None)
Toggle sync pulse state.
source code
 
clear(self, color=None, flip=None)
Clear framebuffer.
source code
 
flip(self, doflip=1)
Flip framebuffer (sync'd to vert-retrace, if possible).
source code
 
recordtog(self, state=None) source code
 
checklshift(self)
LEFT Shift key down?
source code
 
checkrshift(self)
RIGHT Shift key down?
source code
 
checklctrl(self)
LEFT Ctrl key down?
source code
 
checkrctrl(self)
RIGHT Ctrl key down?
source code
 
waitkeys(self)
Wait for keyboard to be clear (no pressed keys).
source code
 
checkkeys(self)
Get list of pressed keys.
source code
 
checkmouse(self)
Get list of pressed mouse buttons.
source code
 
clearkey(self)
Clear keyboard input queue.
source code
 
mouseposition(self)
Query mouse position.
source code
 
getkey(self, wait=None, down=1)
Get next keystroke from queue.
source code
 
ungetkey(self, c)
'unget' keystroke.
source code
 
snapshot(self, filename, size=None)
Save screen snapshot to file.
source code
 
string(self, x, y, s, color, flip=None, bg=None, size=30, rotation=0.0)
Draw string on framebuffer.
source code
 
rectangle(self, cx, cy, w, h, color, width=0, flip=None)
Draw rectangle directly on framebuffer.
source code
 
lines(self, pts, color, width=1, contig=1, closed=0, joins=0, flip=None)
Draw line directly on framebuffer.
source code
 
line(self, start, stop, color, width=1, flip=None)
Draw line directly on framebuffer.
source code
 
circle(self, cx, cy, r, color, width=0, flip=None)
Draw circle directly on framebuffer.
source code

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Properties

Inherited from object: __class__

Method Details

__new__(cls, *args, **kwargs)

source code 
This ensure a single instantation.
Returns: a new object with type S, a subtype of T
Overrides: object.__new__

__init__(self, dpy, width, height, fullscreen, bg=(128,128,128), sync=1, syncsize=50, syncx=None, syncy=None, synclevel=255, mouse=0, app=None, eyefn=None, fbw=None, fbh=None, xscale=1.0, yscale=1.0)
(Constructor)

source code 

pygame+GL-based framebuffer class for pype.

Wrapper for the pygame platform-independent interface to the framebuffer hardware. This should provide a platform independent handle to the video hardware, which is now accessed via OpenGL. Only one instance per application.

Parameters:
  • dpy - string containing name of X11 display to contact (None for default, taken from os.environ['DISPLAY']
  • width, height - (pixels) size of requested display. This corresponds to the PHYSICAL size of the display. In full screen mode, it must match one of the available hardware modes. See [xy]scale and fb[wh] below.
  • fullscreen - (boolean) full screen or windowed mode?
  • bg - default background color. This can be a color triple (r,g,b) or a grey scale value. Actually, it can be anything that the C() function in this module can parse.
  • sync - boolean flag indicating whether or not to setup (and subsequently use) a sync pulse placed on the monkey's video display for external synchronization (this is to drive photodiode that can be used to detect the presence or absence of the syncpulse).
  • syncx, syncy - Position of the sync pulse generator spot in standard sprite coordinates - (0,0) is screen center, positive to left and up. NB this indicates the position for the center of the sync spot, so if you are at a corner, you should probably double the size to get the expected value. Default position (when syncx and syncy are not specified or are None) is lower right hand corner.
  • syncsize - (pixels) size of sync pulse (sync pulse will be syncsize x syncsize pixels and located in the lower right corner of the screen (if syncsize <= 0, then sync pulses are disabled - same as sync=0)
  • mouse - show mouse cursor? default is no
  • app - (PypeApp) application handle
  • eyefn - (optional fn that returns (x,y)) If provided should be a function that returns the current eye position. Flip's will add a mark on the framebuffer at this location (for debugging!)
  • fb[wh] - (optional) specify the size of the internal framebuffer. If specified and not equal to width and height above, specifies the size of the virtual framebuffer that will be scaled onto the physical display.
  • [xy]scale - (optional) alternative (older) method for specifying size of framebuffer. The internal framebuffer will be set to be (width*xscale, height*yscale). fb[wh] overrides this parameter.
Returns:
nothing
Overrides: object.__init__

__del__(self)
(Destructor)

source code 

FrameBuffer cleanup.

Delete held sprites and shut down pygame subsystem.

calcfps(self, duration=250)

source code 

Estimate frames per second.

Try to determine the approximate frame rate automatically. X11R6 doesn't provide a way to set or query the current video frame rate. To circumvent this, we just flip the page a few times and compute the median inter-frame interval.

NB This is always going to be a rought estimate, you should always adjust the /etc/X11/XFConfig-4 file to set the exact frame rate and keep track of in with your data.

Parameters:
  • duration - period of time to flip/test (in ms)
Returns:
float, current frame rate in Hz.

set_gamma(self, r, g=None, b=None)

source code 

Set hardware gamma correction values (if possible).

Set hardware display gammas using pygame/SDL gamma function. Not all hardware supports hardware gamma correction, so this may not always work.

Parameters:
  • r - (Float) if this is the only argument supplied, then this is the simply luminance gamma value and all three guns are set to this value.
  • g, b - (Float) green and blue gamma values. If you specify g, you'ld better specify b as well. Arguments are floating point numbers (1.0 is no gamma correction at all).
Returns:
TRUE on success (ie., if the hardware supports gamma correction)

cursor(self, on=0)

source code 
Turn display of the mouse cursor on or off.
Parameters:
  • on - boolean; 1 to turn the cursor on, 0 to turn it off
Returns:
nothing

cursorpos(self)

source code 
Query current mouse position and bar state (any button) in framebuffer window.
Returns:
(x, y, bardown, lshift, rshift)

sync(self, state, flip=None)

source code 

Draw/set sync pulse sprite.

Set the status of the sync pulse.

Parameters:
  • state - (boolean) 1=light, 0=dark
  • flip - (boolean) do a page flip afterwards?
Returns:
nothing

sync_toggle(self, flip=None)

source code 

Toggle sync pulse state.

Toggle the status of the sync pulse. Light->dark; dark->light.

Parameters:
  • flip - (boolean) do a page flip afterwards?
Returns:
nothing

clear(self, color=None, flip=None)

source code 

Clear framebuffer.

Clear framebuffer to specified color (or default background color, if no color is specfied).

Parameters:
  • color - color to fill with (scalar pixel value for solid grey; triple scalars for an rgb value - anything C() in this module understands is ok). If no color is specified, then self.bg is used (set in the __init__ method).
  • flip - (boolean) do a page flip afterwards?
Returns:
nothing

flip(self, doflip=1)

source code 

Flip framebuffer (sync'd to vert-retrace, if possible).

Draw the syncpulse sprite (if enabled) with the appropriate polarity, blit to the screen and then perform a page flip.

In general, this method should block until the flip occurs, however, not all video hardware until linux supports blocking on page flips. So be careful and check your hardware. You should be able to use the calcfps() method to get a rough idea of the framerate, if it's very fast (>100 Hz), chances are that the hardware doesn't support blocking on flips.

clearkey(self)

source code 

Clear keyboard input queue.

Clear the keyboard buffer. The way things are currently setup any keystrokes coming into pype are pushed into a queue, the getkey() method below returns the next key in the queue

mouseposition(self)

source code 

Query mouse position.

Returns (x,y) coords of mouse in frame buffer coordinates.

getkey(self, wait=None, down=1)

source code 

Get next keystroke from queue.

Return the next key in the keyboard input queue and pop the keystroke off the queue stack.

Parameters:
  • wait - flag indicating whether or not to wait for a keystroke to occur.
  • down - (boolean) boolean flag indicating whether to only accept downstrokes (default is true)
Returns:
keystroke value; negative for key-up, positive for key-down, 0 if no keystrokes are available in the queue.

ungetkey(self, c)

source code 

'unget' keystroke.

Push a keystroke event back onto the keyboard queue. Keyboard queue is simulated in pype as a stack, see getkey() method for details.

Parameters:
  • c - keystroke to push back (same syntax as getkey() method above.

snapshot(self, filename, size=None)

source code 

Save screen snapshot to file.

Take snapshot of the framebuffer and write it to the specified file.

Parameters:
  • filename - name of output file; PIL is used to write the file and PIL automatically determines the filetype from filename's extension.
  • size - optional size of the snapshot; PIL is used to rescale the image to this size. If size is left unspecified, then the snapshot is written at the screen's true resolution.
Returns:
PIL Image structure containing the snapshot (can be converted th PhotoImage for display in Tkinter/Canvas..)

string(self, x, y, s, color, flip=None, bg=None, size=30, rotation=0.0)

source code 

Draw string on framebuffer.

Write text string in default font on the framebuffer screen at the specified location. This is primarily useful for running psychophysical studies and debugging.

NB Requires the SDL_ttf package

Parameters:
  • x, y - coordinates of string CENTER
  • s - string to write
  • color - RGB or greyscale color (anything C() understands)
  • flip - (boolean) flip after write
  • bg - None or C()-compatible color spec
  • size - (pixels) font size
Returns:
nothing

rectangle(self, cx, cy, w, h, color, width=0, flip=None)

source code 
Draw rectangle directly on framebuffer.
Parameters:
  • cx, cy - world coords of the rectangle's CENTER
  • w, h - (pixels) width and height of the rectangle
  • color - C() legal color specification
  • width - 0 means fill the rectangle with the specfied color, anything else means draw the outline of the rectangle in the specified color with strokes of the specified width.
Returns:
nothing

lines(self, pts, color, width=1, contig=1, closed=0, joins=0, flip=None)

source code 

Draw line directly on framebuffer.

Use pygame primitive to draw a straight line on the framebuffer

Parameters:
  • pts - [(x,y)...] world coords of polyline points
  • color - any color acceptable to C()
  • width - (pixels) width of line (0 for filled polygon)
  • contig - (bool) if true (default), contiguous sequence of lines. Otherwise, each pair of points as interpreted as single broken line.
  • closed - (bool) closed polygon?
  • joins - (in) fake joins with circles? (circle r ~ joins*width)
  • flip - (boolean) flip after write
Returns:
nothing

line(self, start, stop, color, width=1, flip=None)

source code 

Draw line directly on framebuffer.

Use pygame primitive to draw a straight line on the framebuffer

Parameters:
  • start - (x,y) world coords of line's starting point
  • stop - (x,y) world coords of line's ending point
  • color - any color acceptable to C()
  • width - (pixels) width of line
  • flip - (boolean) flip after write
Returns:
nothing

circle(self, cx, cy, r, color, width=0, flip=None)

source code 

Draw circle directly on framebuffer.

NB Tue Apr 25 10:14:33 2006 mazer - GL coords are different!!! circles were flipped/mirrored around the x-axis in GL-mode!!!!

Parameters:
  • cx, cy - center coords of the circle
  • r - (pixels) radius
  • color - anything C() understands
  • width - (pixels) width of circle. If width==0, then the circle gets filled instead of just drawing an outline
Returns:
nothing