Skip to content

Commit

Permalink
fix: slice the data in case it exceeds the size of the display
Browse files Browse the repository at this point in the history
  • Loading branch information
sassanh committed Aug 17, 2024
1 parent 61ad609 commit d6acb3d
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 34 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## Version 0.9.7

- fix: slice the data in case it exceeds the size of the display

## Version 0.9.6

- fix: make it compatible with kivy 3
Expand Down
8 changes: 5 additions & 3 deletions headless_kivy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
from kivy.graphics.gl_instructions import ClearBuffers, ClearColor
from kivy.graphics.instructions import Canvas
from kivy.graphics.vertex_instructions import Rectangle
from kivy.metrics import dp
from kivy.properties import ObjectProperty
from kivy.uix.widget import Widget

Expand Down Expand Up @@ -253,10 +254,11 @@ def render_on_display(self: HeadlessWidget, *_: object) -> None:
except Empty:
last_thread = None

height = int(self.height)
width = int(self.width)
height = min(int(self.height), dp(config.height()) - self.y)
width = min(int(self.width), dp(config.width()) - self.x)

data = data.reshape(height, width, -1)
data = data.reshape(int(self.height), int(self.width), -1)
data = data[:height, :width, :]
data = apply_tranformations(data)

if config.rotation() % 2 == 0:
Expand Down
3 changes: 0 additions & 3 deletions headless_kivy/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,6 @@ def setup_headless_kivy(config: SetupHeadlessConfig) -> None:
---------
config: `SetupHeadlessConfig`
splash_screen: `bytes`
it should have a length of `width` x `height` x 2
"""
global _config # noqa: PLW0603
_config = config
Expand Down
4 changes: 2 additions & 2 deletions headless_kivy_pytest/fixtures/snapshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,13 +152,13 @@ def close(self: WindowSnapshot) -> None:
assert not hash_path.exists(), f'Snapshot {filename} not taken'


@pytest.fixture()
@pytest.fixture
def snapshot_prefix() -> str | None:
"""Return the prefix for the snapshots."""
return None


@pytest.fixture()
@pytest.fixture
def window_snapshot(
request: SubRequest,
snapshot_prefix: str | None,
Expand Down
46 changes: 23 additions & 23 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "headless-kivy"
version = "0.9.6"
version = "0.9.7"
description = "Headless renderer for Kivy framework"
authors = ["Sassan Haradji <[email protected]>"]
license = "Apache-2.0"
Expand All @@ -26,8 +26,8 @@ test = ['pypng']

[tool.poetry.group.dev.dependencies]
poethepoet = "^0.24.2"
ruff = "^0.5.0"
pyright = "^1.1.370"
ruff = "^0.6.1"
pyright = "^1.1.376"
pytest = "^8.2.2"

[build-system]
Expand Down

0 comments on commit d6acb3d

Please sign in to comment.