Skip to content

Commit f126cc1

Browse files
committed
feat(py): add copy_rect and bezier2 methods
Also return an object from __exit__ - that's important.
1 parent c9ee2b5 commit f126cc1

File tree

2 files changed

+32
-3
lines changed

2 files changed

+32
-3
lines changed

bindings/py/examples/drawing.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/usr/bin/env python3
2+
3+
"""Create a pane and keep it around for a few seconds."""
4+
5+
import ttds_py
6+
import time
7+
8+
NET_LOC = "100.95.28.105:8080"
9+
NAME = "unique-name"
10+
11+
# Create a connection to NET_LOC. For testing purposes, I've got this hardcoded
12+
# to my testing machine's IP, but you'll probably want to make it
13+
# ttds.tali.network.
14+
conn = ttds_py.Connection(NET_LOC)
15+
16+
# Create a pane with the given name and set it to a dark blue-ish color.
17+
with ttds_py.Pane(NAME, ttds_py.Color(12, 12, 34), conn) as pane:
18+
# Keep it around for a second. Once sleep is done and the with block's
19+
# scope is exited, the pane will be deleted.
20+
#
21+
# Note that five seconds might not be long enough for your pane to come up
22+
# on the display if others are switching theirs in and out.
23+
pane.bezier2(0, 0, 200, 200, 500, 500, ttds_py.Color(100, 100, 255))
24+
pane.copy_rect(0, 0, 200, 200, 300, 200)
25+
time.sleep(5)

bindings/py/ttds_py/__init__.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,12 @@ class Pane:
5858

5959
def __enter__(self):
6060
self._token = self.conn.request("pane", self.name, "create", color=self.color)
61+
return self
6162

6263
def __exit__(self, exc_type, exc_val, exc_traceback):
6364
assert self._token is not None
6465
self.conn.request("pane", self.name, auth=self._token, method="DELETE")
6566

66-
# TODO: copy_rect, bezier2 methods.
67-
# Also, a testing environment in which I port forward into
68-
# ttds.tali.network or the like.
6967
def rect(self, x: int, y: int, w: int, h: int, color: Color):
7068
self._draw("rect", x=x, y=y, w=w, h=h, color=color)
7169

@@ -75,6 +73,12 @@ def circle(self, x: int, y: int, r: int, color: Color):
7573
def line(self, x: int, y: int, x2: int, y2: int, color: Color):
7674
self._draw("line", x=x, y=y, x2=x2, y2=y2, color=color)
7775

76+
def copy_rect(self, x: int, y: int, w: int, h: int, x2: int, y2: int):
77+
self._draw("copy_rect", x=x, y=y, w=w, h=h, x2=x2, y2=y2)
78+
79+
def bezier2(self, x0, y0, x1, y1, x2, y2, color: Color):
80+
self._draw("bezier2", x0=x0, y0=y0, x1=x1, y1=y1, x2=x2, y2=y2, color=color)
81+
7882
def _draw(self, shape, **kwargs):
7983
assert self._token is not None
8084
self.conn.request("pane", self.name, shape, auth=self._token, **kwargs)

0 commit comments

Comments
 (0)