-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpython_example.py
More file actions
69 lines (46 loc) · 1.8 KB
/
python_example.py
File metadata and controls
69 lines (46 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/usr/bin/env python3
"""
python_example.py
=================
Description: Python overlay test/example script
Author: Michael De Pasquale
Creation Date: 2025-05-14
Modification Date: 2025-05-23
"""
# Usage: Before running, build the python interface with 'make python'.
# This will build overlay.so and copy it to the current directory.
import signal
import sys
import time
import overlay
# pylint: disable=c-extension-no-member,invalid-name
def sigintHandler(signal, frame) -> None:
print("Got SIGINT, cleaning up and exiting..")
overlay.cleanup()
sys.exit(0)
def main(*args) -> None:
signal.signal(signal.SIGINT, sigintHandler)
overlay.init()
width, height = overlay.getWidth(), overlay.getHeight()
print(f"Created overlay window with dimensions {width}x{height}")
# Set target window, if provided
if len(args) > 1:
assert len(args) == 2
targetWin = int(args[1], base=0)
targetWidth, targetHeight = overlay.setTargetWindow(targetWin)
print(f"Set target: Window {targetWin}, {targetWidth}x{targetHeight}")
width, height = targetWidth, targetHeight
while 1:
overlay.clear()
# Draw X to indicate bounds
overlay.addLine(0, 0, width, height, 1, 0.5, 0.5, 1.0, 4.0)
overlay.addLine(0, height, width, 0, 1, 0.5, 0.5, 1.0, 4.0)
overlay.addText("TEST", 10, 10, 32, 1, 0.25, 0.25, 1, False)
overlay.addRectangle(128, 128, 256, 256, 0, 0.8, 0.2, 0.8, True, 1)
overlay.addCircle(96, 96, 32, 0, 1, 1, 1, False, 4)
# FIXME: This doesn't draw anything?
overlay.addTriangle(64, 64, 96, 96, 128, 128, 0.2, 0.2, 1, 1, False, 4)
overlay.draw()
time.sleep(0.005)
if __name__ == "__main__":
sys.exit(main(*sys.argv))