Skip to main content

Headless renderer for Kivy framework

Project description

Kivy Headless Renderer

This project provides utilities to render Kivy applications headlessly. It can be used in test environments, it also provides tools for snapshot testing. It can also be used on a Raspberry Pi or similar devices to render the Kivy application on a custom display like an SPI display.

The renderer is optimized to not schedule a render when nothing has changed since the last rendered frame.

📦 Installation

pip install headless-kivy

To use its test tools, you can install it with the following command:

pip install headless-kivy[dev]

🛠 Usage

  1. Call setup_headless() before inheriting the HeadlessWidget class for the root widget of your application, and provide the optional parameters as needed. For example (these are all default values, you only need to provide the ones you want to change):

    setup_headless(
        width=240,
        height=240,
        is_debug_mode=False,
        display_class=ST7789,
        double_buffering=True,
    )
    
  2. Inherit the HeadlessWidget class for the root widget of your Kivy application. For example:

    class FboFloatLayout(FloatLayout, HeadlessWidget):
        pass
    
  3. Run the Kivy app as you normally would.

Checkout Ubo App to see a sample implementation.

⚙️ Parameters

These parameters can be set to control the behavior of headless kivy:

callback

A callback function that will be called when the screen data changes. It should have this signature:

def render(
    *,
    rectangle: tuple[int, int, int, int],
    data: NDArray[np.uint8],
    data_hash: int,
    last_render_thread: Thread,
) -> None: ...

rectangle is a tuple with the coordinates and size of the changed area in the (x, y, width, height) format.

data is a numpy array with the screen RGB data in the uint8 format. So its dimensions are (width, height, 3).

data_hash is probably not very useful for most cases, it is mostly for logging and debugging purposes.

It always runs in a new thread, the previous thread is provided so that it can call its join if desired.

width

The width of the display in pixels.

height

The height of the display in pixels.

is_debug_mode

If set to True, the application will print debug information, including FPS.

double_buffering

Is set to True, it will let Kivy generate the next frame while sending the last frame to the display.

rotation

The rotation of the display. It will be multiplied by 90 degrees.

flip_horizontal

If set to True, it will flip the display horizontally.

flip_vertical

If set to True, it will flip the display vertically.

🤝 Contributing

You need to have uv installed on your machine.

To install the required dependencies, run the following command in the root directory of the project:

uv sync

⚠️ Important Note

This project has only been tested with the ST7789 SPI display module. Other display modules might not be compatible or may require changing the parameters or even modifications to the code.

🔒 License

This project is released under the Apache-2.0 License. See the LICENSE file for more details.

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

headless_kivy-0.12.0.tar.gz (15.9 kB view details)

Uploaded Source

Built Distribution

headless_kivy-0.12.0-py3-none-any.whl (19.5 kB view details)

Uploaded Python 3

File details

Details for the file headless_kivy-0.12.0.tar.gz.

File metadata

  • Download URL: headless_kivy-0.12.0.tar.gz
  • Upload date:
  • Size: 15.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for headless_kivy-0.12.0.tar.gz
Algorithm Hash digest
SHA256 ba550a1f9b7a4cf0638d2962a842d326c3389682eaf13643f0e45379d064633f
MD5 7cfe4bcb54b7a5b050cb4af99af78d14
BLAKE2b-256 09a89e7647e1df0862aadb72f51b4ff7ac22997ed623022dbefc0928b781c28d

See more details on using hashes here.

File details

Details for the file headless_kivy-0.12.0-py3-none-any.whl.

File metadata

File hashes

Hashes for headless_kivy-0.12.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2e8b66ccfd5fbef1b1ac1aa54bc8f1bbed344f2caed3986a75c59c900957445b
MD5 8d11fb95719be71034286e9dc203383d
BLAKE2b-256 5c5c8b55833169f24e804cd1bec5523a32e3a31465d72025347fd603726b66af

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page