open.py 711 B

123456789101112131415161718
  1. from typing import Any, Callable, Union
  2. from .. import globals
  3. def open(target: Union[Callable[..., Any], str], new_tab: bool = False) -> None:
  4. """Open
  5. Can be used to programmatically trigger redirects for a specific client.
  6. Note that *all* clients (i.e. browsers) connected to the page will open the target URL *unless* a socket is specified.
  7. User events like button clicks provide such a socket.
  8. :param target: page function or string that is a an absolute URL or relative path from base URL
  9. :param new_tab: whether to open the target in a new tab
  10. """
  11. path = target if isinstance(target, str) else globals.page_routes[target]
  12. globals.get_client().open(path, new_tab)