Skip to content

Commit

Permalink
FIX client auto-connect
Browse files Browse the repository at this point in the history
* FIX background colors set
  • Loading branch information
rlahmidi committed Apr 2, 2024
1 parent 138f012 commit 3525e1c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
16 changes: 9 additions & 7 deletions pytvpaint/george/client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,21 @@ def _connect_client(
) -> JSONRPCClient:
host = os.getenv("PYTVPAINT_WS_HOST", host)
port = int(os.getenv("PYTVPAINT_WS_PORT", port))
startup_connect = bool(os.getenv("PYTVPAINT_WS_STARTUP_CONNECT", 1))
startup_connect = bool(int(os.getenv("PYTVPAINT_WS_STARTUP_CONNECT", 1)))
timeout = int(os.getenv("PYTVPAINT_WS_TIMEOUT", timeout))

if timeout == 0:
timeout = -1

rpc_client = JSONRPCClient(f"{host}:{port}", timeout)

if not startup_connect:
return rpc_client

start_time = time()
wait_duration = 5
connection_successful = False

while startup_connect and ((time() - start_time) < timeout):
while True:
if timeout and (time() - start_time) > timeout:
break
with contextlib.suppress(ConnectionRefusedError):
rpc_client.connect()
connection_successful = True
Expand All @@ -45,7 +47,7 @@ def _connect_client(
log.warning(f"Connection refused, trying again in {wait_duration} seconds...")
sleep(wait_duration)

if startup_connect and not connection_successful:
if not connection_successful:
# Connection could not be established after timeout
if rpc_client.is_connected:
rpc_client.disconnect()
Expand All @@ -54,7 +56,7 @@ def _connect_client(
"Could not establish connection with a tvpaint instance before timeout !"
)

if startup_connect and connection_successful:
if connection_successful:
log.info(f"Connected to TVPaint on port {port}")

return rpc_client
Expand Down
7 changes: 6 additions & 1 deletion pytvpaint/george/grg_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,12 @@ def tv_background_set(
mode: BackgroundMode,
color: tuple[RGBColor, RGBColor] | RGBColor | None = None,
) -> None:
"""Set the background mode of the project."""
"""Set the background mode of the project.
Args:
mode: color mode (None, checker or one color)
color: None for None mode, RBGColor for one color, and tuple of RGBColors for checker
"""
args = []

if mode == BackgroundMode.CHECK and isinstance(color, tuple):
Expand Down
3 changes: 1 addition & 2 deletions pytvpaint/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,8 +266,7 @@ def background_colors(
self,
colors: tuple[george.RGBColor, george.RGBColor] | george.RGBColor,
) -> None:
colors_args = colors if isinstance(colors, tuple) else [colors]
george.tv_background_set(self.background_mode, *colors_args)
george.tv_background_set(self.background_mode, colors)

@set_as_current
def clear_background(self) -> None:
Expand Down

0 comments on commit 3525e1c

Please sign in to comment.