Skip to content

Commit 8b339b5

Browse files
committed
Adjusted examples README for easier project overview
1 parent 27592df commit 8b339b5

1 file changed

Lines changed: 82 additions & 24 deletions

File tree

examples/README.md

Lines changed: 82 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -9,36 +9,94 @@ Some scripts have additional dependencies; Check `README.md` in the repository r
99
If you set up config.py with your username and API token, you won't have to enter them every time you run a script.
1010
Be aware that API tokens are only valid for a few days.
1111

12-
##### Beware:
13-
Python imports search for the modules in the current folder and in installed packages. So, if you haven't installed
14-
pyghthouse as a package, you need to change the imports of the files in this folder to work.
1512

16-
In the repository root directory should be a file called `example.py`. This file shows the usage of imports of
17-
pyghthouse without having it installed as a package.
18-
Note: To use the imports the same way as `example.py`, your skript has to be in the same folder.
1913

20-
### Available functions
21-
Here you can find a list of functions containing in this package.
14+
## Ways of programming a pyghthouse script
2215

23-
`from_html(html_color)`
24-
Converts an HTML color string like FF7F00 or #c0ffee to RGB
2516

26-
`from_hsv(h: float, s: float, v: float)`
27-
Converts HSV (float values between 0 and 1) colors to RGB.
17+
The Pyghthouse library has two intended ways of usage:
2818

29-
###### The class `Pyghthouse` with
30-
`Pyghthouse(username: str, token: str, ...)`
31-
Set up the `Pyghthouse` object. Needed arguments are `username` and `token`. Optional arguments and further explanation
32-
can be found in the class definition (see `pyghthouse\ph.py`)
19+
- Passing a callback function at creation with `Pyghthouse(..., callback=function)` or with the method `Pyghthouse.set_image_callback(callback)`
3320

34-
`Pyghthouse.empty_image()`
35-
Creates a black image.
36-
This function can also be called with an instance of the `Pyghthouse` object (*`<instance name>.empty_image()`*)
21+
- Setting the currently shown canvas with `Pyghthouse.set_image()`
3722

38-
`<instance name>.set_image(image)`
39-
Sends the given `image`.
4023

41-
`<instance name>.close()`
42-
Closes the connection.
24+
### Programming with callback
4325

44-
*More functions can be found in `pyghthouse\ph.py`*
26+
The following examples uses callback functions:
27+
28+
- `huecircle.py`
29+
- `noisefill.py`
30+
- `rainbow.py`
31+
- `rgbfill.py`
32+
- `rgbscan.py`
33+
- `twopoints.py`
34+
35+
In summary, we first need a callback function to create images when called. After that, we initialize the pyghthouse routine.
36+
37+
When we now start the pyghthouse routine, images will be generated by the given callback function. Generated images are then send to the server. This will happen in an interval given by the frame_rate.
38+
39+
The pyghthouse routine is now running asynchronous to the main script.
40+
41+
**Important to notice** is, that the pyghthouse routine will end when the main script ends. To let a pyghthouse routine run forever (until error or keyboard interrupt), the `keep_running()` method can be used.
42+
43+
44+
### Programming with set_image
45+
46+
The following examples use `set_image`:
47+
48+
- `movingdot.py`
49+
- `whitefill.py`
50+
51+
Compared to the callback function, `set_image` is a lot simpler.
52+
53+
We again need to initialize and start the pyghthouse routine. After that, we only need to call `set_image(new_image)` to send images to the server.
54+
55+
**Important to notice** is, that `set_image`does not wait until the image is send. This means that we can overwrite the currently set image by setting a new one without waiting for the send. So to ensure important frames to be send, we recommend to use the method `wait()`.
56+
57+
58+
59+
## Pyghthouse package content
60+
61+
62+
### The class `pyghthouse.Pyghthouse` with
63+
64+
- `Pyghthouse(username: str, token: str, ...)`:
65+
66+
Set up the `Pyghthouse` object. Needed arguments are `username` and `token`. Optional arguments, like `frame_rate` and further explanations can be found in the class definition (see `pyghthouse\ph.py`)
67+
68+
69+
- `Pyghthouse.start()`
70+
71+
Starts the pyghthouse routine and opens the websocket connection.
72+
73+
74+
- `Pyghthouse.stop()`
75+
76+
Stops the pyghthouse routine and closes the websocket connection.
77+
78+
79+
- `Pyghthouse.empty_image()`
80+
81+
A static method which creates a black image.
82+
This function can also be called with an instance of the `Pyghthouse` object (*`<instance name>.empty_image()`*)
83+
84+
85+
- `Pyghthouse.set_image(image)`
86+
87+
Set the Pyghthouse canvas to `image`. Every `1/frame_rate` seconds, the last image set is send by the pyghthouse routine.
88+
89+
90+
*More functions can be found in `pyghthouse\ph.py`*
91+
92+
93+
### Utils functions
94+
Here are additional functions in the pyghthouse package.
95+
96+
- `pyghthouse.utils.from_html(html_color)`:
97+
98+
Converts an HTML color string like FF7F00 or #c0ffee to RGB
99+
100+
- `pyghthouse.utils.from_hsv(h: float, s: float, v: float)`:
101+
102+
Converts HSV (float values between 0 and 1) colors to RGB.

0 commit comments

Comments
 (0)