API Documentation

Inheritance diagram of luma.core.device, luma.emulator, luma.core.mixin, luma.core.virtual, luma.emulator.device

luma.emulator.device

class luma.emulator.device.capture(width=128, height=64, rotate=0, mode='RGB', transform='scale2x', scale=2, file_template='luma_{0:06}.png', **kwargs)[source]

Bases: luma.emulator.device.emulator

Pseudo-device that acts like a physical display, except that it writes the image to a numbered PNG file when the display() method is called. Supports 24-bit color depth.

capabilities(width, height, rotate, mode='1')

Assigns attributes such as width, height, size and bounding_box correctly oriented from the supplied parameters.

Parameters:
  • width (int) – The device width.
  • height (int) – The device height.
  • rotate (int) – An integer value of 0 (default), 1, 2 or 3 only, where 0 is no rotation, 1 is rotate 90° clockwise, 2 is 180° rotation and 3 represents 270° rotation.
  • mode (str) – The supported color model, one of "1", "RGB" or "RGBA" only.
cleanup()

Attempt to switch the device off or put into low power mode (this helps prolong the life of the device), clear the screen and close resources associated with the underlying serial interface.

If persist is True, the device will not be switched off.

This is a managed function, which is called when the python processs is being shutdown, so shouldn’t usually need be called directly in application code.

clear()

Initializes the device memory with an empty (blank) image.

command(*cmd)

Sends a command or sequence of commands through to the delegated serial interface.

contrast(value)

Switches the display contrast to the desired level, in the range 0-255. Note that setting the level to a low (or zero) value will not necessarily dim the display to nearly off. In other words, this method is NOT suitable for fade-in/out animation.

Parameters:level (int) – Desired contrast level in the range of 0-255.
data(data)

Sends a data byte or sequence of data bytes through to the delegated serial interface.

display(image)[source]

Takes a PIL.Image and dumps it to a numbered PNG file.

hide()

Switches the display mode OFF, putting the device in low-power sleep mode.

preprocess(image)

Provides a preprocessing facility (which may be overridden) whereby the supplied image is rotated according to the device’s rotate capability. If this method is overridden, it is important to call the super method.

Parameters:image (PIL.Image.Image) – An image to pre-process.
Returns:A new processed image.
Return type:PIL.Image.Image
show()

Sets the display mode ON, waking the device out of a prior low-power sleep mode.

to_surface(image, alpha=1.0)

Converts a PIL.Image into a pygame.Surface, transforming it according to the transform and scale constructor arguments.

class luma.emulator.device.gifanim(width=128, height=64, rotate=0, mode='RGB', transform='scale2x', scale=2, filename='luma_anim.gif', duration=0.01, loop=0, max_frames=None, **kwargs)[source]

Bases: luma.emulator.device.emulator

Pseudo-device that acts like a physical display, except that it collects the images when the display() method is called, and on exit, assembles them into an animated GIF image. Supports 24-bit color depth, albeit with an indexed color palette.

capabilities(width, height, rotate, mode='1')

Assigns attributes such as width, height, size and bounding_box correctly oriented from the supplied parameters.

Parameters:
  • width (int) – The device width.
  • height (int) – The device height.
  • rotate (int) – An integer value of 0 (default), 1, 2 or 3 only, where 0 is no rotation, 1 is rotate 90° clockwise, 2 is 180° rotation and 3 represents 270° rotation.
  • mode (str) – The supported color model, one of "1", "RGB" or "RGBA" only.
cleanup()

Attempt to switch the device off or put into low power mode (this helps prolong the life of the device), clear the screen and close resources associated with the underlying serial interface.

If persist is True, the device will not be switched off.

This is a managed function, which is called when the python processs is being shutdown, so shouldn’t usually need be called directly in application code.

clear()

Initializes the device memory with an empty (blank) image.

command(*cmd)

Sends a command or sequence of commands through to the delegated serial interface.

contrast(value)

Switches the display contrast to the desired level, in the range 0-255. Note that setting the level to a low (or zero) value will not necessarily dim the display to nearly off. In other words, this method is NOT suitable for fade-in/out animation.

Parameters:level (int) – Desired contrast level in the range of 0-255.
data(data)

Sends a data byte or sequence of data bytes through to the delegated serial interface.

display(image)[source]

Takes an image, scales it according to the nominated transform, and stores it for later building into an animated GIF.

hide()

Switches the display mode OFF, putting the device in low-power sleep mode.

preprocess(image)

Provides a preprocessing facility (which may be overridden) whereby the supplied image is rotated according to the device’s rotate capability. If this method is overridden, it is important to call the super method.

Parameters:image (PIL.Image.Image) – An image to pre-process.
Returns:A new processed image.
Return type:PIL.Image.Image
show()

Sets the display mode ON, waking the device out of a prior low-power sleep mode.

to_surface(image, alpha=1.0)

Converts a PIL.Image into a pygame.Surface, transforming it according to the transform and scale constructor arguments.

write_animation()[source]
class luma.emulator.device.pygame(width=128, height=64, rotate=0, mode='RGB', transform='scale2x', scale=2, frame_rate=60, **kwargs)[source]

Bases: luma.emulator.device.emulator

Pseudo-device that acts like a physical display, except that it renders to a displayed window. The frame rate is limited to 60FPS (much faster than a Raspberry Pi can achieve, but this can be overridden as necessary). Supports 24-bit color depth.

pygame is used to render the emulated display window, and it’s event loop is checked to see if the ESC key was pressed or the window was dismissed: if so sys.exit() is called.

capabilities(width, height, rotate, mode='1')

Assigns attributes such as width, height, size and bounding_box correctly oriented from the supplied parameters.

Parameters:
  • width (int) – The device width.
  • height (int) – The device height.
  • rotate (int) – An integer value of 0 (default), 1, 2 or 3 only, where 0 is no rotation, 1 is rotate 90° clockwise, 2 is 180° rotation and 3 represents 270° rotation.
  • mode (str) – The supported color model, one of "1", "RGB" or "RGBA" only.
cleanup()

Attempt to switch the device off or put into low power mode (this helps prolong the life of the device), clear the screen and close resources associated with the underlying serial interface.

If persist is True, the device will not be switched off.

This is a managed function, which is called when the python processs is being shutdown, so shouldn’t usually need be called directly in application code.

clear()

Initializes the device memory with an empty (blank) image.

command(*cmd)

Sends a command or sequence of commands through to the delegated serial interface.

contrast(value)

Switches the display contrast to the desired level, in the range 0-255. Note that setting the level to a low (or zero) value will not necessarily dim the display to nearly off. In other words, this method is NOT suitable for fade-in/out animation.

Parameters:level (int) – Desired contrast level in the range of 0-255.
data(data)

Sends a data byte or sequence of data bytes through to the delegated serial interface.

display(image)[source]

Takes a PIL.Image and renders it to a pygame display surface.

hide()

Switches the display mode OFF, putting the device in low-power sleep mode.

preprocess(image)

Provides a preprocessing facility (which may be overridden) whereby the supplied image is rotated according to the device’s rotate capability. If this method is overridden, it is important to call the super method.

Parameters:image (PIL.Image.Image) – An image to pre-process.
Returns:A new processed image.
Return type:PIL.Image.Image
show()

Sets the display mode ON, waking the device out of a prior low-power sleep mode.

to_surface(image, alpha=1.0)

Converts a PIL.Image into a pygame.Surface, transforming it according to the transform and scale constructor arguments.

class luma.emulator.device.asciiart(width=128, height=64, rotate=0, mode='RGB', transform='scale2x', scale=2, **kwargs)[source]

Bases: luma.emulator.device.emulator

Pseudo-device that acts like a physical display, except that it converts the image to display into an ASCII-art representation and downscales colors to match the xterm-256 color scheme. Supports 24-bit color depth.

This device takes hold of the terminal window (using curses), and any output for sysout and syserr is captured and stored, and is replayed when the cleanup method is called.

Loosely based on https://github.com/ajalt/pyasciigen/blob/master/asciigen.py

New in version 0.2.0.

capabilities(width, height, rotate, mode='1')

Assigns attributes such as width, height, size and bounding_box correctly oriented from the supplied parameters.

Parameters:
  • width (int) – The device width.
  • height (int) – The device height.
  • rotate (int) – An integer value of 0 (default), 1, 2 or 3 only, where 0 is no rotation, 1 is rotate 90° clockwise, 2 is 180° rotation and 3 represents 270° rotation.
  • mode (str) – The supported color model, one of "1", "RGB" or "RGBA" only.
cleanup()[source]

Attempt to switch the device off or put into low power mode (this helps prolong the life of the device), clear the screen and close resources associated with the underlying serial interface.

If persist is True, the device will not be switched off.

This is a managed function, which is called when the python processs is being shutdown, so shouldn’t usually need be called directly in application code.

clear()

Initializes the device memory with an empty (blank) image.

command(*cmd)

Sends a command or sequence of commands through to the delegated serial interface.

contrast(value)

Switches the display contrast to the desired level, in the range 0-255. Note that setting the level to a low (or zero) value will not necessarily dim the display to nearly off. In other words, this method is NOT suitable for fade-in/out animation.

Parameters:level (int) – Desired contrast level in the range of 0-255.
data(data)

Sends a data byte or sequence of data bytes through to the delegated serial interface.

display(image)[source]

Takes a PIL.Image and renders it to the current terminal as ASCII-art.

hide()

Switches the display mode OFF, putting the device in low-power sleep mode.

preprocess(image)

Provides a preprocessing facility (which may be overridden) whereby the supplied image is rotated according to the device’s rotate capability. If this method is overridden, it is important to call the super method.

Parameters:image (PIL.Image.Image) – An image to pre-process.
Returns:A new processed image.
Return type:PIL.Image.Image
show()

Sets the display mode ON, waking the device out of a prior low-power sleep mode.

to_surface(image, alpha=1.0)

Converts a PIL.Image into a pygame.Surface, transforming it according to the transform and scale constructor arguments.

class luma.emulator.device.asciiblock(width=128, height=64, rotate=0, mode='RGB', transform='scale2x', scale=2, **kwargs)[source]

Bases: luma.emulator.device.emulator

Pseudo-device that acts like a physical display, except that it converts the image pixels to display into colored ASCII half-blocks (ASCII code 220, ‘▄’), where the upper part background is used for one pixel, and the lower part foreground is used for the pixel on the next row. As most terminal display characters are in ratio 2:1, the half-block appears square.

Inspired by Command Line Curiosities - Making the Terminal Sing by Hamza Haiken

New in version 1.1.0.

capabilities(width, height, rotate, mode='1')

Assigns attributes such as width, height, size and bounding_box correctly oriented from the supplied parameters.

Parameters:
  • width (int) – The device width.
  • height (int) – The device height.
  • rotate (int) – An integer value of 0 (default), 1, 2 or 3 only, where 0 is no rotation, 1 is rotate 90° clockwise, 2 is 180° rotation and 3 represents 270° rotation.
  • mode (str) – The supported color model, one of "1", "RGB" or "RGBA" only.
cleanup()[source]

Attempt to switch the device off or put into low power mode (this helps prolong the life of the device), clear the screen and close resources associated with the underlying serial interface.

If persist is True, the device will not be switched off.

This is a managed function, which is called when the python processs is being shutdown, so shouldn’t usually need be called directly in application code.

clear()

Initializes the device memory with an empty (blank) image.

command(*cmd)

Sends a command or sequence of commands through to the delegated serial interface.

contrast(value)

Switches the display contrast to the desired level, in the range 0-255. Note that setting the level to a low (or zero) value will not necessarily dim the display to nearly off. In other words, this method is NOT suitable for fade-in/out animation.

Parameters:level (int) – Desired contrast level in the range of 0-255.
data(data)

Sends a data byte or sequence of data bytes through to the delegated serial interface.

display(image)[source]

Takes a PIL.Image and renders it to the current terminal as ASCII-blocks.

hide()

Switches the display mode OFF, putting the device in low-power sleep mode.

preprocess(image)

Provides a preprocessing facility (which may be overridden) whereby the supplied image is rotated according to the device’s rotate capability. If this method is overridden, it is important to call the super method.

Parameters:image (PIL.Image.Image) – An image to pre-process.
Returns:A new processed image.
Return type:PIL.Image.Image
show()

Sets the display mode ON, waking the device out of a prior low-power sleep mode.

to_surface(image, alpha=1.0)

Converts a PIL.Image into a pygame.Surface, transforming it according to the transform and scale constructor arguments.

luma.emulator.render

class luma.emulator.render.transformer(pygame, width, height, scale)[source]

Bases: object

Helper class used to dispatch transformation operations.

identity(surface)[source]

Fast scale operation that does not sample the results

led_matrix(surface)[source]

Transforms the input surface into an LED matrix (1 pixel = 1 LED)

none(surface)[source]

No-op transform - used when scale = 1

scale2x(surface)[source]

Scales using the AdvanceMAME Scale2X algorithm which does a ‘jaggie-less’ scale of bitmap graphics.

seven_segment(surface)[source]
smoothscale(surface)[source]

Smooth scaling using MMX or SSE extensions if available