Metadata-Version: 2.4
Name: sd_controls
Version: 0.0.16
Summary: A small and simple framework for streamdeck applications
Home-page: https://github.com/niklasr22/streamdeck-controls
Author: Niklas Rousset
Author-email: byrousset@gmail.com
License: MIT
Project-URL: Bug Tracker, https://github.com/niklasr22/streamdeck-controls/issues
Keywords: streamdeck
Classifier: Programming Language :: Python :: 3
Classifier: Operating System :: OS Independent
Requires-Python: >=3.12
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: hid>=1.0.9
Requires-Dist: Pillow>=13.0.0
Provides-Extra: dev
Requires-Dist: build>=1.6.1; extra == "dev"
Requires-Dist: twine>=7.0; extra == "dev"
Requires-Dist: ruff>=0.17.3; extra == "dev"
Dynamic: license-file

# Streamdeck controls

This project is a simple and small framework which simplifies developing and running custom apps for streamdeck devices.
It allows using streamdecks without the official software so you can use it with any major OS.

## Currently supported Streamdecks

- Streamdeck Mk.2

## Installing

### Prerequisites

- Python 3.12 or newer (development targets Python 3.15)

- [hidapi](https://github.com/libusb/hidapi)

Linux:

```bash
sudo apt install libhidapi-dev
```

macOS:

```bash
brew install hidapi
```

### Installing sd-controls

```bash
pip install sd-controls
```

## Development

```bash
python3.15 -m venv .venv
source .venv/bin/activate
python -m pip install -e ".[dev]"
python -m unittest discover -v
python -m ruff check .
python -m build
```

The virtual deck also requires Tkinter (often a separate OS package).
The test suite uses fake devices and does not require connected hardware.

## Contributing

If you are interested in this project and have a streamdeck, please consider contributing to it.
Adding support for other Streamdecks is greatly appreciated but feel free to propose any other changes too!

## Using this software with Linux (Linux udev rules)

Create a `/etc/udev/rules.d/50-elgato.rules` file with the following content:

```rules
SUBSYSTEM=="input", GROUP="input", MODE="0666"
SUBSYSTEM=="usb", ATTRS{idVendor}=="0fd9", ATTRS{idProduct}=="0080", MODE:="666", GROUP="plugdev"
KERNEL=="hidraw*", ATTRS{idVendor}=="0fd9", ATTRS{idProduct}=="0080", MODE:="666", GROUP="plugdev"
```

## Example app

```python
from PIL import Image
from sd_controls.sdsystem import SDSystem, SDUserApp, Sprites


class HelloWorldApp(SDUserApp):
    _KEY_GREET = 1
    _KEY_ROTATE = 2

    def __init__(self) -> None:
        super().__init__("Settings")
        self._icon = SDUserApp.generate_labeled_img(Sprites.CLEAR, "Hello World")
        self._hello = SDUserApp.generate_labeled_img(Sprites.CLEAR, "Hello")
        self._world = SDUserApp.generate_labeled_img(Sprites.CLEAR, "World")
        self._rotate_key = Sprites.GOAT

    def get_icon(self) -> Image.Image:
        return self._icon

    def init(self) -> None:
        self.set_key(self._KEY_GREET, self._hello)
        self.set_key(self._KEY_ROTATE, self._rotate_key)

    def keys_update(self, keys_before: list[bool], keys: list[bool]) -> None:
        if not keys[self._KEY_GREET] and keys_before[self._KEY_GREET]:
            self.set_key(self._KEY_GREET, self._world)
        if not keys[self._KEY_ROTATE] and keys_before[self._KEY_ROTATE]:
            self._rotate_key = self._rotate_key.rotate(90)
            self.set_key(self._KEY_ROTATE, self._rotate_key)
            

system = SDSystem()
system.register_app(HelloWorldApp())
system.start()
```
