Utilities¶
panel_flowdash.util
¶
Shared helpers for the app shell and the embeddable editor.
notify(severity, message, *, duration=3000, enabled=True)
¶
Emit a Panel notification, falling back to the logger.
pn.state.notifications is None outside a served session (a plain
script, a test, or a notebook without the notifications extension), so
calling it unguarded raises. Embedders can also opt out entirely by passing
enabled=False.
page_dialog()
¶
Return the dialog shared by every component of the current session.
The dialog is created on first use and released with the session. It must
be laid out once to be visible: FlowDashApp places it in every page
layout and FlowDash in its workspace, so only code that builds its own page
around a FlowDash(include_page_dialog=False) needs to call this.
Returns None outside a served session, where there is no document to
own it.
open_dialog(title, content, *, width='sm', full_width=False)
¶
Show content in the session's page dialog, replacing whatever it shows.
The user can dismiss the dialog with its close button, the Escape key or a
click outside it. Use :func:close_dialog to dismiss it from code.
Outside a served session there is nowhere to show a dialog, so a warning is
logged and nothing happens, as with :func:notify.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
title
|
str
|
Heading of the dialog. |
required |
content
|
Any
|
Anything Panel can render. |
required |
width
|
str | bool
|
Maximum width of the dialog, one of |
'sm'
|
full_width
|
bool
|
Whether the dialog takes its whole maximum width rather than its content's. |
False
|
close_dialog()
¶
Close the session's page dialog. Does nothing when it is not open.
confirm(title, content=None, *, on_confirm, on_cancel=None, confirm_label='Confirm', cancel_label='Cancel', width='sm')
¶
Ask the user to confirm an action in the session's page dialog.
Opening the dialog never runs anything. Clicking Confirm closes the
dialog and then calls on_confirm(event); clicking Cancel closes it and
calls on_cancel(event) if one is given. Either handler may be a
coroutine function, which Panel schedules. Only the first click counts, so
a double click cannot run the action twice. A confirmation cannot be
dismissed with Escape or a click outside; if it closes without an answer
anyway, for example through :func:close_dialog, that counts as Cancel
and on_cancel is called with the change event of the dialog's open.
Replacing the dialog (another :func:open_dialog or :func:confirm) before
the user answers also counts as Cancel: on_cancel is called with
None once the replacement is shown, so a dialog it opens in turn replaces
that one. An exception it raises is logged rather than passed to the code
that replaced it.
Outside a served session a warning is logged and neither handler runs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
title
|
str
|
Heading of the dialog, usually the question. |
required |
content
|
Any
|
Anything Panel can render, such as a diff of what will change. |
None
|
on_confirm
|
Callable[[Any], Any]
|
Called with the click event after the dialog has closed. |
required |
on_cancel
|
Callable[[Any], Any] | None
|
Called with the click event after the dialog has closed, with the
|
None
|
confirm_label
|
str
|
Button labels. |
'Confirm'
|
cancel_label
|
str
|
Button labels. |
'Confirm'
|
width
|
str | bool
|
See :func: |
'sm'
|