Skip to content

Commit

Permalink
Merge pull request #93 from ty-porter/dev
Browse files Browse the repository at this point in the history
Release v0.12.3
  • Loading branch information
ty-porter authored Feb 3, 2025
2 parents 6851aa9 + 775510e commit 7d163de
Show file tree
Hide file tree
Showing 68 changed files with 392 additions and 13 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/black.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: black

on: [push]

jobs:
build:

runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.11", "3.12", "3.13"]

steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install hatch
- name: hatch run test:lint_check
run: |
hatch run test:lint_check
26 changes: 26 additions & 0 deletions .github/workflows/unittest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: unittest

on: [push]

jobs:
build:

runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.11", "3.12", "3.13"]

steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install hatch
- name: hatch run test:run
run: |
hatch run test:run
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ __pycache__/
dist
MANIFEST
tmp
emulator_config.json
emulator_config.json
test/result/*
*.bak
47 changes: 43 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

![hello-world](assets/hello-world.gif)

`RGBMatrixEmulator` is a Python package for emulating RGB LED matrices that are normally driven by the `rpi-rgb-led-matrix` library. Most commonly, these are used with single-board computers such as the Raspberry Pi.
`RGBMatrixEmulator` is a Python package for emulating RGB LED matrices that are normally driven by the [rpi-rgb-led-matrix library](https://github.com/hzeller/rpi-rgb-led-matrix). Most commonly, these are used with single-board computers such as the Raspberry Pi.

`RGBMatrixEmulator` (currently) supports a subset of the function calls present in the Python bindings for `rpi-rgb-led-matrix`. As such, it's accuracy is not 100% guaranteed.
`RGBMatrixEmulator` (currently) supports a subset of the function calls present in the [Python bindings for rpi-rgb-led-matrix](https://github.com/hzeller/rpi-rgb-led-matrix/tree/master/bindings/python). As such, it's accuracy is not 100% guaranteed.

## Installation

Expand Down Expand Up @@ -149,9 +149,48 @@ See [Samples README](samples/README.md) for more information about running examp
- Drawing large strings is slow, partly because of the `linelimit` parameter in the BDF font parser this emulator uses to prevent multiline text from being rendered unintentionally.

## Contributing
If you want to help develop RGBMatrixEmulator, you must also install the dev dependencies, which can be done by running ``pip install -e .[dev]`` from within the directory.

Before submitting a PR, please open an issue to help us track development. All development should be based off of the `dev` branch. This branch is kept up-to-date with `main` after releases.
### Pull Requests

Before submitting a PR, please open an issue to help us track development. All development should be based off of the `dev` branch. This branch is kept up-to-date with `main` after releases.

Pull requests that fail builds will not be merged.

### Installing Locally

RGBME uses `hatch` to manage dependencies. To enter a hatch shell:

```sh
hatch shell dev

# Example:
# To run a sample script:
(rgbmatrixemulator) cd samples
(rgbmatrixemulator) python runtext.py
```
---
> [!NOTE]
> hatch has an issue dealing with keyboard interrupts (such as CTRL + C), which is heavily used to stop emulated scripts.
>
> See https://github.com/pypa/hatch/issues/1633 and https://github.com/pypa/hatch/issues/1647
>
> Until this is resolved, you may want to install RGBME directly instead:
> ```sh
> pip install -e .[dev]
> ```
---
#### Running Tests
```sh
hatch run test:run
```
#### Lint

```sh
hatch run test:lint
```

## Contact

Expand Down
12 changes: 10 additions & 2 deletions RGBMatrixEmulator/adapters/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import importlib, json
import importlib, json, os

from RGBMatrixEmulator.logger import Logger

Expand Down Expand Up @@ -33,6 +33,11 @@
"class": "TurtleAdapter",
"type": "turtle",
},
{
"path": "RGBMatrixEmulator.adapters.raw_adapter",
"class": "RawAdapter",
"type": "raw",
},
]

ADAPTER_TYPES = {}
Expand All @@ -55,7 +60,10 @@

ADAPTER_TYPES[adapter_name] = adapter
except Exception as ex:
if suppress_adapter_load_errors:
if (
suppress_adapter_load_errors
or os.environ["RGBME_SUPPRESS_ADAPTER_LOAD_ERRORS"]
):
continue

Logger.exception(
Expand Down
43 changes: 43 additions & 0 deletions RGBMatrixEmulator/adapters/raw_adapter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
from RGBMatrixEmulator.adapters.base import BaseAdapter

from PIL import Image

import numpy as np


class RawAdapter(BaseAdapter):
MAX_FRAMES_STORED = 128
DEFAULT_MAX_FRAME = -1 # Never halts

def __init__(self, width, height, options):
super().__init__(width, height, options)

self._reset()

def draw_to_screen(self, pixels):
self.frames[self.frame] = pixels

if self.frame - self.MAX_FRAMES_STORED in self.frames:
del self.frames[self.frame - RawAdapter.MAX_FRAMES_STORED]

self.frame += 1

if self.halt_after > 0 and self.frame >= self.halt_after:
self.halt_fn()

def load_emulator_window(self):
pass

def _dump_screenshot(self, path):
image = Image.fromarray(np.array(self._last_frame(), dtype="uint8"), "RGB")
image.save(path)

def _last_frame(self):
return self.frames[self.frame - 1]

def _reset(self):
self.frames = {}
self.frame = 0

self.halt_after = RawAdapter.DEFAULT_MAX_FRAME
self.halt_fn = lambda: 1 + 1
2 changes: 1 addition & 1 deletion RGBMatrixEmulator/emulation/canvas.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def brightness(self, value):

def __create_pixel(self, pixel):
return Color.adjust_brightness(tuple(pixel), self.brightness / 100.0)

def __pixel_out_of_bounds(self, x, y):
if x < 0 or x >= self.width:
return True
Expand Down
8 changes: 4 additions & 4 deletions RGBMatrixEmulator/emulation/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def window_size_str(self, pixel_text=""):


class RGBMatrixEmulatorConfig:
__CONFIG_PATH = "emulator_config.json"
CONFIG_PATH = "emulator_config.json"

VALID_PIXEL_STYLES = ["square", "circle"]
DEFAULT_CONFIG = {
Expand Down Expand Up @@ -124,13 +124,13 @@ def __init__(self):
RGBMatrixEmulatorConfig.Utils.set_attributes(self)

def __load_config(self):
if os.path.exists(self.__CONFIG_PATH):
with open(self.__CONFIG_PATH) as f:
if os.path.exists(self.CONFIG_PATH):
with open(self.CONFIG_PATH) as f:
config = json.load(f)

return config

with open(self.__CONFIG_PATH, "w") as f:
with open(self.CONFIG_PATH, "w") as f:
json.dump(self.DEFAULT_CONFIG, f, indent=4)

return self.DEFAULT_CONFIG
Expand Down
2 changes: 1 addition & 1 deletion RGBMatrixEmulator/version.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env python

# package version
__version__ = "0.12.2"
__version__ = "0.12.3"
"""Installed version of RGBMatrixEmulator."""
11 changes: 11 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,14 @@ LICENSE = "docs/LICENSE"
include = [
"/rgbmatrixemulator",
]

[tool.hatch.envs.test]
dependencies = [
"parameterized",
"black"
]

[tool.hatch.envs.test.scripts]
run = "python -m unittest discover -s test"
lint = "black ."
lint_check = "black . --check"
1 change: 1 addition & 0 deletions samples/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import samples.samplebase
Loading

0 comments on commit 7d163de

Please sign in to comment.