notify.py 998 B

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