-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Feature: #2471 notification on_close #2519
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
c61032e
abb750b
ac90ebf
82f6b2a
8e43a35
fafffd8
5dfa8b7
6641a07
4a3d8a1
7d0355d
5e24ea1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -96,3 +96,6 @@ demo[_|-]*/ | |
data_sources | ||
pipelines | ||
pickles | ||
|
||
build.sh | ||
.frontend/taipy-gui/dom/package-lock.json |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
from taipy.gui import Gui, notify | ||
|
||
# Function to trigger a notification | ||
def send_notification(state): | ||
notify(state, "warning", "This is a test notification!", None, None, "3", on_notification_closed) | ||
|
||
# Function triggered when a notification is closed (from frontend) | ||
def on_notification_closed(state, notification_id, reason=None): | ||
print("Notification closed from frontend") | ||
print(f"Notification {notification_id} closed from frontend. Reason: {reason}") | ||
|
||
# GUI page setup | ||
page = """ | ||
# Notification Demo | ||
|
||
Click the button to trigger a notification: | ||
|
||
<|button|text=Send Notification|on_action=send_notification|> | ||
""" | ||
|
||
if __name__ == "__main__": | ||
Gui(page).run() |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1457,14 +1457,16 @@ def __send_ws_download(self, content: str, name: str, on_action: str, module: st | |
) | ||
|
||
def __send_ws_notification( | ||
self, type: str, message: str, system_notification: bool, duration: int, notification_id: t.Optional[str] = None | ||
self, type: str, message: str, system_notification: bool, duration: int, notification_id: t.Optional[str] = None, reason: t.Optional[str] = None, on_close_str: t.Optional[str] = None | ||
) -> None: | ||
payload = { | ||
"type": _WsType.ALERT.value, | ||
"nType": type, | ||
"message": message, | ||
"system": system_notification, | ||
"duration": duration, | ||
"reason": reason, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. and there too (on_close_str) |
||
"onClose": on_close_str, | ||
} | ||
|
||
if notification_id: | ||
|
@@ -2402,27 +2404,49 @@ def _download(self, content: t.Any, name: t.Optional[str] = "", on_action: t.Uni | |
self.__send_ws_download( | ||
content_str, str(name), str(on_action) if on_action is not None else "", self._get_locals_context() | ||
) | ||
|
||
def _notify( | ||
self, | ||
notification_type: str = "I", | ||
message: str = "", | ||
system_notification: t.Optional[bool] = None, | ||
duration: t.Optional[int] = None, | ||
notification_id: t.Optional[str] = None, | ||
): | ||
on_close: t.Optional[t.Union[str, t.Callable[[State, str, str], None]]] = "", | ||
): | ||
on_close_str = None | ||
|
||
if notification_id and on_close: | ||
if isinstance(on_close, str): | ||
FredLL-Avaiga marked this conversation as resolved.
Show resolved
Hide resolved
|
||
func = self._get_user_function(on_close) | ||
if callable(func): | ||
on_close_str = on_close | ||
else: | ||
_warn(f"Notification on_close callback '{on_close}' is not a valid function.") | ||
|
||
elif _is_function(on_close): | ||
on_close_str = on_close.__name__ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. lambda functions are not handled |
||
func = self._get_user_function(on_close_str) | ||
if not callable(func): | ||
_warn(f"Function '{on_close_str}' from on_close callable is not valid.") | ||
else: | ||
_warn(f"Invalid on_close value for notification {notification_id}: {on_close}") | ||
|
||
self.__send_ws_notification( | ||
notification_type, | ||
message, | ||
self._get_config("system_notification", False) if system_notification is None else system_notification, | ||
self._get_config("notification_duration", 3000) if duration is None else duration, | ||
notification_id, | ||
reason= None, | ||
on_close_str= on_close_str, | ||
) | ||
return notification_id | ||
|
||
def _close_notification( | ||
self, | ||
notification_id: str, | ||
reason: t.Optional[str] = "user_action", | ||
): | ||
if notification_id: | ||
self.__send_ws_notification( | ||
|
@@ -2431,6 +2455,8 @@ def _close_notification( | |
system_notification=False, # System notification not needed for closing | ||
duration=0, # No duration since it's an immediate close | ||
notification_id=notification_id, | ||
reason=reason, | ||
on_close_str=None, # No need for on_close callback when closing | ||
) | ||
|
||
def _hold_actions( | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you're only testing the
createSendActionNAmeAction
here ?