-
-
Notifications
You must be signed in to change notification settings - Fork 695
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
feat: add timeout
method for ui.notification
#4444
Conversation
4746bc3
to
e092d6d
Compare
Hi, @falkoschindler # notification.py
class ChangeType(Enum):
NoneChange = auto() # Make sure people don't provide values that are equal to it
class Notification(Element, component='notification.js'):
...
def reset(self,
message: Any = ChangeType.NoneChange,
position: Union[NotificationPosition, ChangeType] = ChangeType.NoneChange,
type: Union[NotificationType, ChangeType] = ChangeType.NoneChange,
timeout: Union[float, int, ChangeType] = ChangeType.NoneChange,) -> None: # For a demo,I only use some params.
self.props["options"]["message"] = str(message) if message != ChangeType.NoneChange else self.props["options"]["message"]
self.props["options"]["position"] = position if position != ChangeType.NoneChange else self.props["options"]["position"]
self.props["options"]["type"] = type if type != ChangeType.NoneChange else self.props["options"]["type"]
self.props["options"]["timeout"] = (timeout or 0)*1000 if timeout != ChangeType.NoneChange else self.props["options"]["timeout"]
self.update() Developers only need to call it like this. # test.py
import asyncio
from nicegui import ui
async def test_reset():
n = ui.notification("Test Notification",timeout=None,position="bottom-right",type="info")
n.on_dismiss(lambda:print("Notification Dismiss."))
await asyncio.sleep(3) # Do something
n.reset("Test Done",timeout=5,type="positive") # This is a new method
ui.button("Test").on_click(test_reset)
ui.run() n.reset("Test Done",timeout=5,type="positive")
# It is approximately equivalent to the following code.
n.message = "Test Done"
n.timeout = 5
n.type = "positive" I think this will be more convenient, can we expand on this? If you have any suggestions for improvements to this idea, please let me know, thank you very much. |
set_timeout
for ui.notification
timeout
method for ui.notification
ff18577
to
06b1a32
Compare
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.
Thanks for the pull request, @weinibuliu!
I cleaned it up a bit and now it's ready to merge.
Regarding a reset method: I'm a bit hesitant because we'll basically need to duplicate the signature and docstring of the initializer. But I guess it would be a useful feature nonetheless. Would you like to create a separate pull request?
Thank you very much for your cleanup and approval. |
I have created a new discussion on it. #4460 |
This PR is based on #4437 , which explores a way to make notifications dismiss after a certain period of time.
This PR provides a method called
timeout
that allows people to directly override the value of timeout (instead of manually modifying the value of the props)I did a simple test.It worked well.
That's all.
If you have any suggestions for changes to this PR, please let me know. Thanks a lot.