From 10d4b853be0e46ae78738d8753a97514bddd95a2 Mon Sep 17 00:00:00 2001 From: Falko Schindler Date: Thu, 19 Oct 2023 16:58:50 +0200 Subject: [PATCH] add hint about new API --- nicegui/client.py | 13 ++++++++++++- nicegui/functions/javascript.py | 15 ++++++++++++++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/nicegui/client.py b/nicegui/client.py index fa75b6739..a94333164 100644 --- a/nicegui/client.py +++ b/nicegui/client.py @@ -126,12 +126,23 @@ async def disconnected(self, check_interval: float = 0.1) -> None: await asyncio.sleep(check_interval) self.is_waiting_for_disconnect = False - def run_javascript(self, code: str, *, timeout: float = 1.0, check_interval: float = 0.01) -> AwaitableResponse: + def run_javascript(self, code: str, *, + respond: Optional[bool] = None, # DEPRECATED + timeout: float = 1.0, check_interval: float = 0.01) -> AwaitableResponse: """Execute JavaScript on the client. The client connection must be established before this method is called. You can do this by `await client.connected()` or register a callback with `client.on_connect(...)`. """ + if respond is True: + globals.log.warning('The "respond" argument of run_javascript() has been removed. ' + 'Now the method always returns an AwaitableResponse that can be awaited. ' + 'Please remove the "respond=True" argument.') + if respond is False: + raise ValueError('The "respond" argument of run_javascript() has been removed. ' + 'Now the method always returns an AwaitableResponse that can be awaited. ' + 'Please remove the "respond=False" argument and call the method without awaiting.') + request_id = str(uuid.uuid4()) target_id = globals._socket_id or self.id # pylint: disable=protected-access diff --git a/nicegui/functions/javascript.py b/nicegui/functions/javascript.py index c0f058c20..09f215b0f 100644 --- a/nicegui/functions/javascript.py +++ b/nicegui/functions/javascript.py @@ -1,8 +1,12 @@ +from typing import Optional + from .. import globals # pylint: disable=redefined-builtin from ..awaitable_response import AwaitableResponse -def run_javascript(code: str, *, timeout: float = 1.0, check_interval: float = 0.01) -> AwaitableResponse: +def run_javascript(code: str, *, + respond: Optional[bool] = None, # DEPRECATED + timeout: float = 1.0, check_interval: float = 0.01) -> AwaitableResponse: """Run JavaScript This function runs arbitrary JavaScript code on a page that is executed in the browser. @@ -16,6 +20,15 @@ def run_javascript(code: str, *, timeout: float = 1.0, check_interval: float = 0 :return: response from the browser, or `None` if `respond` is `False` """ + if respond is True: + globals.log.warning('The "respond" argument of run_javascript() has been removed. ' + 'Now the function always returns an AwaitableResponse that can be awaited. ' + 'Please remove the "respond=True" argument.') + if respond is False: + raise ValueError('The "respond" argument of run_javascript() has been removed. ' + 'Now the function always returns an AwaitableResponse that can be awaited. ' + 'Please remove the "respond=False" argument and call the function without awaiting.') + client = globals.get_client() if not client.has_socket_connection: raise RuntimeError('Cannot run JavaScript before client is connected; '