MCPcopy Index your code
hub / github.com/pywebio/PyWebIO / toast

Function toast

pywebio/output.py:2055–2093  ·  view source on GitHub ↗

Show a notification message. :param str content: Notification content. :param float duration: The duration of the notification display, in seconds. `0` means not to close automatically (at this time, a close button will be displayed next to the message, and the user can close the me

(content: str, duration: float = 2, position: str = 'center', color: str = 'info',
          onclick: Callable[[], None] = None)

Source from the content-addressed store, hash-verified

2053
2054
2055def toast(content: str, duration: float = 2, position: str = 'center', color: str = 'info',
2056 onclick: Callable[[], None] = None):
2057 """Show a notification message.
2058
2059 :param str content: Notification content.
2060 :param float duration: The duration of the notification display, in seconds. `0` means not to close automatically
2061 (at this time, a close button will be displayed next to the message, and the user can close the message manually)
2062 :param str position: Where to display the notification message. Available values are `'left'`, `'center'` and `'right'`.
2063 :param str color: Background color of the notification.
2064 Available values are `'info'`, `'error'`, `'warn'`, `'success'` or hexadecimal color value starting with `'#'`
2065 :param callable onclick: The callback function when the notification message is clicked.
2066 The callback function receives no parameters.
2067
2068 Note: When in :ref:`Coroutine-based session <coroutine_based_session>`, the callback can be a coroutine function.
2069
2070 Example:
2071
2072 .. exportable-codeblock::
2073 :name: toast
2074 :summary: `toast()` usage
2075
2076 def show_msg():
2077 put_text("You clicked the notification.")
2078
2079 toast('New messages', position='right', color='#2188ff', duration=0, onclick=show_msg)
2080
2081 """
2082
2083 colors = {
2084 'info': '#1565c0',
2085 'error': '#e53935',
2086 'warn': '#ef6c00',
2087 'success': '#2e7d32'
2088 }
2089 color = colors.get(color, color)
2090 callback_id = output_register_callback(lambda _: onclick()) if onclick is not None else None
2091
2092 send_msg(cmd='toast', spec=dict(content=content, duration=int(duration * 1000), position=position,
2093 color=color, callback_id=callback_id))
2094
2095
2096clear_scope = clear

Callers 13

targetFunction · 0.85
basic_outputFunction · 0.85
reset_openai_configFunction · 0.85
on_key_pressFunction · 0.85
output_widgetsFunction · 0.85
mainFunction · 0.85
mainFunction · 0.85
mainFunction · 0.85
run_codeFunction · 0.85
copytoclipboardFunction · 0.85
set_stoneFunction · 0.85
on_task_exceptionMethod · 0.85

Calls 3

output_register_callbackFunction · 0.85
send_msgFunction · 0.85
getMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…