notify.py 945 B

1234567891011121314151617181920212223242526
  1. import justpy as jp
  2. from ..task_logger import create_task
  3. from .element import Element
  4. class Notify(Element):
  5. def __init__(self, message: str, *, position: str = 'bottom', close_button: str = None):
  6. """Notification
  7. Displays a notification on the screen.
  8. :param message: content of the notification
  9. :param position: position on the screen ("top-left", "top-right", "bottom-left","bottom-right, "top", "bottom", "left", "right" or "center", default: "bottom")
  10. :param close_button: optional label of a button to dismiss the notification (default: `None`)
  11. """
  12. view = jp.QNotify(message=message, position=position, closeBtn=close_button, temp=False)
  13. super().__init__(view)
  14. create_task(self.notify_async(), name='notify_async')
  15. async def notify_async(self):
  16. self.view.notify = True
  17. await self.parent_view.update()
  18. self.view.notify = False