2. cairotft package

2.2. Submodules

2.3. cairotft.linuxfb module

Small wrapping of linux/fb.h.

update for cairotft: this module has been modified to support

double buffering and is not api-compatible anymore with the original module from Kurichan.

It has also been modified for python 3.4 compat’

class cairotft.linuxfb.FbBitField[source]

Bases: _ctypes.Structure

The fb_bitfield struct from fb.h.

_fields_ = [('offset', <class 'ctypes.c_uint'>), ('length', <class 'ctypes.c_uint'>), ('msb_right', <class 'ctypes.c_uint'>)]
length

Structure/Union member

msb_right

Structure/Union member

offset

Structure/Union member

class cairotft.linuxfb.FbFid[source]

Bases: builtins.int

The framebuffer file descriptor.

The name attribute gives the opened framebuffer file.

class cairotft.linuxfb.FbMem[source]

Bases: builtins.object

The framebuffer memory object.

Made of:
  • the framebuffer file descriptor
  • the fix screen info struct
  • the var screen info struct
  • the mapped memory
fid
fix_info
mmap
var_info
class cairotft.linuxfb.FixScreenInfo[source]

Bases: _ctypes.Structure

The fb_fix_screeninfo from fb.h.

_fields_ = [('id_name', <class 'cairotft.linuxfb.c_char_Array_16'>), ('smem_start', <class 'ctypes.c_ulong'>), ('smem_len', <class 'ctypes.c_uint'>), ('type', <class 'ctypes.c_uint'>), ('type_aux', <class 'ctypes.c_uint'>), ('visual', <class 'ctypes.c_uint'>), ('xpanstep', <class 'ctypes.c_ushort'>), ('ypanstep', <class 'ctypes.c_ushort'>), ('ywrapstep', <class 'ctypes.c_ushort'>), ('line_length', <class 'ctypes.c_uint'>), ('mmio_start', <class 'ctypes.c_ulong'>), ('mmio_len', <class 'ctypes.c_uint'>), ('accel', <class 'ctypes.c_uint'>), ('reserved', <class 'cairotft.linuxfb.c_ushort_Array_3'>)]
accel

Structure/Union member

id_name

Structure/Union member

line_length

Structure/Union member

mmio_len

Structure/Union member

mmio_start

Structure/Union member

reserved

Structure/Union member

smem_len

Structure/Union member

smem_start

Structure/Union member

type

Structure/Union member

type_aux

Structure/Union member

visual

Structure/Union member

xpanstep

Structure/Union member

ypanstep

Structure/Union member

ywrapstep

Structure/Union member

class cairotft.linuxfb.VarScreenInfo[source]

Bases: _ctypes.Structure

The fb_var_screeninfo struct from fb.h.

_fields_ = [('xres', <class 'ctypes.c_uint'>), ('yres', <class 'ctypes.c_uint'>), ('xres_virtual', <class 'ctypes.c_uint'>), ('yres_virtual', <class 'ctypes.c_uint'>), ('xoffset', <class 'ctypes.c_uint'>), ('yoffset', <class 'ctypes.c_uint'>), ('bits_per_pixel', <class 'ctypes.c_uint'>), ('grayscale', <class 'ctypes.c_uint'>), ('red', <class 'cairotft.linuxfb.FbBitField'>), ('green', <class 'cairotft.linuxfb.FbBitField'>), ('blue', <class 'cairotft.linuxfb.FbBitField'>), ('transp', <class 'cairotft.linuxfb.FbBitField'>)]
bits_per_pixel

Structure/Union member

blue

Structure/Union member

grayscale

Structure/Union member

green

Structure/Union member

red

Structure/Union member

transp

Structure/Union member

xoffset

Structure/Union member

xres

Structure/Union member

xres_virtual

Structure/Union member

yoffset

Structure/Union member

yres

Structure/Union member

yres_virtual

Structure/Union member

cairotft.linuxfb.cairo_surface_from_fbmem(fbmem, mem, cairo_format)[source]

Create a cairo surface from FbMem object.

Parameters:
  • fbmem – framebuffer memory object
  • mem – the memory buffer, either created directly or via mmap
  • cairo_format (int) – cairo pixel format.
cairotft.linuxfb.close_fbdev(fbfid)[source]

Close the framebuffer file descriptor.

cairotft.linuxfb.close_fbmem(fbmem)[source]

Close the FbMem framebuffer memory object.

cairotft.linuxfb.get_fix_info(fbfid)[source]

Return the fix screen info from the framebuffer file descriptor.

cairotft.linuxfb.get_var_info(fbfid)[source]

Return the var screen info from the framebuffer file descriptor.

cairotft.linuxfb.map_fb_memory(fbfid, fix_info)[source]

Map the framebuffer memory.

cairotft.linuxfb.memory_buffer(buffer_len)[source]

Create a memory buffer of buffer_len size.

this memory buffer can be used to create a custom cairo surface for double buffering (or n-buffering)

Parameters:buffer_len (int) – size of the buffer.
Returns:the created buffer
cairotft.linuxfb.open_fbdev(fbdev=None)[source]

Return the framebuffer file descriptor.

Try to use the FRAMEBUFFER environment variable if fbdev is not given. Use ‘/dev/fb0’ by default.

cairotft.linuxfb.open_fbmem(fbdev=None)[source]

Create the FbMem framebuffer memory object.

2.4. cairotft.svg_image module

Load an display a svg image in cairo context.

This module is a modified version of the svg_image module from WeasyPrint: https://github.com/Kozea/WeasyPrint/blob/master/weasyprint/images.py#L99

exception cairotft.svg_image.ImageLoadingError[source]

Bases: builtins.ValueError

An error occured when loading an image.

The image data is probably corrupted or in an invalid format.

classmethod from_exception(exception)[source]

Instanciate the class with the given exception.

class cairotft.svg_image.SVGImage(base_url, svg_data=None)[source]

Bases: builtins.object

SVGImage class.

_render()[source]

Draw to a cairo surface but do not write to a file.

This is a CairoSVG surface, not a cairo surface.

static _scale_to_fit(image, frame, enlarge=False)[source]

scale an image always keeping aspect ratio inside the frame.

Parameters:
  • image – tuple of int (width, eight)
  • fram – tuple of int (width, eight)
  • enlarge (bool) – if True, do not only shrink, also enlarge.
:returns= a (widht, eight) tuple representing the target size of the
object.

(thanks to jon for this method)

draw(context, pos_x, pos_y, width, height, enlarge=True, center_y=False)[source]

Draw the svg image inside a box of size (width, eight).

This draw methods keeps automatically the aspect ration of the image.

Parameters:
  • context – cairo context
  • pos_x (int) – x position (top left corner)
  • pos_y (int) – y position (top left corner)
  • width (int) – width of the box the image will fit inside
  • height (int) – height of the box the image will fit inside
  • enlarge (bool) – if true and if the base image is smaller than the box, it will enlarge the image. If False, display the original smaller image.
  • center_y (bool) – if True add an offset to y in order to center the image into the box.
get_intrinsic_size(_image_resolution)[source]

Return a tuple: (intrinsic_width, intrinsic_height).

class cairotft.svg_image.ScaledSVGSurface(tree, output, dpi, parent_surface=None)[source]

Bases: cairosvg.surface.SVGSurface

Have the cairo Surface object have dimension in px instead of pt.

device_units_per_user_units[source]

Force an eventual new scale.

In this case, does nothing new.

2.5. cairotft.tft module

Class for display on tft using linuxfb.

class cairotft.tft.TftDisplay(interface='/dev/fb0', cairo_format=0)[source]

Bases: builtins.object

Display class for the tft display.

blank_screen(ctx, color=(0, 0, 0, 1), blit=True)[source]

Blank the screen with the given color.

Parameters:
  • ctx (cairocffi.Context) – cairocffi context
  • color – 4 int tuple reprensentig the rgba color.
blit()[source]

Display the buffer in the screen.

Take the content of the memory buffer and draw it on the screen.

close()[source]

Close the interface.

draw_interface(ctx)[source]

Method that should be overriden by subclasses.

run()[source]

main loop.

2.6. cairotft.transitions module

Transitions classes.

The Transitions are used in animations to calculates new object positions based on some parameters like transition time, transition type, etc...

Idea and implementation is taken from mootools Fx project: https://github.com/mootools/mootools-core/blob/master/Source/Fx/Fx.Transitions.js

see: http://www.chipwreck.de/blog/2010/02/17/mootools-transitions-explained/

class cairotft.transitions.BackTransition[source]

Bases: cairotft.transitions.BaseTransition

Back transition.

Back moves the value first in the opposite direction and then moves it in direction of the target value.

classmethod pos(progress=0)[source]

calculate pos based on progress value, progress is between 0 and 1.

Parameters:progress (float) – the wanted progression of the transition.
class cairotft.transitions.BaseTransition[source]

Bases: builtins.object

Base class for all transitions.

This class will be subclassed by every transition type.

classmethod ease_in(progress=0)[source]

Method to calculate transition for easeIn display.

Ease in is the default behaviour: Here the function is applied normally.

classmethod ease_in_out(progress=0)[source]

Method to calculate transition for easeInOut display.

Ease in and out is more complex:
In the first half of the time the transition is applied normally, in the second half it is applied reverse.
classmethod ease_out(progress=0)[source]

Method to calculate transition for easeOut display.

Ease out inverts the behaviour - so the effect works backwards.

classmethod pos(progress=0)[source]

calculate pos based on progress value, progress is between 0 and 1.

Parameters:progress (float) – the wanted progression of the transition. 0 is the ‘beginning’ of the transition, i.e. 0% of the transition 1 is the ‘end’ of the transition, i.e. 100% of the transition.

This method is defined in subclasses based on the transition type.

class cairotft.transitions.BounceTransition[source]

Bases: cairotft.transitions.BaseTransition

Bounce transition.

Bounce is the most complex function - it can’t be described as a simple formula. It first approaches the target value linear and then it oscillates between descreasing intervals, creating a bouncing effect.

classmethod pos(progress=0)[source]

calculate pos based on progress value, progress is between 0 and 1.

Parameters:progress (float) – the wanted progression of the transition.
class cairotft.transitions.CircTransition[source]

Bases: cairotft.transitions.BaseTransition

Circular transition.

The circular transition function describes a perfect circle (in this case a quadrant)

classmethod pos(progress=0)[source]

calculate pos based on progress value, progress is between 0 and 1.

Parameters:progress (float) – the wanted progression of the transition.
class cairotft.transitions.CubicTransition[source]

Bases: cairotft.transitions.BaseTransition

Cubic (x^3) transition.

Polynomial (x^n) Transition. For these transition the value will first increase slowly and near the end of the effect it will grow rapidly - like the well-known parabola.

classmethod pos(progress=0)[source]

calculate pos based on progress value, progress is between 0 and 1.

Parameters:progress (float) – the wanted progression of the transition.
class cairotft.transitions.ElasticTransition[source]

Bases: cairotft.transitions.BaseTransition

Elastic transition.

Elastic oscillates in increasing intervals between the opposite direction and the desired one. It’s best used with ease:out or ease:in:out, otherwise it may happen that effect doesn’t reach its target value.

classmethod pos(progress=0)[source]

calculate pos based on progress value, progress is between 0 and 1.

Parameters:progress (float) – the wanted progression of the transition.
class cairotft.transitions.ExpoTransition[source]

Bases: cairotft.transitions.BaseTransition

Exponancial transition.

So the function grows even more rapidly towards the end - compared to the x^n-transitions.

classmethod pos(progress=0)[source]

calculate pos based on progress value, progress is between 0 and 1.

Parameters:progress (float) – the wanted progression of the transition.
class cairotft.transitions.LinearTransition[source]

Bases: cairotft.transitions.BaseTransition

Simple linear transition.

A linear transition has no additional ease-parameter, since it simply divides the range equally along the timeline.

classmethod pos(progress=0)[source]

calculate pos based on progress value, progress is between 0 and 1.

Parameters:progress (float) – the wanted progression of the transition.
class cairotft.transitions.PowTransition[source]

Bases: cairotft.transitions.BaseTransition

x^6 transition.

Polynomial (x^n) Transition. For these transition the value will first increase slowly and near the end of the effect it will grow rapidly - like the well-known parabola.

classmethod pos(progress=0)[source]

calculate pos based on progress value, progress is between 0 and 1.

Parameters:progress (float) – the wanted progression of the transition.
class cairotft.transitions.QuadTransition[source]

Bases: cairotft.transitions.BaseTransition

Quad (x^2) transition.

Polynomial (x^n) Transition. For these transition the value will first increase slowly and near the end of the effect it will grow rapidly - like the well-known parabola.

classmethod pos(progress=0)[source]

calculate pos based on progress value, progress is between 0 and 1.

Parameters:progress (float) – the wanted progression of the transition.
class cairotft.transitions.QuartTransition[source]

Bases: cairotft.transitions.BaseTransition

x^4 transition.

Polynomial (x^n) Transition. For these transition the value will first increase slowly and near the end of the effect it will grow rapidly - like the well-known parabola.

classmethod pos(progress=0)[source]

calculate pos based on progress value, progress is between 0 and 1.

Parameters:progress (float) – the wanted progression of the transition.
class cairotft.transitions.QuintTransition[source]

Bases: cairotft.transitions.BaseTransition

x^5 transition.

Polynomial (x^n) Transition. For these transition the value will first increase slowly and near the end of the effect it will grow rapidly - like the well-known parabola.

classmethod pos(progress=0)[source]

calculate pos based on progress value, progress is between 0 and 1.

Parameters:progress (float) – the wanted progression of the transition.
class cairotft.transitions.SineTransition[source]

Bases: cairotft.transitions.BaseTransition

Sinus transition.

The sinusiodal transition delivers a graph which behaves like a part of a sine-curve, the result in this case is a smooth, nearly linear transition (see the graph below).

classmethod pos(progress=0)[source]

calculate pos based on progress value, progress is between 0 and 1.

Parameters:progress (float) – the wanted progression of the transition.

2.7. Module contents

cairotft module.