You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
## 0.4 - Refactoring, Bugfixes and adding new features
4
+
5
+
### Features
6
+
***Added method:** Added `Pyghthouse.wait` as a new feature to synchronize with the frame building. Commenly used to ensure building a frame with the previous call of `Pyghthouse.set_image`
7
+
***Added method:** Added `Pyghthouse.keep_running` as a new feature to keep the main thread alive. Useable to let callback functions run until keyboard interrupt
8
+
***Error handeling:**`PyghthouseCanvas.set_image` will now throw more useful errors upon invalid image object
9
+
10
+
### Changes
11
+
***start ... stop:**`Pyghthouse.stop` now does the same as `Pyghthouse.close`. For consistency, we recommend to use the start ... stop pattern for the Pyghthouse routine.
12
+
***main thread check:** The pyghthouse routine will now stop when the main thread has died. To keep the pyghthouse routine running, use `Pyghthouse.keep_running`
13
+
***Wait for start:**`Pyghthouse.start` will now wait until the start sequence is completed
14
+
15
+
### Removed
16
+
***Removed dependency:** numpy has been removed as dependency to simplify the image structure
17
+
***Redundant method:**`Pyghthouse.connect` was only intended for internal use and is now combined in `Pyghthouse.start`
18
+
***Redundant behaviour:** signal handler and corresponding method `Pyghthouse._handle_sigint` is now replaced by the main thread check in `PHThread`
19
+
***Unsupported method:**
20
+
+ removed `Pyghthouse.get_image_raw`
21
+
+ removed `Pyghthouse.empty_image_raw`
22
+
23
+
### Bugfixes
24
+
***Keyboard interrupt:** keyboard interrupt should now stop the whole program instead of only the main thread
25
+
***Missing warning:**`VerbosityLevel.ALL` now prints all messages, instead of only messages with number 200
26
+
***Error handeling:** upon error inside the library, the Pyghthouse routine will now close properly
27
+
***Fixed image mutations:** added locks for critical sections in `PyghthouseCanvas` to prevent rare image mutations.
28
+
***Fixed connection deadlock:** added timeout to avoid deadlocks upon unexpected connection behaviour
29
+
30
+
### Refactored
31
+
***Added documentation**
32
+
***Changed data structure:** Changed data structure of `PyghthouseCanvas` from a 3D numpy array to a 3D python list
33
+
***Better maintainability:** Changed overall code structure to allow easier access to single code pieces
34
+
***Changed internal package structure:**
35
+
+ moved `PHThread` to the new script `_thread.py`
36
+
+ moved `PHMessageHandler` into the new script `handler.py`
37
+
+ moved `REID` into the new script `data.py` and renamed from `REID` to `ReID`
38
+
+ moved `VerbosityLevel` into the new script `data.py`
Copy file name to clipboardExpand all lines: examples/README.md
+82-24Lines changed: 82 additions & 24 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,36 +9,94 @@ Some scripts have additional dependencies; Check `README.md` in the repository r
9
9
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.
10
10
Be aware that API tokens are only valid for a few days.
11
11
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.
15
12
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.
19
13
20
-
### Available functions
21
-
Here you can find a list of functions containing in this package.
14
+
## Ways of programming a pyghthouse script
22
15
23
-
`from_html(html_color)`
24
-
Converts an HTML color string like FF7F00 or #c0ffee to RGB
25
16
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:
28
18
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)`
33
20
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()`
37
22
38
-
`<instance name>.set_image(image)`
39
-
Sends the given `image`.
40
23
41
-
`<instance name>.close()`
42
-
Closes the connection.
24
+
### Programming with callback
43
25
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
0 commit comments