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 work on a non-RPi environment, run this:
# pip:
pip install headless-kivy[dev]
# poetry:
poetry --group dev headless-kivy
🛠 Usage
-
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( min_fps=1, max_fps=30, width=240, height=240, is_debug_mode=False, display_class=ST7789, double_buffering=True, automatic_fps=True, )
-
Inherit the
HeadlessWidget
class for the root widget of your Kivy application. For example:class FboFloatLayout(FloatLayout, HeadlessWidget): pass
-
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.
min_fps
Minimum frames per second for when the Kivy application is idle.
max_fps
Maximum frames per second for the Kivy application.
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.
automatic_fps
If set to True
, it will monitor the hash of the screen data, if this hash changes,
it will increase the fps to the maximum and if the hash doesn't change for a while,
it will drop the fps to the minimum.
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 Poetry installed on your machine.
After having poetry, to install the required dependencies, run the following command in the root directory of the project:
poetry install
⚠️ 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
Built Distribution
File details
Details for the file headless_kivy-0.10.1.dev1241025103549954985348100.tar.gz
.
File metadata
- Download URL: headless_kivy-0.10.1.dev1241025103549954985348100.tar.gz
- Upload date:
- Size: 14.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 302741b48bd35b005f5b3d4aaf59c5310b37c6064e2aea411e61fad718322814 |
|
MD5 | 341a6705abbf99573fa02946d642c41f |
|
BLAKE2b-256 | f36363017a1b624e5f2832a04ecdae3f40989e1db2f24115c32031c9d82514f2 |
File details
Details for the file headless_kivy-0.10.1.dev1241025103549954985348100-py3-none-any.whl
.
File metadata
- Download URL: headless_kivy-0.10.1.dev1241025103549954985348100-py3-none-any.whl
- Upload date:
- Size: 17.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8cede7be74498f01c1d8f2944b4af1f9c69d2da14a8079c10f65bce78092d1a8 |
|
MD5 | 8e23aa1e4fb47aaae928a85e5b763929 |
|
BLAKE2b-256 | 7e75fd24fdc7130f5337d8796ee65d8d7ca8fea67e2fc78be3833fc83caa98de |