瀏覽代碼

Change demo to a example external request, removed fairly useless return types

Brian Landry 1 年之前
父節點
當前提交
52b6159835
共有 1 個文件被更改,包括 8 次插入7 次删除
  1. 8 7
      website/more_documentation/button_documentation.py

+ 8 - 7
website/more_documentation/button_documentation.py

@@ -36,23 +36,24 @@ def more() -> None:
             ui.label('Three')
             ui.label('Three')
 
 
     @text_demo('Disable button with a context manager', '''
     @text_demo('Disable button with a context manager', '''
-        This showcases a async context manager that can be used to disable a button for the duration of an async process.
+        This showcases a context manager that can be used to disable a button for the duration of an async process.
     ''')
     ''')
     async def disable_context_manager() -> None:
     async def disable_context_manager() -> None:
-        from asyncio import sleep
         from contextlib import contextmanager
         from contextlib import contextmanager
-        from typing import Awaitable, ContextManager
+        import httpx
 
 
         @contextmanager
         @contextmanager
-        def disable(element: DisableableElement) -> ContextManager[None]:
+        def disable(element: DisableableElement):
             element.disable()
             element.disable()
             try:
             try:
                 yield
                 yield
             finally:
             finally:
                 element.enable()
                 element.enable()
 
 
-        async def disable_and_sleep_3(button: ui.button) -> Awaitable[None]:
+        async def get_slow_response(button: ui.button):
             with disable(button):
             with disable(button):
-                await sleep(3)
+                async with httpx.AsyncClient() as client:
+                    response = await client.get('https://httpbin.org/delay/3', timeout=5)
+                    ui.notify(f"Response code: {response.status_code}")
 
 
-        ui.button("Disable for 3 seconds", on_click=lambda e: disable_and_sleep_3(e.sender))
+        ui.button("Get slow response", on_click=lambda e: get_slow_response(e.sender))