Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 27 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,34 @@ Then install indiepixel
uv add indiepixel
```

Create a basic example: for example, copy [clock.py](https://github.com/tmcw/indiepixel/blob/main/examples/cli/clock.py) to the current directory.
Create a widget file, like `clock.py`:

Then run:
```python
import datetime
from indiepixel import Box, Root, Row, Text

def main():
now = datetime.datetime.now()
return Root(
child=Box(
Row(children=[
Text(content=now.strftime("%I:%M %p"), color="#fff"),
]),
padding=2,
background="#000",
),
)
```

Then run it:

```
uv run indiepixel clock.py
```

Then, bam! You've got that clock rendering. If you want to get fancier,
you can create a directory of widgets and move `clock.py` into it, point
indiepixel at that, and it'll show all of them rendered in its web interface.
Open http://localhost:5000 in your browser and you'll see the clock rendering.
You can also point indiepixel at a directory of widget files and it'll show
all of them in its web interface.

## Deploying

Expand Down Expand Up @@ -108,7 +125,7 @@ uv run pre-commit install

### Running examples

To run `examples/kitchen_sink.py`:
To run examples:

```
uv run indiepixel examples/cli/gradient.py
Expand Down Expand Up @@ -152,8 +169,9 @@ _* = currently not tidbyt-compatible_
- [x] Text
- [x] Box*
- [x] Rect*
- [x] Column*
- [x] Column
- [x] Row
- [x] Root
- [x] Stack
- [x] Circle
- [x] PieChart
Expand All @@ -162,5 +180,5 @@ _* = currently not tidbyt-compatible_
- [x] WrappedText
- [ ] Resizing
- [ ] Animation
- [ ] Plot
- [ ] 'expand' option
- [x] Plot
- [x] Row/Column `expanded`, `main_align`, `cross_align`
3 changes: 2 additions & 1 deletion examples/cli/animated_image.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
"""Render an animation."""

from indiepixel import Animation, Image
from pathlib import Path

from indiepixel import Image


def main():
"""
Expand Down
1 change: 0 additions & 1 deletion examples/cli/animation_nested.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ def main():
This matches the example in https://github.com/tidbyt/pixlet/blob/main/docs/widgets.md#stack
Successfully matches!
"""

return Animation(
debug_label="Outer",
children=[
Expand Down
3 changes: 2 additions & 1 deletion examples/cli/image.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
"""Render an animation."""

from indiepixel import Animation, Image
from pathlib import Path

from indiepixel import Image


def main():
"""
Expand Down
58 changes: 5 additions & 53 deletions examples/kitchen_sink.py → examples/cli/kitchen_sink.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,15 @@
"""Interactive kitchen sink example."""
"""Render a bunch of stuff."""

# ruff: noqa: D103
from io import BytesIO
from pathlib import Path

from flask import Flask, send_file
from PIL import Image as ImagePIL
from PIL import ImageDraw

# import pytz
from indiepixel import Box, Column, Image, Rect, Row, Text


def render():
frames = []
im = ImagePIL.new("RGB", (64, 32))
draw = ImageDraw.Draw(im)
draw.fontmode = "1"
def main():
"""Render a bunch of stuff."""
# tz = pytz.timezone("America/New_York")
layout = Box(
return Box(
Column(
[
Row(
Expand All @@ -28,7 +19,7 @@ def render():
Rect(width=4, height=4, color="orange"),
Rect(width=4, height=4, color="blue"),
],
expand=True,
expanded=True,
),
Row(
[
Expand Down Expand Up @@ -150,42 +141,3 @@ def render():
# ]),
# padding=2, background=(100, 0, 0, 255)
# )
layout.paint(draw, im, (0, 0, 64, 32), 0)
frames.append(im)
return frames


app = Flask(__name__)


@app.route("/")
def root() -> str:
return (
"<p><img "
"style='image-rendering:pixelated;height:320px;width:640px;' "
"src='./image.webp' />"
"</p>"
)


@app.route("/image.webp")
def image():
img_io = BytesIO()
rendered = render()
# It's very important to specify lossless=True here,
# otherwise we get blurry output
rendered[0].save(
img_io,
"WEBP",
lossless=True,
alpha_quality=100,
save_all=True,
append_images=rendered[1:],
duration=100,
)
img_io.seek(0)
return send_file(img_io, mimetype="image/webp")


if __name__ == "__main__":
app.run(debug=True, port=5000)
143 changes: 0 additions & 143 deletions examples/cli/kitchen_sink_cli.py

This file was deleted.

26 changes: 26 additions & 0 deletions examples/cli/plot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
"""Render a plot."""

import math

from indiepixel import Box, Plot, Root


def main():
"""Render a sine wave plot."""
data = [(x / 4, math.sin(x / 4)) for x in range(80)]
return Root(
child=Box(
Plot(
data=data,
width=60,
height=28,
color="#0ff",
color_inverted="#f80",
fill=True,
fill_color="#033",
fill_color_inverted="#330",
),
padding=2,
background="#000",
),
)
6 changes: 6 additions & 0 deletions renovate.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
"extends": [
"config:recommended"
]
}
Loading
Loading