فهرست منبع

add hint about new API

Falko Schindler 1 سال پیش
والد
کامیت
10d4b853be
2فایلهای تغییر یافته به همراه26 افزوده شده و 2 حذف شده
  1. 12 1
      nicegui/client.py
  2. 14 1
      nicegui/functions/javascript.py

+ 12 - 1
nicegui/client.py

@@ -126,12 +126,23 @@ class Client:
             await asyncio.sleep(check_interval)
             await asyncio.sleep(check_interval)
         self.is_waiting_for_disconnect = False
         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.
         """Execute JavaScript on the client.
 
 
         The client connection must be established before this method is called.
         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(...)`.
         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())
         request_id = str(uuid.uuid4())
         target_id = globals._socket_id or self.id  # pylint: disable=protected-access
         target_id = globals._socket_id or self.id  # pylint: disable=protected-access
 
 

+ 14 - 1
nicegui/functions/javascript.py

@@ -1,8 +1,12 @@
+from typing import Optional
+
 from .. import globals  # pylint: disable=redefined-builtin
 from .. import globals  # pylint: disable=redefined-builtin
 from ..awaitable_response import AwaitableResponse
 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
     """Run JavaScript
 
 
     This function runs arbitrary JavaScript code on a page that is executed in the browser.
     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`
     :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()
     client = globals.get_client()
     if not client.has_socket_connection:
     if not client.has_socket_connection:
         raise RuntimeError('Cannot run JavaScript before client is connected; '
         raise RuntimeError('Cannot run JavaScript before client is connected; '