Skip to content

Commit bd004f7

Browse files
committed
ADD doc strings
1 parent 27cad32 commit bd004f7

File tree

4 files changed

+89
-15
lines changed

4 files changed

+89
-15
lines changed

src/gh/components/DF_http_listener/code.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,21 @@ def RunScript(self,
3636
sc.sticky.setdefault(f'{prefix}_prev_load', False) # previous state of toggle
3737
sc.sticky.setdefault(f'{prefix}_thread_running', False) # is a background thread running?
3838

39-
def _import_job(url):
39+
def _import_job(url: str):
40+
4041
"""
42+
Downloads and imports a .ply file from a given URL in a background thread.
4143
Background job:
4244
- Downloads the .ply file from the URL
4345
- Imports it into the active Rhino document
4446
- Extracts the new geometry (point cloud or mesh)
4547
- Cleans up the temporary file and document objects
4648
- Updates sticky state and status message
4749
- Signals to GH that it should re-solve
50+
51+
:param url: A string representing a direct URL to a .ply file (e.g. from GitHub or local server).
52+
The file must end with ".ply".
53+
:returns: None
4854
"""
4955

5056
tmp = None

src/gh/components/DF_tcp_listener/code.py

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,13 @@ def RunScript(self,
4747
# Client handler
4848
def handle_client(conn):
4949
"""
50-
reads the incoming bytes from a single client socket and stores valid data in a shared buffer
50+
Reads the incoming bytes from a single TCP client socket and stores valid data in a shared buffer.
51+
52+
:param conn: A socket object returned by `accept()` representing a live client connection.
53+
The client is expected to send newline-delimited JSON-encoded data, where each
54+
message is a list of 6D values: [x, y, z, r, g, b].
55+
56+
:returns: None
5157
"""
5258
buf = b''
5359
with conn:
@@ -72,8 +78,12 @@ def handle_client(conn):
7278
# thread to accept incoming connections
7379
def server_loop(sock):
7480
"""
75-
runs in its own thread, continuously calling accept() on the listening socket
76-
Each time a client connects, it launches a new thread running handle_client to deal with that connection
81+
Accepts a single client connection and starts a background thread to handle it.
82+
83+
:param sock: A bound and listening TCP socket created by start_server().
84+
This socket will accept one incoming connection, then delegate it to handle_client().
85+
86+
:returns: None. This runs as a background thread and blocks on accept().
7787
"""
7888
try:
7989
conn, _ = sock.accept()
@@ -85,6 +95,8 @@ def server_loop(sock):
8595
def start_server():
8696
"""
8797
creates and binds a TCP socket on the given host/port, marks the server as started and then starts the accept_loop in a background thread
98+
99+
:returns: None.
88100
"""
89101
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
90102
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
@@ -97,6 +109,11 @@ def start_server():
97109
threading.Thread(target=server_loop, args=(sock,), daemon=True).start()
98110

99111
def stop_server():
112+
"""
113+
Stops the running TCP server by closing the listening socket and resetting internal state.
114+
115+
:returns: None.
116+
"""
100117
sock = sc.sticky.get(f'{prefix}_server_sock')
101118
if sock:
102119
try:

src/gh/components/DF_websocket_listener/code.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,16 @@ def RunScript(self,
6767
if i_start and not sc.sticky[f'{prefix}_thread_started']:
6868

6969
async def echo(ws, path):
70+
"""
71+
Handles a single WebSocket client connection and reads messages containing point cloud data.
72+
73+
:param ws: A WebSocket connection object from the 'websockets' server, representing a live client.
74+
:param path: The URL path for the connection (unused here but required by the API).
75+
76+
:returns: None. Updates sc.sticky['ws_last_pcd'] with the most recent valid list of points.
77+
Each message is expected to be a JSON list of 6-element lists:
78+
[x, y, z, r, g, b] for each point.
79+
"""
7080
logs.append("[GH] Client connected")
7181
try:
7282
async for msg in ws:
@@ -83,6 +93,12 @@ async def echo(ws, path):
8393
logs.append(f"Handler crashed: {outer}")
8494

8595
async def server_coro():
96+
"""
97+
Coroutine that starts the WebSocket server and waits for it to be closed.
98+
99+
:returns: None. Stores the server object in sc.sticky['ws_server'] and the event loop
100+
in sc.sticky['ws_loop']. Also logs progress to sc.sticky['ws_logs'].
101+
"""
86102
loop = asyncio.get_running_loop()
87103
sc.sticky[f'{prefix}_loop'] = loop
88104

@@ -94,6 +110,11 @@ async def server_coro():
94110
logs.append("Server coroutine exited")
95111

96112
def run_server():
113+
"""
114+
Blocking function that runs the WebSocket server coroutine in this thread.
115+
116+
:returns: None. Used as the target for a background thread. Logs errors if server startup fails.
117+
"""
97118
try:
98119
asyncio.run(server_coro())
99120
except Exception as ex:

src/gh/diffCheck/diffCheck/df_gh_canvas_utils.py

Lines changed: 41 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def add_str_valuelist(comp,
1111
indx: int,
1212
X_param_coord: float,
1313
Y_param_coord: float,
14-
X_offset: int=87
14+
X_offset: int = 87
1515
) -> None:
1616
"""
1717
Adds a value list of string values to the component input
@@ -53,7 +53,7 @@ def add_slider(comp,
5353
default_value: float,
5454
X_param_coord: float,
5555
Y_param_coord: float,
56-
X_offset: int=100
56+
X_offset: int = 100
5757
) -> None:
5858
"""
5959
Adds a slider to the component input
@@ -85,13 +85,13 @@ def add_slider(comp,
8585
inp.AddSource(slider) # noqa: F821
8686

8787

88-
def add_plane_object(comp,
89-
nickname: str,
90-
indx: int,
91-
X_param_coord: float,
92-
Y_param_coord: float,
93-
X_offset: int=75
94-
) -> None:
88+
def add_plane_object(comp,
89+
nickname: str,
90+
indx: int,
91+
X_param_coord: float,
92+
Y_param_coord: float,
93+
X_offset: int = 75
94+
) -> None:
9595
"""
9696
Adds a plane object to the component input
9797
@@ -117,7 +117,19 @@ def add_plane_object(comp,
117117
inp.AddSource(plane) # noqa: F821
118118

119119

120-
def add_button(comp, nickname, indx, x_offset=60):
120+
def add_button(comp,
121+
nickname: str,
122+
indx: int,
123+
x_offset: int = 60
124+
) -> None:
125+
"""
126+
Adds a one-shot Boolean button to the left of a component input.
127+
128+
:param comp: The Grasshopper component to which the button will be added.
129+
:param nickname: The display label of the button (e.g. "Start", "Load").
130+
:param indx: The index of the component input to wire the button into.
131+
:param x_offset: Horizontal distance (in pixels) to place the button to the left of the input.
132+
"""
121133

122134
inp = comp.Params.Input[indx]
123135
# only add if nothing already connected
@@ -143,7 +155,25 @@ def add_button(comp, nickname, indx, x_offset=60):
143155
inp.AddSource(btn)
144156

145157

146-
def add_panel(comp, nickname, text, indx, x_offset=60, panel_height=20):
158+
def add_panel(comp,
159+
nickname: str,
160+
text: str,
161+
indx: int,
162+
x_offset: int = 60,
163+
panel_height: int = 20
164+
) -> None:
165+
"""
166+
Adds a text panel to the left of a component input with a default string value.
167+
168+
:param comp: The Grasshopper component to which the panel will be added.
169+
:param nickname: The label shown at the top of the panel (e.g. "Host", "Port").
170+
:param text: The default string to display inside the panel.
171+
:param indx: The index of the component input to connect the panel to.
172+
:param x_offset: Horizontal distance (in pixels) to place the panel left of the input.
173+
:param panel_height: Height of the panel in pixels (default is 20).
174+
175+
:returns: None. The panel is created, positioned, and connected if no existing source is present.
176+
"""
147177

148178
inp = comp.Params.Input[indx]
149179
if inp.SourceCount == 0:

0 commit comments

Comments
 (0)